Beispiel #1
0
  @And("^this script has a Wait (\\d+.?\\d*) seconds? brick$")
  public void script_has_wait_s_brick(int seconds) {
    Sprite object = (Sprite) Cucumber.get(Cucumber.KEY_CURRENT_OBJECT);
    Script script = (Script) Cucumber.get(Cucumber.KEY_CURRENT_SCRIPT);

    WaitBrick brick = new WaitBrick(seconds * 1000);
    script.addBrick(brick);
  }
Beispiel #2
0
  @And("^this script has a BroadcastWait '(\\w+)' brick$")
  public void script_has_broadcast_wait_brick(String message) {
    Sprite object = (Sprite) Cucumber.get(Cucumber.KEY_CURRENT_OBJECT);
    Script script = (Script) Cucumber.get(Cucumber.KEY_CURRENT_SCRIPT);

    BroadcastWaitBrick brick = new BroadcastWaitBrick(message);
    script.addBrick(brick);
  }
Beispiel #3
0
  @And("^this script has a Wait (\\d+) milliseconds brick$")
  public void script_has_wait_ms_brick(int millis) {
    Sprite object = (Sprite) Cucumber.get(Cucumber.KEY_CURRENT_OBJECT);
    Script script = (Script) Cucumber.get(Cucumber.KEY_CURRENT_SCRIPT);

    WaitBrick brick = new WaitBrick(millis);
    script.addBrick(brick);
  }
Beispiel #4
0
  @And("^this script has a Repeat end brick$")
  public void script_has_repeat_end_brick() {
    Sprite object = (Sprite) Cucumber.get(Cucumber.KEY_CURRENT_OBJECT);
    Script script = (Script) Cucumber.get(Cucumber.KEY_CURRENT_SCRIPT);

    LoopBeginBrick loopBeginBrick = (LoopBeginBrick) Cucumber.get(Cucumber.KEY_LOOP_BEGIN_BRICK);
    Brick brick = new LoopEndBrick(loopBeginBrick);
    script.addBrick(brick);
  }
Beispiel #5
0
  @And("^this script has a Repeat (\\d+) times brick$")
  public void script_has_repeat_times_brick(int iterations) {
    Sprite object = (Sprite) Cucumber.get(Cucumber.KEY_CURRENT_OBJECT);
    Script script = (Script) Cucumber.get(Cucumber.KEY_CURRENT_SCRIPT);

    Brick brick = new RepeatBrick(new Formula(iterations));
    Cucumber.put(Cucumber.KEY_LOOP_BEGIN_BRICK, brick);
    script.addBrick(brick);
  }
Beispiel #6
0
  @And("^this script has a Print brick with$")
  public void script_has_a_print_brick(String text) {
    Sprite object = (Sprite) Cucumber.get(Cucumber.KEY_CURRENT_OBJECT);
    Script script = (Script) Cucumber.get(Cucumber.KEY_CURRENT_SCRIPT);

    if (outputStream == null) {
      outputStream = new ByteArrayOutputStream();
    }
    PrintBrick brick = new PrintBrick(object, text);
    brick.setOutputStream(outputStream);
    script.addBrick(brick);
  }
Beispiel #7
0
  @Given("^'(\\w+)' has a Start script$")
  public void object_has_start_script(String object) {
    programWaitLockPermits -= 1;
    Project project = ProjectManager.getInstance().getCurrentProject();
    Sprite sprite = Util.findSprite(project, object);
    StartScript script = new StartScript(sprite);

    script.addBrick(
        new CallbackBrick(
            sprite,
            new CallbackBrick.BrickCallback() {
              @Override
              public void onCallback() {
                synchronized (programStartWaitLock) {
                  if (!programHasStarted) {
                    programHasStarted = true;
                    programStartWaitLock.notify();
                  }
                }
              }
            }));

    sprite.addScript(script);
    Cucumber.put(Cucumber.KEY_CURRENT_SCRIPT, script);
  }
Beispiel #8
0
 @Given("^I have a Program$")
 public void I_have_a_program() throws IOException {
   ProjectManager pm = ProjectManager.getInstance();
   pm.initializeNewProject("Cucumber", getContext(), /*empty*/ true);
   Project project = pm.getCurrentProject();
   Cucumber.put(Cucumber.KEY_PROJECT, project);
 }
