Skip to content

Commit

Permalink
Updates and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
comodoro committed Jan 8, 2019
1 parent 2fcd469 commit 0427d29
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 200 deletions.
16 changes: 8 additions & 8 deletions app/build.gradle
Expand Up @@ -51,14 +51,14 @@ android {

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
androidTestImplementation 'androidx.test:runner:1.1.0'
androidTestUtil 'androidx.test:orchestrator:1.1.0'
androidTestImplementation 'androidx.test:core:1.0.0';
androidTestImplementation 'androidx.test.ext:junit:1.0.0'
androidTestImplementation 'androidx.test:runner:1.1.0'
androidTestImplementation 'androidx.test:rules:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.1.0'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestUtil 'androidx.test:orchestrator:1.1.1'
androidTestImplementation 'androidx.test:core:1.1.0';
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test:rules:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.1.1'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.google.code.gson:gson:2.8.5'
testImplementation 'junit:junit:4.12'
Expand Down
71 changes: 32 additions & 39 deletions app/src/androidTest/java/com/draabek/fractal/GLGesturesTest.java
Expand Up @@ -4,35 +4,16 @@
import android.Manifest;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.SystemClock;
import android.support.test.espresso.DataInteraction;
import android.support.test.espresso.NoMatchingViewException;
import android.support.test.espresso.ViewAction;
import android.support.test.espresso.ViewInteraction;
import android.support.test.espresso.action.GeneralLocation;
import android.support.test.espresso.action.GeneralSwipeAction;
import android.support.test.espresso.action.Press;
import android.support.test.espresso.action.Swipe;
import android.support.test.rule.ActivityTestRule;
import android.support.test.rule.GrantPermissionRule;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;

import com.draabek.fractal.activity.MainActivity;
import com.draabek.fractal.fractal.FractalRegistry;

import junit.framework.AssertionFailedError;

import org.hamcrest.CoreMatchers;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.hamcrest.TypeSafeMatcher;
import org.hamcrest.core.IsNot;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Rule;
Expand All @@ -43,23 +24,31 @@
import java.io.IOException;
import java.nio.IntBuffer;

import static android.os.Environment.DIRECTORY_PICTURES;
import static android.os.Environment.getExternalStoragePublicDirectory;
import static android.support.test.InstrumentationRegistry.getInstrumentation;
import static android.support.test.espresso.Espresso.onData;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.action.ViewActions.closeSoftKeyboard;
import static android.support.test.espresso.action.ViewActions.replaceText;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withClassName;
import static android.support.test.espresso.matcher.ViewMatchers.withContentDescription;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.allOf;
import androidx.test.espresso.DataInteraction;
import androidx.test.espresso.NoMatchingViewException;
import androidx.test.espresso.ViewAction;
import androidx.test.espresso.ViewInteraction;
import androidx.test.espresso.action.GeneralLocation;
import androidx.test.espresso.action.GeneralSwipeAction;
import androidx.test.espresso.action.Press;
import androidx.test.espresso.action.Swipe;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.LargeTest;
import androidx.test.rule.ActivityTestRule;
import androidx.test.rule.GrantPermissionRule;

import static androidx.test.espresso.Espresso.onData;
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.action.ViewActions.closeSoftKeyboard;
import static androidx.test.espresso.action.ViewActions.replaceText;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.withClassName;
import static androidx.test.espresso.matcher.ViewMatchers.withContentDescription;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.CoreMatchers.allOf;
import static org.hamcrest.Matchers.anything;
import static org.hamcrest.Matchers.is;
//FIXME
Expand Down Expand Up @@ -120,26 +109,30 @@ public void gLGesturesTest() throws IOException {
waitForRender();
int[] buffer1 = saveBuffer();

float centerY = FractalRegistry.getInstance().getCurrent().getParameters().get("centerY");
ViewInteraction fractalView = onView(
allOf(withId(R.id.fractalGlView), isDisplayed()));

fractalView.perform(swipeDown());
waitForRender();
float centerY2 = FractalRegistry.getInstance().getCurrent().getParameters().get("centerY");
int[] buffer2 = saveBuffer();

Assert.assertEquals(buffer1.length, buffer2.length);
double diff = cumulativeDifference(buffer1, buffer2);
Assert.assertEquals(true, diff > 1);
Assert.assertTrue(diff > 1);
fractalView = onView(
allOf(withId(R.id.fractalGlView), isDisplayed()));
fractalView.perform(swipeUp());
waitForRender();
float newCenterY = FractalRegistry.getInstance().getCurrent().getParameters().get("centerY");
Assert.assertTrue(Math.abs(centerY - centerY2) > Math.abs(centerY - newCenterY));
int[] buffer3 = saveBuffer();
Assert.assertEquals(buffer1.length, buffer3.length);
// TODO Increase precision to be actually relevant
// This just asserts that Original difference is bigger than current difference
double diff2 = cumulativeDifference(buffer1, buffer3);
Assert.assertEquals(0, diff2, diff);
// Assert.assertEquals(0, diff2, diff);
}


Expand Down
@@ -1,14 +1,6 @@
package com.draabek.fractal.activity;


import android.app.Activity;
import android.support.test.espresso.DataInteraction;
import android.support.test.espresso.ViewInteraction;
import android.support.test.espresso.intent.Intents;
import android.support.test.espresso.intent.rule.IntentsTestRule;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
Expand All @@ -22,21 +14,21 @@
import org.junit.Test;
import org.junit.runner.RunWith;

import static android.support.test.espresso.Espresso.onData;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.Espresso.pressBack;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.action.ViewActions.closeSoftKeyboard;
import static android.support.test.espresso.action.ViewActions.replaceText;
import static android.support.test.espresso.intent.Intents.intended;
import static android.support.test.espresso.intent.matcher.IntentMatchers.hasComponent;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withClassName;
import static android.support.test.espresso.matcher.ViewMatchers.withContentDescription;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import androidx.test.espresso.ViewInteraction;
import androidx.test.espresso.intent.rule.IntentsTestRule;
import androidx.test.filters.LargeTest;
import androidx.test.runner.AndroidJUnit4;

import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.Espresso.pressBack;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.intent.Intents.intended;
import static androidx.test.espresso.intent.matcher.IntentMatchers.hasComponent;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.withClassName;
import static androidx.test.espresso.matcher.ViewMatchers.withContentDescription;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.anything;
import static org.hamcrest.Matchers.is;

@LargeTest
Expand All @@ -47,8 +39,7 @@ public class ClickToolbarTest {
public IntentsTestRule<MainActivity> mActivityTestRule = new IntentsTestRule<>(MainActivity.class);

@Test
public void clickToolbarTest() {

public void clickToolbarTest1() {
ViewInteraction actionMenuItemView = onView(
allOf(withId(R.id.fractalList), withContentDescription("Fractal List"),
childAtPosition(
Expand All @@ -61,77 +52,21 @@ public void clickToolbarTest() {

intended(hasComponent(FractalListActivity.class.getName()));

DataInteraction relativeLayout = onData(anything())
.inAdapterView(allOf(withId(android.R.id.list),
childAtPosition(
withId(android.R.id.content),
0)))
.atPosition(0);
relativeLayout.perform(click());

DataInteraction relativeLayout2 = onData(anything())
.inAdapterView(allOf(withId(android.R.id.list),
childAtPosition(
withId(android.R.id.content),
0)))
.atPosition(0);
relativeLayout2.perform(click());

intended(hasComponent(MainActivity.class.getName()));
pressBack();

ViewInteraction actionMenuItemView2 = onView(
allOf(withId(R.id.save), withContentDescription("Save as JPG"),
childAtPosition(
childAtPosition(
withId(R.id.toolbar),
withClassName(is("android.support.v7.widget.Toolbar")),
0),
1),
isDisplayed()));
actionMenuItemView2.perform(click());

intended(hasComponent(SaveBitmapActivity.class.getName()));

ViewInteraction appCompatEditText = onView(
allOf(withId(R.id.bitmap_filename),
childAtPosition(
allOf(withId(R.id.save_bitmap_radio_group),
childAtPosition(
withClassName(is("android.widget.LinearLayout")),
0)),
1),
isDisplayed()));

ViewInteraction appCompatRadioButton = onView(
allOf(withId(R.id.bitmap_filename_radio), withText("Save as file"),
childAtPosition(
allOf(withId(R.id.save_bitmap_radio_group),
childAtPosition(
withClassName(is("android.widget.LinearLayout")),
0)),
0),
isDisplayed()));
appCompatRadioButton.perform(click());

ViewInteraction appCompatEditText2 = onView(
allOf(withId(R.id.bitmap_filename),
childAtPosition(
allOf(withId(R.id.save_bitmap_radio_group),
childAtPosition(
withClassName(is("android.widget.LinearLayout")),
0)),
1),
isDisplayed()));
appCompatEditText2.perform(click());

ViewInteraction appCompatButton = onView(
allOf(withId(R.id.save_bitmap_ok_button), withText("OK"),
childAtPosition(
childAtPosition(
withId(android.R.id.content),
0),
1),
isDisplayed()));
appCompatButton.perform(click());
pressBack();

ViewInteraction actionMenuItemView3 = onView(
allOf(withId(R.id.parameters), withContentDescription("Fractal parameters"),
Expand All @@ -145,16 +80,7 @@ public void clickToolbarTest() {

intended(hasComponent(FractalParametersActivity.class.getName()));

ViewInteraction button = onView(
allOf(withText("OK"),
childAtPosition(
allOf(withId(R.id.layout_parameters),
childAtPosition(
withId(android.R.id.content),
0)),
9),
isDisplayed()));
button.perform(click());
pressBack();

ViewInteraction actionMenuItemView4 = onView(
allOf(withId(R.id.options), withContentDescription("Options"),
Expand All @@ -169,9 +95,6 @@ public void clickToolbarTest() {
intended(hasComponent(FractalPreferenceActivity.class.getName()));

pressBack();

intended(hasComponent(MainActivity.class.getName()));

}

private static Matcher<View> childAtPosition(
Expand Down

0 comments on commit 0427d29

Please sign in to comment.