Пример #1
0
  public void testBroadcast() {
    Sprite sprite = new SingleSprite("testSprite");
    Script script = new StartScript();
    String message = "simpleTest";
    BroadcastBrick broadcastBrick = new BroadcastBrick(message);
    script.addBrick(broadcastBrick);
    sprite.addScript(script);

    BroadcastScript broadcastScript = new BroadcastScript(message);
    int testPosition = 100;
    SetXBrick testBrick = new SetXBrick(testPosition);
    broadcastScript.addBrick(testBrick);
    sprite.addScript(broadcastScript);

    Project project = new Project(getContext(), UiTestUtils.DEFAULT_TEST_PROJECT_NAME);
    Scene scene = project.getDefaultScene();
    scene.addSprite(sprite);
    ProjectManager.getInstance().setProject(project);

    sprite.createStartScriptActionSequenceAndPutToMap(new HashMap<String, List<String>>());

    while (!allActionsOfAllSpritesAreFinished()) {
      for (Sprite spriteOfList : ProjectManager.getInstance().getCurrentScene().getSpriteList()) {
        spriteOfList.look.act(1.0f);
      }
    }

    assertEquals(
        "Simple broadcast failed",
        testPosition,
        (int) sprite.look.getXInUserInterfaceDimensionUnit());
  }
