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

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

    sprite.startStartScripts();

    try {
      Thread.sleep(1000);
    } catch (InterruptedException ignored) {
    }

    assertEquals("Broadcast and wait failed", testPosition, (int) sprite.costume.getXPosition());
  }
Пример #2
0
  private void addBrickToPositionInProject(int position, Brick brick) {
    Sprite currentSprite = ProjectManager.getInstance().getCurrentSprite();

    int[] temp = getScriptAndBrickIndexFromProject(position);

    int scriptPosition = temp[0];
    int brickPosition = temp[1];

    Script script = currentSprite.getScript(scriptPosition);

    if (brick instanceof NestingBrick) {
      ((NestingBrick) draggedBrick).initialize();
      List<NestingBrick> nestingBrickList =
          ((NestingBrick) draggedBrick).getAllNestingBrickParts(true);
      for (int i = 0; i < nestingBrickList.size(); i++) {
        if (nestingBrickList.get(i) instanceof DeadEndBrick) {
          if (i < nestingBrickList.size() - 1) {
            Log.w(TAG, "Adding a DeadEndBrick in the middle of the NestingBricks");
          }
          position = getPositionForDeadEndBrick(position);
          temp = getScriptAndBrickIndexFromProject(position);
          script.addBrick(temp[1], (Brick) nestingBrickList.get(i));
        } else {
          script.addBrick(brickPosition + i, (Brick) nestingBrickList.get(i));
        }
      }
    } else {
      script.addBrick(brickPosition, brick);
    }
  }
Пример #3
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());
  }
  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());
  }
Пример #5
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);
    }
  }
Пример #6
0
 private void addBrickToPositionInUserScript(int position, Brick brick) {
   position = getPositionInUserScript(position);
   if (brick instanceof NestingBrick) {
     ((NestingBrick) draggedBrick).initialize();
     List<NestingBrick> nestingBrickList =
         ((NestingBrick) draggedBrick).getAllNestingBrickParts(true);
     for (int i = 0; i < nestingBrickList.size(); i++) {
       script.addBrick(position + i, (Brick) nestingBrickList.get(i));
     }
   } else {
     script.addBrick(position, brick);
   }
 }
Пример #7
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());
  }
Пример #8
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);
  }
Пример #9
0
  private void addScriptToProject(int position, ScriptBrick scriptBrick) {
    Sprite currentSprite = ProjectManager.getInstance().getCurrentSprite();

    int[] temp = getScriptAndBrickIndexFromProject(position);

    int scriptPosition = temp[0];
    int brickPosition = temp[1];

    Script newScript = scriptBrick.getScriptSafe();
    if (currentSprite.getNumberOfBricks() > 0) {
      int addScriptTo = position == 0 ? 0 : scriptPosition + 1;
      currentSprite.addScript(addScriptTo, newScript);
    } else {
      currentSprite.addScript(newScript);
    }

    Script previousScript = currentSprite.getScript(scriptPosition);
    if (previousScript != null) {
      Brick brick;
      int size = previousScript.getBrickList().size();
      for (int i = brickPosition; i < size; i++) {
        brick = previousScript.getBrick(brickPosition);
        previousScript.removeBrick(brick);
        newScript.addBrick(brick);
      }
    }
    ProjectManager.getInstance().setCurrentScript(newScript);
  }
Пример #10
0
  @And("^this script has a Wait (\\d+.?\\d*) seconds? brick$")
  public void script_has_wait_s_brick(int seconds) {
    Sprite object = (Sprite) Cucumber.get(Cucumber.KEY_CURRENT_OBJECT);
    Script script = (Script) Cucumber.get(Cucumber.KEY_CURRENT_SCRIPT);

    WaitBrick brick = new WaitBrick(seconds * 1000);
    script.addBrick(brick);
  }
Пример #11
0
  @And("^this script has a BroadcastWait '(\\w+)' brick$")
  public void script_has_broadcast_wait_brick(String message) {
    Sprite object = (Sprite) Cucumber.get(Cucumber.KEY_CURRENT_OBJECT);
    Script script = (Script) Cucumber.get(Cucumber.KEY_CURRENT_SCRIPT);

    BroadcastWaitBrick brick = new BroadcastWaitBrick(message);
    script.addBrick(brick);
  }
