From b9d34b55e2281ca151e187d67b1d546cfad0c6dd Mon Sep 17 00:00:00 2001 From: Antonio Zugaldia Date: Mon, 14 Sep 2015 12:45:59 -0400 Subject: [PATCH 01/35] #2317 - README to set up and run Espresso testing --- android/java/MapboxGLAndroidSDKTestApp/README.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 android/java/MapboxGLAndroidSDKTestApp/README.md diff --git a/android/java/MapboxGLAndroidSDKTestApp/README.md b/android/java/MapboxGLAndroidSDKTestApp/README.md new file mode 100644 index 000000000..007a8b1d4 --- /dev/null +++ b/android/java/MapboxGLAndroidSDKTestApp/README.md @@ -0,0 +1,5 @@ +# Mapbox GL Test App + +## Testing + +TBD. From 4a11c312757fecf8609b858b54c58f4c2fe24b33 Mon Sep 17 00:00:00 2001 From: Antonio Zugaldia Date: Mon, 14 Sep 2015 12:51:40 -0400 Subject: [PATCH 02/35] #2317 - added testing dependencies --- android/java/MapboxGLAndroidSDKTestApp/build.gradle | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/android/java/MapboxGLAndroidSDKTestApp/build.gradle b/android/java/MapboxGLAndroidSDKTestApp/build.gradle index 46c95c21e..d39fdfbbe 100644 --- a/android/java/MapboxGLAndroidSDKTestApp/build.gradle +++ b/android/java/MapboxGLAndroidSDKTestApp/build.gradle @@ -78,6 +78,11 @@ dependencies { compile 'com.android.support:support-v4:22.1.1' compile 'com.android.support:appcompat-v7:22.1.1' compile 'com.mapzen.android:lost:1.0.0' + + // Testing dependencies + androidTestCompile 'com.android.support.test:runner:0.3' + androidTestCompile 'com.android.support.test:rules:0.3' + androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2' } checkstyle { From 6d18a2dd6e2d7f040fdb2c6c13e67e98ecfbca80 Mon Sep 17 00:00:00 2001 From: Antonio Zugaldia Date: Mon, 14 Sep 2015 16:01:13 -0400 Subject: [PATCH 03/35] Bumped version to remove conflict with com.android.support:support-annotations versions for app (22.1.1) and test app (22.2.0). --- android/java/MapboxGLAndroidSDKTestApp/build.gradle | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/android/java/MapboxGLAndroidSDKTestApp/build.gradle b/android/java/MapboxGLAndroidSDKTestApp/build.gradle index d39fdfbbe..be49cff90 100644 --- a/android/java/MapboxGLAndroidSDKTestApp/build.gradle +++ b/android/java/MapboxGLAndroidSDKTestApp/build.gradle @@ -74,9 +74,9 @@ dependencies { compile(project(':MapboxGLAndroidSDK')) { transitive = true } - compile 'com.android.support:support-annotations:22.1.1' - compile 'com.android.support:support-v4:22.1.1' - compile 'com.android.support:appcompat-v7:22.1.1' + compile 'com.android.support:support-annotations:22.2.0' + compile 'com.android.support:support-v4:22.2.0' + compile 'com.android.support:appcompat-v7:22.2.0' compile 'com.mapzen.android:lost:1.0.0' // Testing dependencies From 67586c13fc5672aff4665cf1f66eab97deb9fae0 Mon Sep 17 00:00:00 2001 From: Antonio Zugaldia Date: Mon, 14 Sep 2015 16:08:00 -0400 Subject: [PATCH 04/35] Specify AndroidJUnitRunner as the default test instrumentation runner --- android/java/MapboxGLAndroidSDKTestApp/build.gradle | 3 +++ 1 file changed, 3 insertions(+) diff --git a/android/java/MapboxGLAndroidSDKTestApp/build.gradle b/android/java/MapboxGLAndroidSDKTestApp/build.gradle index be49cff90..48c17d1fe 100644 --- a/android/java/MapboxGLAndroidSDKTestApp/build.gradle +++ b/android/java/MapboxGLAndroidSDKTestApp/build.gradle @@ -43,6 +43,9 @@ android { targetSdkVersion 22 versionCode 4 versionName "0.1.3" + + // Specify AndroidJUnitRunner as the default test instrumentation runner + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } compileOptions { From e95d0e030315a35aa0ec6d42597c1be99adf3307 Mon Sep 17 00:00:00 2001 From: Antonio Zugaldia Date: Mon, 14 Sep 2015 17:03:46 -0400 Subject: [PATCH 05/35] tests documentation --- .../java/MapboxGLAndroidSDKTestApp/README.md | 41 ++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/android/java/MapboxGLAndroidSDKTestApp/README.md b/android/java/MapboxGLAndroidSDKTestApp/README.md index 007a8b1d4..87ea2eb13 100644 --- a/android/java/MapboxGLAndroidSDKTestApp/README.md +++ b/android/java/MapboxGLAndroidSDKTestApp/README.md @@ -2,4 +2,43 @@ ## Testing -TBD. +### Run Espresso tests on a device + +This test project comes with all the required Android Testing Support Library dependencies +in the Gradle file. Tests are under the `app/src/androidTest` folder. + +Note that before running your tests, you might want to turn off animations on your test device. +It's a known issue that leaving system animations turned on in a test device +(window animation scale, transition animation scale, animator duration scale) +might cause unexpected results, or may lead tests to fail. + +To create a new run configuration: +* Click on Run -> Edit Configurations... +* Click on the plus sign and then on "Android Tests" +* Give a name to the configuration, e.g. `TestAppTests` +* Choose the `MapboxGLAndroidSDKTestApp` module +* Choose `android.support.test.runner.AndroidJUnitRunner` as the instrumentation runner +* Click OK to save the new configuration + +You can now run this configuration from the main toolbar dropdown menu. + +# Run Espresso tests on AWS Device Farm + +On a terminal, within `mapbox-gl-native/android/java`, +run the tests (`cC` stands for `connectedCheck`): + +``` +$ ./gradlew cC -p MapboxGLAndroidSDKTestApp +``` + +Then: +* Go to your AWS Console and choose Device Farm. +* Create a new project, e.g. `MapboxGLAndroidSDKTestApp` +* On step 1, upload the APK in `mapbox-gl-native/android/java/MapboxGLAndroidSDKTestApp/build/outputs/apk/MapboxGLAndroidSDKTestApp-debug-unaligned.apk` +* On step 2, choose Instrumentation, test filter is `com.mapbox.mapboxgl.testapp.MainActivityTest` and upload the APK in `mapbox-gl-native/android/java/MapboxGLAndroidSDKTestApp/build/outputs/apk/MapboxGLAndroidSDKTestApp-debug-androidTest-unaligned.apk` +* On step 3, choose a device pool. E.g. Top Devices +* On step 4, customize your device state (if needed) +* Finally, confirm the configuration and run the tests. + +If you have no tests for your app, or want to test some random user behaviour, +you can just choose "Built-in: Fuzz" in step 2. From 6f7aa10609258dfe34d1844d89cdb5dafaa24ea9 Mon Sep 17 00:00:00 2001 From: Antonio Zugaldia Date: Mon, 14 Sep 2015 17:04:10 -0400 Subject: [PATCH 06/35] one more exclude required for testing --- android/java/MapboxGLAndroidSDKTestApp/build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/android/java/MapboxGLAndroidSDKTestApp/build.gradle b/android/java/MapboxGLAndroidSDKTestApp/build.gradle index 48c17d1fe..89b9ac90a 100644 --- a/android/java/MapboxGLAndroidSDKTestApp/build.gradle +++ b/android/java/MapboxGLAndroidSDKTestApp/build.gradle @@ -56,6 +56,7 @@ android { packagingOptions { exclude 'META-INF/LICENSE.txt' exclude 'META-INF/NOTICE.txt' + exclude 'LICENSE.txt' } lintOptions { From 9a0d12e1422a82670300abcd6afeeaa2a8d216d5 Mon Sep 17 00:00:00 2001 From: Antonio Zugaldia Date: Mon, 14 Sep 2015 17:04:55 -0400 Subject: [PATCH 07/35] basic espresso testSanity() working locally and on was device farm --- .../com/mapbox/mapboxgl/testapp/BaseTest.java | 27 +++++++++++++++++++ .../mapboxgl/testapp/MainActivityTest.java | 27 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/BaseTest.java create mode 100644 android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/MainActivityTest.java diff --git a/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/BaseTest.java b/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/BaseTest.java new file mode 100644 index 000000000..d9801cf1e --- /dev/null +++ b/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/BaseTest.java @@ -0,0 +1,27 @@ +package com.mapbox.mapboxgl.testapp; + +import android.support.test.InstrumentationRegistry; +import android.test.ActivityInstrumentationTestCase2; + +import org.junit.Before; + +/** + * Base Espresso class for all tests, helps working with ActivityInstrumentationTestCase2 + */ +public class BaseTest + extends ActivityInstrumentationTestCase2 { + + private MainActivity mActivity; + + public BaseTest() { + super(MainActivity.class); + } + + @Before + public void setUp() throws Exception { + super.setUp(); + injectInstrumentation(InstrumentationRegistry.getInstrumentation()); + mActivity = getActivity(); + } + +} diff --git a/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/MainActivityTest.java b/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/MainActivityTest.java new file mode 100644 index 000000000..07485875d --- /dev/null +++ b/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/MainActivityTest.java @@ -0,0 +1,27 @@ +package com.mapbox.mapboxgl.testapp; + +import org.junit.Test; + +import static android.support.test.espresso.Espresso.onView; +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.withId; + +/** + * Tests MainActivity + */ +public class MainActivityTest extends BaseTest { + + /* + * Note that we need to keep the `test` prefix if we want to be able to run these + * tests on AWS Device Farm, annotations are not enough: + * https://github.com/awslabs/aws-device-farm-sample-app-for-android/issues/5#issuecomment-138258444 + */ + + @Test + public void testSanity() { + onView(withId(R.id.layout_map)) + .check(matches(isDisplayed())); + } + +} From 5c74d202d3e0b603ce842c9e60eecc617a9cdbdd Mon Sep 17 00:00:00 2001 From: Antonio Zugaldia Date: Mon, 14 Sep 2015 17:18:52 -0400 Subject: [PATCH 08/35] added info about Monkey --- .../java/MapboxGLAndroidSDKTestApp/README.md | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/android/java/MapboxGLAndroidSDKTestApp/README.md b/android/java/MapboxGLAndroidSDKTestApp/README.md index 87ea2eb13..6748b42c6 100644 --- a/android/java/MapboxGLAndroidSDKTestApp/README.md +++ b/android/java/MapboxGLAndroidSDKTestApp/README.md @@ -2,7 +2,7 @@ ## Testing -### Run Espresso tests on a device +### Running Espresso tests on a device This test project comes with all the required Android Testing Support Library dependencies in the Gradle file. Tests are under the `app/src/androidTest` folder. @@ -22,7 +22,7 @@ To create a new run configuration: You can now run this configuration from the main toolbar dropdown menu. -# Run Espresso tests on AWS Device Farm +### Running Espresso tests on AWS Device Farm On a terminal, within `mapbox-gl-native/android/java`, run the tests (`cC` stands for `connectedCheck`): @@ -42,3 +42,17 @@ Then: If you have no tests for your app, or want to test some random user behaviour, you can just choose "Built-in: Fuzz" in step 2. + +### Running the UI/Application Exerciser Monkey + +Similar to the "Built-in: Fuzz" test mentioned above, Android provides +[Monkey](http://developer.android.com/tools/help/monkey.html), +"a program that runs on your emulator or device and generates pseudo-random streams of user events +such as clicks, touches, or gestures, as well as a number of system-level events." + +To exercise Monkey on the test app, install the package on the device (e.g. via Android Studio) +and then: + +``` +$ adb shell monkey -p com.mapbox.mapboxgl.testapp -v 500 +``` From 7d2f060887697b0ea4163672e438e997fedad048 Mon Sep 17 00:00:00 2001 From: Antonio Zugaldia Date: Mon, 14 Sep 2015 17:27:08 -0400 Subject: [PATCH 09/35] match the new annotations version --- android/java/MapboxGLAndroidSDKTestApp/build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/android/java/MapboxGLAndroidSDKTestApp/build.gradle b/android/java/MapboxGLAndroidSDKTestApp/build.gradle index fea7691d2..69a068713 100644 --- a/android/java/MapboxGLAndroidSDKTestApp/build.gradle +++ b/android/java/MapboxGLAndroidSDKTestApp/build.gradle @@ -95,6 +95,7 @@ dependencies { } // Testing dependencies + androidTestCompile 'com.android.support:support-annotations:23.0.1' androidTestCompile 'com.android.support.test:runner:0.3' androidTestCompile 'com.android.support.test:rules:0.3' androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2' From 8dd8e019615e1ed36eddd328a99ee95b2391d350 Mon Sep 17 00:00:00 2001 From: Antonio Zugaldia Date: Mon, 14 Sep 2015 17:48:43 -0400 Subject: [PATCH 10/35] switch id to new layout mainMapView --- .../java/com/mapbox/mapboxgl/testapp/MainActivityTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/MainActivityTest.java b/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/MainActivityTest.java index 07485875d..1f786affd 100644 --- a/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/MainActivityTest.java +++ b/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/MainActivityTest.java @@ -20,7 +20,7 @@ public class MainActivityTest extends BaseTest { @Test public void testSanity() { - onView(withId(R.id.layout_map)) + onView(withId(R.id.mainMapView)) .check(matches(isDisplayed())); } From d8ffb76ff36915125543c80a0c04b9089cbbb370 Mon Sep 17 00:00:00 2001 From: Antonio Zugaldia Date: Tue, 15 Sep 2015 10:33:34 -0400 Subject: [PATCH 11/35] Take a screenshot after every test --- .../com/mapbox/mapboxgl/testapp/BaseTest.java | 27 ++++++ .../testapp/utils/ScreenshotUtil.java | 88 +++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/utils/ScreenshotUtil.java diff --git a/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/BaseTest.java b/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/BaseTest.java index d9801cf1e..7ec3c3181 100644 --- a/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/BaseTest.java +++ b/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/BaseTest.java @@ -3,6 +3,8 @@ package com.mapbox.mapboxgl.testapp; import android.support.test.InstrumentationRegistry; import android.test.ActivityInstrumentationTestCase2; +import com.mapbox.mapboxgl.testapp.utils.ScreenshotUtil; + import org.junit.Before; /** @@ -17,6 +19,10 @@ public class BaseTest super(MainActivity.class); } + /* + * Get the activity before running every test + */ + @Before public void setUp() throws Exception { super.setUp(); @@ -24,4 +30,25 @@ public class BaseTest mActivity = getActivity(); } + /* + * Take a screenshot after every test + */ + + @Override + protected void tearDown() throws Exception { + try { + // Screenshots should be taken on the UI thread + runTestOnUiThread(new Runnable() { + @Override + public void run() { + ScreenshotUtil.take(getActivity()); + } + }); + } catch (Throwable throwable) { + throwable.printStackTrace(); + } + + super.tearDown(); + } + } diff --git a/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/utils/ScreenshotUtil.java b/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/utils/ScreenshotUtil.java new file mode 100644 index 000000000..0e35fad68 --- /dev/null +++ b/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/utils/ScreenshotUtil.java @@ -0,0 +1,88 @@ +package com.mapbox.mapboxgl.testapp.utils; + +import android.app.Activity; +import android.graphics.Bitmap; +import android.os.Environment; +import android.util.Log; +import android.view.View; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.util.UUID; + +/** + * The built-in Fuzz Suite on AWS Device Farm takes screenshots after every test. However, + * this doesn't happen with Espresso unless we manually do it. This class fixes it. + */ +public class ScreenshotUtil { + + private static final String LOG_TAG = ScreenshotUtil.class.getName(); + + // Where to store the files. This path is required by AWS Device Farm: + // http://docs.aws.amazon.com/devicefarm/latest/developerguide/test-types-android-instrumentation.html#test-types-android-instrumentation-screenshots + private static final String SCREENSHOT_FOLDER = "test-screenshots"; + + // Image type and quality + private static final String DEFAULT_IMAGE_EXTENSION = ".png"; + private static final Bitmap.CompressFormat DEFAULT_IMAGE_FORMAT = Bitmap.CompressFormat.PNG; + private static final int DEFAULT_IMAGE_QUALITY = 100; + + public static void take(Activity activity) { + + // Check if storage is available + if (!isExternalStorageWritable()) { + Log.d(LOG_TAG, "External storage is not available."); + return; + } + + // Get a bitmap from the activity root view. When the drawing cache is enabled, + // the next call to getDrawingCache() will draw the view in a bitmap. + View rootView = activity.getWindow().getDecorView().getRootView(); + rootView.setDrawingCacheEnabled(true); + Bitmap bitmap = Bitmap.createBitmap(rootView.getDrawingCache()); + rootView.setDrawingCacheEnabled(false); + + // Save the bitmap in external storage + String uniqueAbsolutePath = getUniqueAbsolutePath(); + File outputFile = new File(uniqueAbsolutePath); + OutputStream outputStream = null; + try { + outputStream = new FileOutputStream(outputFile); + bitmap.compress(DEFAULT_IMAGE_FORMAT, DEFAULT_IMAGE_QUALITY, outputStream); + outputStream.flush(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (outputStream != null) { + try { + outputStream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } + + /* Checks if external storage is available for read and write */ + public static boolean isExternalStorageWritable() { + String state = Environment.getExternalStorageState(); + if (Environment.MEDIA_MOUNTED.equals(state)) { + return true; + } + return false; + } + + private static String getUniqueAbsolutePath() { + String externalPath = Environment.getExternalStorageDirectory().toString(); + String filename = UUID.randomUUID().toString() + DEFAULT_IMAGE_EXTENSION; + String path = externalPath + File.separator + SCREENSHOT_FOLDER + File.separator + filename; + Log.d(LOG_TAG, "Screenshot path: " + path); + return path; + } + +} From 019a3c05b009c5fba1b65b1aa8803753bf61d643 Mon Sep 17 00:00:00 2001 From: Antonio Zugaldia Date: Tue, 15 Sep 2015 11:20:24 -0400 Subject: [PATCH 12/35] added espresso-contrib to have access to contrib.DrawerMatchers.* --- android/java/MapboxGLAndroidSDKTestApp/build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/android/java/MapboxGLAndroidSDKTestApp/build.gradle b/android/java/MapboxGLAndroidSDKTestApp/build.gradle index 69a068713..93ab32223 100644 --- a/android/java/MapboxGLAndroidSDKTestApp/build.gradle +++ b/android/java/MapboxGLAndroidSDKTestApp/build.gradle @@ -99,6 +99,7 @@ dependencies { androidTestCompile 'com.android.support.test:runner:0.3' androidTestCompile 'com.android.support.test:rules:0.3' androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2' + androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2' } checkstyle { From 06d609d630caecb7831090fc2c49a3c92b770aaa Mon Sep 17 00:00:00 2001 From: Antonio Zugaldia Date: Tue, 15 Sep 2015 12:23:03 -0400 Subject: [PATCH 13/35] we now have 26 UI tests that cover all main elements and core interactions, including drawer and map inner elements --- .../MapboxGLAndroidSDKTestApp/build.gradle | 1 - .../mapboxgl/testapp/MainActivityTest.java | 246 +++++++++++++++++- 2 files changed, 245 insertions(+), 2 deletions(-) diff --git a/android/java/MapboxGLAndroidSDKTestApp/build.gradle b/android/java/MapboxGLAndroidSDKTestApp/build.gradle index 93ab32223..69a068713 100644 --- a/android/java/MapboxGLAndroidSDKTestApp/build.gradle +++ b/android/java/MapboxGLAndroidSDKTestApp/build.gradle @@ -99,7 +99,6 @@ dependencies { androidTestCompile 'com.android.support.test:runner:0.3' androidTestCompile 'com.android.support.test:rules:0.3' androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2' - androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2' } checkstyle { diff --git a/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/MainActivityTest.java b/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/MainActivityTest.java index 1f786affd..08948b33b 100644 --- a/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/MainActivityTest.java +++ b/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/MainActivityTest.java @@ -3,15 +3,27 @@ package com.mapbox.mapboxgl.testapp; import org.junit.Test; 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.doubleClick; +import static android.support.test.espresso.action.ViewActions.longClick; +import static android.support.test.espresso.action.ViewActions.swipeDown; +import static android.support.test.espresso.action.ViewActions.swipeLeft; +import static android.support.test.espresso.action.ViewActions.swipeRight; +import static android.support.test.espresso.action.ViewActions.swipeUp; 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.withContentDescription; import static android.support.test.espresso.matcher.ViewMatchers.withId; +import static android.support.test.espresso.matcher.ViewMatchers.withText; +import static org.hamcrest.Matchers.not; /** - * Tests MainActivity + * Tests on MainActivity */ public class MainActivityTest extends BaseTest { + private final static String HOME_BUTTON_STRING = "Navigate up"; + /* * Note that we need to keep the `test` prefix if we want to be able to run these * tests on AWS Device Farm, annotations are not enough: @@ -24,4 +36,236 @@ public class MainActivityTest extends BaseTest { .check(matches(isDisplayed())); } + /* + * Check UI ids are visible + */ + + @Test + public void testDrawerLayoutIsDisplayed() { + onView(withId(R.id.drawer_layout)) + .check(matches(isDisplayed())); + } + + @Test + public void testToolbarIsDisplayed() { + onView(withId(R.id.toolbar)) + .check(matches(isDisplayed())); + } + + @Test + public void testContentFrameIsDisplayed() { + onView(withId(R.id.content_frame)) + .check(matches(isDisplayed())); + } + + @Test + public void testViewFpsIsDisplayed() { + // By default, R.id.view_fps is not displayed + onView(withId(R.id.view_fps)) + .check(matches(not(isDisplayed()))); + } + + @Test + public void testLocationFABIsDisplayed() { + onView(withId(R.id.locationFAB)) + .check(matches(isDisplayed())); + } + + @Test + public void testNavViewIsNotDisplayed() { + // By default, nav_view not displayed + onView(withId(R.id.nav_view)) + .check(matches(not(isDisplayed()))); + } + + @Test + public void testNavViewIsDisplayed() { + // However, it's displayed when we click the home icon + onView(withContentDescription(HOME_BUTTON_STRING)) + .perform(click()); + onView(withId(R.id.nav_view)) + .check(matches(isDisplayed())); + } + + /* + * Some more tests on the map view (clicks, gestures) + */ + + @Test + public void testClickMap() { + onView(withId(R.id.mainMapView)) + .perform(click()) + .check(matches(isDisplayed())); + } + + @Test + public void testDoubleClickMap() { + onView(withId(R.id.mainMapView)) + .perform(doubleClick()) + .check(matches(isDisplayed())); + } + + @Test + public void testLongClickMap() { + onView(withId(R.id.mainMapView)) + .perform(longClick()) + .check(matches(isDisplayed())); + } + + @Test + public void testSwipeLeftMap() { + onView(withId(R.id.mainMapView)) + .perform(swipeLeft()) + .check(matches(isDisplayed())); + } + + @Test + public void testSwipeRightMap() { + onView(withId(R.id.mainMapView)) + .perform(swipeRight()) + .check(matches(isDisplayed())); + } + + @Test + public void testSwipeDownMap() { + onView(withId(R.id.mainMapView)) + .perform(swipeDown()) + .check(matches(isDisplayed())); + } + + @Test + public void testSwipeUpMap() { + onView(withId(R.id.mainMapView)) + .perform(swipeUp()) + .check(matches(isDisplayed())); + } + + /* + * Test the main drawer options + */ + + @Test + public void testNavViewActionDebug() { + onView(withContentDescription(HOME_BUTTON_STRING)) + .perform(click()); + onView(withText(R.string.action_debug)) + .perform(click()); + + // Clicking the item closes the drawer + onView(withId(R.id.nav_view)) + .check(matches(not(isDisplayed()))); + } + + @Test + public void testNavViewActionPointAnnotations() { + onView(withContentDescription(HOME_BUTTON_STRING)) + .perform(click()); + onView(withText(R.string.action_point_annotations)) + .perform(click()); + + // Clicking the item closes the drawer + onView(withId(R.id.nav_view)) + .check(matches(not(isDisplayed()))); + } + + @Test + public void testNavViewActionCompass() { + onView(withContentDescription(HOME_BUTTON_STRING)) + .perform(click()); + onView(withText(R.string.action_compass)) + .perform(click()); + + // Clicking the item closes the drawer + onView(withId(R.id.nav_view)) + .check(matches(not(isDisplayed()))); + } + + @Test + public void testNavViewStyleMapboxStreets() { + onView(withContentDescription(HOME_BUTTON_STRING)) + .perform(click()); + onView(withText(R.string.styleMapboxStreets)) + .perform(click()); + + // Clicking the item closes the drawer + onView(withId(R.id.nav_view)) + .check(matches(not(isDisplayed()))); + } + + @Test + public void testNavViewStyleEmerald() { + onView(withContentDescription(HOME_BUTTON_STRING)) + .perform(click()); + onView(withText(R.string.styleEmerald)) + .perform(click()); + + // Clicking the item closes the drawer + onView(withId(R.id.nav_view)) + .check(matches(not(isDisplayed()))); + } + + @Test + public void testNavViewStyleLight() { + onView(withContentDescription(HOME_BUTTON_STRING)) + .perform(click()); + onView(withText(R.string.styleLight)) + .perform(click()); + + // Clicking the item closes the drawer + onView(withId(R.id.nav_view)) + .check(matches(not(isDisplayed()))); + } + + @Test + public void testNavViewStyleDark() { + onView(withContentDescription(HOME_BUTTON_STRING)) + .perform(click()); + onView(withText(R.string.styleDark)) + .perform(click()); + + // Clicking the item closes the drawer + onView(withId(R.id.nav_view)) + .check(matches(not(isDisplayed()))); + } + + @Test + public void testNavViewStyleSatellite() { + onView(withContentDescription(HOME_BUTTON_STRING)) + .perform(click()); + onView(withText(R.string.styleSatellite)) + .perform(click()); + + // Clicking the item closes the drawer + onView(withId(R.id.nav_view)) + .check(matches(not(isDisplayed()))); + } + + /* + * We can also check the map inner elements are visible + */ + + @Test + public void testMapIconContentDescription() { + // Mapbox logo + onView(withContentDescription(getActivity().getResources() + .getString(R.string.mapboxIconContentDescription))) + .check(matches(isDisplayed())); + } + + @Test + public void testMapCompassContentDescription() { + // Map compass + onView(withContentDescription(getActivity().getResources() + .getString(R.string.compassContentDescription))) + .check(matches(isDisplayed())); + } + + @Test + public void testMapAttributionsIconContentDescription() { + // Attribution icon + onView(withContentDescription(getActivity().getResources() + .getString(R.string.attributionsIconContentDescription))) + .check(matches(isDisplayed())); + } + } From 3f837ecd94c3b5370577841733048ce18fdc011c Mon Sep 17 00:00:00 2001 From: Antonio Zugaldia Date: Tue, 15 Sep 2015 14:17:46 -0400 Subject: [PATCH 14/35] added permission to save tests screenshots --- .../java/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/android/java/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml b/android/java/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml index 85be72bb7..15d5edc17 100644 --- a/android/java/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml +++ b/android/java/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml @@ -25,4 +25,5 @@ + From 2235a86054d1192b93ce62bd2c6b56a5b8dfcc87 Mon Sep 17 00:00:00 2001 From: Antonio Zugaldia Date: Tue, 15 Sep 2015 14:18:00 -0400 Subject: [PATCH 15/35] manually add a screenshot name --- .../mapboxgl/testapp/utils/ScreenshotUtil.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/utils/ScreenshotUtil.java b/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/utils/ScreenshotUtil.java index 0e35fad68..51eceaca9 100644 --- a/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/utils/ScreenshotUtil.java +++ b/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/utils/ScreenshotUtil.java @@ -30,7 +30,7 @@ public class ScreenshotUtil { private static final Bitmap.CompressFormat DEFAULT_IMAGE_FORMAT = Bitmap.CompressFormat.PNG; private static final int DEFAULT_IMAGE_QUALITY = 100; - public static void take(Activity activity) { + public static void take(Activity activity, String testName) { // Check if storage is available if (!isExternalStorageWritable()) { @@ -46,7 +46,7 @@ public class ScreenshotUtil { rootView.setDrawingCacheEnabled(false); // Save the bitmap in external storage - String uniqueAbsolutePath = getUniqueAbsolutePath(); + String uniqueAbsolutePath = getUniqueAbsolutePath(testName); File outputFile = new File(uniqueAbsolutePath); OutputStream outputStream = null; try { @@ -77,9 +77,14 @@ public class ScreenshotUtil { return false; } - private static String getUniqueAbsolutePath() { - String externalPath = Environment.getExternalStorageDirectory().toString(); + private static String getUniqueAbsolutePath(String testName) { + // A screenshot after every test vs. manual tests String filename = UUID.randomUUID().toString() + DEFAULT_IMAGE_EXTENSION; + if (testName != null && !testName.isEmpty()) { + filename = testName + DEFAULT_IMAGE_EXTENSION; + } + + String externalPath = Environment.getExternalStorageDirectory().toString(); String path = externalPath + File.separator + SCREENSHOT_FOLDER + File.separator + filename; Log.d(LOG_TAG, "Screenshot path: " + path); return path; From df7ef8ee871c53a26a7075ab21efd2f3a7638036 Mon Sep 17 00:00:00 2001 From: Antonio Zugaldia Date: Tue, 15 Sep 2015 14:18:22 -0400 Subject: [PATCH 16/35] flag to enable automatic screenshots on teardown --- .../com/mapbox/mapboxgl/testapp/BaseTest.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/BaseTest.java b/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/BaseTest.java index 7ec3c3181..038cc3099 100644 --- a/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/BaseTest.java +++ b/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/BaseTest.java @@ -14,6 +14,7 @@ public class BaseTest extends ActivityInstrumentationTestCase2 { private MainActivity mActivity; + private final static boolean screenshotOnTearDown = false; public BaseTest() { super(MainActivity.class); @@ -36,12 +37,16 @@ public class BaseTest @Override protected void tearDown() throws Exception { + if (!screenshotOnTearDown) { + return; + } + try { // Screenshots should be taken on the UI thread runTestOnUiThread(new Runnable() { @Override public void run() { - ScreenshotUtil.take(getActivity()); + ScreenshotUtil.take(getActivity(), null); } }); } catch (Throwable throwable) { @@ -51,4 +56,18 @@ public class BaseTest super.tearDown(); } + protected void takeNamedScreenshot(final String name) { + try { + // Screenshots should be taken on the UI thread + runTestOnUiThread(new Runnable() { + @Override + public void run() { + ScreenshotUtil.take(getActivity(), name); + } + }); + } catch (Throwable throwable) { + throwable.printStackTrace(); + } + } + } From c0b9ec6da4654473780c5c747c43e396448b5d36 Mon Sep 17 00:00:00 2001 From: Antonio Zugaldia Date: Tue, 15 Sep 2015 14:19:23 -0400 Subject: [PATCH 17/35] ready for aws screenshots --- .../mapboxgl/testapp/MainActivityTest.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/MainActivityTest.java b/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/MainActivityTest.java index 08948b33b..64485ed59 100644 --- a/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/MainActivityTest.java +++ b/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/MainActivityTest.java @@ -150,7 +150,7 @@ public class MainActivityTest extends BaseTest { .perform(click()); onView(withText(R.string.action_debug)) .perform(click()); - + // Clicking the item closes the drawer onView(withId(R.id.nav_view)) .check(matches(not(isDisplayed()))); @@ -268,4 +268,18 @@ public class MainActivityTest extends BaseTest { .check(matches(isDisplayed())); } + /* + * Take a screenshot of Mapbox Streets to monitor #1649 + */ + + @Test + public void testMapboxStreetsBlackAndWhite() { + // Click home and switch to Mapbox streets + onView(withContentDescription(HOME_BUTTON_STRING)) + .perform(click()); + onView(withText(R.string.styleMapboxStreets)) + .perform(click()); + takeNamedScreenshot("testMapboxStreetsBlackAndWhite"); + } + } From f3e4d3238b52898cd6481a626640cf33f5cd88d8 Mon Sep 17 00:00:00 2001 From: Antonio Zugaldia Date: Tue, 15 Sep 2015 14:20:46 -0400 Subject: [PATCH 18/35] merge from master --- test/ios/KIF | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/ios/KIF b/test/ios/KIF index 21a137bc8..976aafa2e 160000 --- a/test/ios/KIF +++ b/test/ios/KIF @@ -1 +1 @@ -Subproject commit 21a137bc8068f9fb738f835c6e285d44fe2ce4dd +Subproject commit 976aafa2e211dd095411bfef09da6c0919d70476 From 57a7f132039e062e6586a0358211473f284afeac Mon Sep 17 00:00:00 2001 From: Antonio Zugaldia Date: Tue, 15 Sep 2015 17:01:44 -0400 Subject: [PATCH 19/35] bumped versions to todays release --- .mason | 2 +- android/java/MapboxGLAndroidSDKTestApp/build.gradle | 7 +++---- styles | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.mason b/.mason index abdc13127..c066f7d19 160000 --- a/.mason +++ b/.mason @@ -1 +1 @@ -Subproject commit abdc131273c3e50e42f245b1166c27de4c34c582 +Subproject commit c066f7d19f88b854da1002ce2f96aa7aba628cb5 diff --git a/android/java/MapboxGLAndroidSDKTestApp/build.gradle b/android/java/MapboxGLAndroidSDKTestApp/build.gradle index 69a068713..6994c4985 100644 --- a/android/java/MapboxGLAndroidSDKTestApp/build.gradle +++ b/android/java/MapboxGLAndroidSDKTestApp/build.gradle @@ -95,10 +95,9 @@ dependencies { } // Testing dependencies - androidTestCompile 'com.android.support:support-annotations:23.0.1' - androidTestCompile 'com.android.support.test:runner:0.3' - androidTestCompile 'com.android.support.test:rules:0.3' - androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2' + androidTestCompile 'com.android.support.test:runner:0.4' + androidTestCompile 'com.android.support.test:rules:0.4' + androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1' } checkstyle { diff --git a/styles b/styles index 93a23d762..014e36833 160000 --- a/styles +++ b/styles @@ -1 +1 @@ -Subproject commit 93a23d762332a4c75e3dae1c547c4d810101e978 +Subproject commit 014e36833420c81b29bec816b479ea61e94821d4 From d9376a3c0fd1b09e3e5a66c3d27efed22a5ff8b3 Mon Sep 17 00:00:00 2001 From: Antonio Zugaldia Date: Tue, 15 Sep 2015 17:28:11 -0400 Subject: [PATCH 20/35] added LargeTest annotation --- .../java/com/mapbox/mapboxgl/testapp/MainActivityTest.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/MainActivityTest.java b/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/MainActivityTest.java index 64485ed59..86f501b13 100644 --- a/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/MainActivityTest.java +++ b/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/MainActivityTest.java @@ -1,5 +1,7 @@ package com.mapbox.mapboxgl.testapp; +import android.test.suitebuilder.annotation.LargeTest; + import org.junit.Test; import static android.support.test.espresso.Espresso.onView; @@ -20,6 +22,7 @@ import static org.hamcrest.Matchers.not; /** * Tests on MainActivity */ +@LargeTest public class MainActivityTest extends BaseTest { private final static String HOME_BUTTON_STRING = "Navigate up"; From ed161e020ad6c1d6cc9c6eec18f8eac77dddb39a Mon Sep 17 00:00:00 2001 From: Antonio Zugaldia Date: Tue, 15 Sep 2015 17:28:43 -0400 Subject: [PATCH 21/35] fixed teardown --- .../com/mapbox/mapboxgl/testapp/BaseTest.java | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/BaseTest.java b/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/BaseTest.java index 038cc3099..60ac10f14 100644 --- a/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/BaseTest.java +++ b/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/BaseTest.java @@ -37,23 +37,22 @@ public class BaseTest @Override protected void tearDown() throws Exception { - if (!screenshotOnTearDown) { - return; - } - - try { - // Screenshots should be taken on the UI thread - runTestOnUiThread(new Runnable() { - @Override - public void run() { - ScreenshotUtil.take(getActivity(), null); - } - }); - } catch (Throwable throwable) { - throwable.printStackTrace(); + if (screenshotOnTearDown) { + try { + // Screenshots should be taken on the UI thread + runTestOnUiThread(new Runnable() { + @Override + public void run() { + ScreenshotUtil.take(getActivity(), null); + } + }); + } catch (Throwable throwable) { + throwable.printStackTrace(); + } } super.tearDown(); + mActivity = null; } protected void takeNamedScreenshot(final String name) { From 187cc36eb55edb73730fa13a76655f5cf9f8efe5 Mon Sep 17 00:00:00 2001 From: Antonio Zugaldia Date: Tue, 15 Sep 2015 17:57:12 -0400 Subject: [PATCH 22/35] pure junit tests --- .../java/MapboxGLAndroidSDKTestApp/build.gradle | 1 + .../src/test/java/CoordinateSpanTest.java | 15 +++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 android/java/MapboxGLAndroidSDKTestApp/src/test/java/CoordinateSpanTest.java diff --git a/android/java/MapboxGLAndroidSDKTestApp/build.gradle b/android/java/MapboxGLAndroidSDKTestApp/build.gradle index 6994c4985..9bc7d493f 100644 --- a/android/java/MapboxGLAndroidSDKTestApp/build.gradle +++ b/android/java/MapboxGLAndroidSDKTestApp/build.gradle @@ -95,6 +95,7 @@ dependencies { } // Testing dependencies + testCompile 'junit:junit:4.12' androidTestCompile 'com.android.support.test:runner:0.4' androidTestCompile 'com.android.support.test:rules:0.4' androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1' diff --git a/android/java/MapboxGLAndroidSDKTestApp/src/test/java/CoordinateSpanTest.java b/android/java/MapboxGLAndroidSDKTestApp/src/test/java/CoordinateSpanTest.java new file mode 100644 index 000000000..26734e1a7 --- /dev/null +++ b/android/java/MapboxGLAndroidSDKTestApp/src/test/java/CoordinateSpanTest.java @@ -0,0 +1,15 @@ +import com.mapbox.mapboxgl.geometry.CoordinateSpan; + +import org.junit.Test; + +import static org.junit.Assert.assertNotNull; + +public class CoordinateSpanTest { + + @Test + public void testSanity() { + CoordinateSpan coordinateSpan = new CoordinateSpan(0.0, 0.0); + assertNotNull("coordinateSpan should not be null", coordinateSpan); + } + +} From 7e30025abb5dac44372ae71f2d5d409e82d3227f Mon Sep 17 00:00:00 2001 From: Antonio Zugaldia Date: Tue, 15 Sep 2015 17:58:36 -0400 Subject: [PATCH 23/35] Merge remote-tracking branch 'mapbox/master' into 2317-espresso Conflicts: src/mbgl/util/geojsonvt --- .gitmodules | 3 - .../src/main/AndroidManifest.xml | 1 + .../mapbox/mapboxgl/testapp/MainActivity.java | 5 + .../mapboxgl/testapp/SecondMapActivity.java | 101 ++++++++++++++++++ .../drawable-hdpi/ic_looks_two_white_24dp.png | Bin 0 -> 237 bytes .../drawable-mdpi/ic_looks_two_white_24dp.png | Bin 0 -> 155 bytes .../ic_looks_two_white_24dp.png | Bin 0 -> 228 bytes .../ic_looks_two_white_24dp.png | Bin 0 -> 315 bytes .../ic_looks_two_white_24dp.png | Bin 0 -> 408 bytes .../src/main/res/layout/activity_second.xml | 21 ++++ .../src/main/res/menu/menu_drawer.xml | 28 +++-- .../src/main/res/values/strings.xml | 3 + configure | 30 +++++- gyp/core.gypi | 5 + gyp/version.gypi | 2 +- scripts/android/configure.sh | 2 + scripts/build-version.py | 45 +++++--- scripts/ios/configure.sh | 2 + scripts/ios/package.sh | 6 +- scripts/linux/configure.sh | 2 + scripts/main.mk | 10 +- scripts/osx/configure.sh | 2 + scripts/osx/run.sh | 3 - src/mbgl/map/annotation.cpp | 3 +- src/mbgl/map/annotation.hpp | 3 +- test/test.gypi | 3 + 26 files changed, 238 insertions(+), 42 deletions(-) create mode 100644 android/java/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxgl/testapp/SecondMapActivity.java create mode 100644 android/java/MapboxGLAndroidSDKTestApp/src/main/res/drawable-hdpi/ic_looks_two_white_24dp.png create mode 100644 android/java/MapboxGLAndroidSDKTestApp/src/main/res/drawable-mdpi/ic_looks_two_white_24dp.png create mode 100644 android/java/MapboxGLAndroidSDKTestApp/src/main/res/drawable-xhdpi/ic_looks_two_white_24dp.png create mode 100644 android/java/MapboxGLAndroidSDKTestApp/src/main/res/drawable-xxhdpi/ic_looks_two_white_24dp.png create mode 100644 android/java/MapboxGLAndroidSDKTestApp/src/main/res/drawable-xxxhdpi/ic_looks_two_white_24dp.png create mode 100644 android/java/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_second.xml diff --git a/.gitmodules b/.gitmodules index 2aa6d52be..0152ed56b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -14,6 +14,3 @@ path = platform/ios/vendor/SMCalloutView url = https://github.com/nfarina/calloutview.git -[submodule "src/mbgl/util/geojsonvt"] - path = src/mbgl/util/geojsonvt - url = https://github.com/mapbox/geojson-vt-cpp diff --git a/android/java/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml b/android/java/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml index 15d5edc17..f91c57e7e 100644 --- a/android/java/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml +++ b/android/java/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml @@ -17,6 +17,7 @@ + diff --git a/android/java/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxgl/testapp/MainActivity.java b/android/java/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxgl/testapp/MainActivity.java index ed9b7ef06..eb5d891cd 100644 --- a/android/java/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxgl/testapp/MainActivity.java +++ b/android/java/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxgl/testapp/MainActivity.java @@ -1,6 +1,7 @@ package com.mapbox.mapboxgl.testapp; import android.Manifest; +import android.content.Intent; import android.content.pm.PackageManager; import android.graphics.Color; import android.graphics.PointF; @@ -281,6 +282,10 @@ public class MainActivity extends AppCompatActivity { menuItem.setChecked(mMapView.isCompassEnabled()); return true; + case R.id.action_second_map_activity: + startActivity(new Intent(getApplicationContext(), SecondMapActivity.class)); + return true; + /* case R.id.followNone: mMapView.setUserLocationTrackingMode(MapView.UserLocationTrackingMode.NONE); diff --git a/android/java/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxgl/testapp/SecondMapActivity.java b/android/java/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxgl/testapp/SecondMapActivity.java new file mode 100644 index 000000000..976140ffc --- /dev/null +++ b/android/java/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxgl/testapp/SecondMapActivity.java @@ -0,0 +1,101 @@ +package com.mapbox.mapboxgl.testapp; + +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.Toolbar; +import android.util.Log; +import android.view.MenuItem; +import com.mapbox.mapboxgl.views.MapView; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class SecondMapActivity extends AppCompatActivity { + + private static final String TAG = "SecondMapActivity"; + + private MapView mMapView; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + setContentView(R.layout.activity_second); + + Toolbar toolbar = (Toolbar) findViewById(R.id.secondToolBar); + setSupportActionBar(toolbar); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setDisplayShowHomeEnabled(true); + + mMapView = (MapView) findViewById(R.id.secondMapView); + // Load the access token + try { + BufferedReader reader = new BufferedReader(new InputStreamReader(getResources().openRawResource(R.raw.token))); + String line = reader.readLine(); + mMapView.setAccessToken(line); + } catch (IOException e) { + Log.e(TAG, "Error loading access token from token.txt: " + e.toString()); + } + + mMapView.onCreate(savedInstanceState); + + mMapView.setStyleUrl(getString(R.string.styleURLEmerald)); + } + + /** + * Dispatch onStart() to all fragments. Ensure any created loaders are + * now started. + */ + @Override + protected void onStart() { + super.onStart(); + mMapView.onStart(); + } + + @Override + protected void onStop() { + super.onStop(); + mMapView.onStop(); + } + + // Called when our app goes into the background + @Override + public void onPause() { + super.onPause(); + + mMapView.onPause(); + } + + // Called when our app comes into the foreground + @Override + public void onResume() { + super.onResume(); + + mMapView.onResume(); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + mMapView.onDestroy(); + } + + // Called when the system is running low on memory + @Override + public void onLowMemory() { + super.onLowMemory(); + + mMapView.onLowMemory(); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case android.R.id.home: + onBackPressed(); + return true; + default: + return super.onOptionsItemSelected(item); + } + } +} diff --git a/android/java/MapboxGLAndroidSDKTestApp/src/main/res/drawable-hdpi/ic_looks_two_white_24dp.png b/android/java/MapboxGLAndroidSDKTestApp/src/main/res/drawable-hdpi/ic_looks_two_white_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..2c9cf5b3a919b777acd93dc92e623879da06652e GIT binary patch literal 237 zcmeAS@N?(olHy`uVBq!ia0vp^Dj>|k0wldT1B8Lp7Ec$)5Rc<;r(WbetiaD zkrY>j*-a5FkDMJ7A5T2ov|dC+^x-r|PY0KZt=pG%bQo;6H=BO%*ZBpaa_jbP6}4Jb zdD`Lpibr}|?+Xe#HXfYuF;nJ*kT4(H%Ciw|aq%twY^^B|xudPCo&EMs+pp7CGQXkb lP3qeS!JA@M-8;9emM=YH=g1{rxfn zpsFp`@y+CtIe37>Ij1@W$<+Mb6Mw<&;$VF CE;d;J literal 0 HcmV?d00001 diff --git a/android/java/MapboxGLAndroidSDKTestApp/src/main/res/drawable-xhdpi/ic_looks_two_white_24dp.png b/android/java/MapboxGLAndroidSDKTestApp/src/main/res/drawable-xhdpi/ic_looks_two_white_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..c9fc6633e8a2fc4d1dd5401b88fbc93416accfdb GIT binary patch literal 228 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA0wn)(8}b0D)t)YnAr*{oulsT}8;H0*?74mE zlJAr^u2FYZ+E)t}3cFtU`O@UeM9;m2m&)JS$h!#e&a>+GIDKe+?iUxQT@JfWoVk~l zB$p9*O+GMYgFDK^F*;jh}smaTaVi(Rg b)-%|hEYkd4_C)*|(Af;0u6{1-oD!MTBj literal 0 HcmV?d00001 diff --git a/android/java/MapboxGLAndroidSDKTestApp/src/main/res/drawable-xxhdpi/ic_looks_two_white_24dp.png b/android/java/MapboxGLAndroidSDKTestApp/src/main/res/drawable-xxhdpi/ic_looks_two_white_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..f8ab38aa6a228f51fc5c08c8066eb0064643ed04 GIT binary patch literal 315 zcmV-B0mS}^P)Onpm>AAn64g|-30S)^6xC(=iLv#MG^v& zoRo9Uk?B}-Vv2fpEGeX+C5AR*&(s~6si4fBhz?{8)DhJ}1FeZ_tAS2LRW(px1{q|K zc+h2qC*JvO19aIv-)(^s5AJEGcX zpe0dt8mMq2qEE7Z#d!$e+>%sKqOf2~Wr`{rIxl8;uuoF`1Y247L%hy+sE_A z?AZ;EDCx*4w9Gl`)OpYCsIHCo1Q~}TP8XYB+Gh16nvcvM*52d((VRG?)c5b4 zATQ0OBF=zi1wwab>w=6dn5wcV`bGDG&BEnbW~AA@}b`87UX zF_J4d7JR(o0Iz@OM}~Aub`FIG1}2V#{cFw&3zz+5nzdD;_^kMaH@(^S7?LMhFF2}~ z-|%sw^#jXthvV`JpP2sygOmgHL?8Q-`TVDASz-%o?gPPshoanf&L}5{d@Qbd&%fbl zlR0aBgQ3`ta;^S`x(5$u1~oc695`y3aLjK0ajlC_`2`#p7+C}qlE6kW?O=T|zY53) z3Vy2p__bv@-^T{gd9#i)b7k!b`7Fe5;I(JVfgpxhvx*m!{kRq=PPt;UX%?%j4)29E v2`4AMVibSgSXun-GUGpWsN;Z)=e5iS^S8+R@*dw03~>feS3j3^P6 + + + + + + + diff --git a/android/java/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_drawer.xml b/android/java/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_drawer.xml index a374ab18d..ff537aaf3 100644 --- a/android/java/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_drawer.xml +++ b/android/java/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_drawer.xml @@ -19,18 +19,24 @@ android:checkable="true" /> - + diff --git a/android/java/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml b/android/java/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml index 403da277c..836951cc5 100644 --- a/android/java/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml +++ b/android/java/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml @@ -3,6 +3,8 @@ Mapbox GL + Second Activity + Toggle GPS location Disable tracking Use follow tracking mode @@ -10,6 +12,7 @@ Toggle compass Toggle debug mode Toggle point annotations + Launch 2nd Map FPS: diff --git a/configure b/configure index 6fbaa9f7f..6d0ac780c 100755 --- a/configure +++ b/configure @@ -15,8 +15,15 @@ function abort { >&2 echo -e "\033[1m\033[31m$1\033[0m"; exit 1; } function info { >&2 echo -e "\033[1m\033[33m$1\033[0m"; } function warn { >&2 echo -e "\033[1m\033[33m$1\033[0m"; } -# Install mason -export PATH="`pwd`/.mason:${PATH}" MASON_DIR="`pwd`/.mason" +if [ -d "`pwd`/.git" ]; then + info "This build is within a git repository" + export MASON_DIR="`pwd`/.mason" + export PATH="${MASON_DIR}:${PATH}" +else + info "This build is NOT within a git repository" + which mason || abort "You must install mason to build mapbox-gl-native (https://github.com/mapbox/mason)" + export MASON_DIR="$(dirname $(readlink $(which mason)))" +fi # You can override the function for a particular set of flags by defining a # print_XXX_flags function in your dependencies.sh file @@ -37,6 +44,23 @@ function print_flags { fi } +function print_build_flags { + local NAME=$1; shift + if [ "$(type -t print_${NAME}_flags)" = 'function' ]; then + print_${NAME}_flags + else + local VERSION=`echo "${NAME}_VERSION" | tr "[:lower:]" "[:upper:]"` + if [ ! -z ${!VERSION:-} ] ; then + mason build ${NAME} ${!VERSION} + for FLAGS in "$@" ; do + CONFIG+=" '${NAME}_${FLAGS}%': $(quote_flags $(mason ${FLAGS} ${NAME} ${!VERSION})),"$LN + done + else + warn "* Not using ${NAME}" + fi + fi +} + function print_default_flags { : } @@ -93,6 +117,8 @@ print_flags libuv static_libs cflags ldflags print_flags zlib static_libs cflags ldflags print_flags nunicode static_libs cflags ldflags print_flags libzip static_libs cflags ldflags +print_build_flags geojsonvt static_libs cflags ldflags +print_flags variant static_libs cflags ldflags CONFIG+=" } } diff --git a/gyp/core.gypi b/gyp/core.gypi index f9b361032..51009be69 100644 --- a/gyp/core.gypi +++ b/gyp/core.gypi @@ -31,10 +31,14 @@ '<@(libuv_cflags)', '<@(opengl_cflags)', '<@(boost_cflags)', + '<@(geojsonvt_cflags)', + '<@(variant_cflags)', ], 'cflags': [ '<@(libuv_cflags)', '<@(opengl_cflags)', + '<@(geojsonvt_cflags)', + '<@(variant_cflags)', '-fPIC' ], 'ldflags': [ @@ -43,6 +47,7 @@ ], 'libraries': [ '<@(libuv_static_libs)', + '<@(geojsonvt_static_libs)', ], }, diff --git a/gyp/version.gypi b/gyp/version.gypi index 1cc2eb351..4efdd079a 100644 --- a/gyp/version.gypi +++ b/gyp/version.gypi @@ -13,7 +13,7 @@ 'outputs': [ '<(SHARED_INTERMEDIATE_DIR)/include/mbgl/util/version.hpp', ], - 'action': ['<@(_inputs)', '<(SHARED_INTERMEDIATE_DIR)', ' + #include #include #include #include #include #include -#include #include #include diff --git a/src/mbgl/map/annotation.hpp b/src/mbgl/map/annotation.hpp index 5adec162f..6b80d9f6c 100644 --- a/src/mbgl/map/annotation.hpp +++ b/src/mbgl/map/annotation.hpp @@ -1,13 +1,14 @@ #ifndef MBGL_MAP_ANNOTATIONS #define MBGL_MAP_ANNOTATIONS +#include + #include #include #include #include #include #include -#include #include #include diff --git a/test/test.gypi b/test/test.gypi index a35b00133..c53263bd5 100644 --- a/test/test.gypi +++ b/test/test.gypi @@ -95,6 +95,7 @@ 'libraries': [ '<@(libuv_static_libs)', '<@(sqlite_static_libs)', + '<@(geojsonvt_static_libs)', ], 'variables': { 'cflags_cc': [ @@ -102,6 +103,8 @@ '<@(opengl_cflags)', '<@(boost_cflags)', '<@(sqlite_cflags)', + '<@(geojsonvt_cflags)', + '<@(variant_cflags)', ], 'ldflags': [ '<@(libuv_ldflags)', From 99053f47f7a407f3e0a6fbdede5627366349f680 Mon Sep 17 00:00:00 2001 From: Antonio Zugaldia Date: Wed, 16 Sep 2015 09:29:53 -0400 Subject: [PATCH 24/35] merge with master --- CHANGELOG.md | 4 ++++ ios/Mapbox-iOS-SDK.podspec | 2 +- test/ios/MapViewTests.m | 27 +++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9165386ea..f2a33b100 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## iOS 2.1.2 + +- Built with Xcode 6.4 to not yet trigger Bitcode compatibility until Xcode 7 stabilizes. ([#2332](https://github.com/mapbox/mapbox-gl-native/issues/2332)) + ## iOS 2.1.1 - Fixes for Xcode 7 and Bitcode. ([#2238](https://github.com/mapbox/mapbox-gl-native/pull/2238)) diff --git a/ios/Mapbox-iOS-SDK.podspec b/ios/Mapbox-iOS-SDK.podspec index eb94769dd..139ad655f 100644 --- a/ios/Mapbox-iOS-SDK.podspec +++ b/ios/Mapbox-iOS-SDK.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |m| m.name = 'Mapbox-iOS-SDK' - m.version = '2.1.1-symbols' + m.version = '2.1.2-symbols' m.summary = 'Open source vector map solution for iOS with full styling capabilities.' m.description = 'Open source OpenGL-based vector map solution for iOS with full styling capabilities and Cocoa bindings.' diff --git a/test/ios/MapViewTests.m b/test/ios/MapViewTests.m index 98636d1a9..d0913670c 100644 --- a/test/ios/MapViewTests.m +++ b/test/ios/MapViewTests.m @@ -220,6 +220,33 @@ @"panning map right should decrease center longitude"); } +- (void)testSetCenterCancelsTransitions { + XCTestExpectation *cameraIsInDCExpectation = [self expectationWithDescription:@"camera reset to DC"]; + + CLLocationCoordinate2D dc = CLLocationCoordinate2DMake(38.894368, -77.036487); + CLLocationCoordinate2D dc_west = CLLocationCoordinate2DMake(38.894368, -77.076487); + [tester.mapView setCenterCoordinate:dc animated:NO]; + [tester.mapView setCenterCoordinate:dc_west animated:YES]; + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.15 * NSEC_PER_SEC), + dispatch_get_main_queue(), + ^{ + [tester.mapView setCenterCoordinate:dc animated:NO]; + XCTAssertEqualWithAccuracy(dc.latitude, + tester.mapView.centerCoordinate.latitude, + 0.0005, + @"setting center coordinate should cancel transitions"); + XCTAssertEqualWithAccuracy(dc.longitude, + tester.mapView.centerCoordinate.longitude, + 0.0005, + @"setting center coordinate should cancel transitions"); + [cameraIsInDCExpectation fulfill]; + }); + + [self waitForExpectationsWithTimeout:1.0 handler:^(NSError *error) { + ; + }]; +} + - (void)testPanDisabled { tester.mapView.scrollEnabled = NO; CLLocationCoordinate2D centerCoordinate = tester.mapView.centerCoordinate; From e4d1e67d71f17476f6a50d98ee22e9427578ccb5 Mon Sep 17 00:00:00 2001 From: Antonio Zugaldia Date: Wed, 16 Sep 2015 11:01:45 -0400 Subject: [PATCH 25/35] second activity test class --- .../testapp/SecondMapActivityTest.java | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/SecondMapActivityTest.java diff --git a/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/SecondMapActivityTest.java b/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/SecondMapActivityTest.java new file mode 100644 index 000000000..593b0b2ee --- /dev/null +++ b/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/SecondMapActivityTest.java @@ -0,0 +1,41 @@ +package com.mapbox.mapboxgl.testapp; + +import android.support.test.rule.ActivityTestRule; +import android.support.test.runner.AndroidJUnit4; +import android.test.suitebuilder.annotation.LargeTest; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; + +import static android.support.test.espresso.Espresso.onView; +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.withId; + +/** + * Tests on SecondMapActivity. + */ +@RunWith(AndroidJUnit4.class) +@LargeTest +public class SecondMapActivityTest extends BaseTest { + + @Rule + public ActivityTestRule mActivityRule = new ActivityTestRule<>( + SecondMapActivity.class); + + private SecondMapActivity mActivity = null; + + @Before + public void setActivity() { + mActivity = mActivityRule.getActivity(); + } + + @Test + public void testSanity() { + onView(withId(R.id.secondMapView)) + .check(matches(isDisplayed())); + } + +} From c3dffb6e46e28a56f7707443ba2025b1aac4fd12 Mon Sep 17 00:00:00 2001 From: Antonio Zugaldia Date: Wed, 16 Sep 2015 11:02:11 -0400 Subject: [PATCH 26/35] moved screenshot tests to its own class --- .../testapp/MainActivityScreenTest.java | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/MainActivityScreenTest.java diff --git a/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/MainActivityScreenTest.java b/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/MainActivityScreenTest.java new file mode 100644 index 000000000..af35620f6 --- /dev/null +++ b/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/MainActivityScreenTest.java @@ -0,0 +1,61 @@ +package com.mapbox.mapboxgl.testapp; + +import android.support.test.rule.ActivityTestRule; +import android.support.test.runner.AndroidJUnit4; +import android.test.suitebuilder.annotation.LargeTest; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +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.withContentDescription; +import static android.support.test.espresso.matcher.ViewMatchers.withId; +import static android.support.test.espresso.matcher.ViewMatchers.withText; + +/** + * Tests on MainActivity with screenshots + */ +@RunWith(AndroidJUnit4.class) +@LargeTest +public class MainActivityScreenTest extends BaseTest { + + private final static String HOME_BUTTON_STRING = "Navigate up"; + + @Rule + public ActivityTestRule mActivityRule = new ActivityTestRule<>( + MainActivity.class); + + private MainActivity mActivity = null; + + @Before + public void setActivity() { + mActivity = mActivityRule.getActivity(); + } + + @Test + public void testSanity() { + checkViewIsDisplayed(R.id.mainMapView); + } + + /* + * Take a screenshot of Mapbox Streets to monitor #1649 + */ + + @Test + public void testMapboxStreetsBlackAndWhite() { + // Click home and switch to Mapbox streets + onView(withContentDescription(HOME_BUTTON_STRING)) + .perform(click()); + onView(withText(R.string.styleMapboxStreets)) + .perform(click()); + + // Standard screenshot + takeNamedScreenshot(mActivity, "testMapboxStreetsBlackAndWhite"); + } + +} From 602a075333861160ead82067fda8f568deec3112 Mon Sep 17 00:00:00 2001 From: Antonio Zugaldia Date: Wed, 16 Sep 2015 11:03:10 -0400 Subject: [PATCH 27/35] using the new version way of instanstiating the activity class --- .../com/mapbox/mapboxgl/testapp/BaseTest.java | 66 +++++-------------- .../mapboxgl/testapp/MainActivityTest.java | 37 ++++++----- 2 files changed, 36 insertions(+), 67 deletions(-) diff --git a/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/BaseTest.java b/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/BaseTest.java index 60ac10f14..9c6646105 100644 --- a/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/BaseTest.java +++ b/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/BaseTest.java @@ -1,5 +1,6 @@ package com.mapbox.mapboxgl.testapp; +import android.app.Activity; import android.support.test.InstrumentationRegistry; import android.test.ActivityInstrumentationTestCase2; @@ -7,66 +8,31 @@ import com.mapbox.mapboxgl.testapp.utils.ScreenshotUtil; import org.junit.Before; +import static android.support.test.espresso.Espresso.onView; +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.withId; + /** * Base Espresso class for all tests, helps working with ActivityInstrumentationTestCase2 */ -public class BaseTest - extends ActivityInstrumentationTestCase2 { +public class BaseTest { - private MainActivity mActivity; - private final static boolean screenshotOnTearDown = false; + /* + * Shortcuts for common UI tests + */ - public BaseTest() { - super(MainActivity.class); + protected void checkViewIsDisplayed(int id) { + onView(withId(id)) + .check(matches(isDisplayed())); } /* - * Get the activity before running every test + * Screenshots logic */ - @Before - public void setUp() throws Exception { - super.setUp(); - injectInstrumentation(InstrumentationRegistry.getInstrumentation()); - mActivity = getActivity(); - } - - /* - * Take a screenshot after every test - */ - - @Override - protected void tearDown() throws Exception { - if (screenshotOnTearDown) { - try { - // Screenshots should be taken on the UI thread - runTestOnUiThread(new Runnable() { - @Override - public void run() { - ScreenshotUtil.take(getActivity(), null); - } - }); - } catch (Throwable throwable) { - throwable.printStackTrace(); - } - } - - super.tearDown(); - mActivity = null; - } - - protected void takeNamedScreenshot(final String name) { - try { - // Screenshots should be taken on the UI thread - runTestOnUiThread(new Runnable() { - @Override - public void run() { - ScreenshotUtil.take(getActivity(), name); - } - }); - } catch (Throwable throwable) { - throwable.printStackTrace(); - } + protected void takeNamedScreenshot(Activity activity, String name) { + ScreenshotUtil.take(activity, name); } } diff --git a/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/MainActivityTest.java b/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/MainActivityTest.java index 86f501b13..b880176fe 100644 --- a/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/MainActivityTest.java +++ b/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/MainActivityTest.java @@ -1,8 +1,13 @@ package com.mapbox.mapboxgl.testapp; +import android.support.test.rule.ActivityTestRule; +import android.support.test.runner.AndroidJUnit4; import android.test.suitebuilder.annotation.LargeTest; +import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.runner.RunWith; import static android.support.test.espresso.Espresso.onView; import static android.support.test.espresso.action.ViewActions.click; @@ -22,11 +27,23 @@ import static org.hamcrest.Matchers.not; /** * Tests on MainActivity */ +@RunWith(AndroidJUnit4.class) @LargeTest public class MainActivityTest extends BaseTest { private final static String HOME_BUTTON_STRING = "Navigate up"; + @Rule + public ActivityTestRule mActivityRule = new ActivityTestRule<>( + MainActivity.class); + + private MainActivity mActivity = null; + + @Before + public void setActivity() { + mActivity = mActivityRule.getActivity(); + } + /* * Note that we need to keep the `test` prefix if we want to be able to run these * tests on AWS Device Farm, annotations are not enough: @@ -250,7 +267,7 @@ public class MainActivityTest extends BaseTest { @Test public void testMapIconContentDescription() { // Mapbox logo - onView(withContentDescription(getActivity().getResources() + onView(withContentDescription(mActivity.getResources() .getString(R.string.mapboxIconContentDescription))) .check(matches(isDisplayed())); } @@ -258,7 +275,7 @@ public class MainActivityTest extends BaseTest { @Test public void testMapCompassContentDescription() { // Map compass - onView(withContentDescription(getActivity().getResources() + onView(withContentDescription(mActivity.getResources() .getString(R.string.compassContentDescription))) .check(matches(isDisplayed())); } @@ -266,23 +283,9 @@ public class MainActivityTest extends BaseTest { @Test public void testMapAttributionsIconContentDescription() { // Attribution icon - onView(withContentDescription(getActivity().getResources() + onView(withContentDescription(mActivity.getResources() .getString(R.string.attributionsIconContentDescription))) .check(matches(isDisplayed())); } - /* - * Take a screenshot of Mapbox Streets to monitor #1649 - */ - - @Test - public void testMapboxStreetsBlackAndWhite() { - // Click home and switch to Mapbox streets - onView(withContentDescription(HOME_BUTTON_STRING)) - .perform(click()); - onView(withText(R.string.styleMapboxStreets)) - .perform(click()); - takeNamedScreenshot("testMapboxStreetsBlackAndWhite"); - } - } From f775348ec327a4f5341c561ba8d008b4370905eb Mon Sep 17 00:00:00 2001 From: Antonio Zugaldia Date: Wed, 16 Sep 2015 11:03:32 -0400 Subject: [PATCH 28/35] fixed the screenshot class to include the surface view --- .../testapp/utils/ScreenshotUtil.java | 55 ++++++++++++++++--- 1 file changed, 46 insertions(+), 9 deletions(-) diff --git a/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/utils/ScreenshotUtil.java b/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/utils/ScreenshotUtil.java index 51eceaca9..258a38923 100644 --- a/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/utils/ScreenshotUtil.java +++ b/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/utils/ScreenshotUtil.java @@ -2,15 +2,19 @@ package com.mapbox.mapboxgl.testapp.utils; import android.app.Activity; import android.graphics.Bitmap; +import android.graphics.Canvas; import android.os.Environment; import android.util.Log; +import android.view.TextureView; import android.view.View; +import android.view.ViewGroup; import java.io.File; -import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; +import java.util.ArrayList; +import java.util.List; import java.util.UUID; /** @@ -45,6 +49,20 @@ public class ScreenshotUtil { Bitmap bitmap = Bitmap.createBitmap(rootView.getDrawingCache()); rootView.setDrawingCacheEnabled(false); + // Add the SurfaceView bit (see getAllTextureViews() below) + List tilingViews = getAllTextureViews(rootView); + if (tilingViews.size() > 0) { + Canvas canvas = new Canvas(bitmap); + for (TextureView TextureView : tilingViews) { + Bitmap b = TextureView.getBitmap(TextureView.getWidth(), TextureView.getHeight()); + int[] location = new int[2]; + TextureView.getLocationInWindow(location); + int[] location2 = new int[2]; + TextureView.getLocationOnScreen(location2); + canvas.drawBitmap(b, location[0], location[1], null); + } + } + // Save the bitmap in external storage String uniqueAbsolutePath = getUniqueAbsolutePath(testName); File outputFile = new File(uniqueAbsolutePath); @@ -53,8 +71,6 @@ public class ScreenshotUtil { outputStream = new FileOutputStream(outputFile); bitmap.compress(DEFAULT_IMAGE_FORMAT, DEFAULT_IMAGE_QUALITY, outputStream); outputStream.flush(); - } catch (FileNotFoundException e) { - e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { @@ -68,13 +84,34 @@ public class ScreenshotUtil { } } - /* Checks if external storage is available for read and write */ - public static boolean isExternalStorageWritable() { - String state = Environment.getExternalStorageState(); - if (Environment.MEDIA_MOUNTED.equals(state)) { - return true; + /* + * The classic way of taking a screenshot (above) doesn't work with TextureView, this fixes it: + * http://stackoverflow.com/questions/19704060/screen-capture-textureview-is-black-using-drawingcache + */ + + public static List getAllTextureViews(View view) + { + List tilingViews = new ArrayList(); + if (view instanceof TextureView) { + tilingViews.add((TextureView)view); + } else if(view instanceof ViewGroup) { + ViewGroup viewGroup = (ViewGroup)view; + for (int i = 0; i < viewGroup.getChildCount(); i++) { + tilingViews.addAll(getAllTextureViews(viewGroup.getChildAt(i))); + } } - return false; + + return tilingViews; + } + + /* + * Utils + */ + + public static boolean isExternalStorageWritable() { + // Checks if external storage is available for read and write + String state = Environment.getExternalStorageState(); + return Environment.MEDIA_MOUNTED.equals(state); } private static String getUniqueAbsolutePath(String testName) { From ed33a5ee6442510fe511b9ce44a7faa86cd584cf Mon Sep 17 00:00:00 2001 From: Antonio Zugaldia Date: Wed, 16 Sep 2015 11:17:42 -0400 Subject: [PATCH 29/35] screenshots should be taken on ui thread --- .../java/com/mapbox/mapboxgl/testapp/BaseTest.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/BaseTest.java b/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/BaseTest.java index 9c6646105..f3ae2018c 100644 --- a/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/BaseTest.java +++ b/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/BaseTest.java @@ -31,8 +31,16 @@ public class BaseTest { * Screenshots logic */ - protected void takeNamedScreenshot(Activity activity, String name) { - ScreenshotUtil.take(activity, name); + protected void takeNamedScreenshot(final Activity activity, final String name) { + + // Screenshots need to be taken on the UI thread + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + ScreenshotUtil.take(activity, name); + } + }); + } } From 77faa7ea15ae136b2ff504fc49ebfe1926089393 Mon Sep 17 00:00:00 2001 From: Antonio Zugaldia Date: Wed, 16 Sep 2015 11:19:44 -0400 Subject: [PATCH 30/35] zoom in --- .../mapbox/mapboxgl/testapp/MainActivityScreenTest.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/MainActivityScreenTest.java b/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/MainActivityScreenTest.java index af35620f6..80dc0aa77 100644 --- a/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/MainActivityScreenTest.java +++ b/android/java/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxgl/testapp/MainActivityScreenTest.java @@ -11,8 +11,7 @@ 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.action.ViewActions.doubleClick; 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; @@ -54,6 +53,12 @@ public class MainActivityScreenTest extends BaseTest { onView(withText(R.string.styleMapboxStreets)) .perform(click()); + // Zoom in + onView(withId(R.id.mainMapView)) + .perform(doubleClick()); + onView(withId(R.id.mainMapView)) + .perform(doubleClick()); + // Standard screenshot takeNamedScreenshot(mActivity, "testMapboxStreetsBlackAndWhite"); } From 573b43f257fbd4da0b7c87a526c8df61b4165a97 Mon Sep 17 00:00:00 2001 From: Antonio Zugaldia Date: Wed, 16 Sep 2015 13:39:46 -0400 Subject: [PATCH 31/35] unit tests + mockito --- .../MapboxGLAndroidSDKTestApp/build.gradle | 1 + .../src/test/java/CoordinateRegionTest.java | 54 ++++++++++ .../src/test/java/CoordinateSpanTest.java | 33 +++++++ .../src/test/java/LatLngTest.java | 98 +++++++++++++++++++ 4 files changed, 186 insertions(+) create mode 100644 android/java/MapboxGLAndroidSDKTestApp/src/test/java/CoordinateRegionTest.java create mode 100644 android/java/MapboxGLAndroidSDKTestApp/src/test/java/LatLngTest.java diff --git a/android/java/MapboxGLAndroidSDKTestApp/build.gradle b/android/java/MapboxGLAndroidSDKTestApp/build.gradle index 9bc7d493f..98c26912f 100644 --- a/android/java/MapboxGLAndroidSDKTestApp/build.gradle +++ b/android/java/MapboxGLAndroidSDKTestApp/build.gradle @@ -96,6 +96,7 @@ dependencies { // Testing dependencies testCompile 'junit:junit:4.12' + testCompile 'org.mockito:mockito-core:1.+' androidTestCompile 'com.android.support.test:runner:0.4' androidTestCompile 'com.android.support.test:rules:0.4' androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1' diff --git a/android/java/MapboxGLAndroidSDKTestApp/src/test/java/CoordinateRegionTest.java b/android/java/MapboxGLAndroidSDKTestApp/src/test/java/CoordinateRegionTest.java new file mode 100644 index 000000000..9672d9da5 --- /dev/null +++ b/android/java/MapboxGLAndroidSDKTestApp/src/test/java/CoordinateRegionTest.java @@ -0,0 +1,54 @@ +import com.mapbox.mapboxgl.geometry.CoordinateRegion; +import com.mapbox.mapboxgl.geometry.CoordinateSpan; +import com.mapbox.mapboxgl.geometry.LatLng; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +public class CoordinateRegionTest { + + @Test + public void testSanity() { + LatLng center = new LatLng(1.2, 3.4, 5.6); + CoordinateSpan span = new CoordinateSpan(9.8, 7.6); + CoordinateRegion coordinateRegion = new CoordinateRegion(center, span); + assertNotNull("coordinateRegion should not be null", coordinateRegion); + } + + @Test + public void testCenterConstructor() { + LatLng center = new LatLng(1.2, 3.4, 5.6); + CoordinateSpan span = new CoordinateSpan(9.8, 7.6); + CoordinateRegion coordinateRegion = new CoordinateRegion(center, span); + assertEquals("center should match", coordinateRegion.getCenter(), center); + } + + @Test + public void testSpanConstructor() { + LatLng center = new LatLng(1.2, 3.4, 5.6); + CoordinateSpan span = new CoordinateSpan(9.8, 7.6); + CoordinateRegion coordinateRegion = new CoordinateRegion(center, span); + assertEquals("span should match", coordinateRegion.getSpan(), span); + } + + @Test + public void testCenterMethod() { + LatLng center = new LatLng(1.2, 3.4, 5.6); + CoordinateSpan span = new CoordinateSpan(9.8, 7.6); + CoordinateRegion coordinateRegion = new CoordinateRegion(null, span); + coordinateRegion.setCenter(center); + assertEquals("center should match", coordinateRegion.getCenter(), center); + } + + @Test + public void testSpanMethod() { + LatLng center = new LatLng(1.2, 3.4, 5.6); + CoordinateSpan span = new CoordinateSpan(9.8, 7.6); + CoordinateRegion coordinateRegion = new CoordinateRegion(center, null); + coordinateRegion.setSpan(span); + assertEquals("span should match", coordinateRegion.getSpan(), span); + } + +} diff --git a/android/java/MapboxGLAndroidSDKTestApp/src/test/java/CoordinateSpanTest.java b/android/java/MapboxGLAndroidSDKTestApp/src/test/java/CoordinateSpanTest.java index 26734e1a7..0ccb76624 100644 --- a/android/java/MapboxGLAndroidSDKTestApp/src/test/java/CoordinateSpanTest.java +++ b/android/java/MapboxGLAndroidSDKTestApp/src/test/java/CoordinateSpanTest.java @@ -2,14 +2,47 @@ import com.mapbox.mapboxgl.geometry.CoordinateSpan; import org.junit.Test; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; public class CoordinateSpanTest { + private static final double DELTA = 1e-15; + @Test public void testSanity() { CoordinateSpan coordinateSpan = new CoordinateSpan(0.0, 0.0); assertNotNull("coordinateSpan should not be null", coordinateSpan); } + @Test + public void testLatitudeConstructor() { + double latitude = 1.23; + CoordinateSpan coordinateSpan = new CoordinateSpan(latitude, 0.0); + assertEquals("latitude in constructor", coordinateSpan.getLatitudeSpan(), latitude, DELTA); + } + + @Test + public void testLongitudeConstructor() { + double longitude = 1.23; + CoordinateSpan coordinateSpan = new CoordinateSpan(0.0, longitude); + assertEquals("latitude in constructor", coordinateSpan.getLongitudeSpan(), longitude, DELTA); + } + + @Test + public void testLatitudeMethod() { + double latitude = 1.23; + CoordinateSpan coordinateSpan = new CoordinateSpan(0.0, 0.0); + coordinateSpan.setLatitudeSpan(latitude); + assertEquals("latitude in constructor", coordinateSpan.getLatitudeSpan(), latitude, DELTA); + } + + @Test + public void testLongitudeMethod() { + double longitude = 1.23; + CoordinateSpan coordinateSpan = new CoordinateSpan(0.0, 0.0); + coordinateSpan.setLongitudeSpan(longitude); + assertEquals("latitude in constructor", coordinateSpan.getLongitudeSpan(), longitude, DELTA); + } + } diff --git a/android/java/MapboxGLAndroidSDKTestApp/src/test/java/LatLngTest.java b/android/java/MapboxGLAndroidSDKTestApp/src/test/java/LatLngTest.java new file mode 100644 index 000000000..a3065789b --- /dev/null +++ b/android/java/MapboxGLAndroidSDKTestApp/src/test/java/LatLngTest.java @@ -0,0 +1,98 @@ +import android.location.Location; + +import com.mapbox.mapboxgl.geometry.LatLng; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class LatLngTest { + + private static final double DELTA = 1e-15; + + @Test + public void testSanity() { + LatLng latLng = new LatLng(0.0, 0.0); + assertNotNull("latLng should not be null", latLng); + } + + @Test + public void testLatitudeConstructor() { + double latitude = 1.2; + LatLng latLng = new LatLng(latitude, 3.4); + assertEquals("latitude should match", latLng.getLatitude(), latitude, DELTA); + } + + @Test + public void testLongitudeConstructor() { + double longitude = 3.4; + LatLng latLng = new LatLng(1.2, longitude); + assertEquals("longitude should match", latLng.getLongitude(), longitude, DELTA); + } + + @Test + public void testAltitudeConstructor() { + LatLng latLng1 = new LatLng(1.2, 3.4); + assertEquals("altitude default value", latLng1.getAltitude(), 0.0, DELTA); + + double altitude = 5.6; + LatLng latLng2 = new LatLng(1.2, 3.4, altitude); + assertEquals("altitude default value", latLng2.getAltitude(), altitude, DELTA); + } + + /* + * A sample test where Mockito is necessary + */ + + @Test + public void testLocationProvider() { + double latitude = 1.2; + double longitude = 3.4; + double altitude = 5.6; + + // Mock the location class + Location locationMocked = mock(Location.class); + when(locationMocked.getLatitude()).thenReturn(latitude); + when(locationMocked.getLongitude()).thenReturn(longitude); + when(locationMocked.getAltitude()).thenReturn(altitude); + + // Test the constructor + LatLng latLng = new LatLng(locationMocked); + assertEquals("latitude should match", latLng.getLatitude(), latitude, DELTA); + assertEquals("longitude should match", latLng.getLongitude(), longitude, DELTA); + assertEquals("altitude should match", latLng.getAltitude(), altitude, DELTA); + } + + @Test + public void testHashCode() { + double latitude = 1.2; + double longitude = 3.4; + double altitude = 5.6; + LatLng latLng = new LatLng(latitude, longitude, altitude); + assertEquals("hash code should match", latLng.hashCode(), -151519232); + } + + @Test + public void testToString() { + double latitude = 1.2; + double longitude = 3.4; + double altitude = 5.6; + LatLng latLng = new LatLng(latitude, longitude, altitude); + assertEquals("string should match", + latLng.toString(), + "LatLng [longitude=3.4, latitude=1.2, altitude=5.6]"); + } + + @Test + public void testDistanceTo() { + LatLng latLng1 = new LatLng(0.0, 0.0); + LatLng latLng2 = new LatLng(1.0, 1.0); + assertEquals("distances should match", + latLng1.distanceTo(latLng2), + 157425.53710839353, DELTA); + } + +} From 0281d010bd02839f091b64e507a493a497d8daf1 Mon Sep 17 00:00:00 2001 From: Antonio Zugaldia Date: Wed, 16 Sep 2015 13:43:26 -0400 Subject: [PATCH 32/35] two classes at once on aws --- android/java/MapboxGLAndroidSDKTestApp/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/android/java/MapboxGLAndroidSDKTestApp/README.md b/android/java/MapboxGLAndroidSDKTestApp/README.md index 47f6cedcb..96e2e30b7 100644 --- a/android/java/MapboxGLAndroidSDKTestApp/README.md +++ b/android/java/MapboxGLAndroidSDKTestApp/README.md @@ -40,6 +40,8 @@ Then: * On step 4, customize your device state (if needed) * Finally, confirm the configuration and run the tests. +On Step 2, you can also separate by commas different classes: `com.mapbox.mapboxgl.testapp.MainActivityTest,com.mapbox.mapboxgl.testapp.MainActivityScreenTest` + If you have no tests for your app, or want to test some random user behaviour, you can just choose "Built-in: Fuzz" in step 2. From ce2793d84d139118f50061cd17a32f11e1469b64 Mon Sep 17 00:00:00 2001 From: Antonio Zugaldia Date: Wed, 16 Sep 2015 13:49:52 -0400 Subject: [PATCH 33/35] placeholders for the remaining objects --- .../src/test/java/BoundingBoxTest.java | 15 +++++++++++++++ .../src/test/java/LatLngZoomTest.java | 15 +++++++++++++++ .../src/test/java/ProjectedMetersTest.java | 15 +++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 android/java/MapboxGLAndroidSDKTestApp/src/test/java/BoundingBoxTest.java create mode 100644 android/java/MapboxGLAndroidSDKTestApp/src/test/java/LatLngZoomTest.java create mode 100644 android/java/MapboxGLAndroidSDKTestApp/src/test/java/ProjectedMetersTest.java diff --git a/android/java/MapboxGLAndroidSDKTestApp/src/test/java/BoundingBoxTest.java b/android/java/MapboxGLAndroidSDKTestApp/src/test/java/BoundingBoxTest.java new file mode 100644 index 000000000..a94bbc773 --- /dev/null +++ b/android/java/MapboxGLAndroidSDKTestApp/src/test/java/BoundingBoxTest.java @@ -0,0 +1,15 @@ +import com.mapbox.mapboxgl.geometry.BoundingBox; + +import org.junit.Test; + +import static org.junit.Assert.assertNotNull; + +public class BoundingBoxTest { + + @Test + public void testSanity() { + BoundingBox boundingBox = new BoundingBox(0.0, 0.0, 0.0, 0.0); + assertNotNull("boundingBox should not be null", boundingBox); + } + +} diff --git a/android/java/MapboxGLAndroidSDKTestApp/src/test/java/LatLngZoomTest.java b/android/java/MapboxGLAndroidSDKTestApp/src/test/java/LatLngZoomTest.java new file mode 100644 index 000000000..7b6dfbde7 --- /dev/null +++ b/android/java/MapboxGLAndroidSDKTestApp/src/test/java/LatLngZoomTest.java @@ -0,0 +1,15 @@ +import com.mapbox.mapboxgl.geometry.LatLngZoom; + +import org.junit.Test; + +import static org.junit.Assert.assertNotNull; + +public class LatLngZoomTest { + + @Test + public void testSanity() { + LatLngZoom latLngZoom = new LatLngZoom(0.0, 0.0, 0.0); + assertNotNull("latLngZoom should not be null", latLngZoom); + } + +} diff --git a/android/java/MapboxGLAndroidSDKTestApp/src/test/java/ProjectedMetersTest.java b/android/java/MapboxGLAndroidSDKTestApp/src/test/java/ProjectedMetersTest.java new file mode 100644 index 000000000..39655bdf3 --- /dev/null +++ b/android/java/MapboxGLAndroidSDKTestApp/src/test/java/ProjectedMetersTest.java @@ -0,0 +1,15 @@ +import com.mapbox.mapboxgl.geometry.ProjectedMeters; + +import org.junit.Test; + +import static org.junit.Assert.assertNotNull; + +public class ProjectedMetersTest { + + @Test + public void testSanity() { + ProjectedMeters projectedMeters = new ProjectedMeters(0.0, 0.0); + assertNotNull("projectedMeters should not be null", projectedMeters); + } + +} From ec19af2aa5c114f9a485af511ccedbbec1b36c59 Mon Sep 17 00:00:00 2001 From: Antonio Zugaldia Date: Wed, 16 Sep 2015 14:03:03 -0400 Subject: [PATCH 34/35] import JUnit tests instructions --- android/java/MapboxGLAndroidSDKTestApp/README.md | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/android/java/MapboxGLAndroidSDKTestApp/README.md b/android/java/MapboxGLAndroidSDKTestApp/README.md index 96e2e30b7..646f29c4b 100644 --- a/android/java/MapboxGLAndroidSDKTestApp/README.md +++ b/android/java/MapboxGLAndroidSDKTestApp/README.md @@ -48,8 +48,9 @@ you can just choose "Built-in: Fuzz" in step 2. ### Running pure JUnit tests These tests run on a local JVM on your development machine and they are extremely fast to run -(as compared to Espresso). These tests are located under `src/test/java` and to run them you just -need to right click the corresponding test class or method and select "Run ...". +(as compared to Espresso). These tests are located under `src/test/java`. To run them you switch +to the Unit Tests build variant, then right click the corresponding test class or method +and select "Run ...". You can also have a run configuration: * Click on Run -> Edit Configurations... @@ -59,6 +60,12 @@ You can also have a run configuration: * As folder, choose the following folder: `mapbox-gl-native/android/java/MapboxGLAndroidSDKTestApp/src/test/java` * Click OK to save the new configuration +You can also run the tests from the command line with: + +``` +$ ./gradlew test --continue -p MapboxGLAndroidSDKTestApp +``` + ### Running the UI/Application Exerciser Monkey Similar to the "Built-in: Fuzz" test mentioned above, Android provides From fee31b05b9e698f8755a867f7c219d7b7de987c4 Mon Sep 17 00:00:00 2001 From: Antonio Zugaldia Date: Wed, 16 Sep 2015 16:45:18 -0400 Subject: [PATCH 35/35] back to right submodules versions --- .mason | 2 +- styles | 2 +- test/ios/KIF | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.mason b/.mason index c066f7d19..d8597d944 160000 --- a/.mason +++ b/.mason @@ -1 +1 @@ -Subproject commit c066f7d19f88b854da1002ce2f96aa7aba628cb5 +Subproject commit d8597d944533dbb5e28d08dfdba22a82c93171b7 diff --git a/styles b/styles index 014e36833..19dde3cb1 160000 --- a/styles +++ b/styles @@ -1 +1 @@ -Subproject commit 014e36833420c81b29bec816b479ea61e94821d4 +Subproject commit 19dde3cb1c36fe5f42dafc78c806fd7aca98126c diff --git a/test/ios/KIF b/test/ios/KIF index 976aafa2e..21a137bc8 160000 --- a/test/ios/KIF +++ b/test/ios/KIF @@ -1 +1 @@ -Subproject commit 976aafa2e211dd095411bfef09da6c0919d70476 +Subproject commit 21a137bc8068f9fb738f835c6e285d44fe2ce4dd