Skip to content

Commit

Permalink
Revert "removed UI tests for better building"
Browse files Browse the repository at this point in the history
This reverts commit 93c7493.
  • Loading branch information
goschale committed Jun 23, 2022
1 parent 4068ddc commit 205af86
Show file tree
Hide file tree
Showing 66 changed files with 10,939 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ pipeline {
always {
sh './gradlew stopEmulator'
junitAndCoverage "$reports/coverage/debug/report.xml", 'device', javaSrc
archiveArtifacts 'app/build/outputs/logs/logcat.text'
archiveArtifacts 'app/build/outputs/logcat.text'
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Paintroid: An image manipulation application for Android.
* Copyright (C) 2010-2015 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.
*
* 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.paintroid.test.espresso;

import android.util.DisplayMetrics;

import org.catrobat.paintroid.MainActivity;
import org.catrobat.paintroid.test.utils.ScreenshotOnFailRule;
import org.catrobat.paintroid.tools.ToolType;
import org.catrobat.paintroid.tools.Workspace;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.rule.ActivityTestRule;

import static org.catrobat.paintroid.test.espresso.util.wrappers.ToolBarViewInteraction.onToolBarView;
import static org.junit.Assert.assertEquals;

@RunWith(AndroidJUnit4.class)
public class BitmapIntegrationTest {
@Rule
public ActivityTestRule<MainActivity> launchActivityRule = new ActivityTestRule<>(MainActivity.class);

@Rule
public ScreenshotOnFailRule screenshotOnFailRule = new ScreenshotOnFailRule();

@Before
public void setUp() {
onToolBarView()
.performSelectTool(ToolType.BRUSH);
}

@Test
public void drawingSurfaceBitmapIsDisplaySize() {
MainActivity activity = launchActivityRule.getActivity();
Workspace workspace = activity.workspace;
final int bitmapWidth = workspace.getWidth();
final int bitmapHeight = workspace.getHeight();

DisplayMetrics metrics = activity.getResources().getDisplayMetrics();
assertEquals(metrics.widthPixels, bitmapWidth);
assertEquals(metrics.heightPixels, bitmapHeight);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* Paintroid: An image manipulation application for Android.
* Copyright (C) 2010-2021 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.
*
* 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.paintroid.test.espresso

import android.net.Uri
import androidx.test.espresso.Espresso
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.action.ViewActions.replaceText
import androidx.test.espresso.matcher.RootMatchers
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.rule.ActivityTestRule
import androidx.test.rule.GrantPermissionRule
import org.catrobat.paintroid.FileIO
import org.catrobat.paintroid.MainActivity
import org.catrobat.paintroid.R
import org.catrobat.paintroid.test.espresso.util.DrawingSurfaceLocationProvider
import org.catrobat.paintroid.test.espresso.util.EspressoUtils
import org.catrobat.paintroid.test.espresso.util.UiInteractions
import org.catrobat.paintroid.test.espresso.util.wrappers.DrawingSurfaceInteraction.onDrawingSurfaceView
import org.catrobat.paintroid.test.espresso.util.wrappers.TopBarViewInteraction
import org.catrobat.paintroid.test.utils.ScreenshotOnFailRule
import org.hamcrest.Matchers
import org.hamcrest.core.AllOf
import org.junit.After
import org.junit.Assert
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import java.io.File

@RunWith(AndroidJUnit4::class)
class CatrobatImageIOIntegrationTest {

@get:Rule
val launchActivityRule = ActivityTestRule(MainActivity::class.java)

@get:Rule
val screenshotOnFailRule = ScreenshotOnFailRule()

@get:Rule
val grantPermissionRule: GrantPermissionRule = EspressoUtils.grantPermissionRulesVersionCheck()

private lateinit var uriFile: Uri
private lateinit var activity: MainActivity

companion object {
private const val IMAGE_NAME = "fileName"
}
@Before
fun setUp() {
activity = launchActivityRule.activity
}

@After
fun tearDown() {
with(File(uriFile.path!!)) {
if (exists()) {
delete()
}
}
}

@Test
fun testWriteAndReadCatrobatImage() {
onDrawingSurfaceView()
.perform(UiInteractions.touchAt(DrawingSurfaceLocationProvider.MIDDLE))
TopBarViewInteraction.onTopBarView()
.performOpenMoreOptions()
onView(withText(R.string.menu_save_image))
.perform(ViewActions.click())
onView(withId(R.id.pocketpaint_save_dialog_spinner))
.perform(ViewActions.click())
Espresso.onData(
AllOf.allOf(
Matchers.`is`(Matchers.instanceOf<Any>(String::class.java)),
Matchers.`is`<String>(FileIO.FileType.CATROBAT.value)
)
).inRoot(RootMatchers.isPlatformPopup()).perform(ViewActions.click())
onView(withId(R.id.pocketpaint_image_name_save_text))
.perform(replaceText(IMAGE_NAME))
onView(withText(R.string.save_button_text)).perform(ViewActions.click())
uriFile = activity.model.savedPictureUri!!
Assert.assertNotNull(uriFile)
Assert.assertNotNull(activity.workspace.getCommandSerializationHelper().readFromFile(uriFile))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
package org.catrobat.paintroid.test.espresso;

import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.util.Log;

import org.catrobat.paintroid.FileIO;
import org.catrobat.paintroid.MainActivity;
import org.catrobat.paintroid.test.espresso.util.EspressoUtils;
import org.catrobat.paintroid.test.utils.ScreenshotOnFailRule;
import org.catrobat.paintroid.tools.ToolType;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;

import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Objects;

import androidx.test.rule.ActivityTestRule;
import androidx.test.rule.GrantPermissionRule;

import static org.catrobat.paintroid.test.espresso.util.wrappers.ToolBarViewInteraction.onToolBarView;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

public class FileFromOtherSourceIntegrationTest {

private static ArrayList<File> deletionFileList = null;

@Rule
public ActivityTestRule<MainActivity> launchActivityRule = new ActivityTestRule<>(MainActivity.class);

@Rule
public ScreenshotOnFailRule screenshotOnFailRule = new ScreenshotOnFailRule();

@ClassRule
public static GrantPermissionRule grantPermissionRule = EspressoUtils.grantPermissionRulesVersionCheck();

private ContentResolver resolver;
private MainActivity activity;

@Before
public void setUp() {
onToolBarView().performSelectTool(ToolType.BRUSH);
deletionFileList = new ArrayList<>();
activity = launchActivityRule.getActivity();
resolver = launchActivityRule.getActivity().getContentResolver();
}

@Test
public void testGetSharedPictureFromOtherApp() {
Intent intent = new Intent();
Uri receivedUri = createTestImageFile();
Bitmap receivedBitmap = null;

try {
receivedBitmap = FileIO.getBitmapFromUri(resolver, receivedUri, activity);
} catch (Exception e) {
Log.e("Can't read", "Can't get Bitmap from File");
}

Objects.requireNonNull(receivedBitmap);
intent.setData(receivedUri);
intent.setType("image/png");
intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_STREAM, receivedUri);

launchActivityRule.launchActivity(intent);
Intent mainActivityIntent = launchActivityRule.getActivity().getIntent();

String intentAction = intent.getAction();
String intentType = intent.getType();
Bundle intentBundle = intent.getExtras();
Objects.requireNonNull(intentBundle);
Uri intentUri = (Uri) intentBundle.get(Intent.EXTRA_STREAM);

String mainActivityIntentAction = mainActivityIntent.getAction();
String mainActivityIntentType = mainActivityIntent.getType();
Bundle mainActivityIntentBundle = mainActivityIntent.getExtras();
Objects.requireNonNull(mainActivityIntentBundle);
Uri mainActivityIntentUri = (Uri) mainActivityIntentBundle.get(Intent.EXTRA_STREAM);
Bitmap mainActivityIntentBitmap = null;
Objects.requireNonNull(mainActivityIntentUri);

try {
mainActivityIntentBitmap = FileIO.getBitmapFromUri(resolver, mainActivityIntentUri, activity);
} catch (Exception e) {
Log.e("Can't read", "Can't get Bitmap from File");
}

Objects.requireNonNull(mainActivityIntentBitmap);

assertEquals(intentAction, mainActivityIntentAction);
assertEquals(intentType, mainActivityIntentType);
assertEquals(intentUri, mainActivityIntentUri);
assertEquals(receivedBitmap.getWidth(), mainActivityIntentBitmap.getWidth());
assertEquals(receivedBitmap.getHeight(), mainActivityIntentBitmap.getHeight());
}

@After
public void tearDown() {
for (File file : deletionFileList) {
if (file != null && file.exists()) {
assertTrue(file.delete());
}
}
}

private Uri createTestImageFile() {
Bitmap bitmap = Bitmap.createBitmap(400, 400, Bitmap.Config.ARGB_8888);

ContentValues contentValues = new ContentValues();
contentValues.put(MediaStore.Images.Media.DISPLAY_NAME, "testfile.jpg");
contentValues.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
contentValues.put(MediaStore.Images.Media.RELATIVE_PATH, Environment.DIRECTORY_PICTURES);
}

Uri imageUri = resolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues);

try {
OutputStream fos = resolver.openOutputStream(Objects.requireNonNull(imageUri));
assertTrue(bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos));
assert fos != null;
fos.close();
} catch (IOException e) {
throw new AssertionError("Picture file could not be created.", e);
}

File imageFile = new File(imageUri.getPath(), "testfile.jpg");
deletionFileList.add(imageFile);

return imageUri;
}
}
Loading

0 comments on commit 205af86

Please sign in to comment.