Пример #12
0
  @And("^this script has a Wait (\\d+) milliseconds brick$")
  public void script_has_wait_ms_brick(int millis) {
    Sprite object = (Sprite) Cucumber.get(Cucumber.KEY_CURRENT_OBJECT);
    Script script = (Script) Cucumber.get(Cucumber.KEY_CURRENT_SCRIPT);

    WaitBrick brick = new WaitBrick(millis);
    script.addBrick(brick);
  }
Пример #13
0
  @And("^this script has a Repeat (\\d+) times brick$")
  public void script_has_repeat_times_brick(int iterations) {
    Sprite object = (Sprite) Cucumber.get(Cucumber.KEY_CURRENT_OBJECT);
    Script script = (Script) Cucumber.get(Cucumber.KEY_CURRENT_SCRIPT);

    Brick brick = new RepeatBrick(new Formula(iterations));
    Cucumber.put(Cucumber.KEY_LOOP_BEGIN_BRICK, brick);
    script.addBrick(brick);
  }
Пример #14
0
  @And("^this script has a Repeat end brick$")
  public void script_has_repeat_end_brick() {
    Sprite object = (Sprite) Cucumber.get(Cucumber.KEY_CURRENT_OBJECT);
    Script script = (Script) Cucumber.get(Cucumber.KEY_CURRENT_SCRIPT);

    LoopBeginBrick loopBeginBrick = (LoopBeginBrick) Cucumber.get(Cucumber.KEY_LOOP_BEGIN_BRICK);
    Brick brick = new LoopEndBrick(loopBeginBrick);
    script.addBrick(brick);
  }
Пример #15
0
  @And("^this script has a Print brick with$")
  public void script_has_a_print_brick(String text) {
    Sprite object = (Sprite) Cucumber.get(Cucumber.KEY_CURRENT_OBJECT);
    Script script = (Script) Cucumber.get(Cucumber.KEY_CURRENT_SCRIPT);

    if (outputStream == null) {
      outputStream = new ByteArrayOutputStream();
    }
    PrintBrick brick = new PrintBrick(object, text);
    brick.setOutputStream(outputStream);
    script.addBrick(brick);
  }
Пример #16
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);
  }
Пример #17
0
  private void createProject() {
    project = new Project(null, UiTestUtils.DEFAULT_TEST_PROJECT_NAME);
    Sprite sprite = new Sprite("cat");
    Script script = new StartScript(sprite);
    script.addBrick(new StopAllSoundsBrick(sprite));

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

    ProjectManager.getInstance().setProject(project);
    ProjectManager.getInstance().setCurrentSprite(sprite);
    ProjectManager.getInstance().setCurrentScript(script);
  }
Пример #18
0
  private void createProject() {
    project = new Project(null, UiTestUtils.DEFAULT_TEST_PROJECT_NAME);
    Sprite sprite = new Sprite("cat");
    Script script = new StartScript(sprite);
    ifBrick = new IfLogicBeginBrick(sprite, 0);
    IfLogicElseBrick ifElseBrick = new IfLogicElseBrick(sprite, ifBrick);
    IfLogicEndBrick ifEndBrick = new IfLogicEndBrick(sprite, ifElseBrick, ifBrick);
    ifBrick.setElseBrick(ifElseBrick);
    ifBrick.setEndBrick(ifEndBrick);

    script.addBrick(ifBrick);
    script.addBrick(new ChangeYByNBrick(sprite, -10));
    script.addBrick(ifElseBrick);
    script.addBrick(ifEndBrick);

    sprite.addScript(script);
    sprite.addScript(new StartScript(sprite));
    project.addSprite(sprite);

    ProjectManager.getInstance().setProject(project);
    ProjectManager.getInstance().setCurrentSprite(sprite);
    ProjectManager.getInstance().setCurrentScript(script);
  }
  private void createProject() {
    project = new Project(null, UiTestUtils.DEFAULT_TEST_PROJECT_NAME);
    sprite = new Sprite("cat");
    Script script = new StartScript(sprite);
    placeAtBrick = new PlaceAtBrick(sprite, INITIAL_X, INITIAL_Y);
    script.addBrick(placeAtBrick);

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

    ProjectManager.getInstance().setProject(project);
    ProjectManager.getInstance().setCurrentSprite(sprite);
    ProjectManager.getInstance().setCurrentScript(script);
  }
