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