Пример #2
0
  public void testBehaviourWithoutBricks() {
    Project project = ProjectManager.getInstance().getCurrentProject();
    assertNotNull("current project was null", project);

    Sprite blueSprite = project.getSpriteList().get(4);
    while (blueSprite.getNumberOfScripts() > 0) {
      blueSprite.removeScript(blueSprite.getScript(0));
    }

    assertEquals("there shouldn't be any script left", 0, blueSprite.getNumberOfScripts());
    assertEquals("there shouldn't be any script left", 0, blueSprite.getNumberOfBricks());
    StorageHandler.getInstance().loadProject(project.getName());

    solo.waitForActivity(StageActivity.class.getSimpleName());
    solo.sleep(1400);

    byte[] screenArray = StageActivity.stageListener.getPixels(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    UiTestUtils.comparePixelArrayWithPixelScreenArray(
        BLUE_PIXEL, screenArray, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    UiTestUtils.comparePixelArrayWithPixelScreenArray(
        BLUE_PIXEL, screenArray, -19, -19, SCREEN_WIDTH, SCREEN_HEIGHT);
    UiTestUtils.comparePixelArrayWithPixelScreenArray(
        BLUE_PIXEL, screenArray, -19, 19, SCREEN_WIDTH, SCREEN_HEIGHT);
    UiTestUtils.comparePixelArrayWithPixelScreenArray(
        BLUE_PIXEL, screenArray, 19, -19, SCREEN_WIDTH, SCREEN_HEIGHT);
    UiTestUtils.comparePixelArrayWithPixelScreenArray(
        BLUE_PIXEL, screenArray, 19, 19, SCREEN_WIDTH, SCREEN_HEIGHT);

    solo.sleep(2000);
  }
Пример #3
0
  private void createTestProject(String projectName) {
    double size = 0.8;

    Project project = new Project(null, projectName);
    Sprite firstSprite = new Sprite("cat");

    Script testScript = new StartScript();

    brickListToCheck = new ArrayList<Brick>();
    brickListToCheck.add(new HideBrick());
    brickListToCheck.add(new ShowBrick());
    brickListToCheck.add(new SetSizeToBrick(size));

    for (Brick brick : brickListToCheck) {
      testScript.addBrick(brick);
    }

    firstSprite.addScript(testScript);

    project.addSprite(firstSprite);

    ProjectManager.getInstance().setProject(project);
    ProjectManager.getInstance().setCurrentSprite(firstSprite);
    ProjectManager.getInstance().setCurrentScript(testScript);
  }
Пример #4
0
  @Override
  public Sprite clone() {
    final Sprite cloneSprite = new Sprite();

    cloneSprite.setName(this.getName());
    cloneSprite.isBackpackObject = false;

    Project currentProject = ProjectManager.getInstance().getCurrentProject();
    if (currentProject == null || !currentProject.getSpriteList().contains(this)) {
      throw new RuntimeException("The sprite must be in the current project before cloning it.");
    }

    Sprite originalSprite = ProjectManager.getInstance().getCurrentSprite();
    ProjectManager.getInstance().setCurrentSprite(cloneSprite);

    cloneSpriteVariables(currentProject, cloneSprite);
    cloneLooks(cloneSprite);
    cloneSounds(cloneSprite);
    cloneUserBricks(cloneSprite);
    cloneNfcTags(cloneSprite);
    cloneScripts(cloneSprite);

    setUserAndVariableBrickReferences(cloneSprite, userBricks);

    ProjectManager.getInstance().checkCurrentSprite(cloneSprite, false);
    ProjectManager.getInstance().setCurrentSprite(originalSprite);

    return cloneSprite;
  }
Пример #5
0
  public void testBroadcastWait() {
    Sprite sprite = new Sprite("spriteOne");
    Script scriptWait = new StartScript(sprite);
    String message = "waitTest";
    BroadcastWaitBrick broadcastWaitBrick = new BroadcastWaitBrick(sprite, message);
    int testPosition = 100;
    SetXBrick setXBrick = new SetXBrick(sprite, testPosition);
    scriptWait.addBrick(broadcastWaitBrick);
    scriptWait.addBrick(setXBrick);
    sprite.addScript(scriptWait);

    BroadcastScript broadcastScript = new BroadcastScript(sprite, message);
    WaitBrick waitBrick = new WaitBrick(sprite, 500);
    int setTestPosition = 20;
    SetXBrick setXBrick2 = new SetXBrick(sprite, setTestPosition);
    broadcastScript.addBrick(waitBrick);
    broadcastScript.addBrick(setXBrick2);
    sprite.addScript(broadcastScript);

    Project project = new Project(getContext(), "testProject");
    project.addSprite(sprite);
    ProjectManager.getInstance().setProject(project);

    sprite.createStartScriptActionSequence();

    while (!sprite.look.getAllActionsAreFinished()) {
      sprite.look.act(1.0f);
    }

    assertEquals(
        "Broadcast and wait failed",
        testPosition,
        (int) sprite.look.getXInUserInterfaceDimensionUnit());
  }
  public void testBoundaries() {
    Project project = new Project(getContext(), "testProject");
    Group parentGroup = new Group();

    Sprite firstSprite = new Sprite("firstSprite");
    parentGroup.addActor(firstSprite.look);
    project.addSprite(firstSprite);

    for (int i = 0; i < 10; i++) {
      Sprite sprite = new Sprite("testSprite" + i);
      parentGroup.addActor(sprite.look);
      sprite.look.setZIndex(Integer.MAX_VALUE);
      project.addSprite(sprite);
    }

    ProjectManager.getInstance().setProject(project);

    ComeToFrontAction action = ExtendedActions.comeToFront(firstSprite);
    firstSprite.look.addAction(action);
    action.act(1.0f);

    assertEquals(
        "An Integer overflow occured during ComeToFrontBrick Execution",
        getZMaxValue(firstSprite),
        firstSprite.look.getZIndex());
  }
Пример #7
0
 @Override
 public ChangeVariableBrick copyBrickForSprite(Sprite sprite) {
   Project currentProject = ProjectManager.getInstance().getCurrentProject();
   ChangeVariableBrick copyBrick = clone();
   copyBrick.userVariable =
       currentProject.getDataContainer().getUserVariable(userVariable.getName(), sprite);
   return copyBrick;
 }
  private void createProject() {
    Project project = new Project(null, UiTestUtils.PROJECTNAME1);

    Sprite spriteCat = new Sprite(backgroundName);
    Script startScriptCat = new StartScript();
    Script scriptTappedCat = new WhenScript();
    Brick setXBrick = new SetXBrick(50);
    Brick setYBrick = new SetYBrick(50);
    Brick changeXBrick = new ChangeXByNBrick(50);
    startScriptCat.addBrick(setYBrick);
    startScriptCat.addBrick(setXBrick);
    scriptTappedCat.addBrick(changeXBrick);

    spriteCat.addScript(startScriptCat);
    spriteCat.addScript(scriptTappedCat);
    project.addSprite(spriteCat);

    ProjectManager.getInstance().setProject(project);
    ProjectManager.getInstance().setCurrentSprite(spriteCat);
    ProjectManager.getInstance().setCurrentScript(startScriptCat);

    File imageFile =
        UiTestUtils.saveFileToProject(
            project.getName(),
            "catroid_sunglasses.png",
            org.catrobat.catroid.test.R.drawable.catroid_sunglasses,
            getInstrumentation().getContext(),
            UiTestUtils.FileTypes.IMAGE);

    ProjectManager projectManager = ProjectManager.getInstance();
    List<LookData> lookDataList = projectManager.getCurrentSprite().getLookDataList();
    LookData lookData = new LookData();
    lookData.setLookFilename(imageFile.getName());
    lookData.setLookName("Catroid sun");
    lookDataList.add(lookData);
    projectManager
        .getFileChecksumContainer()
        .addChecksum(lookData.getChecksum(), lookData.getAbsolutePath());

    File soundFile =
        UiTestUtils.saveFileToProject(
            project.getName(),
            "longsound.mp3",
            org.catrobat.catroid.test.R.raw.longsound,
            getInstrumentation().getContext(),
            UiTestUtils.FileTypes.SOUND);
    SoundInfo soundInfo = new SoundInfo();
    soundInfo.setSoundFileName(soundFile.getName());
    soundInfo.setTitle("longsound");

    List<SoundInfo> soundInfoList = ProjectManager.getInstance().getCurrentSprite().getSoundList();
    soundInfoList.add(soundInfo);
    ProjectManager.getInstance()
        .getFileChecksumContainer()
        .addChecksum(soundInfo.getChecksum(), soundInfo.getAbsolutePath());
  }
Пример #9
0
  @Override
  public void create() {
    font = new BitmapFont();
    font.setColor(1f, 0f, 0.05f, 1f);
    font.setScale(1.2f);

    project = ProjectManager.getInstance().getCurrentProject();
    pathForScreenshot = Utils.buildProjectPath(project.getName()) + "/";

    virtualWidth = project.getXmlHeader().virtualScreenWidth;
    virtualHeight = project.getXmlHeader().virtualScreenHeight;

    virtualWidthHalf = virtualWidth / 2;
    virtualHeightHalf = virtualHeight / 2;

    stage = new Stage(virtualWidth, virtualHeight, true);
    batch = stage.getSpriteBatch();

    Gdx.gl.glViewport(0, 0, ScreenValues.SCREEN_WIDTH, ScreenValues.SCREEN_HEIGHT);
    initScreenMode();

    sprites = project.getSpriteList();
    for (Sprite sprite : sprites) {
      sprite.resetSprite();
      sprite.look.createBrightnessContrastShader();
      stage.addActor(sprite.look);
      sprite.resume();
    }

    passepartout =
        new Passepartout(
            ScreenValues.SCREEN_WIDTH,
            ScreenValues.SCREEN_HEIGHT,
            maximizeViewPortWidth,
            maximizeViewPortHeight,
            virtualWidth,
            virtualHeight);
    stage.addActor(passepartout);

    if (DEBUG) {
      OrthoCamController camController = new OrthoCamController(camera);
      InputMultiplexer multiplexer = new InputMultiplexer();
      multiplexer.addProcessor(camController);
      multiplexer.addProcessor(stage);
      Gdx.input.setInputProcessor(multiplexer);
      fpsLogger = new FPSLogger();
    } else {
      Gdx.input.setInputProcessor(stage);
    }

    axes = new Texture(Gdx.files.internal("stage/red_pixel.bmp"));
    skipFirstFrameForAutomaticScreenshot = true;
    if (checkIfAutomaticScreenshotShouldBeTaken) {
      makeAutomaticScreenshot = project.manualScreenshotExists(SCREENSHOT_MANUAL_FILE_NAME);
    }
  }
Пример #10
0
  public void testAliasesAndXmlHeader() {

    String projectName = "myProject";

    File projectFile = new File(Constants.DEFAULT_ROOT + "/" + projectName);
    if (projectFile.exists()) {
      UtilFile.deleteDirectory(projectFile);
    }

    Project project = new Project(getContext(), projectName);
    Sprite sprite = new Sprite("testSprite");
    Script startScript = new StartScript(sprite);
    Script whenScript = new WhenScript(sprite);
    sprite.addScript(startScript);
    sprite.addScript(whenScript);
    project.addSprite(sprite);

    ArrayList<Brick> startScriptBrickList = new ArrayList<Brick>();
    ArrayList<Brick> whenScriptBrickList = new ArrayList<Brick>();
    startScriptBrickList.add(new ChangeXByNBrick(sprite, 4));
    startScriptBrickList.add(new ChangeYByNBrick(sprite, 5));
    startScriptBrickList.add(new ComeToFrontBrick(sprite));
    startScriptBrickList.add(new GoNStepsBackBrick(sprite, 5));
    startScriptBrickList.add(new HideBrick(sprite));
    startScriptBrickList.add(new WhenStartedBrick(sprite, startScript));

    whenScriptBrickList.add(new PlaySoundBrick(sprite));
    whenScriptBrickList.add(new SetSizeToBrick(sprite, 50));
    whenScriptBrickList.add(new SetCostumeBrick(sprite));
    whenScriptBrickList.add(new SetXBrick(sprite, 50));
    whenScriptBrickList.add(new SetYBrick(sprite, 50));
    whenScriptBrickList.add(new ShowBrick(sprite));
    whenScriptBrickList.add(new WaitBrick(sprite, 1000));

    for (Brick b : startScriptBrickList) {
      startScript.addBrick(b);
    }
    for (Brick b : whenScriptBrickList) {
      whenScript.addBrick(b);
    }

    storageHandler.saveProject(project);
    String projectString = TestUtils.getProjectfileAsString(projectName);
    assertFalse("project contains package information", projectString.contains("org.catrobat"));

    String xmlHeader = (String) TestUtils.getPrivateField("XML_HEADER", new XmlSerializer(), false);
    assertTrue(
        "Project file did not contain correct XML header.", projectString.startsWith(xmlHeader));

    projectFile = new File(Constants.DEFAULT_ROOT + "/" + projectName);
    if (projectFile.exists()) {
      UtilFile.deleteDirectory(projectFile);
    }
  }
Пример #11
0
  @Then("^the variable '(\\w+)' should be equal (\\d+.?\\d*)$")
  public void var_should_equal_float(String name, float expected) {
    Sprite object = (Sprite) Cucumber.get(Cucumber.KEY_CURRENT_OBJECT);
    Project project = ProjectManager.getInstance().getCurrentProject();

    UserVariable variable = project.getUserVariables().getUserVariable(name, object);
    assertNotNull("The variable does not exist.", variable);

    float actual = variable.getValue().floatValue();
    assertThat("The variable is != the value.", actual, equalTo(expected));
  }
Пример #12
0
  @Override
  protected void setUp() throws Exception {

    TestUtils.clearProject(currentProjectName);
    storageHandler = StorageHandler.getInstance();
    Project testCopyFile = new Project(null, currentProjectName);
    testCopyFile.getXmlHeader().virtualScreenHeight = 1000;
    testCopyFile.getXmlHeader().virtualScreenWidth = 1000;
    projectManager = ProjectManager.getInstance();
    storageHandler.saveProject(testCopyFile);
    projectManager.setProject(testCopyFile);

    final String imagePath = Constants.DEFAULT_ROOT + "/testImage.png";
    testImage = new File(imagePath);
    if (!testImage.exists()) {
      testImage.createNewFile();
    }
    InputStream in =
        getInstrumentation().getContext().getResources().openRawResource(IMAGE_FILE_ID);
    OutputStream out =
        new BufferedOutputStream(new FileOutputStream(testImage), Constants.BUFFER_8K);

    byte[] buffer = new byte[Constants.BUFFER_8K];
    int length = 0;
    while ((length = in.read(buffer)) > 0) {
      out.write(buffer, 0, length);
    }

    in.close();
    out.flush();
    out.close();

    final String soundPath = Constants.DEFAULT_ROOT + "/testsound.mp3";
    testSound = new File(soundPath);
    if (!testSound.exists()) {
      testSound.createNewFile();
    }
    in = getInstrumentation().getContext().getResources().openRawResource(R.raw.testsound);
    out = new BufferedOutputStream(new FileOutputStream(testSound), Constants.BUFFER_8K);
    buffer = new byte[Constants.BUFFER_8K];
    length = 0;
    while ((length = in.read(buffer)) > 0) {
      out.write(buffer, 0, length);
    }

    in.close();
    out.flush();
    out.close();
  }
Пример #13
0
  public void createTestProject(String projectName) {
    StorageHandler storageHandler = StorageHandler.getInstance();
    Project project = new Project(getActivity(), projectName);
    Sprite firstSprite = new Sprite("cat");
    Sprite secondSprite = new Sprite("dog");
    Sprite thirdSprite = new Sprite("horse");
    Sprite fourthSprite = new Sprite("pig");

    project.addSprite(firstSprite);
    project.addSprite(secondSprite);
    project.addSprite(thirdSprite);
    project.addSprite(fourthSprite);

    storageHandler.saveProject(project);
  }
Пример #14
0
    public void refreshSpinnerAfterNewSprite(final Context context, final String newSpriteName) {
      Project project = ProjectManager.getInstance().getCurrentProject();
      for (Sprite sprite : project.getSpriteList()) {
        if (sprite.getName().equals(newSpriteName)) {
          pointedObject = sprite;
        }
      }

      setSpinnerSelection(spinner);

      AlertDialog dialog =
          new CustomAlertDialogBuilder(context)
              .setTitle(R.string.dialog_new_object_switch_title)
              .setMessage(R.string.dialog_new_object_switch_message)
              .setPositiveButton(
                  R.string.yes,
                  new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                      ProjectManager.getInstance().setCurrentSprite(pointedObject);

                      Intent intent = new Intent(context, ProgramMenuActivity.class);
                      intent.putExtra(
                          ProgramMenuActivity.FORWARD_TO_SCRIPT_ACTIVITY,
                          ScriptActivity.FRAGMENT_SCRIPTS);
                      intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                      intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                      context.startActivity(intent);

                      dialog.dismiss();
                    }
                  })
              .setNegativeButton(
                  R.string.no,
                  new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                      spinnerAdapter.notifyDataSetChanged();
                      dialog.dismiss();
                    }
                  })
              .create();
      dialog.setCanceledOnTouchOutside(true);
      dialog.show();
    }