Пример #20
0
  private Project generateMultiplePermissionsProject() {
    final Project project = new Project(getInstrumentation().getTargetContext(), projectName);
    Sprite firstSprite = new SingleSprite("first");
    Sprite secondSprite = new SingleSprite("second");
    Script testScript = new StartScript();
    Script otherScript = new StartScript();
    HideBrick hideBrick = new HideBrick();
    ShowBrick showBrick = new ShowBrick();
    SpeakBrick speakBrick = new SpeakBrick("");
    LegoNxtMotorMoveBrick motorBrick =
        new LegoNxtMotorMoveBrick(LegoNxtMotorMoveBrick.Motor.MOTOR_A, SET_SPEED_INITIALLY);
    SetSizeToBrick setSizeToBrick =
        new SetSizeToBrick(
            new Formula(
                new FormulaElement(
                    FormulaElement.ElementType.SENSOR, Sensors.FACE_SIZE.name(), null)));
    BrickBaseType moveBrick =
        DroneBrickFactory.getInstanceOfDroneBrick(
            DroneBrickFactory.DroneBricks.DRONE_MOVE_FORWARD_BRICK,
            DEFAULT_MOVE_TIME_IN_MILLISECONDS,
            DEFAULT_MOVE_POWER_IN_PERCENT);

    testScript.addBrick(hideBrick);
    testScript.addBrick(showBrick);
    testScript.addBrick(speakBrick);
    testScript.addBrick(motorBrick);
    otherScript.addBrick(setSizeToBrick);
    otherScript.addBrick(moveBrick);

    firstSprite.addScript(testScript);
    secondSprite.addScript(otherScript);

    project.getDefaultScene().addSprite(firstSprite);
    project.getDefaultScene().addSprite(secondSprite);

    return project;
  }
Пример #21
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());
  }
Пример #22
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);
  }
Пример #23
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);
  }
Пример #24
0
  private void createProject() {
    project = new Project(null, UiTestUtils.DEFAULT_TEST_PROJECT_NAME);
    Sprite sprite = new Sprite("cat");
    Script script = new StartScript();

    motorBrick =
        new LegoNxtMotorMoveBrick(LegoNxtMotorMoveBrick.Motor.MOTOR_A, SET_SPEED_INITIALLY);

    script.addBrick(motorBrick);

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

    ProjectManager.getInstance().setProject(project);
    ProjectManager.getInstance().setCurrentSprite(sprite);
    ProjectManager.getInstance().setCurrentScript(script);
  }
Пример #25
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);
  }
Пример #26
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);
  }
Пример #27
0
  private void moveExistingProjectBrick(int from, int to) {
    Sprite currentSprite = ProjectManager.getInstance().getCurrentSprite();

    int[] tempFrom = getScriptAndBrickIndexFromProject(from);
    int scriptPositionFrom = tempFrom[0];
    int brickPositionFrom = tempFrom[1];

    Script fromScript = currentSprite.getScript(scriptPositionFrom);

    Brick brick = fromScript.getBrick(brickPositionFrom);
    if (draggedBrick != brick) {
      Log.e(TAG, "Want to save wrong brick");
      return;
    }
    fromScript.removeBrick(brick);

    int[] tempTo = getScriptAndBrickIndexFromProject(to);
    int scriptPositionTo = tempTo[0];
    int brickPositionTo = tempTo[1];

    Script toScript = currentSprite.getScript(scriptPositionTo);

    toScript.addBrick(brickPositionTo, brick);
  }
Пример #28
0
  public void testBroadcast() {
    Sprite sprite = new Sprite("testSprite");
    Script script = new StartScript(sprite);
    BroadcastBrick broadcastBrick = new BroadcastBrick(sprite);
    String message = "simpleTest";
    broadcastBrick.setSelectedMessage(message);
    script.addBrick(broadcastBrick);
    sprite.addScript(script);

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

    sprite.startStartScripts();
    try {
      Thread.sleep(1000);
    } catch (InterruptedException ignored) {
    }

    assertEquals("Simple broadcast failed", testPosition, (int) sprite.costume.getXPosition());
  }
