Ejemplo n.º 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());
  }
Ejemplo n.º 2
0
  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);
  }
Ejemplo n.º 3
0
  @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);
  }
Ejemplo n.º 4
0
  private Project createTestProject(String projectName) throws IOException, NameNotFoundException {
    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);

    return project;
  }
  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);
  }
Ejemplo n.º 6
0
  public void testRestartButtonScriptPosition() {
    ArrayList<Integer> scriptPositionsStart = new ArrayList<Integer>();
    ArrayList<Integer> scriptPositionsRestart = new ArrayList<Integer>();
    scriptPositionsStart.clear();
    scriptPositionsRestart.clear();

    UiTestUtils.clickOnActionBar(solo, R.id.menu_start);
    solo.waitForActivity(StageActivity.class.getSimpleName());
    solo.sleep(1000);

    ProjectManager projectManager = ProjectManager.getInstance();
    Project projectStart = projectManager.getCurrentProject();

    String projectNameStart = projectStart.getName();

    // scriptPositions at start
    List<Sprite> spriteList = projectStart.getSpriteList();
    for (int i = 0; i < spriteList.size(); i++) {
      Sprite sprite = spriteList.get(i);
      int size = sprite.getNumberOfScripts();
      for (int j = 0; j < size; j++) {
        scriptPositionsRestart.add(sprite.getScript(j).getExecutingBrickIndex());
      }
    }
    spriteList.clear();

    solo.clickOnScreen(Values.SCREEN_WIDTH / 2, Values.SCREEN_HEIGHT / 2);
    solo.sleep(200);
    solo.goBack();
    solo.sleep(100);
    solo.clickOnButton(getActivity().getString(R.string.restart_current_project));
    solo.sleep(300);

    // scriptPositions in between
    Project projectRestart = ProjectManager.getInstance().getCurrentProject();
    String projectNameRestart = projectRestart.getName();

    assertEquals("Wrong project after restart", projectNameStart, projectNameRestart);

    spriteList = projectRestart.getSpriteList();
    for (int i = 0; i < spriteList.size(); i++) {
      Sprite sprite = spriteList.get(i);
      int size = sprite.getNumberOfScripts();
      for (int j = 0; j < size; j++) {
        scriptPositionsRestart.add(sprite.getScript(j).getExecutingBrickIndex());
      }
    }

    for (int i = 0; i < scriptPositionsStart.size(); i++) {
      assertEquals(
          "Script is not at starting position!",
          scriptPositionsStart.get(i).intValue(),
          scriptPositionsRestart.get(i).intValue());
    }
  }
Ejemplo n.º 7
0
  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);
  }
