Skip to content

Commit

Permalink
Merge pull request #2945 from 84n4n4/CATROID-43-hotfixApiLevel19Crashes
Browse files Browse the repository at this point in the history
CATROID-43 HOTFIX Api level 19 crashes on brick spinners and formula …
  • Loading branch information
wslany authored Aug 21, 2018
2 parents ebe6723 + d2c674f commit 34b08ce
Show file tree
Hide file tree
Showing 14 changed files with 329 additions and 26 deletions.
4 changes: 2 additions & 2 deletions catroid/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,9 @@ android {
targetSdkVersion 22
applicationId appId
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
versionCode 45
versionCode 46
println "VersionCode is " + versionCode
versionName "0.9.38"
versionName "0.9.40"
println "VersionName is " + versionName
buildConfigField "String", "GIT_DESCRIBE", "\"${versionName}\""
buildConfigField "String", "GIT_CURRENT_BRANCH", "\"${getCurrentGitBranch()}\""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2018 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* An additional term exception under section 7 of the GNU Affero
* General Public License, version 3, is available at
* http://developer.catrobat.org/license_additional_term
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package org.catrobat.catroid.uiespresso.content.brick.app;

import android.support.test.runner.AndroidJUnit4;

import org.catrobat.catroid.R;
import org.catrobat.catroid.content.bricks.ChangeSizeByNBrick;
import org.catrobat.catroid.content.bricks.PlaySoundBrick;
import org.catrobat.catroid.content.bricks.PointToBrick;
import org.catrobat.catroid.content.bricks.SceneStartBrick;
import org.catrobat.catroid.content.bricks.SceneTransitionBrick;
import org.catrobat.catroid.content.bricks.SetLookBrick;
import org.catrobat.catroid.content.bricks.WhenBackgroundChangesBrick;
import org.catrobat.catroid.ui.SpriteActivity;
import org.catrobat.catroid.uiespresso.content.brick.utils.BrickTestUtils;
import org.catrobat.catroid.uiespresso.formulaeditor.utils.FormulaEditorWrapper;
import org.catrobat.catroid.uiespresso.testsuites.Cat;
import org.catrobat.catroid.uiespresso.testsuites.Level;
import org.catrobat.catroid.uiespresso.util.rules.BaseActivityInstrumentationRule;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;

import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withText;

import static org.catrobat.catroid.uiespresso.content.brick.utils.BrickDataInteractionWrapper.onBrickAtPosition;

@RunWith(AndroidJUnit4.class)
public class API19SpinnerAndFormulaFieldCrashesRegressionTest {

@Rule
public BaseActivityInstrumentationRule<SpriteActivity> baseActivityTestRule = new
BaseActivityInstrumentationRule<>(SpriteActivity.class, SpriteActivity.EXTRA_FRAGMENT_POSITION, SpriteActivity.FRAGMENT_SCRIPTS);

@Before
public void setUp() throws Exception {
}

@After
public void tearDown() {
}

@Category({Cat.AppUi.class, Cat.ApiLevel19Regression.class, Level.Smoke.class})
@Test
public void testFormulaFieldBrickRegressionTest() {
BrickTestUtils.createProjectAndGetStartScript("ChangeSizeByNBrick")
.addBrick(new ChangeSizeByNBrick());
baseActivityTestRule.launchActivity();
onBrickAtPosition(1)
.onFormulaTextField(R.id.brick_change_size_by_edit_text)
.perform(click());
onView(FormulaEditorWrapper.FORMULA_EDITOR_KEYBOARD_MATCHER)
.check(matches(isDisplayed()));
}

@Category({Cat.AppUi.class, Cat.ApiLevel19Regression.class, Level.Smoke.class})
@Test
public void testPlaySoundBrickSpinnerRegressionTest() {
BrickTestUtils.createProjectAndGetStartScript("PlaySoundBrick")
.addBrick(new PlaySoundBrick());
baseActivityTestRule.launchActivity();
onBrickAtPosition(1)
.onSpinner(R.id.brick_play_sound_spinner)
.performSelect(R.string.new_broadcast_message);
onView(withText(R.string.new_sound_dialog_title))
.check(matches(isDisplayed()));
}

@Category({Cat.AppUi.class, Cat.ApiLevel19Regression.class, Level.Smoke.class})
@Test
public void testPointToBrickSpinnerRegressionTest() {
BrickTestUtils.createProjectAndGetStartScript("PointToBrick")
.addBrick(new PointToBrick());
baseActivityTestRule.launchActivity();
onBrickAtPosition(1)
.onSpinner(R.id.brick_point_to_spinner)
.performSelect(R.string.new_broadcast_message);
onView(withText(R.string.new_look_dialog_title))
.check(matches(isDisplayed()));
}

@Category({Cat.AppUi.class, Cat.ApiLevel19Regression.class, Level.Smoke.class})
@Test
public void testSceneStartBrickSpinnerRegressionTest() {
BrickTestUtils.createProjectAndGetStartScript("SceneStartBrick")
.addBrick(new SceneStartBrick("Scene 1"));
baseActivityTestRule.launchActivity();
onBrickAtPosition(1)
.onSpinner(R.id.brick_scene_start_spinner)
.performSelect(R.string.new_broadcast_message);
onView(withText(R.string.new_scene_dialog))
.check(matches(isDisplayed()));
}

@Category({Cat.AppUi.class, Cat.ApiLevel19Regression.class, Level.Smoke.class})
@Test
public void testSceneTransitionBrickSpinnerRegressionTest() {
BrickTestUtils.createProjectAndGetStartScript("SceneTransitionBrick")
.addBrick(new SceneTransitionBrick("Scene 1"));
baseActivityTestRule.launchActivity();
onBrickAtPosition(1)
.onSpinner(R.id.brick_scene_transition_spinner)
.performSelect(R.string.new_broadcast_message);
onView(withText(R.string.new_scene_dialog))
.check(matches(isDisplayed()));
}

@Category({Cat.AppUi.class, Cat.ApiLevel19Regression.class, Level.Smoke.class})
@Test
public void testSetLookBrickSpinnerRegressionTest() {
BrickTestUtils.createProjectAndGetStartScript("SetLookBrick")
.addBrick(new SetLookBrick());
baseActivityTestRule.launchActivity();
onBrickAtPosition(1)
.onSpinner(R.id.brick_set_look_spinner)
.performSelect(R.string.new_broadcast_message);
onView(withText(R.string.new_look_dialog_title))
.check(matches(isDisplayed()));
}

@Category({Cat.AppUi.class, Cat.ApiLevel19Regression.class, Level.Smoke.class})
@Test
public void testWhenBackgroundChangesBrickSpinnerRegressionTest() {
BrickTestUtils.createProjectAndGetStartScript("WhenBackgroundChangesBrick")
.addBrick(new WhenBackgroundChangesBrick());
baseActivityTestRule.launchActivity();
onBrickAtPosition(1)
.onSpinner(R.id.brick_when_background_spinner)
.performSelect(R.string.new_broadcast_message);
onView(withText(R.string.new_look_dialog_title))
.check(matches(isDisplayed()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2018 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* An additional term exception under section 7 of the GNU Affero
* General Public License, version 3, is available at
* http://developer.catrobat.org/license_additional_term
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package org.catrobat.catroid.uiespresso.testsuites;

import org.junit.experimental.categories.Categories;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;

@RunWith(Categories.class)
@Categories.IncludeCategory({Cat.ApiLevel19Regression.class})
@Suite.SuiteClasses(AllEspressoTestsSuite.class)
public class ApiLevel19RegressionTestsSuite {
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ interface Network {
interface SensorBox {
}

//Regression tests for Api 19, stuff that just works on higher Apis, but needs special treatment on 19
interface ApiLevel19Regression {
}

//Educational tests that are in place to demonstrate how to test something
interface Educational {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.catrobat.catroid.content.Sprite;
import org.catrobat.catroid.content.actions.ScriptSequenceAction;
import org.catrobat.catroid.content.bricks.brickspinner.SpinnerAdapterWithNewOption;
import org.catrobat.catroid.ui.UiUtils;
import org.catrobat.catroid.ui.recyclerview.dialog.NewSoundDialogFragment;
import org.catrobat.catroid.ui.recyclerview.dialog.dialoginterface.NewItemInterface;

Expand Down Expand Up @@ -125,10 +126,15 @@ private List<String> getSoundNames() {
@Override
public boolean onNewOptionInDropDownClicked(View v) {
spinnerSelectionBuffer = spinner.getSelectedItemPosition();
Activity activity = UiUtils.getActivityFromView(v);
if (activity == null) {
return false;
}

new NewSoundFromBrickSpinnerDialogFragment(this,
ProjectManager.getInstance().getCurrentlyEditedScene(),
ProjectManager.getInstance().getCurrentSprite())
.show(((Activity) v.getContext()).getFragmentManager(), NewSoundDialogFragment.TAG);
.show(activity.getFragmentManager(), NewSoundDialogFragment.TAG);
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.catrobat.catroid.content.Sprite;
import org.catrobat.catroid.content.actions.ScriptSequenceAction;
import org.catrobat.catroid.content.bricks.brickspinner.SpinnerAdapterWithNewOption;
import org.catrobat.catroid.ui.UiUtils;
import org.catrobat.catroid.ui.recyclerview.dialog.NewSpriteDialogWrapper;
import org.catrobat.catroid.ui.recyclerview.dialog.dialoginterface.NewItemInterface;

Expand Down Expand Up @@ -104,14 +105,19 @@ private List<String> getSpriteNames() {
@Override
public boolean onNewOptionInDropDownClicked(View v) {
spinnerSelectionBuffer = spinner.getSelectedItemPosition();
Activity activity = UiUtils.getActivityFromView(v);
if (activity == null) {
return false;
}

new NewSpriteDialogWrapper(this, ProjectManager.getInstance().getCurrentlyEditedScene()) {

@Override
public void onWorkflowCanceled() {
super.onWorkflowCanceled();
spinner.setSelection(spinnerSelectionBuffer);
}
}.showDialog(((Activity) v.getContext()).getFragmentManager());
}.showDialog(activity.getFragmentManager());
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.catrobat.catroid.content.Sprite;
import org.catrobat.catroid.content.actions.ScriptSequenceAction;
import org.catrobat.catroid.content.bricks.brickspinner.SpinnerAdapterWithNewOption;
import org.catrobat.catroid.ui.UiUtils;
import org.catrobat.catroid.ui.recyclerview.dialog.NewSceneDialogFragment;
import org.catrobat.catroid.ui.recyclerview.dialog.dialoginterface.NewItemInterface;

Expand Down Expand Up @@ -103,8 +104,13 @@ public void onNothingSelected(AdapterView<?> parent) {
@Override
public boolean onNewOptionInDropDownClicked(View v) {
spinnerSelectionBuffer = spinner.getSelectedItemPosition();
Activity activity = UiUtils.getActivityFromView(v);
if (activity == null) {
return false;
}

new NewSceneFromBrickDialogFragment(this, ProjectManager.getInstance().getCurrentProject())
.show(((Activity) v.getContext()).getFragmentManager(), NewSceneDialogFragment.TAG);
.show(activity.getFragmentManager(), NewSceneDialogFragment.TAG);
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.catrobat.catroid.content.Sprite;
import org.catrobat.catroid.content.actions.ScriptSequenceAction;
import org.catrobat.catroid.content.bricks.brickspinner.SpinnerAdapterWithNewOption;
import org.catrobat.catroid.ui.UiUtils;
import org.catrobat.catroid.ui.recyclerview.dialog.NewSceneDialogFragment;
import org.catrobat.catroid.ui.recyclerview.dialog.dialoginterface.NewItemInterface;

Expand Down Expand Up @@ -106,8 +107,13 @@ public void onNothingSelected(AdapterView<?> parent) {
@Override
public boolean onNewOptionInDropDownClicked(View v) {
spinnerSelectionBuffer = spinner.getSelectedItemPosition();
Activity activity = UiUtils.getActivityFromView(v);
if (activity == null) {
return false;
}

new NewSceneFromBrickDialogFragment(this, ProjectManager.getInstance().getCurrentProject())
.show(((Activity) v.getContext()).getFragmentManager(), NewSceneDialogFragment.TAG);
.show(activity.getFragmentManager(), NewSceneDialogFragment.TAG);
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.catrobat.catroid.content.Sprite;
import org.catrobat.catroid.content.actions.ScriptSequenceAction;
import org.catrobat.catroid.content.bricks.brickspinner.SpinnerAdapterWithNewOption;
import org.catrobat.catroid.ui.UiUtils;
import org.catrobat.catroid.ui.recyclerview.dialog.NewLookDialogFragment;
import org.catrobat.catroid.ui.recyclerview.dialog.dialoginterface.NewItemInterface;

Expand Down Expand Up @@ -134,10 +135,15 @@ private List<String> getLookNames() {
@Override
public boolean onNewOptionInDropDownClicked(View v) {
spinnerSelectionBuffer = spinner.getSelectedItemPosition();
Activity activity = UiUtils.getActivityFromView(view);
if (activity == null) {
return false;
}

new NewLookFromBrickDialogFragment(this,
ProjectManager.getInstance().getCurrentlyEditedScene(),
getSprite())
.show(((Activity) v.getContext()).getFragmentManager(), NewLookDialogFragment.TAG);
.show(activity.getFragmentManager(), NewLookDialogFragment.TAG);
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.catrobat.catroid.content.WhenBackgroundChangesScript;
import org.catrobat.catroid.content.actions.ScriptSequenceAction;
import org.catrobat.catroid.content.bricks.brickspinner.SpinnerAdapterWithNewOption;
import org.catrobat.catroid.ui.UiUtils;
import org.catrobat.catroid.ui.recyclerview.dialog.NewLookDialogFragment;
import org.catrobat.catroid.ui.recyclerview.dialog.dialoginterface.NewItemInterface;

Expand Down Expand Up @@ -140,10 +141,15 @@ private List<String> getLookNames() {
@Override
public boolean onNewOptionInDropDownClicked(View v) {
previouslySelectedLook = getLook();
Activity activity = UiUtils.getActivityFromView(view);
if (activity == null) {
return false;
}

new NewLookFromBrickDialogFragment(this,
ProjectManager.getInstance().getCurrentlyEditedScene(),
ProjectManager.getInstance().getCurrentSprite())
.show(((Activity) v.getContext()).getFragmentManager(), NewLookDialogFragment.TAG);
.show(activity.getFragmentManager(), NewLookDialogFragment.TAG);
return false;
}

Expand Down
Loading

0 comments on commit 34b08ce

Please sign in to comment.