Пример #29
0
  public void testSerializeProject() {

    int xPosition = 457;
    int yPosition = 598;
    double size = 0.8;

    Project project = new Project(getContext(), "testProject");
    Sprite firstSprite = new Sprite("first");
    Sprite secondSprite = new Sprite("second");
    Sprite thirdSprite = new Sprite("third");
    Sprite fourthSprite = new Sprite("fourth");
    Script testScript = new StartScript(firstSprite);
    Script otherScript = new StartScript(secondSprite);
    HideBrick hideBrick = new HideBrick(firstSprite);
    ShowBrick showBrick = new ShowBrick(firstSprite);
    SetSizeToBrick setSizeToBrick = new SetSizeToBrick(secondSprite, size);
    ComeToFrontBrick comeToFrontBrick = new ComeToFrontBrick(firstSprite);
    PlaceAtBrick placeAtBrick = new PlaceAtBrick(secondSprite, xPosition, yPosition);

    // adding Bricks: ----------------
    testScript.addBrick(hideBrick);
    testScript.addBrick(showBrick);
    testScript.addBrick(setSizeToBrick);
    testScript.addBrick(comeToFrontBrick);

    otherScript.addBrick(placeAtBrick); // secondSprite
    otherScript.setPaused(true);
    // -------------------------------

    firstSprite.addScript(testScript);
    secondSprite.addScript(otherScript);

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

    storageHandler.saveProject(project);

    Project loadedProject = storageHandler.loadProject("testProject");

    ArrayList<Sprite> preSpriteList = (ArrayList<Sprite>) project.getSpriteList();
    ArrayList<Sprite> postSpriteList = (ArrayList<Sprite>) loadedProject.getSpriteList();

    // Test sprite names:
    assertEquals(
        "First sprite does not match after deserialization",
        preSpriteList.get(0).getName(),
        postSpriteList.get(0).getName());
    assertEquals(
        "Second sprite does not match after deserialization",
        preSpriteList.get(1).getName(),
        postSpriteList.get(1).getName());
    assertEquals(
        "Third sprite does not match after deserialization",
        preSpriteList.get(2).getName(),
        postSpriteList.get(2).getName());
    assertEquals(
        "Fourth sprite does not match after deserialization",
        preSpriteList.get(3).getName(),
        postSpriteList.get(3).getName());
    assertEquals(
        "Fifth sprite does not match after deserialization",
        preSpriteList.get(4).getName(),
        postSpriteList.get(4).getName());

    // Test project name:
    assertEquals(
        "Title missmatch after deserialization", project.getName(), loadedProject.getName());

    // Test random brick values
    int actualXPosition =
        (Integer)
            TestUtils.getPrivateField(
                "xPosition", (postSpriteList.get(2).getScript(0).getBrickList().get(0)), false);
    int actualYPosition =
        (Integer)
            TestUtils.getPrivateField(
                "yPosition", (postSpriteList.get(2).getScript(0).getBrickList().get(0)), false);

    double actualSize =
        (Double)
            TestUtils.getPrivateField(
                "size", (postSpriteList.get(1).getScript(0).getBrickList().get(2)), false);

    assertEquals("Size was not deserialized right", size, actualSize);
    assertEquals("XPosition was not deserialized right", xPosition, actualXPosition);
    assertEquals("YPosition was not deserialized right", yPosition, actualYPosition);

    assertFalse("paused should not be set in script", preSpriteList.get(1).getScript(0).isPaused());

    // Test version codes and names
    //		final int preVersionCode = (Integer) TestUtils.getPrivateField("catroidVersionCode",
    // project, false);
    //		final int postVersionCode = (Integer) TestUtils.getPrivateField("catroidVersionCode",
    // loadedProject, false);
    //		assertEquals("Version codes are not equal", preVersionCode, postVersionCode);
    //
    //		final String preVersionName = (String) TestUtils.getPrivateField("catroidVersionName",
    // project, false);
    //		final String postVersionName = (String) TestUtils.getPrivateField("catroidVersionName",
    // loadedProject, false);
    //		assertEquals("Version names are not equal", preVersionName, postVersionName);
  }
Пример #30
0
 private void moveUserBrick(int from, int to) {
   Brick brick = script.getBrick(getPositionInUserScript(from));
   script.removeBrick(brick);
   script.addBrick(getPositionInUserScript(to), brick);
 }