Exemple #1
0
  public void testBehaviourWithoutBricks() {
    Project project = ProjectManager.getInstance().getCurrentProject();
    assertNotNull("current project was null", project);

    Sprite blueSprite = project.getSpriteList().get(4);
    while (blueSprite.getNumberOfScripts() > 0) {
      blueSprite.removeScript(blueSprite.getScript(0));
    }

    assertEquals("there shouldn't be any script left", 0, blueSprite.getNumberOfScripts());
    assertEquals("there shouldn't be any script left", 0, blueSprite.getNumberOfBricks());
    StorageHandler.getInstance().loadProject(project.getName());

    solo.waitForActivity(StageActivity.class.getSimpleName());
    solo.sleep(1400);

    byte[] screenArray = StageActivity.stageListener.getPixels(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    UiTestUtils.comparePixelArrayWithPixelScreenArray(
        BLUE_PIXEL, screenArray, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    UiTestUtils.comparePixelArrayWithPixelScreenArray(
        BLUE_PIXEL, screenArray, -19, -19, SCREEN_WIDTH, SCREEN_HEIGHT);
    UiTestUtils.comparePixelArrayWithPixelScreenArray(
        BLUE_PIXEL, screenArray, -19, 19, SCREEN_WIDTH, SCREEN_HEIGHT);
    UiTestUtils.comparePixelArrayWithPixelScreenArray(
        BLUE_PIXEL, screenArray, 19, -19, SCREEN_WIDTH, SCREEN_HEIGHT);
    UiTestUtils.comparePixelArrayWithPixelScreenArray(
        BLUE_PIXEL, screenArray, 19, 19, SCREEN_WIDTH, SCREEN_HEIGHT);

    solo.sleep(2000);
  }
  @Device
  public void testVariableBricks() {
    Spinner setVariableSpinner = solo.getCurrentViews(Spinner.class).get(0);
    Spinner changeVariableSpinner = solo.getCurrentViews(Spinner.class).get(1);

    solo.clickOnView(setVariableSpinner);
    solo.clickOnText("p2");
    solo.clickOnView(changeVariableSpinner);
    solo.clickOnText("p2", 1);

    //		UiTestUtils.testBrickWithFormulaEditor(solo, 0, 1, 50, "variable_formula",
    // setVariableBrick);
    solo.clickOnText("0");
    UiTestUtils.insertIntegerIntoEditText(solo, 50);
    solo.goBack();

    //		UiTestUtils.testBrickWithFormulaEditor(solo, 0, 1, -8, "variable_formula",
    // changeVariableBrick);
    solo.clickOnText("1");
    UiTestUtils.insertDoubleIntoEditText(solo, -8.0);
    solo.goBack();

    solo.waitForView(solo.getView(R.id.button_play));
    UiTestUtils.clickOnBottomBar(solo, R.id.button_play);
    solo.waitForActivity(StageActivity.class.getSimpleName());
    solo.sleep(1500);

    assertEquals(
        "Variable has the wrong value after stage",
        42.0,
        userVariablesContainer.getUserVariable("p2", sprite).getValue());
  }
 @Override
 public void setUp() throws Exception {
   super.setUp();
   createProject();
   UiTestUtils.prepareStageForTest();
   lookFile = UiTestUtils.setUpLookFile(solo, getActivity());
 }
 @Override
 public void setUp() throws Exception {
   super.setUp();
   createProject();
   UiTestUtils.prepareStageForTest();
   UiTestUtils.getIntoScriptActivityFromMainMenu(solo);
 }
Exemple #5
0
 @Override
 public void tearDown() throws Exception {
   UiTestUtils.goBackToHome(getInstrumentation());
   solo.finishOpenedActivities();
   UiTestUtils.clearAllUtilTestProjects();
   super.tearDown();
 }
Exemple #6
0
 @Override
 public void setUp() throws Exception {
   super.setUp();
   createProject();
   UiTestUtils.prepareStageForTest();
   UiTestUtils.getIntoSpritesFromMainMenu(solo);
   UiTestUtils.clickOnBottomBar(solo, R.id.button_play);
 }
 @Override
 public void setUp() throws Exception {
   super.setUp();
   UiTestUtils.clearAllUtilTestProjects();
   createProject();
   solo = new Solo(getInstrumentation(), getActivity());
   UiTestUtils.prepareStageForTest();
   UiTestUtils.getIntoScriptActivityFromMainMenu(solo);
 }
  private void createProject() {
    Project project = new Project(null, UiTestUtils.PROJECTNAME1);

    Sprite spriteCat = new Sprite(backgroundName);
    Script startScriptCat = new StartScript();
    Script scriptTappedCat = new WhenScript();
    Brick setXBrick = new SetXBrick(50);
    Brick setYBrick = new SetYBrick(50);
    Brick changeXBrick = new ChangeXByNBrick(50);
    startScriptCat.addBrick(setYBrick);
    startScriptCat.addBrick(setXBrick);
    scriptTappedCat.addBrick(changeXBrick);

    spriteCat.addScript(startScriptCat);
    spriteCat.addScript(scriptTappedCat);
    project.addSprite(spriteCat);

    ProjectManager.getInstance().setProject(project);
    ProjectManager.getInstance().setCurrentSprite(spriteCat);
    ProjectManager.getInstance().setCurrentScript(startScriptCat);

    File imageFile =
        UiTestUtils.saveFileToProject(
            project.getName(),
            "catroid_sunglasses.png",
            org.catrobat.catroid.test.R.drawable.catroid_sunglasses,
            getInstrumentation().getContext(),
            UiTestUtils.FileTypes.IMAGE);

    ProjectManager projectManager = ProjectManager.getInstance();
    List<LookData> lookDataList = projectManager.getCurrentSprite().getLookDataList();
    LookData lookData = new LookData();
    lookData.setLookFilename(imageFile.getName());
    lookData.setLookName("Catroid sun");
    lookDataList.add(lookData);
    projectManager
        .getFileChecksumContainer()
        .addChecksum(lookData.getChecksum(), lookData.getAbsolutePath());

    File soundFile =
        UiTestUtils.saveFileToProject(
            project.getName(),
            "longsound.mp3",
            org.catrobat.catroid.test.R.raw.longsound,
            getInstrumentation().getContext(),
            UiTestUtils.FileTypes.SOUND);
    SoundInfo soundInfo = new SoundInfo();
    soundInfo.setSoundFileName(soundFile.getName());
    soundInfo.setTitle("longsound");

    List<SoundInfo> soundInfoList = ProjectManager.getInstance().getCurrentSprite().getSoundList();
    soundInfoList.add(soundInfo);
    ProjectManager.getInstance()
        .getFileChecksumContainer()
        .addChecksum(soundInfo.getChecksum(), soundInfo.getAbsolutePath());
  }
 @Override
 public void tearDown() throws Exception {
   UiTestUtils.goBackToHome(getInstrumentation());
   solo.finishOpenedActivities();
   UiTestUtils.clearAllUtilTestProjects();
   if (lookFile.exists()) {
     lookFile.delete();
   }
   if (lookFile2.exists()) {
     lookFile2.delete();
   }
   super.tearDown();
   solo = null;
 }
  private void createProject() {
    ProjectManager projectManager = ProjectManager.getInstance();
    Project project = new Project(null, UiTestUtils.DEFAULT_TEST_PROJECT_NAME);
    Sprite firstSprite = new Sprite("cat");
    Script testScript = new StartScript(firstSprite);

    SetLookBrick setLookBrick = new SetLookBrick(firstSprite);
    testScript.addBrick(setLookBrick);

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

    projectManager.setProject(project);
    projectManager.setCurrentSprite(firstSprite);
    projectManager.setCurrentScript(testScript);
    lookDataList = projectManager.getCurrentSprite().getLookDataList();

    lookFile =
        UiTestUtils.saveFileToProject(
            UiTestUtils.DEFAULT_TEST_PROJECT_NAME,
            "image.png",
            RESOURCE_LOOK,
            getInstrumentation().getContext(),
            UiTestUtils.FileTypes.IMAGE);
    LookData lookData = new LookData();
    lookData.setLookFilename(lookFile.getName());
    lookData.setLookName(lookName);

    lookFile2 =
        UiTestUtils.saveFileToProject(
            UiTestUtils.DEFAULT_TEST_PROJECT_NAME,
            "image2.png",
            RESOURCE_LOOK2,
            getInstrumentation().getContext(),
            UiTestUtils.FileTypes.IMAGE);
    LookData lookData2 = new LookData();
    lookData2.setLookFilename(lookFile2.getName());
    lookData2.setLookName(lookName2);

    lookDataList.add(lookData);
    lookDataList.add(lookData2);
    ProjectManager.getInstance()
        .getFileChecksumContainer()
        .addChecksum(lookData.getChecksum(), lookData.getAbsolutePath());
    ProjectManager.getInstance()
        .getFileChecksumContainer()
        .addChecksum(lookData2.getChecksum(), lookData2.getAbsolutePath());
  }
Exemple #11
0
  public void testProjectDescriptionUploadProject() throws Throwable {
    UiTestUtils.createValidUser(getActivity());
    solo.clickOnText(solo.getString(R.string.main_menu_upload));
    boolean uploadDialogShown = solo.waitForText(uploadDialogTitle);

    assertTrue("upload project dialog not shown", uploadDialogShown);
    EditText editTextUploadName = solo.getEditText(0);
    EditText editTextUploadDescription = solo.getEditText(1);
    int projectUploadNameInputType = editTextUploadName.getInputType();
    int projectUploadDescriptionInputType = editTextUploadDescription.getInputType();
    int newProjectInputTypeReference =
        android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_NORMAL;
    int newProjectDescriptionInputTypeReference =
        android.text.InputType.TYPE_TEXT_FLAG_MULTI_LINE
            | android.text.InputType.TYPE_CLASS_TEXT
            | android.text.InputType.TYPE_TEXT_VARIATION_NORMAL;
    solo.sleep(200);
    assertEquals(
        "Project name field is not a text field",
        newProjectInputTypeReference,
        projectUploadNameInputType);
    assertEquals(
        "Project description field is not multiline",
        newProjectDescriptionInputTypeReference,
        projectUploadDescriptionInputType);

    int projectUploadNameNumberOfLines = editTextUploadName.getLineCount();
    assertEquals("Project name field is not a text field", 1, projectUploadNameNumberOfLines);

    int projectUploadDescriptionNumberOfLines = editTextUploadDescription.getMaxLines();
    assertEquals(
        "Project description field is not multiline", 2, projectUploadDescriptionNumberOfLines);
  }
  public void testTitle() {
    solo.clickOnText(solo.getString(R.string.main_menu_continue));
    solo.waitForActivity(ProjectActivity.class.getSimpleName());
    solo.waitForFragmentById(R.id.fragment_container);

    String spriteName = "sprite1";

    UiTestUtils.addNewSprite(solo, spriteName, lookFile, null);
    solo.clickOnText(backgroundName);
    solo.waitForActivity(ProgramMenuActivity.class.getSimpleName());

    String currentSpriteName = ProjectManager.getInstance().getCurrentSprite().getName();

    assertEquals("Current sprite is not " + backgroundName, backgroundName, currentSpriteName);
    assertTrue(
        "Title doesn't match " + backgroundName,
        solo.waitForText(currentSpriteName, 0, 200, false, true));

    solo.goBack();
    solo.waitForActivity(ProjectActivity.class.getSimpleName());
    solo.waitForFragmentById(R.id.fragment_container);
    solo.waitForText(spriteName);
    solo.clickOnText(spriteName);
    solo.waitForActivity(ProgramMenuActivity.class.getSimpleName());

    currentSpriteName = ProjectManager.getInstance().getCurrentSprite().getName();

    assertEquals("Current sprite is not " + spriteName, spriteName, currentSpriteName);
    assertTrue(
        "Title doesn't match " + spriteName,
        solo.waitForText(currentSpriteName, 0, 200, false, true));
  }
  public void testNXTMotorActionBrick() {
    ListView dragDropListView = UiTestUtils.getScriptListView(solo);
    BrickAdapter adapter = (BrickAdapter) dragDropListView.getAdapter();

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

    assertEquals("Incorrect number of bricks.", 2, dragDropListView.getChildCount());
    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(solo.getString(R.string.nxt_brick_motor_move)));
    assertNotNull(
        "TextView does not exist.", solo.getText(solo.getString(R.string.nxt_motor_speed_to)));

    UiTestUtils.testBrickWithFormulaEditor(
        solo,
        ProjectManager.getInstance().getCurrentSprite(),
        R.id.motor_action_speed_edit_text,
        SET_SPEED,
        Brick.BrickField.LEGO_NXT_SPEED,
        motorBrick);

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

    int legoSpinnerIndex = 0;

    Spinner currentSpinner = solo.getCurrentViews(Spinner.class).get(legoSpinnerIndex);
    solo.pressSpinnerItem(legoSpinnerIndex, 0);
    solo.waitForActivity(ScriptActivity.class.getSimpleName());
    assertEquals("Wrong item in spinner!", motors[0], currentSpinner.getSelectedItem());
    solo.pressSpinnerItem(legoSpinnerIndex, 1);
    solo.waitForActivity(ScriptActivity.class.getSimpleName());
    assertEquals("Wrong item in spinner!", motors[1], currentSpinner.getSelectedItem());
    solo.pressSpinnerItem(legoSpinnerIndex, 1);
    solo.waitForActivity(ScriptActivity.class.getSimpleName());
    assertEquals("Wrong item in spinner!", motors[2], currentSpinner.getSelectedItem());
    solo.pressSpinnerItem(legoSpinnerIndex, 1);
    solo.waitForActivity(ScriptActivity.class.getSimpleName());
    assertEquals("Wrong item in spinner!", motors[3], currentSpinner.getSelectedItem());
  }
 public void testLookButtonTextChange() {
   String spriteName = "sprite1";
   solo.clickOnText(solo.getString(R.string.main_menu_continue));
   solo.waitForActivity(ProjectActivity.class.getSimpleName());
   UiTestUtils.addNewSprite(solo, spriteName, lookFile, null);
   solo.clickOnText(spriteName);
   solo.waitForActivity(ProgramMenuActivity.class.getSimpleName());
   assertTrue(
       "Text on look button is not 'Looks'", solo.searchText(solo.getString(R.string.looks)));
   UiTestUtils.clickOnHomeActionBarButton(solo);
   solo.clickOnText(solo.getString(R.string.main_menu_continue));
   solo.clickOnText(backgroundName);
   solo.waitForText(solo.getString(R.string.backgrounds));
   assertTrue(
       "Text on look button is not 'Backgrounds'",
       solo.searchText(solo.getString(R.string.backgrounds)));
 }
  public void testRenameSpriteDialogMixedCase() throws NameNotFoundException, IOException {
    createTestProject(testProject);
    solo.clickOnButton(solo.getString(R.string.main_menu_programs));
    solo.waitForActivity(MyProjectsActivity.class.getSimpleName());
    solo.sleep(500);
    assertTrue("Cannot click on project.", UiTestUtils.clickOnTextInList(solo, testProject));
    solo.clickLongOnText(cat);

    solo.sleep(1000);
    solo.clickOnText(solo.getString(R.string.rename));
    solo.clearEditText(0);
    UiTestUtils.enterText(solo, 0, catMixedCase);
    solo.sendKey(Solo.ENTER);

    ListView spriteList = (ListView) solo.getCurrentActivity().findViewById(android.R.id.list);
    String first = ((Sprite) spriteList.getItemAtPosition(1)).getName();
    assertEquals("The first sprite name was not renamed to Mixed Case", first, catMixedCase);
  }
Exemple #16
0
  public void testAddLooksCategoryBrick() {
    String brickSetLookText = solo.getString(R.string.brick_set_look);
    UiTestUtils.addNewBrick(solo, R.string.brick_set_look);

    solo.sleep(500);
    UiTestUtils.dragFloatingBrickDownwards(solo);
    solo.sleep(500);

    assertTrue("Set look brick was not added", solo.searchText(brickSetLookText));

    UiTestUtils.addNewBrick(solo, R.string.brick_set_size_to);

    solo.sleep(500);
    UiTestUtils.dragFloatingBrickDownwards(solo);
    solo.sleep(500);

    assertTrue(
        "Set size to brick was not added",
        solo.searchText(solo.getString(R.string.brick_set_size_to)));
  }
  public void testChangeYByNBrick() {
    ListView dragDropListView = UiTestUtils.getScriptListView(solo);
    BrickAdapter adapter = (BrickAdapter) dragDropListView.getAdapter();

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

    assertEquals("Incorrect number of bricks.", 2, dragDropListView.getChildCount());
    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(solo.getString(R.string.brick_change_y_by)));

    UiTestUtils.testBrickWithFormulaEditor(solo, 0, 1, Y_TO_CHANGE, "yMovement", changeYByNBrick);
  }
  public void testMainMenuButton() {
    solo.clickOnText(solo.getString(R.string.main_menu_continue));
    solo.waitForActivity(ProjectActivity.class.getSimpleName());
    solo.clickOnText(backgroundName);
    UiTestUtils.clickOnHomeActionBarButton(solo);
    solo.waitForActivity(MainMenuActivity.class.getSimpleName());

    assertTrue(
        "Clicking on main menu button did not cause main menu to be displayed",
        solo.getCurrentActivity() instanceof MainMenuActivity);
  }
