@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); }
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); }