Пример #15
0
  private void createProject() {
    ProjectManager projectManager = ProjectManager.getInstance();
    Project project = new Project(null, UiTestUtils.DEFAULT_TEST_PROJECT_NAME);
    Sprite firstSprite = new Sprite("cat");
    Script testScript = new StartScript(firstSprite);

    SetLookBrick setLookBrick = new SetLookBrick(firstSprite);
    testScript.addBrick(setLookBrick);

    firstSprite.addScript(testScript);
    project.addSprite(firstSprite);

    projectManager.setProject(project);
    projectManager.setCurrentSprite(firstSprite);
    projectManager.setCurrentScript(testScript);
    lookDataList = projectManager.getCurrentSprite().getLookDataList();

    lookFile =
        UiTestUtils.saveFileToProject(
            UiTestUtils.DEFAULT_TEST_PROJECT_NAME,
            "image.png",
            RESOURCE_LOOK,
            getInstrumentation().getContext(),
            UiTestUtils.FileTypes.IMAGE);
    LookData lookData = new LookData();
    lookData.setLookFilename(lookFile.getName());
    lookData.setLookName(lookName);

    lookFile2 =
        UiTestUtils.saveFileToProject(
            UiTestUtils.DEFAULT_TEST_PROJECT_NAME,
            "image2.png",
            RESOURCE_LOOK2,
            getInstrumentation().getContext(),
            UiTestUtils.FileTypes.IMAGE);
    LookData lookData2 = new LookData();
    lookData2.setLookFilename(lookFile2.getName());
    lookData2.setLookName(lookName2);

    lookDataList.add(lookData);
    lookDataList.add(lookData2);
    ProjectManager.getInstance()
        .getFileChecksumContainer()
        .addChecksum(lookData.getChecksum(), lookData.getAbsolutePath());
    ProjectManager.getInstance()
        .getFileChecksumContainer()
        .addChecksum(lookData2.getChecksum(), lookData2.getAbsolutePath());
  }