Exemple #19
0
  public void testDeleteScript() {
    UiTestUtils.addNewBrick(solo, R.string.brick_broadcast_receive);

    solo.sleep(500);
    UiTestUtils.dragFloatingBrick(solo, 0);
    solo.sleep(500);

    int numberOfScripts = ProjectManager.getInstance().getCurrentSprite().getNumberOfScripts();
    assertEquals("Incorrect number of scripts in list", 2, numberOfScripts);

    solo.waitForText(solo.getString(R.string.brick_when_started));
    solo.clickOnText(solo.getString(R.string.brick_when_started));
    solo.waitForText(solo.getString(R.string.brick_context_dialog_delete_script));
    solo.clickOnText(solo.getString(R.string.brick_context_dialog_delete_script));

    solo.waitForText(solo.getString(R.string.yes));
    solo.clickOnButton(solo.getString(R.string.yes));
    solo.waitForText(solo.getString(R.string.brick_broadcast_receive));

    numberOfScripts = ProjectManager.getInstance().getCurrentSprite().getNumberOfScripts();
    assertEquals("Incorrect number of scripts in scriptList", 1, numberOfScripts);
    assertEquals(
        "Incorrect number of elements in listView",
        3,
        UiTestUtils.getScriptListView(solo).getChildCount());

    solo.waitForText(solo.getString(R.string.brick_broadcast_receive));
    solo.clickOnText(solo.getString(R.string.brick_broadcast_receive));
    solo.waitForText(solo.getString(R.string.brick_context_dialog_delete_script));
    solo.clickOnText(solo.getString(R.string.brick_context_dialog_delete_script));
    solo.waitForText(solo.getString(R.string.yes));
    solo.clickOnButton(solo.getString(R.string.yes));
    solo.waitForText(solo.getString(R.string.brick_when_started));

    numberOfScripts = ProjectManager.getInstance().getCurrentSprite().getNumberOfScripts();
    assertEquals("Incorrect number of scripts in list", 0, numberOfScripts);
    assertEquals(
        "Incorrect number of elements in listView",
        0,
        UiTestUtils.getScriptListView(solo).getChildCount());

    UiTestUtils.addNewBrick(solo, R.string.brick_hide);

    solo.sleep(500);
    UiTestUtils.dragFloatingBrickDownwards(solo);
    solo.sleep(500);

    solo.waitForText(solo.getString(R.string.brick_when_started));

    numberOfScripts = ProjectManager.getInstance().getCurrentSprite().getNumberOfScripts();
    assertEquals("Incorrect number of scripts in scriptList", 1, numberOfScripts);
    assertEquals(
        "Incorrect number of elements in listView",
        2,
        UiTestUtils.getScriptListView(solo).getChildCount());
  }
