Esempio n. 1
0
  public void testSelectCostumeAndPlay() {
    solo.clickOnText(getActivity().getString(R.string.broadcast_nothing_selected));
    solo.clickOnText(costumeName);
    assertTrue(costumeName + " is not selected in Spinner", solo.searchText(costumeName));

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

    solo.waitForActivity(StageActivity.class.getSimpleName());
    solo.sleep(2000);
    Costume costume =
        ProjectManager.getInstance().getCurrentProject().getSpriteList().get(0).costume;
    assertEquals(
        "costume not set", costume.getImagePath(), costumeDataList.get(0).getAbsolutePath());
    solo.goBack();
    solo.goBack();
    solo.waitForActivity(ScriptTabActivity.class.getSimpleName());

    solo.clickOnText(costumeName);
    solo.clickOnText(costumeName2);
    assertTrue(costumeName2 + " is not selected in Spinner", solo.searchText(costumeName2));
    UiTestUtils.clickOnActionBar(solo, R.id.menu_start);
    solo.waitForActivity(StageActivity.class.getSimpleName());
    solo.sleep(2000);
    costume = ProjectManager.getInstance().getCurrentProject().getSpriteList().get(0).costume;
    assertEquals(
        "costume not set", costume.getImagePath(), costumeDataList.get(1).getAbsolutePath());
  }
  /**
   * For some unknown reason the brick stays hovering and invisible after MotionEvent.ACTION_DOWN.
   * This behavior appears only in a test, not in the application itself.
   */
  @Smoke
  public void testMoveBrickAcrossScript() {
    //		ScriptTabActivity activity = (ScriptTabActivity) solo.getCurrentActivity();
    //		ScriptFragment fragment = (ScriptFragment)
    // activity.getTabFragment(ScriptTabActivity.INDEX_TAB_SCRIPTS);
    //		BrickAdapter adapter = fragment.getAdapter();

    ArrayList<Integer> yPositionList = UiTestUtils.getListItemYPositions(solo);
    assertTrue("Test project brick list smaller than expected", yPositionList.size() >= 6);

    int numberOfBricks = ProjectManager.getInstance().getCurrentScript().getBrickList().size();
    UiTestUtils.longClickAndDrag(solo, 10, yPositionList.get(7), 10, yPositionList.get(2), 20);
    assertTrue(
        "Number of Bricks inside Script hasn't changed",
        (numberOfBricks + 1)
            == ProjectManager.getInstance().getCurrentScript().getBrickList().size());
    longClickAndDrag(10, yPositionList.get(7), 10, yPositionList.get(2), 20);
    //		assertTrue("Number of Bricks inside Script hasn't changed", (numberOfBricks - 1) ==
    // ProjectManager
    //				.getInstance().getCurrentSprite().getScript(0).getBrickList().size());
    //
    //		assertEquals("Incorrect Brick after dragging over Script", (Brick) adapter.getItem(7)
    // instanceof WaitBrick,
    //				true);
  }
 @Override
 public void onPause() {
   super.onPause();
   ProjectManager projectManager = ProjectManager.getInstance();
   if (projectManager.getCurrentProject() != null) {
     projectManager.saveProject();
   }
 }
Esempio n. 4
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());
    }
  }
Esempio n. 5
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);
  }
  @Override
  protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);
    String title =
        this.getResources().getString(R.string.project_name)
            + " "
            + ProjectManager.getInstance().getCurrentProject().getName();
    activityHelper.setupActionBar(false, title);

    activityHelper.addActionButton(
        R.id.btn_action_add_button,
        R.drawable.ic_plus_black,
        R.string.add,
        new View.OnClickListener() {
          public void onClick(View v) {
            showDialog(DIALOG_NEW_SPRITE);
          }
        },
        false);

    activityHelper.addActionButton(
        R.id.btn_action_play,
        R.drawable.ic_play_black,
        R.string.start,
        new View.OnClickListener() {
          public void onClick(View v) {
            Intent intent = new Intent(ProjectActivity.this, PreStageActivity.class);
            startActivityForResult(intent, PreStageActivity.REQUEST_RESOURCES_INIT);
          }
        },
        false);
  }
Esempio n. 7
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());
  }