Пример #16
0
  private void initScreenMode() {
    switch (project.getScreenMode()) {
      case STRETCH:
        stage.setViewport(virtualWidth, virtualHeight, false);
        screenshotWidth = ScreenValues.SCREEN_WIDTH;
        screenshotHeight = ScreenValues.SCREEN_HEIGHT;
        screenshotX = 0;
        screenshotY = 0;
        break;

      case MAXIMIZE:
        stage.setViewport(virtualWidth, virtualHeight, true);
        screenshotWidth = maximizeViewPortWidth;
        screenshotHeight = maximizeViewPortHeight;
        screenshotX = maximizeViewPortX;
        screenshotY = maximizeViewPortY;
        break;

      default:
        break;
    }
    camera = (OrthographicCamera) stage.getCamera();
    camera.position.set(0, 0, 0);
    camera.update();
  }
Пример #17
0
  public void toggleScreenMode() {
    switch (project.getScreenMode()) {
      case MAXIMIZE:
        project.setScreenMode(ScreenModes.STRETCH);
        break;
      case STRETCH:
        project.setScreenMode(ScreenModes.MAXIMIZE);
        break;
    }

    initScreenMode();

    if (checkIfAutomaticScreenshotShouldBeTaken) {
      makeAutomaticScreenshot = project.manualScreenshotExists(SCREENSHOT_MANUAL_FILE_NAME);
    }
  }