Exemple #20
0
  @Smoke
  public void testIfBrick() {
    ListView view = UiTestUtils.getScriptListView(solo);
    ListView dragDropListView = UiTestUtils.getScriptListView(solo);
    BrickAdapter adapter = (BrickAdapter) view.getAdapter();

    int childrenCount = adapter.getChildCountFromLastGroup();

    UiTestUtils.testBrickWithFormulaEditor(solo, 0, 1, 5, "ifCondition", ifBrick);

    assertEquals(
        "Incorrect number of bricks.",
        6,
        dragDropListView.getChildCount()); // don't forget the footer
    assertEquals("Incorrect number of bricks.", 0, childrenCount);

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

    assertTrue("Wrong Brick instance.", projectBrickList.get(0) instanceof IfLogicBeginBrick);
    assertNotNull(
        "TextView does not exist", solo.getText(getActivity().getString(R.string.brick_if_begin)));
  }
 public void selectLook(String newLook, String oldName, String lookImagePath) {
   solo.clickOnText(oldName);
   solo.clickOnText(newLook);
   UiTestUtils.clickOnBottomBar(solo, R.id.button_play);
   solo.sleep(5000);
   solo.waitForActivity(StageActivity.class.getSimpleName());
   solo.sleep(2000);
   String lookPath = ProjectManager.getInstance().getCurrentSprite().look.getImagePath();
   assertEquals(
       "Wrong image shown in stage --> Problem with Adapter update in Script",
       lookImagePath,
       lookPath);
   solo.goBack();
   solo.goBack();
 }
  public void testPlayButton() {
    solo.assertMemoryNotLow();
    solo.waitForActivity(MainMenuActivity.class.getSimpleName());
    UiTestUtils.getIntoProgramMenuFromMainMenu(solo, 0);

    assertTrue(
        "Bottombar is not visible", solo.getView(R.id.button_play).getVisibility() == View.VISIBLE);
    assertTrue(
        "Play button is not visible",
        solo.getView(R.id.button_play).getVisibility() == View.VISIBLE);
    assertTrue(
        "Add button is not visible", solo.getView(R.id.button_add).getVisibility() == View.GONE);
    assertTrue(
        "Bottombar separator is not visible",
        solo.getView(R.id.bottom_bar_separator).getVisibility() == View.GONE);

    UiTestUtils.clickOnBottomBar(solo, R.id.button_play);
    solo.waitForActivity(StageActivity.class.getSimpleName());
    solo.assertCurrentActivity("Not in StageActivity", StageActivity.class);
    solo.goBack();
    solo.goBack();
    solo.waitForActivity(ProgramMenuActivity.class.getSimpleName());
    solo.assertCurrentActivity("Not in ProgramMenuActivity", ProgramMenuActivity.class);
  }
  public void testMainMenuItemsNotVisibleInProgramActivity() {
    UiTestUtils.getIntoProgramMenuFromMainMenu(solo, 0);

    solo.sendKey(Solo.MENU);

    assertFalse(
        "rate us is visible",
        solo.waitForText(solo.getString(R.string.main_menu_rate_app), 1, 5000, false));
    assertFalse(
        "terms of use is visible",
        solo.waitForText(solo.getString(R.string.main_menu_terms_of_use), 1, 1000, false));
    assertFalse(
        "about pocket-code is visible",
        solo.waitForText(solo.getString(R.string.main_menu_about_pocketcode), 1, 1000, false));
  }
  public void testSelectLookAndPlay() {
    assertTrue(lookName + " is not selected in Spinner", solo.isSpinnerTextSelected(lookName));

    UiTestUtils.clickOnBottomBar(solo, R.id.button_play);

    solo.waitForActivity(StageActivity.class.getSimpleName());
    solo.sleep(1000);
    Look look = ProjectManager.getInstance().getCurrentProject().getSpriteList().get(0).look;
    assertEquals("look not set", look.getImagePath(), lookDataList.get(0).getAbsolutePath());
    solo.goBack();
    solo.goBack();
    solo.waitForActivity(ScriptActivity.class.getSimpleName());

    solo.clickOnText(lookName);
    solo.clickOnText(lookName2);
    assertTrue(lookName2 + " is not selected in Spinner", solo.searchText(lookName2));

    UiTestUtils.clickOnBottomBar(solo, R.id.button_play);

    solo.waitForActivity(StageActivity.class.getSimpleName());
    solo.sleep(1000);
    look = ProjectManager.getInstance().getCurrentProject().getSpriteList().get(0).look;
    assertEquals("look not set", look.getImagePath(), lookDataList.get(1).getAbsolutePath());
  }