Beispiel #9
0
  @When("^I start the program$")
  public void I_start_the_program() throws InterruptedException {
    programWaitLock = new Semaphore(programWaitLockPermits);
    addScriptEndCallbacks();

    Solo solo = (Solo) Cucumber.get(Cucumber.KEY_SOLO);
    assertEquals(
        "I am in the wrong Activity.",
        MainMenuActivity.class,
        solo.getCurrentActivity().getClass());
    solo.clickOnView(solo.getView(org.catrobat.catroid.R.id.main_menu_button_continue));
    solo.waitForActivity(ProjectActivity.class.getSimpleName(), 3000);
    assertEquals(
        "I am in the wrong Activity.", ProjectActivity.class, solo.getCurrentActivity().getClass());
    solo.clickOnView(solo.getView(org.catrobat.catroid.R.id.button_play));
    solo.waitForActivity(StageActivity.class.getSimpleName(), 3000);
    assertEquals(
        "I am in the wrong Activity.", StageActivity.class, solo.getCurrentActivity().getClass());

    synchronized (programStartWaitLock) {
      if (!programHasStarted) {
        programStartWaitLock.wait(10000);
      }
    }
  }
Beispiel #10
0
  @And("^this script has a change '(\\w+)' by (\\d+.?\\d*) brick$")
  public void script_has_change_var_by_val_brick(String name, String value) {
    Sprite object = (Sprite) Cucumber.get(Cucumber.KEY_CURRENT_OBJECT);
    Script script = (Script) Cucumber.get(Cucumber.KEY_CURRENT_SCRIPT);
    Project project = ProjectManager.getInstance().getCurrentProject();

    UserVariable variable = project.getUserVariables().getUserVariable(name, object);
    if (variable == null) {
      variable = project.getUserVariables().addSpriteUserVariableToSprite(object, name);
    }

    FormulaElement elemValue = new FormulaElement(ElementType.NUMBER, value, null);

    Brick brick = new ChangeVariableBrick(new Formula(elemValue), variable);
    script.addBrick(brick);
  }
Beispiel #11
0
  @And("^this script has a set '(\\w+)' to '(\\w+)' brick$")
  public void script_has_set_var_to_var_brick(String a, String b) {
    Sprite object = (Sprite) Cucumber.get(Cucumber.KEY_CURRENT_OBJECT);
    Script script = (Script) Cucumber.get(Cucumber.KEY_CURRENT_SCRIPT);
    Project project = ProjectManager.getInstance().getCurrentProject();

    UserVariable varA = project.getUserVariables().getUserVariable(a, object);
    if (varA == null) {
      varA = project.getUserVariables().addSpriteUserVariableToSprite(object, a);
    }

    FormulaElement elemB = new FormulaElement(ElementType.USER_VARIABLE, b, null);

    Brick brick = new SetVariableBrick(new Formula(elemB), varA);
    script.addBrick(brick);
  }
Beispiel #12
0
 @Given("^this program has an Object '(\\w+)'$")
 public void program_has_object(String name) {
   int lookId = org.catrobat.catroid.R.drawable.default_project_mole_1;
   ProjectManager pm = ProjectManager.getInstance();
   Project project = pm.getCurrentProject();
   Sprite sprite = Util.addNewObjectWithLook(getContext(), project, name, lookId);
   Cucumber.put(Cucumber.KEY_CURRENT_OBJECT, sprite);
 }
Beispiel #13
0
  @Given("^'(\\w+)' has a When '(\\w+)' script$")
  public void object_has_a_when_script(String object, String message) {
    programWaitLockPermits -= 1;
    Project project = ProjectManager.getInstance().getCurrentProject();
    Sprite sprite = Util.findSprite(project, object);
    BroadcastScript script = new BroadcastScript(sprite, message);

    sprite.addScript(script);
    Cucumber.put(Cucumber.KEY_CURRENT_SCRIPT, script);
  }
Beispiel #14
0
  @Then("^the variable '(\\w+)' should be equal (\\d+.?\\d*)$")
  public void var_should_equal_float(String name, float expected) {
    Sprite object = (Sprite) Cucumber.get(Cucumber.KEY_CURRENT_OBJECT);
    Project project = ProjectManager.getInstance().getCurrentProject();

    UserVariable variable = project.getUserVariables().getUserVariable(name, object);
    assertNotNull("The variable does not exist.", variable);

    float actual = variable.getValue().floatValue();
    assertThat("The variable is != the value.", actual, equalTo(expected));
  }