Пример #18
0
  @And("^this script has a change '(\\w+)' by (\\d+.?\\d*) brick$")
  public void script_has_change_var_by_val_brick(String name, String value) {
    Sprite object = (Sprite) Cucumber.get(Cucumber.KEY_CURRENT_OBJECT);
    Script script = (Script) Cucumber.get(Cucumber.KEY_CURRENT_SCRIPT);
    Project project = ProjectManager.getInstance().getCurrentProject();

    UserVariable variable = project.getUserVariables().getUserVariable(name, object);
    if (variable == null) {
      variable = project.getUserVariables().addSpriteUserVariableToSprite(object, name);
    }

    FormulaElement elemValue = new FormulaElement(ElementType.NUMBER, value, null);

    Brick brick = new ChangeVariableBrick(new Formula(elemValue), variable);
    script.addBrick(brick);
  }
Пример #19
0
  @And("^this script has a set '(\\w+)' to '(\\w+)' brick$")
  public void script_has_set_var_to_var_brick(String a, String b) {
    Sprite object = (Sprite) Cucumber.get(Cucumber.KEY_CURRENT_OBJECT);
    Script script = (Script) Cucumber.get(Cucumber.KEY_CURRENT_SCRIPT);
    Project project = ProjectManager.getInstance().getCurrentProject();

    UserVariable varA = project.getUserVariables().getUserVariable(a, object);
    if (varA == null) {
      varA = project.getUserVariables().addSpriteUserVariableToSprite(object, a);
    }

    FormulaElement elemB = new FormulaElement(ElementType.USER_VARIABLE, b, null);

    Brick brick = new SetVariableBrick(new Formula(elemB), varA);
    script.addBrick(brick);
  }
  public void testComeToFront() {
    Project project = new Project(getContext(), "testProject");
    Group parentGroup = new Group();

    Sprite bottomSprite = new Sprite("catroid");
    parentGroup.addActor(bottomSprite.look);
    assertEquals("Unexpected initial z position of bottomSprite", 0, bottomSprite.look.getZIndex());

    Sprite middleSprite = new Sprite("catroid cat");
    parentGroup.addActor(middleSprite.look);
    assertEquals("Unexpected initial z position of middleSprite", 1, middleSprite.look.getZIndex());

    Sprite topSprite = new Sprite("scratch");
    parentGroup.addActor(topSprite.look);
    assertEquals("Unexpected initial z position of topSprite", 2, topSprite.look.getZIndex());

    project.addSprite(bottomSprite);
    project.addSprite(middleSprite);
    project.addSprite(topSprite);
    ProjectManager.getInstance().setProject(project);

    checkIfEveryZIndexUsedOnlyOnceFromZeroToNMinus1(project);

    ComeToFrontAction action = ExtendedActions.comeToFront(middleSprite);
    middleSprite.look.addAction(action);
    action.act(1.0f);
    assertEquals(
        "bottomSprite z position should now be 2",
        middleSprite.look.getZIndex(),
        getZMaxValue(middleSprite));

    Sprite nextSprite = new Sprite("dog");
    parentGroup.addActor(nextSprite.look);
    project.addSprite(nextSprite);

    assertEquals("Unexpected initial z position of topSprite", 3, nextSprite.look.getZIndex());

    ComeToFrontAction action2 = ExtendedActions.comeToFront(bottomSprite);
    bottomSprite.look.addAction(action);
    action2.act(1.0f);
    assertEquals(
        "bottomSprite z position should now be 3",
        bottomSprite.look.getZIndex(),
        getZMaxValue(bottomSprite));

    checkIfEveryZIndexUsedOnlyOnceFromZeroToNMinus1(project);
  }