Exemple #25
0
  public void testHideBrick() {
    ListView dragDropListView = UiTestUtils.getScriptListView(solo);
    BrickAdapter adapter = (BrickAdapter) dragDropListView.getAdapter();

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

    assertEquals("Incorrect number of bricks.", 2, dragDropListView.getChildCount());
    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(solo.getString(R.string.brick_hide)));
  }
Exemple #26
0
  public void testRatingDialog() throws Throwable {
    SharedPreferences sharedPreferences =
        PreferenceManager.getDefaultSharedPreferences(getActivity());
    sharedPreferences.edit().putInt(UploadProjectDialog.NUMBER_OF_UPLOADED_PROJECTS, 0).commit();
    UiTestUtils.createValidUser(getActivity());
    createTestProject();

    solo.clickOnButton(solo.getString(R.string.upload_button));
    solo.waitForDialogToOpen();
    solo.clickOnButton(solo.getString(R.string.upload_button));
    solo.waitForDialogToClose();

    solo.clickOnButton(solo.getString(R.string.upload_button));
    solo.waitForDialogToOpen();
    solo.clickOnButton(solo.getString(R.string.upload_button));
    solo.waitForDialogToClose();

    assertTrue("rating dialog", solo.waitForText(solo.getString(R.string.rating_dialog_rate_now)));
  }
  private File loadBackpackFile(String jsonName) throws IOException {
    UiTestUtils.clearBackPack(true);
    InputStream inputStream =
        getInstrumentation().getContext().getResources().getAssets().open(jsonName);
    File backPackFile = new File(backpackFilePath);
    assertFalse("Backpack.json should not exist!", backPackFile.exists());

    byte[] buffer = new byte[inputStream.available()];
    inputStream.read(buffer);

    File targetFile = new File(backpackFilePath);
    OutputStream outStream = new FileOutputStream(targetFile);
    outStream.write(buffer);
    assertTrue("Backpack.json should exist!", backPackFile.exists());
    assertTrue(
        "Backpacked items not deleted!",
        BackPackListManager.getInstance().getBackpack().backpackedScripts.isEmpty());
    return backPackFile;
  }
  public void testAdapterUpdateInScriptActivity() {
    String look1ImagePath = lookDataList.get(0).getAbsolutePath();
    String look2ImagePath = lookDataList.get(1).getAbsolutePath();
    assertTrue(lookName + " is not selected in Spinner", solo.isSpinnerTextSelected(lookName));

    UiTestUtils.clickOnBottomBar(solo, R.id.button_play);
    solo.waitForActivity(StageActivity.class.getSimpleName());
    String lookPath =
        ProjectManager.getInstance().getCurrentSprite().getLookDataList().get(0).getAbsolutePath();
    assertEquals(
        "Wrong image shown in stage --> Problem with Adapter update in Script",
        look1ImagePath,
        lookPath);
    solo.goBack();
    solo.goBack();

    for (int i = 0; i < 5; ++i) {
      selectLook(lookName2, lookName, look2ImagePath);
      selectLook(lookName, lookName2, look1ImagePath);
    }
  }
