Exemple #1
0
  public void testPauseOnBackButton() {
    double scale = 100.0;

    Project project = new Project(getActivity(), testProject);
    Sprite sprite = new Sprite("testSprite");
    Script script = new StartScript(sprite);
    WaitBrick waitBrick = new WaitBrick(sprite, 5000);
    SetSizeToBrick scaleCostumeBrick = new SetSizeToBrick(sprite, scale);

    script.addBrick(waitBrick);
    script.addBrick(scaleCostumeBrick);
    sprite.addScript(script);
    project.addSprite(sprite);

    storageHandler.saveProject(project);
    ProjectManager.getInstance().setProject(project);

    UiTestUtils.clickOnActionBar(solo, R.id.menu_start);

    //		assertEquals("Unexpected sprite size", 100.0, sprite.getSize());
    //		solo.goBack();
    //		solo.sleep(6000);
    //		solo.goBack();
    //		assertEquals("Unexpected sprite size", 100.0, sprite.getSize());
    //		solo.sleep(4000);
    //		assertEquals("Unexpected sprite size", scale, sprite.getSize());
  }
  @Override
  public void setUp() throws Exception {
    super.setUp();
    UiTestUtils.clearAllUtilTestProjects();

    ProjectManager projectManager = ProjectManager.getInstance();
    Project project = new Project(null, UiTestUtils.DEFAULT_TEST_PROJECT_NAME);
    Sprite firstSprite = new Sprite("cat");
    Script testScript = new StartScript(firstSprite);

    SetCostumeBrick setCostumeBrick = new SetCostumeBrick(firstSprite);
    testScript.addBrick(setCostumeBrick);

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

    projectManager.setProject(project);
    projectManager.setCurrentSprite(firstSprite);
    projectManager.setCurrentScript(testScript);
    costumeDataList = projectManager.getCurrentSprite().getCostumeDataList();

    costumeFile =
        UiTestUtils.saveFileToProject(
            UiTestUtils.DEFAULT_TEST_PROJECT_NAME,
            "image.png",
            RESOURCE_COSTUME,
            getInstrumentation().getContext(),
            UiTestUtils.FileTypes.IMAGE);
    CostumeData costumeData = new CostumeData();
    costumeData.setCostumeFilename(costumeFile.getName());
    costumeData.setCostumeName(costumeName);

    costumeFile2 =
        UiTestUtils.saveFileToProject(
            UiTestUtils.DEFAULT_TEST_PROJECT_NAME,
            "image2.png",
            RESOURCE_COSTUME2,
            getInstrumentation().getContext(),
            UiTestUtils.FileTypes.IMAGE);
    CostumeData costumeData2 = new CostumeData();
    costumeData2.setCostumeFilename(costumeFile2.getName());
    costumeData2.setCostumeName(costumeName2);

    costumeDataList.add(costumeData);
    costumeDataList.add(costumeData2);
    ProjectManager.getInstance()
        .getFileChecksumContainer()
        .addChecksum(costumeData.getChecksum(), costumeData.getAbsolutePath());
    ProjectManager.getInstance()
        .getFileChecksumContainer()
        .addChecksum(costumeData2.getChecksum(), costumeData2.getAbsolutePath());

    solo = new Solo(getInstrumentation(), getActivity());

    Intent intent = new Intent(getActivity(), ScriptTabActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    getActivity().startActivity(intent);
  }
Exemple #3
0
  public void testRestartProjectWithSound() {
    String projectName = UiTestUtils.PROJECTNAME1;
    // creating sprites for project:
    Sprite firstSprite = new Sprite("sprite1");
    Script startScript = new StartScript(firstSprite);

    PlaySoundBrick playSoundBrick = new PlaySoundBrick(firstSprite);

    startScript.addBrick(playSoundBrick);

    firstSprite.addScript(startScript);

    ArrayList<Sprite> spriteList = new ArrayList<Sprite>();
    spriteList.add(firstSprite);
    Project project = UiTestUtils.createProject(projectName, spriteList, getActivity());

    File soundFile =
        UiTestUtils.saveFileToProject(
            projectName,
            "soundfile.mp3",
            at.tugraz.ist.catroid.uitest.R.raw.longsound,
            getInstrumentation().getContext(),
            UiTestUtils.FileTypes.SOUND);

    SoundInfo soundInfo = new SoundInfo();
    soundInfo.setSoundFileName(soundFile.getName());
    soundInfo.setTitle(soundFile.getName());
    playSoundBrick.setSoundInfo(soundInfo);

    firstSprite.getSoundList().add(soundInfo);

    storageHandler.saveProject(project);

    MediaPlayer mediaPlayer = SoundManager.getInstance().getMediaPlayer();
    UiTestUtils.clickOnActionBar(solo, R.id.menu_start);
    solo.waitForActivity(StageActivity.class.getSimpleName());
    solo.sleep(1000);
    assertTrue("Sound not playing.", mediaPlayer.isPlaying());
    int positionBeforeRestart = mediaPlayer.getCurrentPosition();
    solo.goBack();
    solo.sleep(500);
    assertFalse("Sound playing but should be paused.", mediaPlayer.isPlaying());
    solo.clickOnButton(getActivity().getString(R.string.restart_current_project));
    solo.sleep(300);
    @SuppressWarnings("unchecked")
    ArrayList<MediaPlayer> mediaPlayerArrayList =
        (ArrayList<MediaPlayer>)
            UiTestUtils.getPrivateField("mediaPlayers", SoundManager.getInstance());
    int positionAfterRestart = mediaPlayerArrayList.get(0).getCurrentPosition();
    assertTrue("Sound not playing after stage restart.", mediaPlayerArrayList.get(0).isPlaying());
    assertTrue("Sound did not play from start!", positionBeforeRestart > positionAfterRestart);
  }
  private void createProject() {
    Values.SCREEN_HEIGHT = 20;
    Values.SCREEN_WIDTH = 20;
    ProjectManager projectManager = ProjectManager.getInstance();
    Project project = new Project(null, UiTestUtils.DEFAULT_TEST_PROJECT_NAME);

    Sprite firstSprite = new Sprite("cat");

    testScript = new StartScript(firstSprite);

    ArrayList<Brick> brickList = new ArrayList<Brick>();
    brickList.add(new SpeakBrick(firstSprite, "ich bin der erste text"));
    brickList.add(new SpeakBrick(firstSprite, "und ich bin der zweite text"));

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

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

    projectManager.setFileChecksumContainer(new FileChecksumContainer());
    projectManager.setProject(project);
    projectManager.setCurrentSprite(firstSprite);
    projectManager.setCurrentScript(testScript);

    projectManager.setProject(project);
    StorageHandler.getInstance().saveProject(project);
  }
  private void createProject() {
    project = new Project(null, UiTestUtils.DEFAULT_TEST_PROJECT_NAME);
    Sprite sprite = new Sprite("cat");
    Script script = new StartScript(sprite);

    motorBrick =
        new NXTMotorActionBrick(sprite, NXTMotorActionBrick.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);
  }
  private void createProject(String projectName) {
    double size = 0.8;

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

    Script startScript1 = new StartScript(firstSprite);
    Script whenScript1 = new WhenScript(firstSprite);
    Script whenScript2 = new WhenScript(firstSprite);

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

    secondBrickListForMoving = new ArrayList<Brick>();
    secondBrickListForMoving.add(new ShowBrick(firstSprite));
    secondBrickListForMoving.add(new WaitBrick(firstSprite, 200));
    secondBrickListForMoving.add(new SetBrightnessBrick(firstSprite, 2.0));
    secondBrickListForMoving.add(new SetXBrick(firstSprite, 100));
    secondBrickListForMoving.add(new SetSizeToBrick(firstSprite, size));

    // adding Bricks: ----------------
    for (Brick brick : brickListToCheck) {
      startScript1.addBrick(brick);
    }

    for (Brick brick : secondBrickListForMoving) {
      whenScript1.addBrick(brick);
    }

    whenScript2.addBrick(new WaitBrick(firstSprite, 300));
    whenScript2.addBrick(new ShowBrick(firstSprite));
    // -------------------------------

    firstSprite.addScript(startScript1);
    firstSprite.addScript(whenScript1);
    firstSprite.addScript(whenScript2);

    project.addSprite(firstSprite);

    ProjectManager.getInstance().setProject(project);
    ProjectManager.getInstance().setCurrentSprite(firstSprite);
  }
  public void testSimple() {
    solo.waitForActivity(PreStageActivity.class.getSimpleName());

    Intent intent = new Intent(getActivity(), StageActivity.class);
    getActivity().startActivity(intent);

    solo.waitForActivity(StageActivity.class.getSimpleName());
    solo.sleep(500);
    assertEquals("wrong execution index. ", 0, testScript.getExecutingBrickIndex());
    assertEquals("isFinished is wrong. ", false, testScript.isFinished());
    solo.sleep(2300);
    assertEquals("wrong execution index. ", 1, testScript.getExecutingBrickIndex());
    assertEquals("isFinished is wrong. ", false, testScript.isFinished());
    solo.sleep(2000);
    assertEquals("wrong execution index. ", 1, testScript.getExecutingBrickIndex());
    assertEquals("isFinished is wrong. ", true, testScript.isFinished());
  }