Пример #21
0
  @Override
  protected void setUp() {
    Project project = new Project(null, "testProject");
    firstSprite = new SingleSprite("firstSprite");
    StartScript startScript = new StartScript();
    ChangeSizeByNBrick changeBrick = new ChangeSizeByNBrick(10);
    firstSprite.addScript(startScript);
    startScript.addBrick(changeBrick);
    project.getDefaultScene().addSprite(firstSprite);
    ProjectManager.getInstance().setProject(project);
    ProjectManager.getInstance().setCurrentSprite(firstSprite);

    dataContainer = ProjectManager.getInstance().getCurrentScene().getDataContainer();
    dataContainer.addProjectUserList(PROJECT_USER_LIST_NAME);
    dataContainer.addSpriteUserListToSprite(firstSprite, SPRITE_USER_LIST_NAME);
    dataContainer.addProjectUserList(PROJECT_USER_LIST_NAME_2);
  }
Пример #22
0
 private void addScriptEndCallbacks() {
   Project project = ProjectManager.getInstance().getCurrentProject();
   for (Sprite sprite : project.getSpriteList()) {
     for (int i = 0; i < sprite.getNumberOfScripts(); i++) {
       sprite
           .getScript(i)
           .addBrick(
               new CallbackBrick(
                   sprite,
                   new CallbackBrick.BrickCallback() {
                     @Override
                     public void onCallback() {
                       programWaitLock.release();
                     }
                   }));
     }
   }
 }