Ejemplo n.º 8
0
  public void testMaximizeStretch() throws NameNotFoundException, IOException {
    Project project = createTestProject(testProject);
    project.virtualScreenWidth = 480;
    project.virtualScreenHeight = 700;
    project.setDeviceData(getActivity());
    storageHandler.saveProject(project);
    solo.clickOnButton(getActivity().getString(R.string.my_projects));
    solo.waitForActivity(MyProjectsActivity.class.getSimpleName());
    solo.waitForFragmentById(R.id.fr_projects_list);
    assertTrue("Cannot click project.", UiTestUtils.clickOnTextInList(solo, testProject));
    solo.waitForActivity(ProjectActivity.class.getSimpleName());

    Utils.updateScreenWidthAndHeight(getActivity());
    UiTestUtils.clickOnActionBar(solo, R.id.menu_start);
    solo.waitForActivity(StageActivity.class.getSimpleName());
    assertTrue(
        "Stage not resizeable.", ((StageActivity) solo.getCurrentActivity()).getResizePossible());
    byte[] whitePixel = {(byte) 255, (byte) 255, (byte) 255, (byte) 255};
    byte[] screenPixel = StageActivity.stageListener.getPixels(0, 0, 1, 1);
    UiTestUtils.compareByteArrays(whitePixel, screenPixel);
    screenPixel =
        StageActivity.stageListener.getPixels(
            Values.SCREEN_WIDTH - 1, Values.SCREEN_HEIGHT - 1, 1, 1);
    UiTestUtils.compareByteArrays(whitePixel, screenPixel);
    screenPixel = StageActivity.stageListener.getPixels(Values.SCREEN_WIDTH - 1, 0, 1, 1);
    UiTestUtils.compareByteArrays(whitePixel, screenPixel);
    screenPixel = StageActivity.stageListener.getPixels(0, Values.SCREEN_HEIGHT - 1, 1, 1);
    UiTestUtils.compareByteArrays(whitePixel, screenPixel);
    solo.goBack();
    solo.clickOnButton(getActivity().getString(R.string.stagemenu_screen_size));
    solo.clickOnButton(getActivity().getString(R.string.resume_current_project));
    solo.sleep(100);
    byte[] blackPixel = {0, 0, 0, (byte) 255};
    screenPixel = StageActivity.stageListener.getPixels(0, 0, 1, 1);
    UiTestUtils.compareByteArrays(blackPixel, screenPixel);
    screenPixel =
        StageActivity.stageListener.getPixels(
            Values.SCREEN_WIDTH - 1, Values.SCREEN_HEIGHT - 1, 1, 1);
    UiTestUtils.compareByteArrays(blackPixel, screenPixel);
    screenPixel = StageActivity.stageListener.getPixels(Values.SCREEN_WIDTH - 1, 0, 1, 1);
    UiTestUtils.compareByteArrays(blackPixel, screenPixel);
    screenPixel = StageActivity.stageListener.getPixels(0, Values.SCREEN_HEIGHT - 1, 1, 1);
    UiTestUtils.compareByteArrays(blackPixel, screenPixel);

    screenPixel =
        StageActivity.stageListener.getPixels(Values.SCREEN_WIDTH, Values.SCREEN_HEIGHT, 1, 1);
    UiTestUtils.compareByteArrays(whitePixel, screenPixel);

    solo.goBack();
    solo.clickOnButton(getActivity().getString(R.string.stagemenu_screen_size));
    solo.clickOnButton(getActivity().getString(R.string.resume_current_project));
    solo.sleep(100);
    screenPixel = StageActivity.stageListener.getPixels(0, 0, 1, 1);
    UiTestUtils.compareByteArrays(whitePixel, screenPixel);
    screenPixel =
        StageActivity.stageListener.getPixels(
            Values.SCREEN_WIDTH - 1, Values.SCREEN_HEIGHT - 1, 1, 1);
    UiTestUtils.compareByteArrays(whitePixel, screenPixel);
    screenPixel = StageActivity.stageListener.getPixels(Values.SCREEN_WIDTH - 1, 0, 1, 1);
    UiTestUtils.compareByteArrays(whitePixel, screenPixel);
    screenPixel = StageActivity.stageListener.getPixels(0, Values.SCREEN_HEIGHT - 1, 1, 1);
    UiTestUtils.compareByteArrays(whitePixel, screenPixel);
  }