Exemple #29
0
  public void testUploadDialog() throws Throwable {
    UiTestUtils.createValidUser(getActivity());
    solo.clickOnText(solo.getString(R.string.main_menu_upload));
    solo.waitForText(uploadDialogTitle);

    View renameView = solo.getText(solo.getString(R.string.project_rename));
    assertNotNull("View for rename project could not be found", renameView);
    assertEquals("rename View is visible.", renameView.getVisibility(), View.GONE);

    // clear the title
    solo.clearEditText(0);
    assertEquals("rename View is hidden.", renameView.getVisibility(), View.VISIBLE);

    // enter the same title
    solo.enterText(0, testProject);
    assertEquals("rename View is visible.", renameView.getVisibility(), View.GONE);

    // enter a new title
    solo.clearEditText(0);
    solo.enterText(0, UiTestUtils.PROJECTNAME2);
    assertEquals("rename View is hidden.", renameView.getVisibility(), View.VISIBLE);

    solo.clickOnButton(solo.getString(R.string.cancel_button));
  }
Exemple #30
0
  public void testUploadingProjectDescriptionDefaultValue() throws Throwable {
    UiTestUtils.createValidUser(getActivity());
    String testDescription = "Test description";
    String actionSetDescriptionText = solo.getString(R.string.set_description);

    solo.clickOnButton(solo.getString(R.string.main_menu_programs));
    solo.waitForActivity(MyProjectsActivity.class.getSimpleName());
    solo.waitForFragmentById(R.id.fragment_projects_list);
    solo.clickLongOnText(uploadProject.getName());
    assertTrue(
        "context menu not loaded in 5 seconds",
        solo.waitForText(actionSetDescriptionText, 0, 5000));
    solo.clickOnText(actionSetDescriptionText);
    assertTrue(
        "dialog not loaded in 5 seconds", solo.waitForText(actionSetDescriptionText, 0, 5000));
    solo.clearEditText(0);
    solo.enterText(0, testDescription);
    assertTrue(
        "dialog not loaded in 5 seconds", solo.waitForText(actionSetDescriptionText, 0, 5000));
    solo.sleep(300);

    solo.clickOnText(solo.getString(R.string.ok));

    solo.waitForDialogToClose(500);
    solo.goBack();
    solo.waitForActivity(MainMenuActivity.class.getSimpleName());

    solo.clickOnText(solo.getString(R.string.main_menu_upload));
    boolean uploadDialogShown = solo.waitForText(uploadDialogTitle);

    assertTrue("upload project dialog not shown", uploadDialogShown);
    EditText uploadDescriptionView = (EditText) solo.getView(R.id.project_description_upload);
    String uploadDescription = uploadDescriptionView.getText().toString();
    solo.sleep(500);
    assertEquals("Project description was not set or is wrong", testDescription, uploadDescription);
  }