Пример #23
0
  public void reloadProject(Context context, StageDialog stageDialog) {
    if (reloadProject) {
      return;
    }
    this.stageDialog = stageDialog;

    project.getUserVariables().resetAllUserVariables();

    reloadProject = true;
  }
Пример #24
0
 private void cloneSpriteVariables(Project currentProject, Sprite cloneSprite) {
   DataContainer userVariables = currentProject.getDataContainer();
   List<UserVariable> originalSpriteVariables =
       userVariables.getOrCreateVariableListForSprite(this);
   List<UserVariable> clonedSpriteVariables =
       userVariables.getOrCreateVariableListForSprite(cloneSprite);
   for (UserVariable variable : originalSpriteVariables) {
     clonedSpriteVariables.add(new UserVariable(variable.getName(), variable.getValue()));
   }
 }
Пример #25
0
  public void testGetProjectNames() {
    Project project = new Project(null, projectName);
    ProjectManager.getInstance().setProject(project);
    Sprite sprite = new Sprite("new sprite");
    project.addSprite(sprite);
    StorageHandler.getInstance().saveProject(project);

    File catroidDirectoryFile = new File(CATROID_DIRECTORY);
    File project1Directory = new File(catroidDirectoryFile + "/" + projectName);

    List<String> projectList = UtilFile.getProjectNames(catroidDirectoryFile);

    assertTrue(
        "project1 should be in Projectlist - is a valid Catroid project",
        projectList.contains(project1Directory.getName()));
    assertFalse(
        "testDirectory should not be in Projectlist - not a Catroid project",
        projectList.contains(testDirectory.getName()));
  }
Пример #26
0
  public void testRestartingOfWhenScriptWithBroadcastWaitBrick() {
    String messageOne = "messageOne";
    String messageTwo = "messageTwo";
    final int xMovement = 1;

    Sprite sprite = new SingleSprite("cat");
    Script startScript = new StartScript();
    BroadcastBrick startBroadcastBrick = new BroadcastBrick(messageOne);
    startScript.addBrick(startBroadcastBrick);
    sprite.addScript(startScript);

    BroadcastScript broadcastScriptMessageOne = new BroadcastScript(messageOne);
    ChangeXByNBrick changeXByNBrickOne = new ChangeXByNBrick(xMovement);
    BroadcastWaitBrick broadcastWaitBrickOne = new BroadcastWaitBrick(messageTwo);
    broadcastScriptMessageOne.addBrick(changeXByNBrickOne);
    broadcastScriptMessageOne.addBrick(broadcastWaitBrickOne);
    sprite.addScript(broadcastScriptMessageOne);

    BroadcastScript broadcastScriptMessageTwo = new BroadcastScript(messageTwo);
    ChangeXByNBrick changeXByNBrickTwo = new ChangeXByNBrick(xMovement);
    BroadcastWaitBrick broadcastWaitBrickTwo = new BroadcastWaitBrick(messageOne);
    broadcastScriptMessageTwo.addBrick(changeXByNBrickTwo);
    broadcastScriptMessageTwo.addBrick(broadcastWaitBrickTwo);
    sprite.addScript(broadcastScriptMessageTwo);

    Project project = new Project(getContext(), UiTestUtils.DEFAULT_TEST_PROJECT_NAME);
    project.getDefaultScene().addSprite(sprite);
    ProjectManager.getInstance().setProject(project);

    sprite.createStartScriptActionSequenceAndPutToMap(new HashMap<String, List<String>>());

    int loopCounter = 0;
    while (!allActionsOfAllSpritesAreFinished() && loopCounter++ < 20) {
      for (Sprite spriteOfList : ProjectManager.getInstance().getCurrentScene().getSpriteList()) {
        spriteOfList.look.act(1.0f);
      }
    }

    assertTrue(
        "When script does not restart itself when a BroadcastWait is sent! ",
        (int) sprite.look.getXInUserInterfaceDimensionUnit() > 5 * xMovement);
  }