Ejemplo n.º 9
0
  @Smoke
  public void testNXTMotorActionBrick() {
    ScriptTabActivity activity = (ScriptTabActivity) solo.getCurrentActivity();
    ScriptFragment fragment =
        (ScriptFragment) activity.getTabFragment(ScriptTabActivity.INDEX_TAB_SCRIPTS);
    BrickAdapter adapter = fragment.getAdapter();

    int childrenCount = adapter.getChildCountFromLastGroup();
    int groupCount = adapter.getScriptCount();

    assertEquals(
        "Incorrect number of bricks.",
        2 + 1,
        solo.getCurrentListViews().get(0).getChildCount()); // don't forget the footer
    assertEquals("Incorrect number of bricks.", 1, childrenCount);

    ArrayList<Brick> projectBrickList = project.getSpriteList().get(0).getScript(0).getBrickList();
    assertEquals("Incorrect number of bricks.", 1, projectBrickList.size());

    assertEquals(
        "Wrong Brick instance.", projectBrickList.get(0), adapter.getChild(groupCount - 1, 0));
    assertNotNull(
        "TextView does not exist.",
        solo.getText(getActivity().getString(R.string.brick_motor_action)));
    assertNotNull(
        "TextView does not exist.", solo.getText(getActivity().getString(R.string.motor_speed)));

    String buttonOkText = solo.getString(R.string.ok);
    solo.clickOnEditText(0);
    solo.waitForText(buttonOkText);
    solo.clearEditText(0);
    solo.enterText(0, SET_SPEED + "");
    solo.clickOnButton(buttonOkText);

    int speed = (Integer) UiTestUtils.getPrivateField("speed", motorBrick);
    assertEquals("Wrong text in field.", SET_SPEED, speed);
    assertEquals(
        "Value in Brick is not updated.", SET_SPEED + "", solo.getEditText(0).getText().toString());
    assertEquals(
        "SeekBar is at wrong position",
        SET_SPEED + 100,
        solo.getCurrentProgressBars().get(0).getProgress());

    solo.setProgressBar(
        0,
        SET_SPEED_INITIALLY
            + 100); // robotium doesnt go through proper function onProgressChanged() to change
                    // value on progress bar!
    solo.sleep(200);
    speed = (Integer) UiTestUtils.getPrivateField("speed", motorBrick);
    assertEquals("Wrong text in field.", SET_SPEED_INITIALLY, speed);
    assertEquals(
        "Value in Brick is not updated.",
        SET_SPEED_INITIALLY + "",
        solo.getEditText(0).getText().toString());
    assertEquals(
        "SeekBar is at wrong position",
        SET_SPEED_INITIALLY + 100,
        solo.getCurrentProgressBars().get(0).getProgress());

    solo.clickOnButton(0);
    int speedCounter = (Integer) UiTestUtils.getPrivateField("speed", motorBrick);
    assertEquals("Wrong text in field.", speedCounter, speed - 1);
    assertEquals(
        "Value in Brick is not updated.", speed - 1 + "", solo.getEditText(0).getText().toString());
    assertEquals(
        "SeekBar is at wrong position",
        speed - 1 + 100,
        solo.getCurrentProgressBars().get(0).getProgress());

    solo.clickOnButton(1);
    speedCounter = (Integer) UiTestUtils.getPrivateField("speed", motorBrick);
    assertEquals("Wrong text in field.", speedCounter, speed);
    assertEquals(
        "Value in Brick is not updated.", speed + "", solo.getEditText(0).getText().toString());
    assertEquals(
        "SeekBar is at wrong position",
        speed + 100,
        solo.getCurrentProgressBars().get(0).getProgress());

    solo.setProgressBar(0, 1);
    solo.clickOnButton(0);
    solo.clickOnButton(0);
    speed = (Integer) UiTestUtils.getPrivateField("speed", motorBrick);
    assertEquals("Wrong text in field.", speed, MIN_SPEED);
    assertEquals(
        "Value in Brick is not updated.", speed + "", solo.getEditText(0).getText().toString());
    assertEquals(
        "SeekBar is at wrong position",
        speed + 100,
        solo.getCurrentProgressBars().get(0).getProgress());

    solo.setProgressBar(0, MAX_SPEED + 100);
    solo.clickOnButton(1);
    solo.clickOnButton(1);
    speed = (Integer) UiTestUtils.getPrivateField("speed", motorBrick);
    assertEquals("Wrong text in field.", speed, MAX_SPEED);
    assertEquals(
        "Value in Brick is not updated.", speed + "", solo.getEditText(0).getText().toString());
    assertEquals(
        "SeekBar is at wrong position",
        speed + 100,
        solo.getCurrentProgressBars().get(0).getProgress());

    String[] motors = getActivity().getResources().getStringArray(R.array.nxt_motor_chooser);
    assertTrue("Spinner items list too short!", motors.length == 4);

    Spinner currentSpinner = solo.getCurrentSpinners().get(0);
    solo.pressSpinnerItem(0, 0);
    solo.waitForActivity(ScriptTabActivity.class.getSimpleName());
    assertEquals("Wrong item in spinner!", motors[0], currentSpinner.getSelectedItem());
    solo.pressSpinnerItem(0, 1);
    solo.waitForActivity(ScriptTabActivity.class.getSimpleName());
    assertEquals("Wrong item in spinner!", motors[1], currentSpinner.getSelectedItem());
    solo.pressSpinnerItem(0, 1);
    solo.waitForActivity(ScriptTabActivity.class.getSimpleName());
    assertEquals("Wrong item in spinner!", motors[2], currentSpinner.getSelectedItem());
    solo.pressSpinnerItem(0, 1);
    solo.waitForActivity(ScriptTabActivity.class.getSimpleName());
    assertEquals("Wrong item in spinner!", motors[3], currentSpinner.getSelectedItem());
  }