Esempio n. 8
0
  public void testAdapterUpdateInScriptActivity() {
    String costume1ImagePath = costumeDataList.get(0).getAbsolutePath();
    String costume2ImagePath = costumeDataList.get(1).getAbsolutePath();
    solo.clickOnText(getActivity().getString(R.string.broadcast_nothing_selected));
    solo.clickOnText(costumeName);

    UiTestUtils.clickOnActionBar(solo, R.id.menu_start);
    solo.waitForActivity(StageActivity.class.getSimpleName());
    String costumePath =
        ProjectManager.getInstance()
            .getCurrentSprite()
            .getCostumeDataList()
            .get(0)
            .getAbsolutePath();
    assertEquals(
        "Wrong image shown in stage --> Problem with Adapter update in Script",
        costume1ImagePath,
        costumePath);
    solo.goBack();
    solo.sleep(500);
    solo.goBack();
    for (int i = 0; i < 5; i++) {
      selectCostume(costumeName2, costumeName, costume2ImagePath);
      selectCostume(costumeName, costumeName2, costume1ImagePath);
    }
  }
Esempio n. 9
0
 @Override
 protected void tearDown() throws Exception {
   UiTestUtils.goBackToHome(getInstrumentation());
   solo.finishOpenedActivities();
   ProjectManager.getInstance().deleteCurrentProject();
   UiTestUtils.clearAllUtilTestProjects();
   super.tearDown();
 }
Esempio n. 10
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);
  }
Esempio n. 11
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);
  }
  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);
  }
 @Override
 public boolean onKeyDown(int keyCode, KeyEvent event) {
   if (keyCode == KeyEvent.KEYCODE_BACK) {
     Utils.saveToPreferences(
         this,
         Consts.PREF_PROJECTNAME_KEY,
         ProjectManager.getInstance().getCurrentProject().getName());
     Intent intent = new Intent(this, MainMenuActivity.class);
     intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
     this.startActivity(intent);
   }
   return super.onKeyDown(keyCode, event);
 }
Esempio n. 14
0
  public void testBackButtonPressedTwice() throws NameNotFoundException, IOException {
    Project project = createTestProject(testProject);
    ProjectManager.getInstance().setProject(project);

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

    solo.goBack();
    solo.waitForActivity(MainMenuActivity.class.getSimpleName());
    solo.assertCurrentActivity("Program is not in stage activity", MainMenuActivity.class);
  }
Esempio n. 15
0
 public void selectCostume(String newCostume, String oldName, String costumeImagePath) {
   solo.clickOnText(oldName);
   solo.clickOnText(newCostume);
   UiTestUtils.clickOnActionBar(solo, R.id.menu_start);
   solo.sleep(5000);
   solo.waitForActivity(StageActivity.class.getSimpleName());
   solo.sleep(2000);
   String costumePath = ProjectManager.getInstance().getCurrentSprite().costume.getImagePath();
   assertEquals(
       "Wrong image shown in stage --> Problem with Adapter update in Script",
       costumeImagePath,
       costumePath);
   solo.goBack();
   solo.goBack();
 }
  private void initListeners() {
    spriteList =
        (ArrayList<Sprite>) ProjectManager.getInstance().getCurrentProject().getSpriteList();
    spriteAdapter =
        new SpriteAdapter(
            this, R.layout.activity_project_spritelist_item, R.id.sprite_title, spriteList);

    setListAdapter(spriteAdapter);
    getListView().setTextFilterEnabled(true);
    getListView().setDivider(null);
    getListView().setDividerHeight(0);

    getListView()
        .setOnItemClickListener(
            new ListView.OnItemClickListener() {
              public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                ProjectManager.getInstance().setCurrentSprite(spriteAdapter.getItem(position));
                Intent intent = new Intent(ProjectActivity.this, ScriptTabActivity.class);
                startActivity(intent);
              }
            });
    getListView()
        .setOnItemLongClickListener(
            new OnItemLongClickListener() {
              public boolean onItemLongClick(
                  AdapterView<?> parent, View view, int position, long id) {
                spriteToEdit = spriteList.get(position);

                // as long as background sprite is always the first one, we're fine
                if (ProjectManager.getInstance()
                        .getCurrentProject()
                        .getSpriteList()
                        .indexOf(spriteToEdit)
                    == 0) {
                  return true;
                }
                removeDialog(DIALOG_CONTEXT_MENU);
                showDialog(DIALOG_CONTEXT_MENU);
                return true;
              }
            });
  }