Пример #27
0
  public void testWritePermissionFile() throws IOException {
    Project project = generateMultiplePermissionsProject();
    ProjectManager.getInstance().setProject(project);
    StorageHandler.getInstance().saveProject(project);

    File permissionsFile = new File(buildProjectPath(project.getName()), PROJECTPERMISSIONS_NAME);
    assertTrue("File containing the permissions could not be written", permissionsFile.exists());

    // only for assertions. Add future permission; Vibration and LED not activated
    Set<String> permissions = new HashSet<String>();
    permissions.add(Constants.ARDRONE_SUPPORT);
    permissions.add(Constants.BLUETOOTH_LEGO_NXT);
    permissions.add(Constants.TEXT_TO_SPEECH);
    permissions.add(Constants.FACE_DETECTION);

    BufferedReader reader = new BufferedReader(new FileReader(permissionsFile));
    String line;
    while ((line = reader.readLine()) != null) {
      assertTrue("Wrong permission in File found", permissions.contains(line));
    }
  }
  private void checkIfEveryZIndexUsedOnlyOnceFromZeroToNMinus1(Project project) {
    int spriteSize = project.getSpriteList().size();
    int actualZIndex;

    List<Sprite> spriteList = project.getSpriteList();
    boolean zIndexFound;

    for (int zIndex = 0; zIndex < spriteSize - 1; zIndex++) {
      zIndexFound = false;
      for (int i = 0; i < spriteSize; i++) {
        actualZIndex = spriteList.get(i).look.getZIndex();
        if (actualZIndex == zIndex) {
          zIndexFound = true;
          break;
        }
      }
      assertTrue(
          "z-indexing not correct. z-index have to be from 0 to n-1 each value only once",
          zIndexFound);
    }
  }
Пример #29
0
  public void testWhenScriptRestartingItself() {
    Sprite sprite = new SingleSprite("testSprite");
    Script script = new StartScript();

    String message = "simpleTest";
    BroadcastBrick broadcastBrick = new BroadcastBrick(message);
    script.addBrick(broadcastBrick);
    sprite.addScript(script);

    BroadcastScript broadcastScript = new BroadcastScript(message);

    final int xMovement = 1;
    ChangeXByNBrick changeXByNBrick = new ChangeXByNBrick(xMovement);
    broadcastScript.addBrick(changeXByNBrick);

    BroadcastBrick broadcastBrickLoop = new BroadcastBrick(message);
    broadcastScript.addBrick(broadcastBrickLoop);

    WaitBrick wb = new WaitBrick(5);
    broadcastScript.addBrick(wb);

    sprite.addScript(broadcastScript);

    Project project = new Project(getContext(), UiTestUtils.DEFAULT_TEST_PROJECT_NAME);
    project.getDefaultScene().addSprite(sprite);
    ProjectManager.getInstance().setProject(project);

    sprite.createStartScriptActionSequenceAndPutToMap(new HashMap<String, List<String>>());

    int loopCounter = 0;
    while (!allActionsOfAllSpritesAreFinished() && loopCounter++ < 20) {
      for (Sprite spriteOfList : ProjectManager.getInstance().getCurrentScene().getSpriteList()) {
        spriteOfList.look.act(1.0f);
      }
    }

    assertTrue(
        "When script does not restart itself!",
        (int) sprite.look.getXInUserInterfaceDimensionUnit() > xMovement);
  }
Пример #30
0
  private void createProject() {
    project = new Project(null, UiTestUtils.DEFAULT_TEST_PROJECT_NAME);
    sprite = new Sprite("cat");
    Script script = new StartScript(sprite);
    ProjectManager.getInstance().setProject(project);
    ProjectManager.getInstance().setCurrentSprite(sprite);
    ProjectManager.getInstance().setCurrentScript(script);

    userVariablesContainer = project.getUserVariables();
    userVariablesContainer.addProjectUserVariable("p1");
    userVariablesContainer.addProjectUserVariable("p2");
    userVariablesContainer.addSpriteUserVariable("sprite_var1");
    userVariablesContainer.addSpriteUserVariable("sprite_var2");

    setVariableBrick = new SetVariableBrick(sprite, 0.0);
    script.addBrick(setVariableBrick);
    changeVariableBrick = new ChangeVariableBrick(sprite, 1.1);
    script.addBrick(changeVariableBrick);

    sprite.addScript(script);
    project.addSprite(sprite);
  }