/* * Catroid: An on-device visual programming system for Android devices * Copyright (C) 2010-2016 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.uitest.content.brick.physics; import android.test.ActivityInstrumentationTestCase2; import android.test.suitebuilder.annotation.Smoke; import android.widget.ListView; import com.robotium.solo.Solo; import org.catrobat.catroid.ProjectManager; import org.catrobat.catroid.R; import org.catrobat.catroid.content.Project; import org.catrobat.catroid.content.Script; import org.catrobat.catroid.content.SingleSprite; import org.catrobat.catroid.content.Sprite; import org.catrobat.catroid.content.StartScript; import org.catrobat.catroid.content.bricks.Brick; import org.catrobat.catroid.physics.PhysicsObject; import org.catrobat.catroid.physics.content.bricks.SetMassBrick; import org.catrobat.catroid.ui.ScriptActivity; import org.catrobat.catroid.ui.adapter.BrickAdapter; import org.catrobat.catroid.uitest.util.UiTestUtils; import java.util.ArrayList; public class SetMassBrickTest extends ActivityInstrumentationTestCase2<ScriptActivity> { private Solo solo; private Project project; private SetMassBrick setMassBrick; public SetMassBrickTest() { super(ScriptActivity.class); } @Override public void setUp() throws Exception { createProject(); solo = new Solo(getInstrumentation(), getActivity()); } @Override public void tearDown() throws Exception { UiTestUtils.goBackToHome(getInstrumentation()); solo.finishOpenedActivities(); UiTestUtils.clearAllUtilTestProjects(); super.tearDown(); solo = null; } @Smoke public void testSetMassByBrick() { this.checkSetup(); float mass = 1.234f; UiTestUtils.testBrickWithFormulaEditor(solo, ProjectManager.getInstance().getCurrentSprite(), R.id.brick_set_mass_edit_text, mass, Brick.BrickField.PHYSICS_GRAVITY_X.PHYSICS_MASS, setMassBrick); } @Smoke public void testSetInvalidMassValues() { this.checkSetup(); float[] masses = { -1.0f, 0.0f, PhysicsObject.MIN_MASS / 10.0f, PhysicsObject.MIN_MASS / 1.1f }; for (float mass : masses) { UiTestUtils.testBrickWithFormulaEditor(solo, ProjectManager.getInstance().getCurrentSprite(), R.id.brick_set_mass_edit_text, mass, Brick.BrickField.PHYSICS_MASS, setMassBrick); } } private void checkSetup() { 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.getDefaultScene().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)); String textSetMass = solo.getString(R.string.brick_set_mass); assertNotNull("TextView does not exist.", solo.getText(textSetMass)); } private void createProject() { project = new Project(null, UiTestUtils.DEFAULT_TEST_PROJECT_NAME); Sprite sprite = new SingleSprite("cat"); Script script = new StartScript(); setMassBrick = new SetMassBrick(0.0f); script.addBrick(setMassBrick); sprite.addScript(script); project.getDefaultScene().addSprite(sprite); ProjectManager.getInstance().setProject(project); ProjectManager.getInstance().setCurrentSprite(sprite); ProjectManager.getInstance().setCurrentScript(script); } }