Skip to content

Commit

Permalink
CATROID-766 Evaluate “when touches actor or object” to false initially
Browse files Browse the repository at this point in the history
  • Loading branch information
moemgva2910 committed Jan 17, 2023
1 parent 6e31477 commit e7328a8
Show file tree
Hide file tree
Showing 132 changed files with 2,654 additions and 1,662 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2021 The Catrobat Team
* Copyright (C) 2010-2022 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -429,6 +429,8 @@ public static Collection<Object[]> data() {
FlashBrick.class,
WriteVariableOnDeviceBrick.class,
ReadVariableFromDeviceBrick.class,
WriteVariableToFileBrick.class,
ReadVariableFromFileBrick.class,
WriteListOnDeviceBrick.class,
ReadListFromDeviceBrick.class,
TapAtBrick.class,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2021 The Catrobat Team
* Copyright (C) 2010-2022 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -37,8 +37,6 @@
import org.catrobat.catroid.content.bricks.PlaceAtBrick;
import org.catrobat.catroid.formulaeditor.UserList;
import org.catrobat.catroid.formulaeditor.UserVariable;
import org.catrobat.catroid.io.ResourceImporter;
import org.catrobat.catroid.io.StorageOperations;
import org.catrobat.catroid.io.XstreamSerializer;
import org.catrobat.catroid.ui.controller.BackpackListManager;
import org.catrobat.catroid.ui.recyclerview.controller.SceneController;
Expand All @@ -52,24 +50,30 @@

import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.platform.app.InstrumentationRegistry;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;

import static org.catrobat.catroid.common.Constants.IMAGE_DIRECTORY_NAME;
import static org.catrobat.catroid.common.Constants.SCREENSHOT_AUTOMATIC_FILE_NAME;
import static org.catrobat.catroid.common.Constants.SCREENSHOT_MANUAL_FILE_NAME;
import static org.catrobat.catroid.common.Constants.SOUND_DIRECTORY_NAME;
import static org.catrobat.catroid.io.ResourceImporter.createImageFileFromResourcesInDirectory;
import static org.catrobat.catroid.io.ResourceImporter.createSoundFileFromResourcesInDirectory;
import static org.catrobat.catroid.io.StorageOperations.deleteDir;
import static org.catrobat.catroid.test.utils.TestUtils.clearBackPack;
import static org.catrobat.catroid.uiespresso.util.FileTestUtils.assertFileDoesNotExist;
import static org.catrobat.catroid.uiespresso.util.FileTestUtils.assertFileExists;

import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;

@RunWith(AndroidJUnit4.class)
public class SceneControllerTest {

private Project project;
private Scene scene;
private BackpackListManager backpackListManager;
private String newName = "new Scene Name";
private final String newName = "new Scene Name";

@Before
public void setUp() throws IOException {
Expand Down Expand Up @@ -107,27 +111,35 @@ public void testCopyScene() throws IOException {
assertEquals(scene.getSpriteList().size(), copy.getSpriteList().size());

for (int i = 0; i < copy.getSpriteList().size(); i++) {
assertEquals(
scene.getSpriteList().get(i).getLookList().size(),
copy.getSpriteList().get(i).getLookList().size());

assertEquals(
scene.getSpriteList().get(i).getSoundList().size(),
copy.getSpriteList().get(i).getSoundList().size());

assertEquals(
scene.getSpriteList().get(i).getNumberOfScripts(),
copy.getSpriteList().get(i).getNumberOfScripts());

assertEquals(
scene.getSpriteList().get(i).getNumberOfBricks(),
copy.getSpriteList().get(i).getNumberOfBricks());
assertEquals(scene.getSpriteList().get(i).getLookList().size(), copy.getSpriteList().get(i).getLookList().size());
assertEquals(scene.getSpriteList().get(i).getSoundList().size(), copy.getSpriteList().get(i).getSoundList().size());
assertEquals(scene.getSpriteList().get(i).getNumberOfScripts(), copy.getSpriteList().get(i).getNumberOfScripts());
assertEquals(scene.getSpriteList().get(i).getNumberOfBricks(), copy.getSpriteList().get(i).getNumberOfBricks());
}

assertScreenshotFileExistsInScene(SCREENSHOT_AUTOMATIC_FILE_NAME, copy);
assertLookFileExistsInScene(copy.getSpriteList().get(1).getLookList().get(0).getFile().getName(), copy);
assertSoundFileExistsInScene(copy.getSpriteList().get(1).getSoundList().get(0).getFile().getName(), copy);
}

@Test
public void testCopySceneWithManualScreenshot() throws IOException {
createImageFileFromResourcesInDirectory(
getInstrumentation().getContext().getResources(),
org.catrobat.catroid.test.R.raw.icon,
new File(scene.getDirectory().getPath()),
SCREENSHOT_MANUAL_FILE_NAME,
1);

XstreamSerializer.getInstance().saveProject(project);

SceneController controller = new SceneController();
Scene copy = controller.copy(scene, project);

assertScreenshotFileExistsInScene(SCREENSHOT_MANUAL_FILE_NAME, copy);
assertFileDoesNotExist(new File(copy.getDirectory(), SCREENSHOT_AUTOMATIC_FILE_NAME));
}

@Test
public void testDeleteScene() throws IOException {
SceneController controller = new SceneController();
Expand Down Expand Up @@ -160,37 +172,21 @@ public void testPackScene() throws IOException {

assertEquals(0, BackpackListManager.getInstance().getScenes().size());

assertEquals(new File(backpackListManager.backpackSceneDirectory, packedScene.getName()),
packedScene.getDirectory());
assertEquals(new File(backpackListManager.backpackSceneDirectory, packedScene.getName()), packedScene.getDirectory());
assertFileExists(packedScene.getDirectory());

assertEquals(scene.getSpriteList().size(), packedScene.getSpriteList().size());

for (int i = 0; i < packedScene.getSpriteList().size(); i++) {
assertEquals(
scene.getSpriteList().get(i).getLookList().size(),
packedScene.getSpriteList().get(i).getLookList().size());

assertEquals(
scene.getSpriteList().get(i).getSoundList().size(),
packedScene.getSpriteList().get(i).getSoundList().size());

assertEquals(
scene.getSpriteList().get(i).getNumberOfScripts(),
packedScene.getSpriteList().get(i).getNumberOfScripts());

assertEquals(
scene.getSpriteList().get(i).getNumberOfBricks(),
packedScene.getSpriteList().get(i).getNumberOfBricks());
assertEquals(scene.getSpriteList().get(i).getLookList().size(), packedScene.getSpriteList().get(i).getLookList().size());
assertEquals(scene.getSpriteList().get(i).getSoundList().size(), packedScene.getSpriteList().get(i).getSoundList().size());
assertEquals(scene.getSpriteList().get(i).getNumberOfScripts(), packedScene.getSpriteList().get(i).getNumberOfScripts());
assertEquals(scene.getSpriteList().get(i).getNumberOfBricks(), packedScene.getSpriteList().get(i).getNumberOfBricks());
}

assertLookFileExistsInScene(
packedScene.getSpriteList().get(1).getLookList().get(0).getFile().getName(),
packedScene);

assertSoundFileExistsInScene(
packedScene.getSpriteList().get(1).getSoundList().get(0).getFile().getName(),
packedScene);
assertScreenshotFileExistsInScene(SCREENSHOT_AUTOMATIC_FILE_NAME, packedScene);
assertLookFileExistsInScene(packedScene.getSpriteList().get(1).getLookList().get(0).getFile().getName(), packedScene);
assertSoundFileExistsInScene(packedScene.getSpriteList().get(1).getSoundList().get(0).getFile().getName(), packedScene);
}

@Test
Expand All @@ -207,30 +203,19 @@ public void testUnpackScene() throws IOException {
assertEquals(scene.getSpriteList().size(), unpackedScene.getSpriteList().size());

for (int i = 0; i < unpackedScene.getSpriteList().size(); i++) {
assertEquals(
scene.getSpriteList().get(i).getLookList().size(),
unpackedScene.getSpriteList().get(i).getLookList().size());

assertEquals(
scene.getSpriteList().get(i).getSoundList().size(),
unpackedScene.getSpriteList().get(i).getSoundList().size());

assertEquals(
scene.getSpriteList().get(i).getNumberOfScripts(),
unpackedScene.getSpriteList().get(i).getNumberOfScripts());

assertEquals(
scene.getSpriteList().get(i).getNumberOfBricks(),
unpackedScene.getSpriteList().get(i).getNumberOfBricks());
assertEquals(scene.getSpriteList().get(i).getLookList().size(), unpackedScene.getSpriteList().get(i).getLookList().size());
assertEquals(scene.getSpriteList().get(i).getSoundList().size(), unpackedScene.getSpriteList().get(i).getSoundList().size());
assertEquals(scene.getSpriteList().get(i).getNumberOfScripts(), unpackedScene.getSpriteList().get(i).getNumberOfScripts());
assertEquals(scene.getSpriteList().get(i).getNumberOfBricks(), unpackedScene.getSpriteList().get(i).getNumberOfBricks());
}

assertLookFileExistsInScene(
unpackedScene.getSpriteList().get(1).getLookList().get(0).getFile().getName(),
unpackedScene);
assertScreenshotFileExistsInScene(SCREENSHOT_AUTOMATIC_FILE_NAME, unpackedScene);
assertLookFileExistsInScene(unpackedScene.getSpriteList().get(1).getLookList().get(0).getFile().getName(), unpackedScene);
assertSoundFileExistsInScene(unpackedScene.getSpriteList().get(1).getSoundList().get(0).getFile().getName(), unpackedScene);
}

assertSoundFileExistsInScene(
unpackedScene.getSpriteList().get(1).getSoundList().get(0).getFile().getName(),
unpackedScene);
private void assertScreenshotFileExistsInScene(String fileName, Scene scene) {
assertFileExists(new File(scene.getDirectory(), fileName));
}

private void assertLookFileExistsInScene(String fileName, Scene scene) {
Expand Down Expand Up @@ -264,17 +249,24 @@ private void createProject() throws IOException {

XstreamSerializer.getInstance().saveProject(project);

File imageFile = ResourceImporter.createImageFileFromResourcesInDirectory(
InstrumentationRegistry.getInstrumentation().getContext().getResources(),
createImageFileFromResourcesInDirectory(
getInstrumentation().getContext().getResources(),
org.catrobat.catroid.test.R.raw.icon,
new File(scene.getDirectory().getPath()),
SCREENSHOT_AUTOMATIC_FILE_NAME,
1);

File imageFile = createImageFileFromResourcesInDirectory(
getInstrumentation().getContext().getResources(),
org.catrobat.catroid.test.R.raw.red_image,
new File(project.getDefaultScene().getDirectory(), IMAGE_DIRECTORY_NAME),
"red_image.png",
1);

sprite.getLookList().add(new LookData("testLook", imageFile));

File soundFile = ResourceImporter.createSoundFileFromResourcesInDirectory(
InstrumentationRegistry.getInstrumentation().getContext().getResources(),
File soundFile = createSoundFileFromResourcesInDirectory(
getInstrumentation().getContext().getResources(),
org.catrobat.catroid.test.R.raw.longsound,
new File(project.getDefaultScene().getDirectory(), SOUND_DIRECTORY_NAME),
"longsound.mp3");
Expand All @@ -286,7 +278,7 @@ private void createProject() throws IOException {

private void deleteProject() throws IOException {
if (project.getDirectory().exists()) {
StorageOperations.deleteDir(project.getDirectory());
deleteDir(project.getDirectory());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
import static org.catrobat.catroid.common.Constants.SOUND_DIRECTORY_NAME;
import static org.catrobat.catroid.uiespresso.content.brick.utils.BrickDataInteractionWrapper.onBrickAtPosition;
import static org.catrobat.catroid.uiespresso.ui.fragment.rvutils.RecyclerViewInteractionWrapper.onRecyclerView;
import static org.catrobat.catroid.uiespresso.util.UiTestUtils.openActionBar;
import static org.catrobat.catroid.uiespresso.util.UiTestUtils.openActionBarMenu;
import static org.catrobat.catroid.uiespresso.util.actions.TabActionsKt.selectTabAtPosition;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.instanceOf;
Expand Down Expand Up @@ -187,7 +187,7 @@ public void testPlaySoundBrickUpdateRename() {
private void deleteSound(int position) {
onView(withId(R.id.tab_layout))
.perform(selectTabAtPosition(SpriteActivity.FRAGMENT_SOUNDS));
openActionBar();
openActionBarMenu();
onView(withText(R.string.delete))
.perform(click());
onRecyclerView().atPosition(position)
Expand All @@ -207,7 +207,7 @@ private void deleteSound(int position) {
private void renameSound(int position, String oldName, String newName) {
onView(withId(R.id.tab_layout))
.perform(selectTabAtPosition(SpriteActivity.FRAGMENT_SOUNDS));
openActionBar();
openActionBarMenu();
onView(withText(R.string.rename))
.perform(click());
onRecyclerView().atPosition(position)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
import static org.catrobat.catroid.uiespresso.content.brick.utils.BrickDataInteractionWrapper.onBrickAtPosition;
import static org.catrobat.catroid.uiespresso.ui.fragment.rvutils.RecyclerViewInteractionWrapper.onRecyclerView;
import static org.catrobat.catroid.uiespresso.util.UiTestUtils.getResourcesString;
import static org.catrobat.catroid.uiespresso.util.UiTestUtils.openActionBar;
import static org.catrobat.catroid.uiespresso.util.UiTestUtils.openActionBarMenu;
import static org.catrobat.catroid.uiespresso.util.actions.TabActionsKt.selectTabAtPosition;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.instanceOf;
Expand Down Expand Up @@ -99,7 +99,7 @@ public void setUp() throws Exception {
private void renameSound(int position, String newSoundName) {
onView(withId(R.id.tab_layout))
.perform(selectTabAtPosition(SpriteActivity.FRAGMENT_SOUNDS));
openActionBar();
openActionBarMenu();
onView(withText(R.string.rename))
.perform(click());
onRecyclerView().atPosition(position)
Expand All @@ -114,7 +114,7 @@ private void renameSound(int position, String newSoundName) {
private void deleteSound(int position) {
onView(withId(R.id.tab_layout))
.perform(selectTabAtPosition(SpriteActivity.FRAGMENT_SOUNDS));
openActionBar();
openActionBarMenu();
onView(withText(R.string.delete))
.perform(click());
onRecyclerView().atPosition(position)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void performSelect() {
}

public void performDelete() {
onChildView(R.id.settingsButton)
onChildView(R.id.settings_button)
.perform(click());
onView(withText(R.string.delete))
.perform(click());
Expand All @@ -57,7 +57,7 @@ public void performDelete() {
}

public void performRename(String newName) {
onChildView(R.id.settingsButton)
onChildView(R.id.settings_button)
.perform(click());
onView(withText(R.string.rename))
.perform(click());
Expand All @@ -68,7 +68,7 @@ public void performRename(String newName) {
}

public void performEdit(String newValue) {
onChildView(R.id.settingsButton)
onChildView(R.id.settings_button)
.perform(click());
onView(withText(R.string.edit))
.perform(click());
Expand Down
Loading

0 comments on commit e7328a8

Please sign in to comment.