diff options
author | tobrun <tobrun.van.nuland@gmail.com> | 2018-07-06 10:00:32 +0200 |
---|---|---|
committer | tobrun <tobrun.van.nuland@gmail.com> | 2018-07-06 10:00:32 +0200 |
commit | 2eafb1aa7c3df42d7b6300f0e26d9021fa36043f (patch) | |
tree | 6b7c579f2256222fcebab015149c394d7326f78f /platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps | |
parent | ec472cb45ace58b2f159d42f439f51199ca5e34b (diff) | |
download | qtlocation-mapboxgl-2eafb1aa7c3df42d7b6300f0e26d9021fa36043f.tar.gz |
[android] - consolidate all instrumentation tests in maps packageupstream/tvn-move-tests
Diffstat (limited to 'platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps')
51 files changed, 8075 insertions, 11 deletions
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java index 26960ddb61..3e4c8ae97a 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java @@ -17,10 +17,10 @@ import com.mapbox.mapboxsdk.exceptions.InvalidMarkerPositionException; import com.mapbox.mapboxsdk.geometry.LatLng; import com.mapbox.mapboxsdk.geometry.LatLngBounds; import com.mapbox.mapboxsdk.testapp.R; -import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest; -import com.mapbox.mapboxsdk.testapp.activity.espresso.EspressoTestActivity; -import com.mapbox.mapboxsdk.testapp.utils.TestConstants; -import com.mapbox.mapboxsdk.testapp.utils.ViewUtils; +import com.mapbox.mapboxsdk.maps.activity.BaseActivityTest; +import com.mapbox.mapboxsdk.maps.activity.espresso.EspressoTestActivity; +import com.mapbox.mapboxsdk.maps.utils.TestConstants; +import com.mapbox.mapboxsdk.maps.utils.ViewUtils; import org.hamcrest.Matcher; import org.junit.Ignore; import org.junit.Test; @@ -32,7 +32,7 @@ import java.util.List; import static android.support.test.espresso.Espresso.onView; import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; import static android.support.test.espresso.matcher.ViewMatchers.withId; -import static com.mapbox.mapboxsdk.testapp.utils.TestConstants.LAT_LNG_DELTA; +import static com.mapbox.mapboxsdk.maps.utils.TestConstants.LAT_LNG_DELTA; import static junit.framework.TestCase.assertFalse; import static junit.framework.TestCase.assertNotNull; import static org.junit.Assert.assertEquals; diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/OrientationTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/OrientationTest.java index 89397c30eb..737e3aa89a 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/OrientationTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/OrientationTest.java @@ -1,15 +1,15 @@ package com.mapbox.mapboxsdk.maps; -import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest; -import com.mapbox.mapboxsdk.testapp.activity.camera.CameraAnimationTypeActivity; +import com.mapbox.mapboxsdk.maps.activity.BaseActivityTest; +import com.mapbox.mapboxsdk.maps.activity.camera.CameraAnimationTypeActivity; import org.junit.Test; import static android.support.test.espresso.Espresso.onView; import static android.support.test.espresso.matcher.ViewMatchers.isRoot; -import static com.mapbox.mapboxsdk.testapp.action.OrientationChangeAction.orientationLandscape; -import static com.mapbox.mapboxsdk.testapp.action.OrientationChangeAction.orientationLandscapeReverse; -import static com.mapbox.mapboxsdk.testapp.action.OrientationChangeAction.orientationPortrait; -import static com.mapbox.mapboxsdk.testapp.action.OrientationChangeAction.orientationPortraitReverse; +import static com.mapbox.mapboxsdk.maps.action.OrientationChangeAction.orientationLandscape; +import static com.mapbox.mapboxsdk.maps.action.OrientationChangeAction.orientationLandscapeReverse; +import static com.mapbox.mapboxsdk.maps.action.OrientationChangeAction.orientationPortrait; +import static com.mapbox.mapboxsdk.maps.action.OrientationChangeAction.orientationPortraitReverse; public class OrientationTest extends BaseActivityTest { diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/action/MapboxMapAction.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/action/MapboxMapAction.java new file mode 100644 index 0000000000..349fcdc1d4 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/action/MapboxMapAction.java @@ -0,0 +1,49 @@ +package com.mapbox.mapboxsdk.maps.action; + +import android.support.test.espresso.UiController; +import android.support.test.espresso.ViewAction; +import android.view.View; + +import com.mapbox.mapboxsdk.maps.MapboxMap; + +import org.hamcrest.Matcher; + +import static android.support.test.espresso.Espresso.onView; +import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; +import static android.support.test.espresso.matcher.ViewMatchers.withId; + +public class MapboxMapAction implements ViewAction { + + private OnInvokeActionListener invokeViewAction; + private MapboxMap mapboxMap; + + public MapboxMapAction(OnInvokeActionListener invokeViewAction, MapboxMap mapboxMap) { + this.invokeViewAction = invokeViewAction; + this.mapboxMap = mapboxMap; + } + + @Override + public Matcher<View> getConstraints() { + return isDisplayed(); + } + + @Override + public String getDescription() { + return getClass().getSimpleName(); + } + + @Override + public void perform(UiController uiController, View view) { + invokeViewAction.onInvokeAction(uiController, mapboxMap); + } + + public static void invoke(MapboxMap mapboxMap, OnInvokeActionListener invokeViewAction) { + onView(withId(android.R.id.content)).perform(new MapboxMapAction(invokeViewAction, mapboxMap)); + } + + public interface OnInvokeActionListener { + void onInvokeAction(UiController uiController, MapboxMap mapboxMap); + } +} + + diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/action/OrientationChangeAction.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/action/OrientationChangeAction.java new file mode 100644 index 0000000000..59071ddc94 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/action/OrientationChangeAction.java @@ -0,0 +1,74 @@ +package com.mapbox.mapboxsdk.maps.action; + + +import android.app.Activity; +import android.content.Context; +import android.content.ContextWrapper; +import android.content.pm.ActivityInfo; +import android.support.test.espresso.UiController; +import android.support.test.espresso.ViewAction; +import android.view.View; +import android.view.ViewGroup; +import org.hamcrest.Matcher; + +import static android.support.test.espresso.matcher.ViewMatchers.isRoot; + +public class OrientationChangeAction implements ViewAction { + + private final int orientation; + + private OrientationChangeAction(int orientation) { + this.orientation = orientation; + } + + public static ViewAction orientationLandscape() { + return new OrientationChangeAction(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); + } + + public static ViewAction orientationPortrait() { + return new OrientationChangeAction(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); + } + + public static ViewAction orientationLandscapeReverse() { + return new OrientationChangeAction(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE); + } + + public static ViewAction orientationPortraitReverse() { + return new OrientationChangeAction(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT); + } + + @Override + public Matcher<View> getConstraints() { + return isRoot(); + } + + @Override + public String getDescription() { + return "change orientation to " + orientation; + } + + @Override + public void perform(UiController uiController, View view) { + uiController.loopMainThreadUntilIdle(); + Activity activity = getActivity(view.getContext()); + if (activity == null && view instanceof ViewGroup) { + ViewGroup v = (ViewGroup) view; + int c = v.getChildCount(); + for (int i = 0; i < c && activity == null; ++i) { + activity = getActivity(v.getChildAt(i).getContext()); + } + } + activity.setRequestedOrientation(orientation); + } + + private Activity getActivity(Context context) { + while (context instanceof ContextWrapper) { + if (context instanceof Activity) { + return (Activity) context; + } + context = ((ContextWrapper) context).getBaseContext(); + } + return null; + } + +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/action/WaitAction.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/action/WaitAction.java new file mode 100644 index 0000000000..3312daecac --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/action/WaitAction.java @@ -0,0 +1,39 @@ +package com.mapbox.mapboxsdk.maps.action; + +import android.support.test.espresso.UiController; +import android.support.test.espresso.ViewAction; +import android.view.View; + +import org.hamcrest.Matcher; + +import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; + +public final class WaitAction implements ViewAction { + + private static final long DEFAULT_LOOP_TIME = 375; + private final long loopTime; + + public WaitAction() { + this(DEFAULT_LOOP_TIME); + } + + public WaitAction(long loopTime) { + this.loopTime = loopTime; + } + + @Override + public Matcher<View> getConstraints() { + return isDisplayed(); + } + + @Override + public String getDescription() { + return getClass().getSimpleName(); + } + + @Override + public void perform(UiController uiController, View view) { + uiController.loopMainThreadForAtLeast(loopTime); + } +} + diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/activity/BaseActivityTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/activity/BaseActivityTest.java new file mode 100644 index 0000000000..334c407d4f --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/activity/BaseActivityTest.java @@ -0,0 +1,98 @@ +package com.mapbox.mapboxsdk.maps.activity; + +import android.app.Activity; +import android.content.Context; +import android.net.ConnectivityManager; +import android.net.NetworkInfo; +import android.support.test.espresso.Espresso; +import android.support.test.espresso.IdlingResourceTimeoutException; +import android.support.test.espresso.ViewInteraction; +import android.support.test.rule.ActivityTestRule; +import com.mapbox.mapboxsdk.maps.MapboxMap; +import com.mapbox.mapboxsdk.testapp.R; +import com.mapbox.mapboxsdk.maps.action.MapboxMapAction; +import com.mapbox.mapboxsdk.maps.action.WaitAction; +import com.mapbox.mapboxsdk.maps.utils.OnMapReadyIdlingResource; +import junit.framework.Assert; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import timber.log.Timber; + +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; + +public abstract class BaseActivityTest { + + @Rule + public ActivityTestRule<Activity> rule = new ActivityTestRule<>(getActivityClass()); + protected MapboxMap mapboxMap; + protected OnMapReadyIdlingResource idlingResource; + + @Before + public void beforeTest() { + try { + Timber.e("@Before test: register idle resource"); + idlingResource = new OnMapReadyIdlingResource(rule.getActivity()); + Espresso.registerIdlingResources(idlingResource); + checkViewIsDisplayed(R.id.mapView); + mapboxMap = idlingResource.getMapboxMap(); + } catch (IdlingResourceTimeoutException idlingResourceTimeoutException) { + Timber.e("Idling resource timed out. Couldn't not validate if map is ready."); + throw new RuntimeException("Could not start test for " + getActivityClass().getSimpleName() + ".\n" + + "The ViewHierarchy doesn't contain a view with resource id = R.id.mapView or \n" + + "the Activity doesn't contain an instance variable with a name equal to mapboxMap.\n" + + "You can resolve this issue by adding the requirements above or\n add " + + getActivityClass().getSimpleName() + " to the platform/android/scripts/exclude-activity-gen.json to blacklist" + + " the Activity from being generated.\n"); + } + } + + protected void validateTestSetup() { + Assert.assertTrue("Device is not connected to the Internet.", isConnected(rule.getActivity())); + checkViewIsDisplayed(R.id.mapView); + Assert.assertNotNull(mapboxMap); + } + + protected MapboxMap getMapboxMap() { + return mapboxMap; + } + + protected abstract Class getActivityClass(); + + protected void checkViewIsDisplayed(int id) { + onView(withId(id)).check(matches(isDisplayed())); + } + + protected void waitAction() { + waitAction(500); + } + + protected void waitAction(long waitTime) { + onView(withId(R.id.mapView)).perform(new WaitAction(waitTime)); + } + + static boolean isConnected(Context context) { + ConnectivityManager connectivityManager + = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); + NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo(); + return activeNetworkInfo != null && activeNetworkInfo.isConnected(); + } + + protected ViewInteraction onMapView() { + return onView(withId(R.id.mapView)); + } + + protected MapboxMapAction getMapboxMapAction(MapboxMapAction.OnInvokeActionListener onInvokeActionListener) { + return new MapboxMapAction(onInvokeActionListener, mapboxMap); + } + + @After + public void afterTest() { + Timber.e("@After test: unregister idle resource"); + Espresso.unregisterIdlingResources(idlingResource); + } +} + diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/activity/activity.junit.ejs b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/activity/activity.junit.ejs new file mode 100644 index 0000000000..03d4de17f4 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/activity/activity.junit.ejs @@ -0,0 +1,37 @@ +<% + const activity = locals[0]; + const subPackage = locals[1]; +-%> +// This file is generated. Edit android/platform/scripts/generate-test-code.js, then run `make generate-test-android`. +package com.mapbox.mapboxsdk.testapp.activity.gen.<%- subPackage %>; + +import android.support.test.runner.AndroidJUnit4; + +import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest; +import com.mapbox.mapboxsdk.testapp.R; +import com.mapbox.mapboxsdk.testapp.activity.<%- subPackage %>.<%- activity %>; + +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; + +/** + * Sanity test for <%- activity %> + */ +@RunWith(AndroidJUnit4.class) +public class <%- activity %>Test extends BaseActivityTest { + + @Test + public void testSanity() { + validateTestSetup(); + } + + @Override + protected Class getActivityClass() { + return <%- activity %>.class; + } +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/annotations/IconTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/annotations/IconTest.java new file mode 100644 index 0000000000..ca146c8328 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/annotations/IconTest.java @@ -0,0 +1,153 @@ +package com.mapbox.mapboxsdk.maps.annotations; + +import android.app.Activity; +import android.support.v4.content.res.ResourcesCompat; +import com.mapbox.mapboxsdk.annotations.Icon; +import com.mapbox.mapboxsdk.annotations.IconFactory; +import com.mapbox.mapboxsdk.annotations.Marker; +import com.mapbox.mapboxsdk.annotations.MarkerOptions; +import com.mapbox.mapboxsdk.geometry.LatLng; +import com.mapbox.mapboxsdk.maps.IconManagerResolver; +import com.mapbox.mapboxsdk.testapp.R; +import com.mapbox.mapboxsdk.maps.activity.BaseActivityTest; +import com.mapbox.mapboxsdk.maps.activity.espresso.EspressoTestActivity; +import com.mapbox.mapboxsdk.maps.utils.IconUtils; +import org.junit.Before; +import org.junit.Test; + +import java.util.Map; + +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertFalse; +import static junit.framework.Assert.assertNull; +import static junit.framework.Assert.assertTrue; + +/** + * Tests integration between Icons and Markers + */ +public class IconTest extends BaseActivityTest { + + private Map<Icon, Integer> iconMap; + + @Before + public void beforeTest() { + super.beforeTest(); + iconMap = new IconManagerResolver(getMapboxMap()).getIconMap(); + } + + @Test + public void testEmpty() { + assertTrue(iconMap.isEmpty()); + } + + @Test + public void testAddSameIconMarker() { + validateTestSetup(); + onMapView().perform(getMapboxMapAction((uiController, mapboxMap) -> { + Icon defaultMarker = IconFactory.getInstance(rule.getActivity()).defaultMarker(); + mapboxMap.addMarker(new MarkerOptions().position(new LatLng())); + mapboxMap.addMarker(new MarkerOptions().position(new LatLng(1, 1))); + assertEquals(1, iconMap.size()); + assertEquals(2, iconMap.get(defaultMarker), 0); + })); + } + + @Test + public void testAddDifferentIconMarker() { + validateTestSetup(); + onMapView().perform(getMapboxMapAction((uiController, mapboxMap) -> { + Icon icon = IconFactory.getInstance(rule.getActivity()).fromResource(R.drawable.mapbox_logo_icon); + getMapboxMap().addMarker(new MarkerOptions().icon(icon).position(new LatLng())); + getMapboxMap().addMarker(new MarkerOptions().position(new LatLng(1, 1))); + assertEquals(iconMap.size(), 2); + assertTrue(iconMap.containsKey(icon)); + assertTrue(iconMap.get(icon) == 1); + })); + } + + @Test + public void testAddRemoveIconMarker() { + validateTestSetup(); + onMapView().perform(getMapboxMapAction((uiController, mapboxMap) -> { + Icon icon = IconFactory.getInstance(rule.getActivity()).fromResource(R.drawable.mapbox_logo_icon); + Marker marker = mapboxMap.addMarker(new MarkerOptions().icon(icon).position(new LatLng())); + mapboxMap.addMarker(new MarkerOptions().position(new LatLng(1, 1))); + assertEquals(iconMap.size(), 2); + assertTrue(iconMap.containsKey(icon)); + assertTrue(iconMap.get(icon) == 1); + + mapboxMap.removeMarker(marker); + assertEquals(iconMap.size(), 1); + assertFalse(iconMap.containsKey(icon)); + })); + } + + @Test + public void testAddRemoveDefaultMarker() { + validateTestSetup(); + onMapView().perform(getMapboxMapAction((uiController, mapboxMap) -> { + Marker marker = mapboxMap.addMarker(new MarkerOptions().position(new LatLng(1, 1))); + assertEquals(iconMap.size(), 1); + + mapboxMap.removeMarker(marker); + assertEquals(iconMap.size(), 0); + + mapboxMap.addMarker(new MarkerOptions().position(new LatLng())); + assertEquals(iconMap.size(), 1); + })); + } + + @Test + public void testAddRemoveMany() { + validateTestSetup(); + onMapView().perform(getMapboxMapAction((uiController, mapboxMap) -> { + Activity activity = rule.getActivity(); + IconFactory iconFactory = IconFactory.getInstance(activity); + + // add 2 default icon markers + Marker defaultMarkerOne = mapboxMap.addMarker(new MarkerOptions().position(new LatLng(1, 1))); + Marker defaultMarkerTwo = mapboxMap.addMarker(new MarkerOptions().position(new LatLng(2, 1))); + + // add 4 unique icon markers + mapboxMap.addMarker(new MarkerOptions() + .icon(iconFactory.fromResource(R.drawable.mapbox_logo_icon)) + .position(new LatLng(3, 1)) + ); + mapboxMap.addMarker(new MarkerOptions() + .icon(iconFactory.fromResource(R.drawable.mapbox_compass_icon)) + .position(new LatLng(4, 1)) + ); + mapboxMap.addMarker(new MarkerOptions() + .icon(IconUtils.drawableToIcon(activity, R.drawable.ic_stars, + ResourcesCompat.getColor(activity.getResources(), + R.color.blueAccent, activity.getTheme()))) + .position(new LatLng(5, 1)) + ); + mapboxMap.addMarker(new MarkerOptions() + .icon(iconFactory.fromResource(R.drawable.ic_android)) + .position(new LatLng(6, 1)) + ); + + assertEquals("Amount of icons should match 5", 5, iconMap.size()); + assertEquals("Refcounter of default marker should match 2", 2, iconMap.get(iconFactory.defaultMarker()), 0); + + mapboxMap.removeMarker(defaultMarkerOne); + + assertEquals("Amount of icons should match 5", 5, iconMap.size()); + assertEquals("Refcounter of default marker should match 1", 1, iconMap.get(iconFactory.defaultMarker()), 0); + + mapboxMap.removeMarker(defaultMarkerTwo); + + assertEquals("Amount of icons should match 4", 4, iconMap.size()); + assertNull("DefaultMarker shouldn't exist anymore", iconMap.get(iconFactory.defaultMarker())); + + mapboxMap.clear(); + assertEquals("Amount of icons should match 0", 0, iconMap.size()); + })); + } + + @Override + protected Class getActivityClass() { + return EspressoTestActivity.class; + } +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/annotations/MarkerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/annotations/MarkerTest.java new file mode 100644 index 0000000000..c690528040 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/annotations/MarkerTest.java @@ -0,0 +1,69 @@ +package com.mapbox.mapboxsdk.maps.annotations; + +import com.mapbox.mapboxsdk.annotations.Marker; +import com.mapbox.mapboxsdk.annotations.MarkerOptions; +import com.mapbox.mapboxsdk.geometry.LatLng; +import com.mapbox.mapboxsdk.maps.action.MapboxMapAction; +import com.mapbox.mapboxsdk.maps.activity.BaseActivityTest; +import com.mapbox.mapboxsdk.maps.activity.espresso.EspressoTestActivity; +import com.mapbox.mapboxsdk.maps.utils.TestConstants; + +import org.junit.Ignore; +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.withText; +import static com.mapbox.mapboxsdk.maps.action.MapboxMapAction.invoke; +import static org.junit.Assert.assertEquals; + +public class MarkerTest extends BaseActivityTest { + + private Marker marker; + + @Override + protected Class getActivityClass() { + return EspressoTestActivity.class; + } + + @Test + @Ignore + public void addMarkerTest() { + validateTestSetup(); + MapboxMapAction.invoke(mapboxMap, (uiController, mapboxMap) -> { + assertEquals("Markers should be empty", 0, mapboxMap.getMarkers().size()); + + MarkerOptions options = new MarkerOptions(); + options.setPosition(new LatLng()); + options.setSnippet(TestConstants.TEXT_MARKER_SNIPPET); + options.setTitle(TestConstants.TEXT_MARKER_TITLE); + marker = mapboxMap.addMarker(options); + + assertEquals("Markers size should be 1, ", 1, mapboxMap.getMarkers().size()); + assertEquals("Marker id should be 0", 0, marker.getId()); + assertEquals("Marker target should match", new LatLng(), marker.getPosition()); + assertEquals("Marker snippet should match", TestConstants.TEXT_MARKER_SNIPPET, marker.getSnippet()); + assertEquals("Marker target should match", TestConstants.TEXT_MARKER_TITLE, marker.getTitle()); + mapboxMap.clear(); + assertEquals("Markers should be empty", 0, mapboxMap.getMarkers().size()); + }); + } + + @Test + @Ignore + public void showInfoWindowTest() { + validateTestSetup(); + invoke(mapboxMap, (uiController, mapboxMap) -> { + final MarkerOptions options = new MarkerOptions(); + options.setPosition(new LatLng()); + options.setSnippet(TestConstants.TEXT_MARKER_SNIPPET); + options.setTitle(TestConstants.TEXT_MARKER_TITLE); + marker = mapboxMap.addMarker(options); + mapboxMap.selectMarker(marker); + }); + onView(withText(TestConstants.TEXT_MARKER_TITLE)).check(matches(isDisplayed())); + onView(withText(TestConstants.TEXT_MARKER_SNIPPET)).check(matches(isDisplayed())); + } + +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/annotations/MarkerViewTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/annotations/MarkerViewTest.java new file mode 100644 index 0000000000..08cfdcc105 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/annotations/MarkerViewTest.java @@ -0,0 +1,79 @@ +package com.mapbox.mapboxsdk.maps.annotations; + +import com.mapbox.mapboxsdk.annotations.Marker; +import com.mapbox.mapboxsdk.geometry.LatLng; +import com.mapbox.mapboxsdk.maps.activity.BaseActivityTest; +import com.mapbox.mapboxsdk.maps.activity.annotation.MarkerViewActivity; +import com.mapbox.mapboxsdk.maps.activity.espresso.EspressoTestActivity; +import com.mapbox.mapboxsdk.testapp.model.annotations.TextMarkerViewOptions; +import com.mapbox.mapboxsdk.maps.utils.TestConstants; + +import org.junit.Ignore; +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.withText; +import static com.mapbox.mapboxsdk.maps.action.MapboxMapAction.invoke; +import static org.junit.Assert.assertEquals; + +public class MarkerViewTest extends BaseActivityTest { + + private Marker marker; + + @Override + protected Class getActivityClass() { + return EspressoTestActivity.class; + } + + @Test + @Ignore + public void addMarkerViewTest() { + validateTestSetup(); + addAdapter(); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertEquals("Markers should be empty", 0, mapboxMap.getMarkers().size()); + + TextMarkerViewOptions options = new TextMarkerViewOptions(); + options.text(TestConstants.TEXT_MARKER_TEXT); + options.position(new LatLng()); + options.snippet(TestConstants.TEXT_MARKER_SNIPPET); + options.title(TestConstants.TEXT_MARKER_TITLE); + marker = mapboxMap.addMarker(options); + assertEquals("Markers size should be 1, ", 1, mapboxMap.getMarkers().size()); + assertEquals("Marker id should be 0", 0, marker.getId()); + assertEquals("Marker target should match", new LatLng(), marker.getPosition()); + assertEquals("Marker snippet should match", TestConstants.TEXT_MARKER_SNIPPET, marker.getSnippet()); + assertEquals("Marker target should match", TestConstants.TEXT_MARKER_TITLE, marker.getTitle()); + uiController.loopMainThreadForAtLeast(500); + }); + onView(withText(TestConstants.TEXT_MARKER_TEXT)).check(matches(isDisplayed())); + } + + @Test + @Ignore + public void showInfoWindowTest() { + validateTestSetup(); + addAdapter(); + invoke(mapboxMap, (uiController, mapboxMap) -> { + final TextMarkerViewOptions options = new TextMarkerViewOptions(); + options.position(new LatLng()); + options.text(TestConstants.TEXT_MARKER_TEXT); + options.snippet(TestConstants.TEXT_MARKER_SNIPPET); + options.title(TestConstants.TEXT_MARKER_TITLE); + marker = mapboxMap.addMarker(options); + uiController.loopMainThreadForAtLeast(500); + mapboxMap.selectMarker(marker); + }); + onView(withText(TestConstants.TEXT_MARKER_TEXT)).check(matches(isDisplayed())); + onView(withText(TestConstants.TEXT_MARKER_TITLE)).check(matches(isDisplayed())); + onView(withText(TestConstants.TEXT_MARKER_SNIPPET)).check(matches(isDisplayed())); + } + + private void addAdapter() { + invoke(mapboxMap, (uiController, mapboxMap) -> mapboxMap.getMarkerViewManager().addMarkerViewAdapter( + new MarkerViewActivity.TextAdapter(rule.getActivity(), mapboxMap))); + } + +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/annotations/PolygonTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/annotations/PolygonTest.java new file mode 100644 index 0000000000..8c8db37cdd --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/annotations/PolygonTest.java @@ -0,0 +1,52 @@ +package com.mapbox.mapboxsdk.maps.annotations; + +import android.graphics.Color; + +import com.mapbox.mapboxsdk.annotations.Polygon; +import com.mapbox.mapboxsdk.annotations.PolygonOptions; +import com.mapbox.mapboxsdk.geometry.LatLng; +import com.mapbox.mapboxsdk.maps.activity.BaseActivityTest; +import com.mapbox.mapboxsdk.maps.activity.espresso.EspressoTestActivity; + +import org.junit.Ignore; +import org.junit.Test; + +import static com.mapbox.mapboxsdk.maps.action.MapboxMapAction.invoke; +import static org.junit.Assert.assertEquals; + +public class PolygonTest extends BaseActivityTest { + + @Override + protected Class getActivityClass() { + return EspressoTestActivity.class; + } + + @Test + @Ignore + public void addPolygonTest() { + validateTestSetup(); + invoke(mapboxMap, (uiController, mapboxMap) -> { + LatLng latLngOne = new LatLng(); + LatLng latLngTwo = new LatLng(1, 0); + LatLng latLngThree = new LatLng(1, 1); + + assertEquals("Polygons should be empty", 0, mapboxMap.getPolygons().size()); + + final PolygonOptions options = new PolygonOptions(); + options.strokeColor(Color.BLUE); + options.fillColor(Color.RED); + options.add(latLngOne); + options.add(latLngTwo); + options.add(latLngThree); + Polygon polygon = mapboxMap.addPolygon(options); + + assertEquals("Polygons should be 1", 1, mapboxMap.getPolygons().size()); + assertEquals("Polygon id should be 0", 0, polygon.getId()); + assertEquals("Polygon points size should match", 3, polygon.getPoints().size()); + assertEquals("Polygon stroke color should match", Color.BLUE, polygon.getStrokeColor()); + assertEquals("Polygon target should match", Color.RED, polygon.getFillColor()); + mapboxMap.clear(); + assertEquals("Polygons should be empty", 0, mapboxMap.getPolygons().size()); + }); + } +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/annotations/PolylineTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/annotations/PolylineTest.java new file mode 100644 index 0000000000..dda60d647a --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/annotations/PolylineTest.java @@ -0,0 +1,48 @@ +package com.mapbox.mapboxsdk.maps.annotations; + +import android.graphics.Color; + +import com.mapbox.mapboxsdk.annotations.Polyline; +import com.mapbox.mapboxsdk.annotations.PolylineOptions; +import com.mapbox.mapboxsdk.geometry.LatLng; +import com.mapbox.mapboxsdk.maps.activity.BaseActivityTest; +import com.mapbox.mapboxsdk.maps.activity.espresso.EspressoTestActivity; + +import org.junit.Ignore; +import org.junit.Test; + +import static com.mapbox.mapboxsdk.maps.action.MapboxMapAction.invoke; +import static org.junit.Assert.assertEquals; + +public class PolylineTest extends BaseActivityTest { + + @Override + protected Class getActivityClass() { + return EspressoTestActivity.class; + } + + @Test + @Ignore + public void addPolylineTest() { + validateTestSetup(); + invoke(mapboxMap, (uiController, mapboxMap) -> { + LatLng latLngOne = new LatLng(); + LatLng latLngTwo = new LatLng(1, 0); + + assertEquals("Polygons should be empty", 0, mapboxMap.getPolygons().size()); + + final PolylineOptions options = new PolylineOptions(); + options.color(Color.BLUE); + options.add(latLngOne); + options.add(latLngTwo); + Polyline polyline = mapboxMap.addPolyline(options); + + assertEquals("Polylines should be 1", 1, mapboxMap.getPolylines().size()); + assertEquals("Polyline id should be 0", 0, polyline.getId()); + assertEquals("Polyline points size should match", 2, polyline.getPoints().size()); + assertEquals("Polyline stroke color should match", Color.BLUE, polyline.getColor()); + mapboxMap.clear(); + assertEquals("Polyline should be empty", 0, mapboxMap.getPolylines().size()); + }); + } +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/camera/CameraAnimateTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/camera/CameraAnimateTest.java new file mode 100644 index 0000000000..12f3a214ba --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/camera/CameraAnimateTest.java @@ -0,0 +1,188 @@ +package com.mapbox.mapboxsdk.maps.camera; + +import android.graphics.PointF; + +import com.mapbox.mapboxsdk.camera.CameraPosition; +import com.mapbox.mapboxsdk.camera.CameraUpdateFactory; +import com.mapbox.mapboxsdk.geometry.LatLng; +import com.mapbox.mapboxsdk.geometry.LatLngBounds; +import com.mapbox.mapboxsdk.maps.activity.BaseActivityTest; +import com.mapbox.mapboxsdk.maps.activity.espresso.DeviceIndependentTestActivity; +import com.mapbox.mapboxsdk.maps.utils.TestConstants; + +import org.junit.Test; + +import static com.mapbox.mapboxsdk.maps.action.MapboxMapAction.invoke; +import static org.junit.Assert.assertEquals; + +public class CameraAnimateTest extends BaseActivityTest { + + @Override + protected Class getActivityClass() { + return DeviceIndependentTestActivity.class; + } + + @Test + public void testAnimateToCameraPositionTarget() { + validateTestSetup(); + invoke(mapboxMap, (uiController, mapboxMap) -> { + float zoom = 1.0f; + LatLng moveTarget = new LatLng(1, 1); + CameraPosition initialPosition = new CameraPosition.Builder().target( + new LatLng()).zoom(zoom).bearing(0).tilt(0).build(); + CameraPosition cameraPosition = mapboxMap.getCameraPosition(); + assertEquals("Default camera position should match default", cameraPosition, initialPosition); + mapboxMap.animateCamera(CameraUpdateFactory.newLatLng(moveTarget)); + uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME); + cameraPosition = mapboxMap.getCameraPosition(); + assertEquals("Moved camera position latitude should match", cameraPosition.target.getLatitude(), + moveTarget.getLatitude(), TestConstants.LAT_LNG_DELTA); + assertEquals("Moved camera position longitude should match", cameraPosition.target.getLongitude(), + moveTarget.getLongitude(), TestConstants.LAT_LNG_DELTA); + }); + } + + @Test + public void testAnimateToCameraPositionTargetZoom() { + validateTestSetup(); + invoke(mapboxMap, (uiController, mapboxMap) -> { + final float moveZoom = 15.5f; + final LatLng moveTarget = new LatLng(1.0000000001, 1.0000000003); + mapboxMap.animateCamera(CameraUpdateFactory.newLatLngZoom(moveTarget, moveZoom)); + uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME); + CameraPosition cameraPosition = mapboxMap.getCameraPosition(); + assertEquals("Moved camera position latitude should match", cameraPosition.target.getLatitude(), + moveTarget.getLatitude(), TestConstants.LAT_LNG_DELTA); + assertEquals("Moved camera position longitude should match", cameraPosition.target.getLongitude(), + moveTarget.getLongitude(), TestConstants.LAT_LNG_DELTA); + assertEquals("Moved zoom should match", cameraPosition.zoom, moveZoom, TestConstants.ZOOM_DELTA); + }); + } + + @Test + public void testAnimateToCameraPosition() { + validateTestSetup(); + invoke(mapboxMap, (uiController, mapboxMap) -> { + final LatLng moveTarget = new LatLng(1.0000000001, 1.0000000003); + final float moveZoom = 15.5f; + final float moveTilt = 45.5f; + final float moveBearing = 12.5f; + + mapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition( + new CameraPosition.Builder() + .target(moveTarget) + .zoom(moveZoom) + .tilt(moveTilt) + .bearing(moveBearing) + .build()) + ); + uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME); + CameraPosition cameraPosition = mapboxMap.getCameraPosition(); + assertEquals("Moved camera position latitude should match", cameraPosition.target.getLatitude(), + moveTarget.getLatitude(), TestConstants.LAT_LNG_DELTA); + assertEquals("Moved camera position longitude should match", cameraPosition.target.getLongitude(), + moveTarget.getLongitude(), TestConstants.LAT_LNG_DELTA); + assertEquals("Moved zoom should match", cameraPosition.zoom, moveZoom, TestConstants.ZOOM_DELTA); + assertEquals("Moved zoom should match", cameraPosition.tilt, moveTilt, TestConstants.TILT_DELTA); + assertEquals("Moved bearing should match", cameraPosition.bearing, moveBearing, TestConstants.BEARING_DELTA); + }); + } + + @Test + public void testAnimateToBounds() { + validateTestSetup(); + invoke(mapboxMap, (uiController, mapboxMap) -> { + final LatLng centerBounds = new LatLng(1, 1); + LatLng cornerOne = new LatLng(); + LatLng cornerTwo = new LatLng(2, 2); + final LatLngBounds.Builder builder = new LatLngBounds.Builder(); + builder.include(cornerOne); + builder.include(cornerTwo); + mapboxMap.animateCamera(CameraUpdateFactory.newLatLngBounds(builder.build(), 0)); + uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME); + CameraPosition cameraPosition = mapboxMap.getCameraPosition(); + assertEquals("Moved camera position latitude should match center bounds", + cameraPosition.target.getLatitude(), + centerBounds.getLatitude(), + TestConstants.LAT_LNG_DELTA); + assertEquals("Moved camera position longitude should match center bounds", + cameraPosition.target.getLongitude(), + centerBounds.getLongitude(), + TestConstants.LAT_LNG_DELTA); + }); + } + + @Test + public void testAnimateToMoveBy() { + validateTestSetup(); + invoke(mapboxMap, (uiController, mapboxMap) -> { + final PointF centerPoint = mapboxMap.getProjection().toScreenLocation(mapboxMap.getCameraPosition().target); + final LatLng moveTarget = new LatLng(2, 2); + final PointF moveTargetPoint = mapboxMap.getProjection().toScreenLocation(moveTarget); + mapboxMap.animateCamera(CameraUpdateFactory.scrollBy( + moveTargetPoint.x - centerPoint.x, moveTargetPoint.y - centerPoint.y)); + uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME); + CameraPosition cameraPosition = mapboxMap.getCameraPosition(); + assertEquals("Moved camera position latitude should match", cameraPosition.target.getLatitude(), + moveTarget.getLatitude(), TestConstants.LAT_LNG_DELTA_LARGE); + assertEquals("Moved camera position longitude should match", cameraPosition.target.getLongitude(), + moveTarget.getLongitude(), TestConstants.LAT_LNG_DELTA_LARGE); + }); + } + + @Test + public void testAnimateToZoomIn() { + validateTestSetup(); + invoke(mapboxMap, (uiController, mapboxMap) -> { + float zoom = 1.0f; + mapboxMap.animateCamera(CameraUpdateFactory.zoomIn()); + uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME); + CameraPosition cameraPosition = mapboxMap.getCameraPosition(); + assertEquals("Moved camera zoom should match moved camera zoom", cameraPosition.zoom, zoom + 1, + TestConstants.ZOOM_DELTA); + }); + } + + @Test + public void testAnimateToZoomOut() { + validateTestSetup(); + invoke(mapboxMap, (uiController, mapboxMap) -> { + float zoom = 10.0f; + mapboxMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(), zoom)); + uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME); + mapboxMap.animateCamera(CameraUpdateFactory.zoomOut()); + uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME); + CameraPosition cameraPosition = mapboxMap.getCameraPosition(); + assertEquals("Moved camera zoom should match moved camera zoom", cameraPosition.zoom, zoom - 1, + TestConstants.ZOOM_DELTA); + }); + } + + @Test + public void testAnimateToZoomBy() { + validateTestSetup(); + invoke(mapboxMap, (uiController, mapboxMap) -> { + float zoom = 1.0f; + final float zoomBy = 2.45f; + mapboxMap.animateCamera(CameraUpdateFactory.zoomBy(zoomBy)); + uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME); + CameraPosition cameraPosition = mapboxMap.getCameraPosition(); + assertEquals("Moved camera zoom should match moved camera zoom", cameraPosition.zoom, zoom + zoomBy, + TestConstants.ZOOM_DELTA); + }); + } + + @Test + public void testAnimateToZoomTo() { + validateTestSetup(); + invoke(mapboxMap, (uiController, mapboxMap) -> { + final float zoomTo = 2.45f; + mapboxMap.animateCamera(CameraUpdateFactory.zoomTo(zoomTo)); + uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME); + CameraPosition cameraPosition = mapboxMap.getCameraPosition(); + assertEquals("Moved camera zoom should match moved camera zoom", cameraPosition.zoom, zoomTo, + TestConstants.ZOOM_DELTA); + }); + } +} + diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/camera/CameraEaseTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/camera/CameraEaseTest.java new file mode 100644 index 0000000000..30473b29a8 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/camera/CameraEaseTest.java @@ -0,0 +1,187 @@ +package com.mapbox.mapboxsdk.maps.camera; + +import android.graphics.PointF; + +import com.mapbox.mapboxsdk.camera.CameraPosition; +import com.mapbox.mapboxsdk.camera.CameraUpdateFactory; +import com.mapbox.mapboxsdk.geometry.LatLng; +import com.mapbox.mapboxsdk.geometry.LatLngBounds; +import com.mapbox.mapboxsdk.maps.activity.BaseActivityTest; +import com.mapbox.mapboxsdk.maps.activity.espresso.DeviceIndependentTestActivity; +import com.mapbox.mapboxsdk.maps.utils.TestConstants; + +import org.junit.Test; + +import static com.mapbox.mapboxsdk.maps.action.MapboxMapAction.invoke; +import static org.junit.Assert.assertEquals; + +public class CameraEaseTest extends BaseActivityTest { + + @Override + protected Class getActivityClass() { + return DeviceIndependentTestActivity.class; + } + + @Test + public void testEaseToCameraPositionTarget() { + validateTestSetup(); + invoke(mapboxMap, (uiController, mapboxMap) -> { + float zoom = 1.0f; + LatLng moveTarget = new LatLng(1, 1); + CameraPosition initialPosition = new CameraPosition.Builder().target( + new LatLng()).zoom(zoom).bearing(0).tilt(0).build(); + CameraPosition cameraPosition = mapboxMap.getCameraPosition(); + assertEquals("Default camera position should match default", cameraPosition, initialPosition); + mapboxMap.easeCamera(CameraUpdateFactory.newLatLng(moveTarget)); + uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME); + cameraPosition = mapboxMap.getCameraPosition(); + assertEquals("Moved camera position latitude should match", cameraPosition.target.getLatitude(), + moveTarget.getLatitude(), TestConstants.LAT_LNG_DELTA); + assertEquals("Moved camera position longitude should match", cameraPosition.target.getLongitude(), + moveTarget.getLongitude(), TestConstants.LAT_LNG_DELTA); + }); + } + + @Test + public void testEaseToCameraPositionTargetZoom() { + validateTestSetup(); + invoke(mapboxMap, (uiController, mapboxMap) -> { + final float moveZoom = 15.5f; + final LatLng moveTarget = new LatLng(1.0000000001, 1.0000000003); + mapboxMap.easeCamera(CameraUpdateFactory.newLatLngZoom(moveTarget, moveZoom)); + uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME); + CameraPosition cameraPosition = mapboxMap.getCameraPosition(); + assertEquals("Moved camera position latitude should match", cameraPosition.target.getLatitude(), + moveTarget.getLatitude(), TestConstants.LAT_LNG_DELTA); + assertEquals("Moved camera position longitude should match", cameraPosition.target.getLongitude(), + moveTarget.getLongitude(), TestConstants.LAT_LNG_DELTA); + assertEquals("Moved zoom should match", cameraPosition.zoom, moveZoom, TestConstants.ZOOM_DELTA); + }); + } + + @Test + public void testEaseToCameraPosition() { + validateTestSetup(); + invoke(mapboxMap, (uiController, mapboxMap) -> { + final LatLng moveTarget = new LatLng(1.0000000001, 1.0000000003); + final float moveZoom = 15.5f; + final float moveTilt = 45.5f; + final float moveBearing = 12.5f; + + mapboxMap.easeCamera(CameraUpdateFactory.newCameraPosition( + new CameraPosition.Builder() + .target(moveTarget) + .zoom(moveZoom) + .tilt(moveTilt) + .bearing(moveBearing) + .build()) + ); + uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME); + CameraPosition cameraPosition = mapboxMap.getCameraPosition(); + assertEquals("Moved camera position latitude should match", cameraPosition.target.getLatitude(), + moveTarget.getLatitude(), TestConstants.LAT_LNG_DELTA); + assertEquals("Moved camera position longitude should match", cameraPosition.target.getLongitude(), + moveTarget.getLongitude(), TestConstants.LAT_LNG_DELTA); + assertEquals("Moved zoom should match", cameraPosition.zoom, moveZoom, TestConstants.ZOOM_DELTA); + assertEquals("Moved zoom should match", cameraPosition.tilt, moveTilt, TestConstants.TILT_DELTA); + assertEquals("Moved bearing should match", cameraPosition.bearing, moveBearing, TestConstants.BEARING_DELTA); + }); + } + + @Test + public void testEaseToBounds() { + validateTestSetup(); + invoke(mapboxMap, (uiController, mapboxMap) -> { + final LatLng centerBounds = new LatLng(1, 1); + LatLng cornerOne = new LatLng(); + LatLng cornerTwo = new LatLng(2, 2); + final LatLngBounds.Builder builder = new LatLngBounds.Builder(); + builder.include(cornerOne); + builder.include(cornerTwo); + mapboxMap.easeCamera(CameraUpdateFactory.newLatLngBounds(builder.build(), 0)); + uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME); + CameraPosition cameraPosition = mapboxMap.getCameraPosition(); + assertEquals("Moved camera position latitude should match center bounds", + cameraPosition.target.getLatitude(), + centerBounds.getLatitude(), + TestConstants.LAT_LNG_DELTA); + assertEquals("Moved camera position longitude should match center bounds", + cameraPosition.target.getLongitude(), + centerBounds.getLongitude(), + TestConstants.LAT_LNG_DELTA); + }); + } + + @Test + public void testEaseToMoveBy() { + validateTestSetup(); + invoke(mapboxMap, (uiController, mapboxMap) -> { + final PointF centerPoint = mapboxMap.getProjection().toScreenLocation(mapboxMap.getCameraPosition().target); + final LatLng moveTarget = new LatLng(2, 2); + final PointF moveTargetPoint = mapboxMap.getProjection().toScreenLocation(moveTarget); + mapboxMap.easeCamera(CameraUpdateFactory.scrollBy( + moveTargetPoint.x - centerPoint.x, moveTargetPoint.y - centerPoint.y)); + uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME); + CameraPosition cameraPosition = mapboxMap.getCameraPosition(); + assertEquals("Moved camera position latitude should match", cameraPosition.target.getLatitude(), + moveTarget.getLatitude(), TestConstants.LAT_LNG_DELTA_LARGE); + assertEquals("Moved camera position longitude should match", cameraPosition.target.getLongitude(), + moveTarget.getLongitude(), TestConstants.LAT_LNG_DELTA_LARGE); + }); + } + + @Test + public void testEaseToZoomIn() { + validateTestSetup(); + invoke(mapboxMap, (uiController, mapboxMap) -> { + float zoom = 1.0f; + mapboxMap.easeCamera(CameraUpdateFactory.zoomIn()); + uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME); + CameraPosition cameraPosition = mapboxMap.getCameraPosition(); + assertEquals("Moved camera zoom should match moved camera zoom", cameraPosition.zoom, zoom + 1, + TestConstants.ZOOM_DELTA); + }); + } + + @Test + public void testEaseToZoomOut() { + validateTestSetup(); + invoke(mapboxMap, (uiController, mapboxMap) -> { + float zoom = 10.0f; + mapboxMap.easeCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(), zoom)); + uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME); + mapboxMap.easeCamera(CameraUpdateFactory.zoomOut()); + uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME); + CameraPosition cameraPosition = mapboxMap.getCameraPosition(); + assertEquals("Moved camera zoom should match moved camera zoom", cameraPosition.zoom, zoom - 1, + TestConstants.ZOOM_DELTA); + }); + } + + @Test + public void testEaseToZoomBy() { + validateTestSetup(); + invoke(mapboxMap, (uiController, mapboxMap) -> { + float zoom = 1.0f; + final float zoomBy = 2.45f; + mapboxMap.easeCamera(CameraUpdateFactory.zoomBy(zoomBy)); + uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME); + CameraPosition cameraPosition = mapboxMap.getCameraPosition(); + assertEquals("Moved camera zoom should match moved camera zoom", cameraPosition.zoom, zoom + zoomBy, + TestConstants.ZOOM_DELTA); + }); + } + + @Test + public void testEaseToZoomTo() { + validateTestSetup(); + invoke(mapboxMap, (uiController, mapboxMap) -> { + final float zoomTo = 2.45f; + mapboxMap.easeCamera(CameraUpdateFactory.zoomTo(zoomTo)); + uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME); + CameraPosition cameraPosition = mapboxMap.getCameraPosition(); + assertEquals("Moved camera zoom should match moved camera zoom", cameraPosition.zoom, zoomTo, + TestConstants.ZOOM_DELTA); + }); + } +}
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/camera/CameraForTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/camera/CameraForTest.java new file mode 100644 index 0000000000..2f11641bad --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/camera/CameraForTest.java @@ -0,0 +1,268 @@ +package com.mapbox.mapboxsdk.maps.camera; + +import android.support.annotation.NonNull; +import com.mapbox.geojson.Point; +import com.mapbox.geojson.Polygon; +import com.mapbox.mapboxsdk.camera.CameraPosition; +import com.mapbox.mapboxsdk.geometry.LatLng; +import com.mapbox.mapboxsdk.geometry.LatLngBounds; +import com.mapbox.mapboxsdk.maps.activity.BaseActivityTest; +import com.mapbox.mapboxsdk.maps.activity.espresso.DeviceIndependentTestActivity; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.assertEquals; + +public class CameraForTest extends BaseActivityTest { + + @Test + public void testGetCameraForLatLngBounds() { + validateTestSetup(); + onMapView().perform(getMapboxMapAction((uiController, mapboxMap) -> { + CameraPosition actualPosition = mapboxMap.getCameraForLatLngBounds( + LatLngBounds.from(10, 10, -10, -10)); + CameraPosition expectedPosition = new CameraPosition.Builder() + .target(new LatLng()).zoom(4.16).tilt(0).bearing(0).build(); + assertEquals("Latitude should match", + expectedPosition.target.getLatitude(), actualPosition.target.getLatitude(), 0.00001f); + assertEquals("Longitude should match", + expectedPosition.target.getLongitude(), actualPosition.target.getLongitude(), 0.00001f); + assertEquals("Bearing should match", + expectedPosition.zoom, actualPosition.zoom, 0.01f); + assertEquals("Tilt should match", expectedPosition.tilt, actualPosition.tilt, 0.01f); + })); + } + + @Test + public void testGetCameraForLatLngBoundsPadding() { + validateTestSetup(); + onMapView().perform(getMapboxMapAction((uiController, mapboxMap) -> { + CameraPosition actualPosition = mapboxMap.getCameraForLatLngBounds( + LatLngBounds.from(10, 10, -10, -10), new int[] {5, 5, 5, 5}); + CameraPosition expectedPosition = new CameraPosition.Builder() + .target(new LatLng()).zoom(4.13).tilt(0).bearing(0).build(); + assertEquals("Latitude should match", + expectedPosition.target.getLatitude(), actualPosition.target.getLatitude(), 0.00001f); + assertEquals("Longitude should match", + expectedPosition.target.getLongitude(), actualPosition.target.getLongitude(), 0.00001f); + assertEquals("Zoom should match", + expectedPosition.zoom, actualPosition.zoom, 0.01f); + assertEquals("Tilt should match", + expectedPosition.tilt, actualPosition.tilt, 0.01f); + assertEquals("Bearing should match", + expectedPosition.bearing, actualPosition.bearing, 0.01f); + })); + } + + @Test + public void testGetCameraForLatLngBoundsBearing() { + validateTestSetup(); + onMapView().perform(getMapboxMapAction((uiController, mapboxMap) -> { + CameraPosition actualPosition = mapboxMap.getCameraForLatLngBounds( + LatLngBounds.from(10, 10, -10, -10), 45, 0); + CameraPosition expectedPosition = new CameraPosition.Builder() + .target(new LatLng()).zoom(3.66).tilt(0).bearing(45).build(); + assertEquals("Latitude should match", + expectedPosition.target.getLatitude(), actualPosition.target.getLatitude(), 0.00001f); + assertEquals("Longitude should match", + expectedPosition.target.getLongitude(), actualPosition.target.getLongitude(), 0.00001f); + assertEquals("Zoom should match", + expectedPosition.zoom, actualPosition.zoom, 0.01f); + assertEquals("Tilt should match", + expectedPosition.tilt, actualPosition.tilt, 0.01f); + assertEquals("Bearing should match", + expectedPosition.bearing, actualPosition.bearing, 0.01f); + })); + } + + @Test + public void testGetCameraForLatLngBoundsTilt() { + validateTestSetup(); + onMapView().perform(getMapboxMapAction((uiController, mapboxMap) -> { + CameraPosition actualPosition = mapboxMap.getCameraForLatLngBounds( + LatLngBounds.from(10, 10, -10, -10), 0, 45); + CameraPosition expectedPosition = new CameraPosition.Builder() + .target(new LatLng(-0.264576975267, 0)).zoom(4.13).tilt(45).bearing(0).build(); + assertEquals("Latitude should match", + expectedPosition.target.getLatitude(), actualPosition.target.getLatitude(), 0.00001f); + assertEquals("Longitude should match", + expectedPosition.target.getLongitude(), actualPosition.target.getLongitude(), 0.00001f); + assertEquals("Zoom should match", + expectedPosition.zoom, actualPosition.zoom, 0.01f); + assertEquals("Tilt should match", + expectedPosition.tilt, actualPosition.tilt, 0.01f); + assertEquals("Bearing should match", + expectedPosition.bearing, actualPosition.bearing, 0.01f); + })); + } + + @Test + public void testGetCameraForLatLngBoundsAll() { + validateTestSetup(); + onMapView().perform(getMapboxMapAction((uiController, mapboxMap) -> { + CameraPosition actualPosition = mapboxMap.getCameraForLatLngBounds( + LatLngBounds.from(10, 10, -10, -10), new int[] {5, 5, 5, 5}, 45, 45); + CameraPosition expectedPosition = new CameraPosition.Builder() + .target(new LatLng(-0.3732134634, -0.3713191053)).zoom(3.63).tilt(45).bearing(45).build(); + assertEquals("Latitude should match", + expectedPosition.target.getLatitude(), actualPosition.target.getLatitude(), 0.00001f); + assertEquals("Longitude should match", + expectedPosition.target.getLongitude(), actualPosition.target.getLongitude(), 0.00001f); + assertEquals("Zoom should match", + expectedPosition.zoom, actualPosition.zoom, 0.01f); + assertEquals("Tilt should match", + expectedPosition.tilt, actualPosition.tilt, 0.01f); + assertEquals("Bearing should match", + expectedPosition.bearing, actualPosition.bearing, 0.01f); + })); + } + + @Test + public void testGetCameraForGeometry() { + validateTestSetup(); + onMapView().perform(getMapboxMapAction((uiController, mapboxMap) -> { + List<List<Point>> polygonDefinition = getPolygonDefinition(); + CameraPosition actualPosition = mapboxMap.getCameraForGeometry(Polygon.fromLngLats(polygonDefinition)); + CameraPosition expectedPosition = new CameraPosition.Builder() + .target(new LatLng()).zoom(4.16).tilt(0).bearing(0).build(); + assertEquals("Latitude should match", + expectedPosition.target.getLatitude(), actualPosition.target.getLatitude(), 0.00001f); + assertEquals("Longitude should match", + expectedPosition.target.getLongitude(), actualPosition.target.getLongitude(), 0.00001f); + assertEquals("Bearing should match", + expectedPosition.zoom, actualPosition.zoom, 0.01f); + assertEquals("Tilt should match", expectedPosition.tilt, actualPosition.tilt, 0.01f); + })); + } + + @NonNull + private List<List<Point>> getPolygonDefinition() { + return new ArrayList<List<Point>>() { + { + add(new ArrayList<Point>() { + { + add(Point.fromLngLat(10, 10)); + add(Point.fromLngLat(-10, 10)); + add(Point.fromLngLat(-10, -10)); + add(Point.fromLngLat(10, -10)); + } + }); + } + }; + } + + @Test + public void testGetCameraForGeometryPadding() { + validateTestSetup(); + onMapView().perform(getMapboxMapAction((uiController, mapboxMap) -> { + List<List<Point>> polygonDefinition = getPolygonDefinition(); + CameraPosition actualPosition = mapboxMap.getCameraForGeometry(Polygon.fromLngLats(polygonDefinition), + new int[] {5, 5, 5, 5}); + CameraPosition expectedPosition = new CameraPosition.Builder() + .target(new LatLng()).zoom(4.13).tilt(0).bearing(0).build(); + assertEquals("Latitude should match", + expectedPosition.target.getLatitude(), actualPosition.target.getLatitude(), 0.00001f); + assertEquals("Longitude should match", + expectedPosition.target.getLongitude(), actualPosition.target.getLongitude(), 0.00001f); + assertEquals("Zoom should match", + expectedPosition.zoom, actualPosition.zoom, 0.01f); + assertEquals("Tilt should match", + expectedPosition.tilt, actualPosition.tilt, 0.01f); + assertEquals("Bearing should match", + expectedPosition.bearing, actualPosition.bearing, 0.01f); + })); + } + + @Test + public void testGetCameraForGeometryBearing() { + validateTestSetup(); + onMapView().perform(getMapboxMapAction((uiController, mapboxMap) -> { + List<List<Point>> polygonDefinition = getPolygonDefinition(); + CameraPosition actualPosition = mapboxMap.getCameraForGeometry(Polygon.fromLngLats(polygonDefinition), 45, 0); + CameraPosition expectedPosition = new CameraPosition.Builder() + .target(new LatLng()).zoom(3.66).tilt(0).bearing(45).build(); + assertEquals("Latitude should match", + expectedPosition.target.getLatitude(), actualPosition.target.getLatitude(), 0.00001f); + assertEquals("Longitude should match", + expectedPosition.target.getLongitude(), actualPosition.target.getLongitude(), 0.00001f); + assertEquals("Zoom should match", + expectedPosition.zoom, actualPosition.zoom, 0.01f); + assertEquals("Tilt should match", + expectedPosition.tilt, actualPosition.tilt, 0.01f); + assertEquals("Bearing should match", + expectedPosition.bearing, actualPosition.bearing, 0.01f); + })); + } + + @Test + public void testGetCameraForGeometryTilt() { + validateTestSetup(); + onMapView().perform(getMapboxMapAction((uiController, mapboxMap) -> { + List<List<Point>> polygonDefinition = getPolygonDefinition(); + CameraPosition actualPosition = mapboxMap.getCameraForGeometry(Polygon.fromLngLats(polygonDefinition), 0, 45); + CameraPosition expectedPosition = new CameraPosition.Builder() + .target(new LatLng(-0.2645769752, 0)).zoom(4.13).tilt(45).bearing(0).build(); + assertEquals("Latitude should match", + expectedPosition.target.getLatitude(), actualPosition.target.getLatitude(), 0.00001f); + assertEquals("Longitude should match", + expectedPosition.target.getLongitude(), actualPosition.target.getLongitude(), 0.00001f); + assertEquals("Zoom should match", + expectedPosition.zoom, actualPosition.zoom, 0.01f); + assertEquals("Tilt should match", + expectedPosition.tilt, actualPosition.tilt, 0.01f); + assertEquals("Bearing should match", + expectedPosition.bearing, actualPosition.bearing, 0.01f); + })); + } + + @Test + public void testGetCameraForGeometryAll() { + validateTestSetup(); + onMapView().perform(getMapboxMapAction((uiController, mapboxMap) -> { + List<List<Point>> polygonDefinition = getPolygonDefinition(); + CameraPosition actualPosition = mapboxMap.getCameraForGeometry(Polygon.fromLngLats(polygonDefinition), + new int[] {5, 5, 5, 5}, 45, 45); + CameraPosition expectedPosition = new CameraPosition.Builder() + .target(new LatLng(-0.373213463, -0.37131910534)).zoom(3.63).tilt(45).bearing(45).build(); + assertEquals("Latitude should match", + expectedPosition.target.getLatitude(), actualPosition.target.getLatitude(), 0.00001f); + assertEquals("Longitude should match", + expectedPosition.target.getLongitude(), actualPosition.target.getLongitude(), 0.00001f); + assertEquals("Zoom should match", + expectedPosition.zoom, actualPosition.zoom, 0.01f); + assertEquals("Tilt should match", + expectedPosition.tilt, actualPosition.tilt, 0.01f); + assertEquals("Bearing should match", + expectedPosition.bearing, actualPosition.bearing, 0.01f); + })); + } + + @Test + public void testGetCameraForGeometryDeprecatedApi() { + validateTestSetup(); + onMapView().perform(getMapboxMapAction((uiController, mapboxMap) -> { + List<List<Point>> polygonDefinition = getPolygonDefinition(); + CameraPosition actualPosition = mapboxMap.getCameraForGeometry(Polygon.fromLngLats(polygonDefinition), 45, + new int[] {5, 5, 5, 5}); + CameraPosition expectedPosition = new CameraPosition.Builder() + .target(new LatLng()).zoom(3.63).tilt(0).bearing(45).build(); + assertEquals("Latitude should match", + expectedPosition.target.getLatitude(), actualPosition.target.getLatitude(), 0.00001f); + assertEquals("Longitude should match", + expectedPosition.target.getLongitude(), actualPosition.target.getLongitude(), 0.00001f); + assertEquals("Zoom should match", + expectedPosition.zoom, actualPosition.zoom, 0.01f); + assertEquals("Tilt should match", + expectedPosition.tilt, actualPosition.tilt, 0.01f); + assertEquals("Bearing should match", + expectedPosition.bearing, actualPosition.bearing, 0.01f); + })); + } + + @Override + protected Class getActivityClass() { + return DeviceIndependentTestActivity.class; + } +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/camera/CameraMoveTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/camera/CameraMoveTest.java new file mode 100644 index 0000000000..60d8f21e3d --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/camera/CameraMoveTest.java @@ -0,0 +1,189 @@ + +package com.mapbox.mapboxsdk.maps.camera; + +import android.graphics.PointF; + +import com.mapbox.mapboxsdk.camera.CameraPosition; +import com.mapbox.mapboxsdk.camera.CameraUpdateFactory; +import com.mapbox.mapboxsdk.geometry.LatLng; +import com.mapbox.mapboxsdk.geometry.LatLngBounds; +import com.mapbox.mapboxsdk.maps.activity.BaseActivityTest; +import com.mapbox.mapboxsdk.maps.activity.espresso.DeviceIndependentTestActivity; +import com.mapbox.mapboxsdk.maps.utils.TestConstants; + +import org.junit.Test; + +import static com.mapbox.mapboxsdk.maps.action.MapboxMapAction.invoke; +import static org.junit.Assert.assertEquals; + +public class CameraMoveTest extends BaseActivityTest { + + @Override + protected Class getActivityClass() { + return DeviceIndependentTestActivity.class; + } + + @Test + public void testMoveToCameraPositionTarget() { + validateTestSetup(); + invoke(mapboxMap, (uiController, mapboxMap) -> { + float zoom = 1.0f; + LatLng moveTarget = new LatLng(1, 1); + CameraPosition initialPosition = new CameraPosition.Builder().target( + new LatLng()).zoom(zoom).bearing(0).tilt(0).build(); + CameraPosition cameraPosition = mapboxMap.getCameraPosition(); + assertEquals("Default camera position should match default", cameraPosition, initialPosition); + mapboxMap.moveCamera(CameraUpdateFactory.newLatLng(moveTarget)); + uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME); + cameraPosition = mapboxMap.getCameraPosition(); + assertEquals("Moved camera position latitude should match", cameraPosition.target.getLatitude(), + moveTarget.getLatitude(), TestConstants.LAT_LNG_DELTA); + assertEquals("Moved camera position longitude should match", cameraPosition.target.getLongitude(), + moveTarget.getLongitude(), TestConstants.LAT_LNG_DELTA); + }); + } + + @Test + public void testMoveToCameraPositionTargetZoom() { + validateTestSetup(); + invoke(mapboxMap, (uiController, mapboxMap) -> { + final float moveZoom = 15.5f; + final LatLng moveTarget = new LatLng(1.0000000001, 1.0000000003); + mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(moveTarget, moveZoom)); + uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME); + CameraPosition cameraPosition = mapboxMap.getCameraPosition(); + assertEquals("Moved camera position latitude should match", cameraPosition.target.getLatitude(), + moveTarget.getLatitude(), TestConstants.LAT_LNG_DELTA); + assertEquals("Moved camera position longitude should match", cameraPosition.target.getLongitude(), + moveTarget.getLongitude(), TestConstants.LAT_LNG_DELTA); + assertEquals("Moved zoom should match", cameraPosition.zoom, moveZoom, TestConstants.ZOOM_DELTA); + }); + } + + @Test + public void testMoveToCameraPosition() { + validateTestSetup(); + invoke(mapboxMap, (uiController, mapboxMap) -> { + final LatLng moveTarget = new LatLng(1.0000000001, 1.0000000003); + final float moveZoom = 15.5f; + final float moveTilt = 45.5f; + final float moveBearing = 12.5f; + + mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition( + new CameraPosition.Builder() + .target(moveTarget) + .zoom(moveZoom) + .tilt(moveTilt) + .bearing(moveBearing) + .build()) + ); + uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME); + CameraPosition cameraPosition = mapboxMap.getCameraPosition(); + assertEquals("Moved camera position latitude should match", cameraPosition.target.getLatitude(), + moveTarget.getLatitude(), TestConstants.LAT_LNG_DELTA); + assertEquals("Moved camera position longitude should match", cameraPosition.target.getLongitude(), + moveTarget.getLongitude(), TestConstants.LAT_LNG_DELTA); + assertEquals("Moved zoom should match", cameraPosition.zoom, moveZoom, TestConstants.ZOOM_DELTA); + assertEquals("Moved zoom should match", cameraPosition.tilt, moveTilt, TestConstants.TILT_DELTA); + assertEquals("Moved bearing should match", cameraPosition.bearing, moveBearing, TestConstants.BEARING_DELTA); + }); + } + + @Test + public void testMoveToBounds() { + validateTestSetup(); + invoke(mapboxMap, (uiController, mapboxMap) -> { + final LatLng centerBounds = new LatLng(1, 1); + LatLng cornerOne = new LatLng(); + LatLng cornerTwo = new LatLng(2, 2); + final LatLngBounds.Builder builder = new LatLngBounds.Builder(); + builder.include(cornerOne); + builder.include(cornerTwo); + mapboxMap.moveCamera(CameraUpdateFactory.newLatLngBounds(builder.build(), 0)); + uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME); + CameraPosition cameraPosition = mapboxMap.getCameraPosition(); + assertEquals("Moved camera position latitude should match center bounds", + cameraPosition.target.getLatitude(), + centerBounds.getLatitude(), + TestConstants.LAT_LNG_DELTA); + assertEquals("Moved camera position longitude should match center bounds", + cameraPosition.target.getLongitude(), + centerBounds.getLongitude(), + TestConstants.LAT_LNG_DELTA); + }); + } + + @Test + public void testMoveToMoveBy() { + validateTestSetup(); + invoke(mapboxMap, (uiController, mapboxMap) -> { + final PointF centerPoint = mapboxMap.getProjection().toScreenLocation(mapboxMap.getCameraPosition().target); + final LatLng moveTarget = new LatLng(2, 2); + final PointF moveTargetPoint = mapboxMap.getProjection().toScreenLocation(moveTarget); + mapboxMap.moveCamera(CameraUpdateFactory.scrollBy( + moveTargetPoint.x - centerPoint.x, moveTargetPoint.y - centerPoint.y)); + uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME); + CameraPosition cameraPosition = mapboxMap.getCameraPosition(); + assertEquals("Moved camera position latitude should match", cameraPosition.target.getLatitude(), + moveTarget.getLatitude(), TestConstants.LAT_LNG_DELTA_LARGE); + assertEquals("Moved camera position longitude should match", cameraPosition.target.getLongitude(), + moveTarget.getLongitude(), TestConstants.LAT_LNG_DELTA_LARGE); + }); + } + + @Test + public void testMoveToZoomIn() { + validateTestSetup(); + invoke(mapboxMap, (uiController, mapboxMap) -> { + float zoom = 1.0f; + mapboxMap.moveCamera(CameraUpdateFactory.zoomIn()); + uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME); + CameraPosition cameraPosition = mapboxMap.getCameraPosition(); + assertEquals("Moved camera zoom should match moved camera zoom", cameraPosition.zoom, zoom + 1, + TestConstants.ZOOM_DELTA); + }); + } + + @Test + public void testMoveToZoomOut() { + validateTestSetup(); + invoke(mapboxMap, (uiController, mapboxMap) -> { + float zoom = 10.0f; + mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(), zoom)); + uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME); + mapboxMap.moveCamera(CameraUpdateFactory.zoomOut()); + uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME); + CameraPosition cameraPosition = mapboxMap.getCameraPosition(); + assertEquals("Moved camera zoom should match moved camera zoom", cameraPosition.zoom, zoom - 1, + TestConstants.ZOOM_DELTA); + }); + } + + @Test + public void testMoveToZoomBy() { + validateTestSetup(); + invoke(mapboxMap, (uiController, mapboxMap) -> { + float zoom = 1.0f; + final float zoomBy = 2.45f; + mapboxMap.moveCamera(CameraUpdateFactory.zoomBy(zoomBy)); + uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME); + CameraPosition cameraPosition = mapboxMap.getCameraPosition(); + assertEquals("Moved camera zoom should match moved camera zoom", cameraPosition.zoom, zoom + zoomBy, + TestConstants.ZOOM_DELTA); + }); + } + + @Test + public void testMoveToZoomTo() { + validateTestSetup(); + invoke(mapboxMap, (uiController, mapboxMap) -> { + final float zoomTo = 2.45f; + mapboxMap.moveCamera(CameraUpdateFactory.zoomTo(zoomTo)); + uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME); + CameraPosition cameraPosition = mapboxMap.getCameraPosition(); + assertEquals("Moved camera zoom should match moved camera zoom", cameraPosition.zoom, zoomTo, + TestConstants.ZOOM_DELTA); + }); + } +} + diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/feature/QueryRenderedFeaturesBoxCountTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/feature/QueryRenderedFeaturesBoxCountTest.java new file mode 100644 index 0000000000..becc06a6c8 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/feature/QueryRenderedFeaturesBoxCountTest.java @@ -0,0 +1,43 @@ +package com.mapbox.mapboxsdk.maps.feature; + +import com.mapbox.mapboxsdk.testapp.R; +import com.mapbox.mapboxsdk.maps.activity.BaseActivityTest; +import com.mapbox.mapboxsdk.maps.activity.feature.QueryRenderedFeaturesBoxCountActivity; + +import org.junit.Ignore; +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.assertion.ViewAssertions.matches; +import static android.support.test.espresso.matcher.RootMatchers.withDecorView; +import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; +import static android.support.test.espresso.matcher.ViewMatchers.withId; +import static android.support.test.espresso.matcher.ViewMatchers.withText; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.not; + +/** + * Instrumentation test to validate if clicking on the blue rectangle from + * QueryRenderedFeaturesBoxSymbolCountActivity shows a Toast that 149 features were found. + */ +public class QueryRenderedFeaturesBoxCountTest extends BaseActivityTest { + + @Override + protected Class getActivityClass() { + return QueryRenderedFeaturesBoxCountActivity.class; + } + + @Test + @Ignore + public void testCountFeatures() { + // click on box to query map + onView(withId(R.id.selection_box)).perform(click()); + + // validate if toast is shown + onView(withText("149 features in box")) + .inRoot(withDecorView(not(is(rule.getActivity().getWindow().getDecorView())))) + .check(matches(isDisplayed())); + } + +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/feature/QueryRenderedFeaturesHighlightTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/feature/QueryRenderedFeaturesHighlightTest.java new file mode 100644 index 0000000000..3022ffbef2 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/feature/QueryRenderedFeaturesHighlightTest.java @@ -0,0 +1,42 @@ +package com.mapbox.mapboxsdk.maps.feature; + +import com.mapbox.mapboxsdk.testapp.R; +import com.mapbox.mapboxsdk.maps.activity.BaseActivityTest; +import com.mapbox.mapboxsdk.maps.activity.feature.QueryRenderedFeaturesBoxHighlightActivity; + +import org.junit.Ignore; +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.assertion.ViewAssertions.matches; +import static android.support.test.espresso.matcher.RootMatchers.withDecorView; +import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; +import static android.support.test.espresso.matcher.ViewMatchers.withId; +import static android.support.test.espresso.matcher.ViewMatchers.withText; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.not; + +/** + * Instrumentation test to validate if clicking box on screen highlights features. + */ +public class QueryRenderedFeaturesHighlightTest extends BaseActivityTest { + + @Override + protected Class getActivityClass() { + return QueryRenderedFeaturesBoxHighlightActivity.class; + } + + @Test + @Ignore + public void testCountFeatures() { + // click on box to query map + onView(withId(R.id.selection_box)).perform(click()); + + // validate if toast is shown + onView(withText("50 features in box")) + .inRoot(withDecorView(not(is(rule.getActivity().getWindow().getDecorView())))) + .check(matches(isDisplayed())); + } + +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/feature/QueryRenderedFeaturesPropertiesTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/feature/QueryRenderedFeaturesPropertiesTest.java new file mode 100644 index 0000000000..da785cadf2 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/feature/QueryRenderedFeaturesPropertiesTest.java @@ -0,0 +1,54 @@ +package com.mapbox.mapboxsdk.maps.feature; + +import android.graphics.PointF; +import android.support.test.espresso.ViewAction; +import android.support.test.espresso.action.GeneralClickAction; +import android.support.test.espresso.action.Press; +import android.support.test.espresso.action.Tap; + +import com.mapbox.mapboxsdk.geometry.LatLng; +import com.mapbox.mapboxsdk.testapp.R; +import com.mapbox.mapboxsdk.maps.activity.BaseActivityTest; +import com.mapbox.mapboxsdk.maps.activity.feature.QueryRenderedFeaturesPropertiesActivity; + +import org.junit.Ignore; +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; +import static android.support.test.espresso.matcher.ViewMatchers.withText; + +/** + * Instrumentation test to validate if clicking center of screen returns the correct features. + */ +public class QueryRenderedFeaturesPropertiesTest extends BaseActivityTest { + + @Override + protected Class getActivityClass() { + return QueryRenderedFeaturesPropertiesActivity.class; + } + + @Test + @Ignore + public void testCountFeatures() { + LatLng centerScreen = mapboxMap.getCameraPosition().target; + PointF centerPixel = mapboxMap.getProjection().toScreenLocation(centerScreen); + onView(withId(R.id.mapView)).perform(clickXY(centerPixel.x, centerPixel.y)); + onView(withText("Found 4 features")).check(matches(isDisplayed())); + } + + private static ViewAction clickXY(final float x, final float y) { + return new GeneralClickAction( + Tap.SINGLE, + view -> { + final int[] screenPos = new int[2]; + view.getLocationOnScreen(screenPos); + final float screenX = screenPos[0] + x; + final float screenY = screenPos[1] + y; + return new float[] {screenX, screenY}; + }, + Press.FINGER); + } +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/feature/QueryRenderedSymbolBoxCountTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/feature/QueryRenderedSymbolBoxCountTest.java new file mode 100644 index 0000000000..df1e1eb87a --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/feature/QueryRenderedSymbolBoxCountTest.java @@ -0,0 +1,43 @@ +package com.mapbox.mapboxsdk.maps.feature; + +import com.mapbox.mapboxsdk.testapp.R; +import com.mapbox.mapboxsdk.maps.activity.BaseActivityTest; +import com.mapbox.mapboxsdk.maps.activity.feature.QueryRenderedFeaturesBoxSymbolCountActivity; + +import org.junit.Ignore; +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.assertion.ViewAssertions.matches; +import static android.support.test.espresso.matcher.RootMatchers.withDecorView; +import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; +import static android.support.test.espresso.matcher.ViewMatchers.withId; +import static android.support.test.espresso.matcher.ViewMatchers.withText; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.not; + +/** + * Instrumentation test to validate if clicking on the blue rectangle from + * QueryRenderedFeaturesBoxSymbolCountActivity shows a Toast that 2 symbols were found. + */ +public class QueryRenderedSymbolBoxCountTest extends BaseActivityTest { + + @Override + protected Class getActivityClass() { + return QueryRenderedFeaturesBoxSymbolCountActivity.class; + } + + @Test + @Ignore + public void testCountSymbols() { + // click on box to query map + onView(withId(R.id.selection_box)).perform(click()); + + // validate if toast is shown + onView(withText("2 features in box")) + .inRoot(withDecorView(not(is(rule.getActivity().getWindow().getDecorView())))) + .check(matches(isDisplayed())); + } +} + diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/geometry/LatLngBoundsTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/geometry/LatLngBoundsTest.java new file mode 100644 index 0000000000..e077018bb2 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/geometry/LatLngBoundsTest.java @@ -0,0 +1,34 @@ +package com.mapbox.mapboxsdk.maps.geometry; + +import com.mapbox.mapboxsdk.camera.CameraUpdateFactory; +import com.mapbox.mapboxsdk.geometry.LatLng; +import com.mapbox.mapboxsdk.geometry.LatLngBounds; +import com.mapbox.mapboxsdk.maps.action.MapboxMapAction; +import com.mapbox.mapboxsdk.maps.activity.BaseActivityTest; +import com.mapbox.mapboxsdk.maps.activity.feature.QueryRenderedFeaturesBoxHighlightActivity; + +import org.junit.Test; + +/** + * Instrumentation test to validate integration of LatLngBounds + */ +public class LatLngBoundsTest extends BaseActivityTest { + + @Override + protected Class getActivityClass() { + return QueryRenderedFeaturesBoxHighlightActivity.class; + } + + @Test + public void testLatLngBounds() { + // regression test for #9322 + validateTestSetup(); + MapboxMapAction.invoke(mapboxMap, (uiController, mapboxMap) -> { + LatLngBounds bounds = new LatLngBounds.Builder() + .include(new LatLng(48.8589506, 2.2773457)) + .include(new LatLng(47.2383171, -1.6309316)) + .build(); + mapboxMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 0)); + }); + } +}
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/offline/OfflineUtilsTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/offline/OfflineUtilsTest.java new file mode 100644 index 0000000000..0359b1e25a --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/offline/OfflineUtilsTest.java @@ -0,0 +1,44 @@ +package com.mapbox.mapboxsdk.maps.offline; + +import com.mapbox.mapboxsdk.maps.activity.BaseActivityTest; +import com.mapbox.mapboxsdk.maps.activity.espresso.EspressoTestActivity; +import com.mapbox.mapboxsdk.maps.utils.OfflineUtils; + +import org.junit.Test; + +import java.io.UnsupportedEncodingException; +import java.util.Arrays; + +import static com.mapbox.mapboxsdk.maps.activity.offline.OfflineActivity.JSON_CHARSET; +import static junit.framework.Assert.assertEquals; +import static junit.framework.TestCase.assertTrue; + +public class OfflineUtilsTest extends BaseActivityTest { + + private static final String REGION_NAME = "hello world"; + private static final String CONVERTED_REGION_NAME = "{\"FIELD_REGION_NAME\":\"hello world\"}"; + + @Override + protected Class getActivityClass() { + return EspressoTestActivity.class; + } + + @Test + public void testOfflineUtilsConvertToBytes() throws UnsupportedEncodingException { + byte[] expected = CONVERTED_REGION_NAME.getBytes(JSON_CHARSET); + byte[] actual = OfflineUtils.convertRegionName(REGION_NAME); + assertTrue("Bytes arrays should match", Arrays.equals(expected, actual)); + } + + @Test + public void testOfflineUtilsConvertToString() throws UnsupportedEncodingException { + String actual = OfflineUtils.convertRegionName(CONVERTED_REGION_NAME.getBytes(JSON_CHARSET)); + assertEquals("Strings should match", REGION_NAME, actual); + } + + @Test + public void testOfflineUtilsConvertNoOp() { + String convertNoOp = OfflineUtils.convertRegionName(OfflineUtils.convertRegionName(REGION_NAME)); + assertEquals("Strings should match", REGION_NAME, convertNoOp); + } +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/render/RenderTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/render/RenderTest.java new file mode 100644 index 0000000000..790493f802 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/render/RenderTest.java @@ -0,0 +1,70 @@ +package com.mapbox.mapboxsdk.maps.render; + +import android.Manifest; +import android.support.test.espresso.IdlingPolicies; +import android.support.test.espresso.IdlingRegistry; +import android.support.test.espresso.IdlingResourceTimeoutException; +import android.support.test.rule.ActivityTestRule; +import android.support.test.rule.GrantPermissionRule; +import android.support.test.runner.AndroidJUnit4; +import com.mapbox.mapboxsdk.maps.activity.render.RenderTestActivity; +import com.mapbox.mapboxsdk.maps.utils.SnapshotterIdlingResource; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import timber.log.Timber; + +import java.util.concurrent.TimeUnit; + +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; + +/** + * Instrumentation render tests + */ +@RunWith(AndroidJUnit4.class) +public class RenderTest { + + private static final int RENDER_TEST_TIMEOUT = 30; + private SnapshotterIdlingResource idlingResource; + + @Rule + public ActivityTestRule<RenderTestActivity> activityRule = new ActivityTestRule<>(RenderTestActivity.class); + + @Rule + public GrantPermissionRule writeRule = GrantPermissionRule.grant(Manifest.permission.WRITE_EXTERNAL_STORAGE); + + @Rule + public GrantPermissionRule readRule = GrantPermissionRule.grant(Manifest.permission.READ_EXTERNAL_STORAGE); + + @Before + public void beforeTest() { + IdlingPolicies.setMasterPolicyTimeout(RENDER_TEST_TIMEOUT, TimeUnit.MINUTES); + setupIdlingResource(); + } + + private void setupIdlingResource() { + try { + Timber.e("@Before test: register idle resource"); + IdlingPolicies.setIdlingResourceTimeout(RENDER_TEST_TIMEOUT, TimeUnit.MINUTES); + IdlingRegistry.getInstance().register(idlingResource = new SnapshotterIdlingResource(activityRule.getActivity())); + } catch (IdlingResourceTimeoutException idlingResourceTimeoutException) { + throw new RuntimeException("Idling out!"); + } + } + + @Test + public void testRender() { + onView(withId(android.R.id.content)).check(matches(isDisplayed())); + } + + @After + public void afterTest() { + Timber.e("@After test: unregister idle resource"); + IdlingRegistry.getInstance().unregister(idlingResource); + } +}
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/storage/FileSourceTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/storage/FileSourceTest.java new file mode 100644 index 0000000000..b5e417a159 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/storage/FileSourceTest.java @@ -0,0 +1,131 @@ +package com.mapbox.mapboxsdk.maps.storage; + +import android.os.Looper; +import android.support.test.espresso.UiController; +import android.support.test.espresso.ViewAction; +import android.support.test.rule.ActivityTestRule; +import android.support.test.runner.AndroidJUnit4; +import android.view.View; + +import com.mapbox.mapboxsdk.storage.FileSource; +import com.mapbox.mapboxsdk.testapp.R; +import com.mapbox.mapboxsdk.maps.action.WaitAction; +import com.mapbox.mapboxsdk.maps.activity.FeatureOverviewActivity; + +import org.hamcrest.Matcher; +import org.junit.Before; +import org.junit.Ignore; +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.Espresso.pressBack; +import static android.support.test.espresso.action.ViewActions.click; +import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; +import static android.support.test.espresso.matcher.ViewMatchers.isRoot; +import static android.support.test.espresso.matcher.ViewMatchers.withId; +import static android.support.test.espresso.matcher.ViewMatchers.withText; +import static com.mapbox.mapboxsdk.maps.action.OrientationChangeAction.orientationLandscape; +import static junit.framework.TestCase.assertFalse; +import static junit.framework.TestCase.assertTrue; + +@RunWith(AndroidJUnit4.class) +public class FileSourceTest { + + @Rule + public ActivityTestRule<FeatureOverviewActivity> rule = new ActivityTestRule<>(FeatureOverviewActivity.class); + + private FileSource fileSource; + + @Before + public void setUp() throws Exception { + onView(withId(R.id.recyclerView)).perform(new FileSourceCreator()); + } + + @Test + public void testDefault() throws Exception { + assertFalse("FileSource should not be active", fileSource.isActivated()); + } + + @Test + public void testActivateDeactivate() throws Exception { + assertFalse("1) FileSource should not be active", fileSource.isActivated()); + onView(withId(R.id.recyclerView)).perform(new FileSourceActivator(true)); + assertTrue("2) FileSource should be active", fileSource.isActivated()); + onView(withId(R.id.recyclerView)).perform(new FileSourceActivator(false)); + assertFalse("3) FileSource should not be active", fileSource.isActivated()); + } + + @Test + public void testOpenCloseMapView() throws Exception { + assertFalse("1) FileSource should not be active", fileSource.isActivated()); + onView(withText("Simple Map")).perform(click()); + onView(withId(R.id.mapView)).perform(new WaitAction()); + assertTrue("2) FileSource should be active", fileSource.isActivated()); + onView(withId(R.id.mapView)).perform(new WaitAction()); + pressBack(); + assertFalse("3) FileSource should not be active", fileSource.isActivated()); + } + + @Test + @Ignore + public void testRotateMapView() throws Exception { + assertFalse("1) FileSource should not be active", fileSource.isActivated()); + onView(withText("Simple Map")).perform(click()); + onView(withId(R.id.mapView)).perform(new WaitAction()); + onView(isRoot()).perform(orientationLandscape()); + onView(withId(R.id.mapView)).perform(new WaitAction()); + assertTrue("2) FileSource should be active", fileSource.isActivated()); + onView(withId(R.id.mapView)).perform(new WaitAction()); + pressBack(); + assertFalse("3) FileSource should not be active", fileSource.isActivated()); + } + + private class FileSourceCreator implements ViewAction { + @Override + public Matcher<View> getConstraints() { + return isDisplayed(); + } + + @Override + public String getDescription() { + return "Creates the filesource instance on the UI thread"; + } + + @Override + public void perform(UiController uiController, View view) { + assertTrue(Looper.myLooper() == Looper.getMainLooper()); + fileSource = FileSource.getInstance(rule.getActivity()); + } + } + + private class FileSourceActivator implements ViewAction { + + private boolean activate; + + FileSourceActivator(boolean activate) { + this.activate = activate; + } + + @Override + public Matcher<View> getConstraints() { + return isDisplayed(); + } + + @Override + public String getDescription() { + return "Creates the filesource instance on the UI thread"; + } + + @Override + public void perform(UiController uiController, View view) { + assertTrue(Looper.myLooper() == Looper.getMainLooper()); + if (activate) { + fileSource.activate(); + } else { + fileSource.deactivate(); + } + } + } +}
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/style/BackgroundLayerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/style/BackgroundLayerTest.java new file mode 100644 index 0000000000..aa09f43a4a --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/style/BackgroundLayerTest.java @@ -0,0 +1,163 @@ +// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. + +package com.mapbox.mapboxsdk.maps.style; + +import android.graphics.Color; +import android.support.test.runner.AndroidJUnit4; + +import timber.log.Timber; + +import com.mapbox.mapboxsdk.style.expressions.Expression; +import com.mapbox.mapboxsdk.style.layers.BackgroundLayer; +import com.mapbox.mapboxsdk.maps.activity.BaseActivityTest; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static com.mapbox.mapboxsdk.style.expressions.Expression.*; +import static com.mapbox.mapboxsdk.maps.action.MapboxMapAction.invoke; +import static org.junit.Assert.*; +import static com.mapbox.mapboxsdk.style.layers.Property.*; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.*; + +import com.mapbox.mapboxsdk.style.layers.TransitionOptions; +import com.mapbox.mapboxsdk.maps.activity.espresso.EspressoTestActivity; + +/** + * Basic smoke tests for BackgroundLayer + */ +@RunWith(AndroidJUnit4.class) +public class BackgroundLayerTest extends BaseActivityTest { + + private BackgroundLayer layer; + + @Override + protected Class getActivityClass() { + return EspressoTestActivity.class; + } + + private void setupLayer() { + Timber.i("Retrieving layer"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + layer = mapboxMap.getLayerAs("background"); + }); + } + + @Test + public void testSetVisibility() { + validateTestSetup(); + setupLayer(); + Timber.i("Visibility"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Get initial + assertEquals(layer.getVisibility().getValue(), VISIBLE); + + // Set + layer.setProperties(visibility(NONE)); + assertEquals(layer.getVisibility().getValue(), NONE); + }); + } + + @Test + public void testBackgroundColorTransition() { + validateTestSetup(); + setupLayer(); + Timber.i("background-colorTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setBackgroundColorTransition(options); + assertEquals(layer.getBackgroundColorTransition(), options); + }); + } + + @Test + public void testBackgroundColorAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("background-color"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(backgroundColor("rgba(0, 0, 0, 1)")); + assertEquals((String) layer.getBackgroundColor().getValue(), (String) "rgba(0, 0, 0, 1)"); + }); + } + + @Test + public void testBackgroundColorAsIntConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("background-color"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(backgroundColor(Color.RED)); + assertEquals(layer.getBackgroundColorAsInt(), Color.RED); + }); + } + + @Test + public void testBackgroundPatternTransition() { + validateTestSetup(); + setupLayer(); + Timber.i("background-patternTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setBackgroundPatternTransition(options); + assertEquals(layer.getBackgroundPatternTransition(), options); + }); + } + + @Test + public void testBackgroundPatternAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("background-pattern"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(backgroundPattern("pedestrian-polygon")); + assertEquals((String) layer.getBackgroundPattern().getValue(), (String) "pedestrian-polygon"); + }); + } + + @Test + public void testBackgroundOpacityTransition() { + validateTestSetup(); + setupLayer(); + Timber.i("background-opacityTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setBackgroundOpacityTransition(options); + assertEquals(layer.getBackgroundOpacityTransition(), options); + }); + } + + @Test + public void testBackgroundOpacityAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("background-opacity"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(backgroundOpacity(0.3f)); + assertEquals((Float) layer.getBackgroundOpacity().getValue(), (Float) 0.3f); + }); + } +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/style/CircleLayerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/style/CircleLayerTest.java new file mode 100644 index 0000000000..23a902b595 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/style/CircleLayerTest.java @@ -0,0 +1,521 @@ +// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. + +package com.mapbox.mapboxsdk.maps.style; + +import android.graphics.Color; +import android.support.test.runner.AndroidJUnit4; + +import timber.log.Timber; + +import com.mapbox.mapboxsdk.style.expressions.Expression; +import com.mapbox.mapboxsdk.style.layers.CircleLayer; +import com.mapbox.mapboxsdk.maps.activity.BaseActivityTest; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static com.mapbox.mapboxsdk.style.expressions.Expression.*; +import static com.mapbox.mapboxsdk.maps.action.MapboxMapAction.invoke; +import static org.junit.Assert.*; +import static com.mapbox.mapboxsdk.style.layers.Property.*; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.*; + +import com.mapbox.mapboxsdk.style.layers.TransitionOptions; +import com.mapbox.mapboxsdk.maps.activity.espresso.EspressoTestActivity; + +/** + * Basic smoke tests for CircleLayer + */ +@RunWith(AndroidJUnit4.class) +public class CircleLayerTest extends BaseActivityTest { + + private CircleLayer layer; + + @Override + protected Class getActivityClass() { + return EspressoTestActivity.class; + } + + private void setupLayer() { + Timber.i("Retrieving layer"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { + Timber.i("Adding layer"); + layer = new CircleLayer("my-layer", "composite"); + layer.setSourceLayer("composite"); + mapboxMap.addLayer(layer); + // Layer reference is now stale, get new reference + layer = mapboxMap.getLayerAs("my-layer"); + } + }); + } + + @Test + public void testSetVisibility() { + validateTestSetup(); + setupLayer(); + Timber.i("Visibility"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Get initial + assertEquals(layer.getVisibility().getValue(), VISIBLE); + + // Set + layer.setProperties(visibility(NONE)); + assertEquals(layer.getVisibility().getValue(), NONE); + }); + } + + @Test + public void testSourceLayer() { + validateTestSetup(); + setupLayer(); + Timber.i("SourceLayer"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Get initial + assertEquals(layer.getSourceLayer(), "composite"); + + // Set + final String sourceLayer = "test"; + layer.setSourceLayer(sourceLayer); + assertEquals(layer.getSourceLayer(), sourceLayer); + }); + } + + @Test + public void testFilter() { + validateTestSetup(); + setupLayer(); + Timber.i("Filter"); + invoke(mapboxMap, (uiController, mapboxMap1) -> { + assertNotNull(layer); + + // Get initial + assertEquals(layer.getFilter(), null); + + // Set + Expression filter = eq(get("undefined"), literal(1.0)); + layer.setFilter(filter); + assertEquals(layer.getFilter().toString(), filter.toString()); + }); + } + + + + @Test + public void testCircleRadiusTransition() { + validateTestSetup(); + setupLayer(); + Timber.i("circle-radiusTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setCircleRadiusTransition(options); + assertEquals(layer.getCircleRadiusTransition(), options); + }); + } + + @Test + public void testCircleRadiusAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("circle-radius"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(circleRadius(0.3f)); + assertEquals((Float) layer.getCircleRadius().getValue(), (Float) 0.3f); + }); + } + + @Test + public void testCircleRadiusAsExpression() { + validateTestSetup(); + setupLayer(); + Timber.i("circle-radius-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + Expression expression = number(Expression.get("undefined")); + layer.setProperties(circleRadius(expression)); + assertEquals(layer.getCircleRadius().getExpression(), expression); + }); + } + + + @Test + public void testCircleColorTransition() { + validateTestSetup(); + setupLayer(); + Timber.i("circle-colorTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setCircleColorTransition(options); + assertEquals(layer.getCircleColorTransition(), options); + }); + } + + @Test + public void testCircleColorAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("circle-color"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(circleColor("rgba(0, 0, 0, 1)")); + assertEquals((String) layer.getCircleColor().getValue(), (String) "rgba(0, 0, 0, 1)"); + }); + } + + @Test + public void testCircleColorAsExpression() { + validateTestSetup(); + setupLayer(); + Timber.i("circle-color-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + Expression expression = toColor(Expression.get("undefined")); + layer.setProperties(circleColor(expression)); + assertEquals(layer.getCircleColor().getExpression(), expression); + }); + } + + + @Test + public void testCircleColorAsIntConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("circle-color"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(circleColor(Color.RED)); + assertEquals(layer.getCircleColorAsInt(), Color.RED); + }); + } + + @Test + public void testCircleBlurTransition() { + validateTestSetup(); + setupLayer(); + Timber.i("circle-blurTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setCircleBlurTransition(options); + assertEquals(layer.getCircleBlurTransition(), options); + }); + } + + @Test + public void testCircleBlurAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("circle-blur"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(circleBlur(0.3f)); + assertEquals((Float) layer.getCircleBlur().getValue(), (Float) 0.3f); + }); + } + + @Test + public void testCircleBlurAsExpression() { + validateTestSetup(); + setupLayer(); + Timber.i("circle-blur-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + Expression expression = number(Expression.get("undefined")); + layer.setProperties(circleBlur(expression)); + assertEquals(layer.getCircleBlur().getExpression(), expression); + }); + } + + + @Test + public void testCircleOpacityTransition() { + validateTestSetup(); + setupLayer(); + Timber.i("circle-opacityTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setCircleOpacityTransition(options); + assertEquals(layer.getCircleOpacityTransition(), options); + }); + } + + @Test + public void testCircleOpacityAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("circle-opacity"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(circleOpacity(0.3f)); + assertEquals((Float) layer.getCircleOpacity().getValue(), (Float) 0.3f); + }); + } + + @Test + public void testCircleOpacityAsExpression() { + validateTestSetup(); + setupLayer(); + Timber.i("circle-opacity-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + Expression expression = number(Expression.get("undefined")); + layer.setProperties(circleOpacity(expression)); + assertEquals(layer.getCircleOpacity().getExpression(), expression); + }); + } + + + @Test + public void testCircleTranslateTransition() { + validateTestSetup(); + setupLayer(); + Timber.i("circle-translateTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setCircleTranslateTransition(options); + assertEquals(layer.getCircleTranslateTransition(), options); + }); + } + + @Test + public void testCircleTranslateAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("circle-translate"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(circleTranslate(new Float[] {0f, 0f})); + assertEquals((Float[]) layer.getCircleTranslate().getValue(), (Float[]) new Float[] {0f, 0f}); + }); + } + + @Test + public void testCircleTranslateAnchorAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("circle-translate-anchor"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(circleTranslateAnchor(CIRCLE_TRANSLATE_ANCHOR_MAP)); + assertEquals((String) layer.getCircleTranslateAnchor().getValue(), (String) CIRCLE_TRANSLATE_ANCHOR_MAP); + }); + } + + @Test + public void testCirclePitchScaleAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("circle-pitch-scale"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(circlePitchScale(CIRCLE_PITCH_SCALE_MAP)); + assertEquals((String) layer.getCirclePitchScale().getValue(), (String) CIRCLE_PITCH_SCALE_MAP); + }); + } + + @Test + public void testCirclePitchAlignmentAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("circle-pitch-alignment"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(circlePitchAlignment(CIRCLE_PITCH_ALIGNMENT_MAP)); + assertEquals((String) layer.getCirclePitchAlignment().getValue(), (String) CIRCLE_PITCH_ALIGNMENT_MAP); + }); + } + + @Test + public void testCircleStrokeWidthTransition() { + validateTestSetup(); + setupLayer(); + Timber.i("circle-stroke-widthTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setCircleStrokeWidthTransition(options); + assertEquals(layer.getCircleStrokeWidthTransition(), options); + }); + } + + @Test + public void testCircleStrokeWidthAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("circle-stroke-width"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(circleStrokeWidth(0.3f)); + assertEquals((Float) layer.getCircleStrokeWidth().getValue(), (Float) 0.3f); + }); + } + + @Test + public void testCircleStrokeWidthAsExpression() { + validateTestSetup(); + setupLayer(); + Timber.i("circle-stroke-width-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + Expression expression = number(Expression.get("undefined")); + layer.setProperties(circleStrokeWidth(expression)); + assertEquals(layer.getCircleStrokeWidth().getExpression(), expression); + }); + } + + + @Test + public void testCircleStrokeColorTransition() { + validateTestSetup(); + setupLayer(); + Timber.i("circle-stroke-colorTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setCircleStrokeColorTransition(options); + assertEquals(layer.getCircleStrokeColorTransition(), options); + }); + } + + @Test + public void testCircleStrokeColorAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("circle-stroke-color"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(circleStrokeColor("rgba(0, 0, 0, 1)")); + assertEquals((String) layer.getCircleStrokeColor().getValue(), (String) "rgba(0, 0, 0, 1)"); + }); + } + + @Test + public void testCircleStrokeColorAsExpression() { + validateTestSetup(); + setupLayer(); + Timber.i("circle-stroke-color-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + Expression expression = toColor(Expression.get("undefined")); + layer.setProperties(circleStrokeColor(expression)); + assertEquals(layer.getCircleStrokeColor().getExpression(), expression); + }); + } + + + @Test + public void testCircleStrokeColorAsIntConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("circle-stroke-color"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(circleStrokeColor(Color.RED)); + assertEquals(layer.getCircleStrokeColorAsInt(), Color.RED); + }); + } + + @Test + public void testCircleStrokeOpacityTransition() { + validateTestSetup(); + setupLayer(); + Timber.i("circle-stroke-opacityTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setCircleStrokeOpacityTransition(options); + assertEquals(layer.getCircleStrokeOpacityTransition(), options); + }); + } + + @Test + public void testCircleStrokeOpacityAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("circle-stroke-opacity"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(circleStrokeOpacity(0.3f)); + assertEquals((Float) layer.getCircleStrokeOpacity().getValue(), (Float) 0.3f); + }); + } + + @Test + public void testCircleStrokeOpacityAsExpression() { + validateTestSetup(); + setupLayer(); + Timber.i("circle-stroke-opacity-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + Expression expression = number(Expression.get("undefined")); + layer.setProperties(circleStrokeOpacity(expression)); + assertEquals(layer.getCircleStrokeOpacity().getExpression(), expression); + }); + } + +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/style/ExpressionTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/style/ExpressionTest.java new file mode 100644 index 0000000000..cea8296593 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/style/ExpressionTest.java @@ -0,0 +1,234 @@ +package com.mapbox.mapboxsdk.maps.style; + +import android.graphics.Color; +import android.support.test.runner.AndroidJUnit4; +import com.mapbox.mapboxsdk.style.expressions.Expression; +import com.mapbox.mapboxsdk.style.layers.FillLayer; +import com.mapbox.mapboxsdk.style.sources.GeoJsonSource; +import com.mapbox.mapboxsdk.style.sources.Source; +import com.mapbox.mapboxsdk.testapp.R; +import com.mapbox.mapboxsdk.maps.activity.BaseActivityTest; +import com.mapbox.mapboxsdk.maps.activity.espresso.EspressoTestActivity; +import com.mapbox.mapboxsdk.maps.utils.ResourceUtils; +import org.junit.Test; +import org.junit.runner.RunWith; +import timber.log.Timber; + +import java.io.IOException; + +import static com.mapbox.mapboxsdk.style.expressions.Expression.exponential; +import static com.mapbox.mapboxsdk.style.expressions.Expression.get; +import static com.mapbox.mapboxsdk.style.expressions.Expression.interpolate; +import static com.mapbox.mapboxsdk.style.expressions.Expression.literal; +import static com.mapbox.mapboxsdk.style.expressions.Expression.match; +import static com.mapbox.mapboxsdk.style.expressions.Expression.rgb; +import static com.mapbox.mapboxsdk.style.expressions.Expression.rgba; +import static com.mapbox.mapboxsdk.style.expressions.Expression.step; +import static com.mapbox.mapboxsdk.style.expressions.Expression.stop; +import static com.mapbox.mapboxsdk.style.expressions.Expression.string; +import static com.mapbox.mapboxsdk.style.expressions.Expression.toColor; +import static com.mapbox.mapboxsdk.style.expressions.Expression.zoom; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillAntialias; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillColor; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillOutlineColor; +import static com.mapbox.mapboxsdk.maps.action.MapboxMapAction.invoke; +import static org.junit.Assert.assertEquals; + +@RunWith(AndroidJUnit4.class) +public class ExpressionTest extends BaseActivityTest { + + private FillLayer layer; + + @Test + public void testConstantExpressionConversion() { + validateTestSetup(); + setupStyle(); + Timber.i("camera function"); + + invoke(mapboxMap, (uiController, mapboxMap) -> { + // create color expression + Expression inputExpression = rgba(255.0f, 0.0f, 0.0f, 1.0f); + + // set color expression + layer.setProperties( + fillColor(inputExpression) + ); + + // get color value + int color = layer.getFillColor().getColorInt(); + + // compare + assertEquals("input expression should match", Color.RED, color); + }); + } + + @Test + public void testGetExpressionWrapping() { + validateTestSetup(); + setupStyle(); + Timber.i("camera function"); + + invoke(mapboxMap, (uiController, mapboxMap) -> { + // create get expression + Expression inputExpression = get("fill"); + + // set get expression + layer.setProperties( + fillColor(inputExpression) + ); + + // get actual expression + Expression actualExpression = layer.getFillColor().getExpression(); + + // create wrapped expected expression + Expression expectedExpression = toColor(get("fill")); + + // compare + assertEquals("input expression should match", expectedExpression, actualExpression); + }); + } + + @Test + public void testCameraFunction() { + validateTestSetup(); + setupStyle(); + Timber.i("camera function"); + + invoke(mapboxMap, (uiController, mapboxMap) -> { + // create camera function expression + Expression inputExpression = interpolate( + exponential(0.5f), zoom(), + stop(1.0f, rgba(255.0f, 0.0f, 0.0f, 1.0f)), + stop(5.0f, rgba(0.0f, 0.0f, 255.0f, 1.0f)), + stop(10.0f, rgba(0.0f, 255.0f, 0.0f, 1.0f)) + ); + + // set camera function expression + layer.setProperties( + fillColor(inputExpression) + ); + + // get camera function expression + Expression outputExpression = layer.getFillColor().getExpression(); + + // compare + assertEquals("input expression should match", inputExpression, outputExpression); + }); + } + + @Test + public void testSourceFunction() { + validateTestSetup(); + setupStyle(); + Timber.i("camera function"); + + invoke(mapboxMap, (uiController, mapboxMap) -> { + // create camera function expression + Expression inputExpression = toColor(get("fill")); + + // set camera function expression + layer.setProperties( + fillColor(inputExpression) + ); + + // get camera function expression + Expression outputExpression = layer.getFillColor().getExpression(); + + // compare + assertEquals("input expression should match", inputExpression, outputExpression); + }); + } + + @Test + public void testCompositeFunction() { + validateTestSetup(); + setupStyle(); + Timber.i("camera function"); + + invoke(mapboxMap, (uiController, mapboxMap) -> { + // create camera function expression + Expression inputExpression = step(zoom(), + rgba(255.0f, 255.0f, 255.0f, 1.0f), + stop(7.0f, match( + string(get("name")), + literal("Westerpark"), rgba(255.0f, 0.0f, 0.0f, 1.0f), + rgba(255.0f, 255.0f, 255.0f, 1.0f) + )), + stop(8.0f, match( + string(get("name")), + literal("Westerpark"), rgba(0.0f, 0.0f, 255.0f, 1.0f), + rgba(255.0f, 255.0f, 255.0f, 1.0f) + )) + ); + + // set camera function expression + layer.setProperties( + fillColor(inputExpression) + ); + + // get camera function expression + Expression outputExpression = layer.getFillColor().getExpression(); + + // compare + assertEquals("input expression should match", inputExpression, outputExpression); + }); + } + + @Test + public void testLiteralProperty() { + validateTestSetup(); + setupStyle(); + invoke(mapboxMap, (uiController, mapboxMap) -> { + layer.setProperties( + fillColor(literal("#4286f4")) + ); + }); + } + + @Test + public void testLiteralMatchExpression() { + validateTestSetup(); + setupStyle(); + invoke(mapboxMap, (uiController, mapboxMap) -> { + Expression expression = match(literal("something"), literal(0f), + stop("1", get("1")), + stop("2", get("2")), + stop("3", get("3")), + stop("4", get("4")) + ); + + layer.setProperties( + fillColor(expression) + ); + expression.toArray(); + }); + } + + private void setupStyle() { + invoke(mapboxMap, (uiController, mapboxMap) -> { + // Add a source + Source source; + try { + source = new GeoJsonSource("amsterdam-parks-source", + ResourceUtils.readRawResource(rule.getActivity(), R.raw.amsterdam)); + mapboxMap.addSource(source); + } catch (IOException ioException) { + return; + } + + // Add a fill layer + mapboxMap.addLayer(layer = new FillLayer("amsterdam-parks-layer", source.getId()) + .withProperties( + fillColor(rgba(0.0f, 0.0f, 0.0f, 0.5f)), + fillOutlineColor(rgb(0, 0, 255)), + fillAntialias(true) + ) + ); + }); + } + + @Override + protected Class getActivityClass() { + return EspressoTestActivity.class; + } +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/style/FillExtrusionLayerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/style/FillExtrusionLayerTest.java new file mode 100644 index 0000000000..d0f941b0fd --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/style/FillExtrusionLayerTest.java @@ -0,0 +1,357 @@ +// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. + +package com.mapbox.mapboxsdk.maps.style; + +import android.graphics.Color; +import android.support.test.runner.AndroidJUnit4; + +import timber.log.Timber; + +import com.mapbox.mapboxsdk.style.expressions.Expression; +import com.mapbox.mapboxsdk.style.layers.FillExtrusionLayer; +import com.mapbox.mapboxsdk.maps.activity.BaseActivityTest; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static com.mapbox.mapboxsdk.style.expressions.Expression.*; +import static com.mapbox.mapboxsdk.maps.action.MapboxMapAction.invoke; +import static org.junit.Assert.*; +import static com.mapbox.mapboxsdk.style.layers.Property.*; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.*; + +import com.mapbox.mapboxsdk.style.layers.TransitionOptions; +import com.mapbox.mapboxsdk.maps.activity.espresso.EspressoTestActivity; + +/** + * Basic smoke tests for FillExtrusionLayer + */ +@RunWith(AndroidJUnit4.class) +public class FillExtrusionLayerTest extends BaseActivityTest { + + private FillExtrusionLayer layer; + + @Override + protected Class getActivityClass() { + return EspressoTestActivity.class; + } + + private void setupLayer() { + Timber.i("Retrieving layer"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { + Timber.i("Adding layer"); + layer = new FillExtrusionLayer("my-layer", "composite"); + layer.setSourceLayer("composite"); + mapboxMap.addLayer(layer); + // Layer reference is now stale, get new reference + layer = mapboxMap.getLayerAs("my-layer"); + } + }); + } + + @Test + public void testSetVisibility() { + validateTestSetup(); + setupLayer(); + Timber.i("Visibility"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Get initial + assertEquals(layer.getVisibility().getValue(), VISIBLE); + + // Set + layer.setProperties(visibility(NONE)); + assertEquals(layer.getVisibility().getValue(), NONE); + }); + } + + @Test + public void testSourceLayer() { + validateTestSetup(); + setupLayer(); + Timber.i("SourceLayer"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Get initial + assertEquals(layer.getSourceLayer(), "composite"); + + // Set + final String sourceLayer = "test"; + layer.setSourceLayer(sourceLayer); + assertEquals(layer.getSourceLayer(), sourceLayer); + }); + } + + @Test + public void testFilter() { + validateTestSetup(); + setupLayer(); + Timber.i("Filter"); + invoke(mapboxMap, (uiController, mapboxMap1) -> { + assertNotNull(layer); + + // Get initial + assertEquals(layer.getFilter(), null); + + // Set + Expression filter = eq(get("undefined"), literal(1.0)); + layer.setFilter(filter); + assertEquals(layer.getFilter().toString(), filter.toString()); + }); + } + + + + @Test + public void testFillExtrusionOpacityTransition() { + validateTestSetup(); + setupLayer(); + Timber.i("fill-extrusion-opacityTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setFillExtrusionOpacityTransition(options); + assertEquals(layer.getFillExtrusionOpacityTransition(), options); + }); + } + + @Test + public void testFillExtrusionOpacityAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("fill-extrusion-opacity"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(fillExtrusionOpacity(0.3f)); + assertEquals((Float) layer.getFillExtrusionOpacity().getValue(), (Float) 0.3f); + }); + } + + @Test + public void testFillExtrusionColorTransition() { + validateTestSetup(); + setupLayer(); + Timber.i("fill-extrusion-colorTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setFillExtrusionColorTransition(options); + assertEquals(layer.getFillExtrusionColorTransition(), options); + }); + } + + @Test + public void testFillExtrusionColorAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("fill-extrusion-color"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(fillExtrusionColor("rgba(0, 0, 0, 1)")); + assertEquals((String) layer.getFillExtrusionColor().getValue(), (String) "rgba(0, 0, 0, 1)"); + }); + } + + @Test + public void testFillExtrusionColorAsExpression() { + validateTestSetup(); + setupLayer(); + Timber.i("fill-extrusion-color-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + Expression expression = toColor(Expression.get("undefined")); + layer.setProperties(fillExtrusionColor(expression)); + assertEquals(layer.getFillExtrusionColor().getExpression(), expression); + }); + } + + + @Test + public void testFillExtrusionColorAsIntConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("fill-extrusion-color"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(fillExtrusionColor(Color.RED)); + assertEquals(layer.getFillExtrusionColorAsInt(), Color.RED); + }); + } + + @Test + public void testFillExtrusionTranslateTransition() { + validateTestSetup(); + setupLayer(); + Timber.i("fill-extrusion-translateTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setFillExtrusionTranslateTransition(options); + assertEquals(layer.getFillExtrusionTranslateTransition(), options); + }); + } + + @Test + public void testFillExtrusionTranslateAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("fill-extrusion-translate"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(fillExtrusionTranslate(new Float[] {0f, 0f})); + assertEquals((Float[]) layer.getFillExtrusionTranslate().getValue(), (Float[]) new Float[] {0f, 0f}); + }); + } + + @Test + public void testFillExtrusionTranslateAnchorAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("fill-extrusion-translate-anchor"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(fillExtrusionTranslateAnchor(FILL_EXTRUSION_TRANSLATE_ANCHOR_MAP)); + assertEquals((String) layer.getFillExtrusionTranslateAnchor().getValue(), (String) FILL_EXTRUSION_TRANSLATE_ANCHOR_MAP); + }); + } + + @Test + public void testFillExtrusionPatternTransition() { + validateTestSetup(); + setupLayer(); + Timber.i("fill-extrusion-patternTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setFillExtrusionPatternTransition(options); + assertEquals(layer.getFillExtrusionPatternTransition(), options); + }); + } + + @Test + public void testFillExtrusionPatternAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("fill-extrusion-pattern"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(fillExtrusionPattern("pedestrian-polygon")); + assertEquals((String) layer.getFillExtrusionPattern().getValue(), (String) "pedestrian-polygon"); + }); + } + + @Test + public void testFillExtrusionHeightTransition() { + validateTestSetup(); + setupLayer(); + Timber.i("fill-extrusion-heightTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setFillExtrusionHeightTransition(options); + assertEquals(layer.getFillExtrusionHeightTransition(), options); + }); + } + + @Test + public void testFillExtrusionHeightAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("fill-extrusion-height"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(fillExtrusionHeight(0.3f)); + assertEquals((Float) layer.getFillExtrusionHeight().getValue(), (Float) 0.3f); + }); + } + + @Test + public void testFillExtrusionHeightAsExpression() { + validateTestSetup(); + setupLayer(); + Timber.i("fill-extrusion-height-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + Expression expression = number(Expression.get("undefined")); + layer.setProperties(fillExtrusionHeight(expression)); + assertEquals(layer.getFillExtrusionHeight().getExpression(), expression); + }); + } + + + @Test + public void testFillExtrusionBaseTransition() { + validateTestSetup(); + setupLayer(); + Timber.i("fill-extrusion-baseTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setFillExtrusionBaseTransition(options); + assertEquals(layer.getFillExtrusionBaseTransition(), options); + }); + } + + @Test + public void testFillExtrusionBaseAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("fill-extrusion-base"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(fillExtrusionBase(0.3f)); + assertEquals((Float) layer.getFillExtrusionBase().getValue(), (Float) 0.3f); + }); + } + + @Test + public void testFillExtrusionBaseAsExpression() { + validateTestSetup(); + setupLayer(); + Timber.i("fill-extrusion-base-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + Expression expression = number(Expression.get("undefined")); + layer.setProperties(fillExtrusionBase(expression)); + assertEquals(layer.getFillExtrusionBase().getExpression(), expression); + }); + } + +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/style/FillLayerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/style/FillLayerTest.java new file mode 100644 index 0000000000..044b42c77b --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/style/FillLayerTest.java @@ -0,0 +1,356 @@ +// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. + +package com.mapbox.mapboxsdk.maps.style; + +import android.graphics.Color; +import android.support.test.runner.AndroidJUnit4; + +import timber.log.Timber; + +import com.mapbox.mapboxsdk.style.expressions.Expression; +import com.mapbox.mapboxsdk.style.layers.FillLayer; +import com.mapbox.mapboxsdk.maps.activity.BaseActivityTest; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static com.mapbox.mapboxsdk.style.expressions.Expression.*; +import static com.mapbox.mapboxsdk.maps.action.MapboxMapAction.invoke; +import static org.junit.Assert.*; +import static com.mapbox.mapboxsdk.style.layers.Property.*; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.*; + +import com.mapbox.mapboxsdk.style.layers.TransitionOptions; +import com.mapbox.mapboxsdk.maps.activity.espresso.EspressoTestActivity; + +/** + * Basic smoke tests for FillLayer + */ +@RunWith(AndroidJUnit4.class) +public class FillLayerTest extends BaseActivityTest { + + private FillLayer layer; + + @Override + protected Class getActivityClass() { + return EspressoTestActivity.class; + } + + private void setupLayer() { + Timber.i("Retrieving layer"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { + Timber.i("Adding layer"); + layer = new FillLayer("my-layer", "composite"); + layer.setSourceLayer("composite"); + mapboxMap.addLayer(layer); + // Layer reference is now stale, get new reference + layer = mapboxMap.getLayerAs("my-layer"); + } + }); + } + + @Test + public void testSetVisibility() { + validateTestSetup(); + setupLayer(); + Timber.i("Visibility"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Get initial + assertEquals(layer.getVisibility().getValue(), VISIBLE); + + // Set + layer.setProperties(visibility(NONE)); + assertEquals(layer.getVisibility().getValue(), NONE); + }); + } + + @Test + public void testSourceLayer() { + validateTestSetup(); + setupLayer(); + Timber.i("SourceLayer"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Get initial + assertEquals(layer.getSourceLayer(), "composite"); + + // Set + final String sourceLayer = "test"; + layer.setSourceLayer(sourceLayer); + assertEquals(layer.getSourceLayer(), sourceLayer); + }); + } + + @Test + public void testFilter() { + validateTestSetup(); + setupLayer(); + Timber.i("Filter"); + invoke(mapboxMap, (uiController, mapboxMap1) -> { + assertNotNull(layer); + + // Get initial + assertEquals(layer.getFilter(), null); + + // Set + Expression filter = eq(get("undefined"), literal(1.0)); + layer.setFilter(filter); + assertEquals(layer.getFilter().toString(), filter.toString()); + }); + } + + + + @Test + public void testFillAntialiasAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("fill-antialias"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(fillAntialias(true)); + assertEquals((Boolean) layer.getFillAntialias().getValue(), (Boolean) true); + }); + } + + @Test + public void testFillOpacityTransition() { + validateTestSetup(); + setupLayer(); + Timber.i("fill-opacityTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setFillOpacityTransition(options); + assertEquals(layer.getFillOpacityTransition(), options); + }); + } + + @Test + public void testFillOpacityAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("fill-opacity"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(fillOpacity(0.3f)); + assertEquals((Float) layer.getFillOpacity().getValue(), (Float) 0.3f); + }); + } + + @Test + public void testFillOpacityAsExpression() { + validateTestSetup(); + setupLayer(); + Timber.i("fill-opacity-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + Expression expression = number(Expression.get("undefined")); + layer.setProperties(fillOpacity(expression)); + assertEquals(layer.getFillOpacity().getExpression(), expression); + }); + } + + + @Test + public void testFillColorTransition() { + validateTestSetup(); + setupLayer(); + Timber.i("fill-colorTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setFillColorTransition(options); + assertEquals(layer.getFillColorTransition(), options); + }); + } + + @Test + public void testFillColorAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("fill-color"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(fillColor("rgba(0, 0, 0, 1)")); + assertEquals((String) layer.getFillColor().getValue(), (String) "rgba(0, 0, 0, 1)"); + }); + } + + @Test + public void testFillColorAsExpression() { + validateTestSetup(); + setupLayer(); + Timber.i("fill-color-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + Expression expression = toColor(Expression.get("undefined")); + layer.setProperties(fillColor(expression)); + assertEquals(layer.getFillColor().getExpression(), expression); + }); + } + + + @Test + public void testFillColorAsIntConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("fill-color"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(fillColor(Color.RED)); + assertEquals(layer.getFillColorAsInt(), Color.RED); + }); + } + + @Test + public void testFillOutlineColorTransition() { + validateTestSetup(); + setupLayer(); + Timber.i("fill-outline-colorTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setFillOutlineColorTransition(options); + assertEquals(layer.getFillOutlineColorTransition(), options); + }); + } + + @Test + public void testFillOutlineColorAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("fill-outline-color"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(fillOutlineColor("rgba(0, 0, 0, 1)")); + assertEquals((String) layer.getFillOutlineColor().getValue(), (String) "rgba(0, 0, 0, 1)"); + }); + } + + @Test + public void testFillOutlineColorAsExpression() { + validateTestSetup(); + setupLayer(); + Timber.i("fill-outline-color-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + Expression expression = toColor(Expression.get("undefined")); + layer.setProperties(fillOutlineColor(expression)); + assertEquals(layer.getFillOutlineColor().getExpression(), expression); + }); + } + + + @Test + public void testFillOutlineColorAsIntConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("fill-outline-color"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(fillOutlineColor(Color.RED)); + assertEquals(layer.getFillOutlineColorAsInt(), Color.RED); + }); + } + + @Test + public void testFillTranslateTransition() { + validateTestSetup(); + setupLayer(); + Timber.i("fill-translateTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setFillTranslateTransition(options); + assertEquals(layer.getFillTranslateTransition(), options); + }); + } + + @Test + public void testFillTranslateAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("fill-translate"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(fillTranslate(new Float[] {0f, 0f})); + assertEquals((Float[]) layer.getFillTranslate().getValue(), (Float[]) new Float[] {0f, 0f}); + }); + } + + @Test + public void testFillTranslateAnchorAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("fill-translate-anchor"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(fillTranslateAnchor(FILL_TRANSLATE_ANCHOR_MAP)); + assertEquals((String) layer.getFillTranslateAnchor().getValue(), (String) FILL_TRANSLATE_ANCHOR_MAP); + }); + } + + @Test + public void testFillPatternTransition() { + validateTestSetup(); + setupLayer(); + Timber.i("fill-patternTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setFillPatternTransition(options); + assertEquals(layer.getFillPatternTransition(), options); + }); + } + + @Test + public void testFillPatternAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("fill-pattern"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(fillPattern("pedestrian-polygon")); + assertEquals((String) layer.getFillPattern().getValue(), (String) "pedestrian-polygon"); + }); + } +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/style/GeoJsonSourceTests.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/style/GeoJsonSourceTests.java new file mode 100644 index 0000000000..a59830f37c --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/style/GeoJsonSourceTests.java @@ -0,0 +1,173 @@ +package com.mapbox.mapboxsdk.maps.style; + +import android.support.annotation.RawRes; +import android.support.test.espresso.UiController; +import android.support.test.espresso.ViewAction; +import android.support.test.runner.AndroidJUnit4; +import android.view.View; + +import com.mapbox.mapboxsdk.style.layers.CircleLayer; +import com.mapbox.mapboxsdk.style.layers.Layer; +import com.mapbox.mapboxsdk.style.sources.GeoJsonSource; +import com.mapbox.mapboxsdk.testapp.R; +import com.mapbox.mapboxsdk.maps.activity.BaseActivityTest; +import com.mapbox.mapboxsdk.maps.activity.style.RuntimeStyleTestActivity; +import com.mapbox.mapboxsdk.maps.utils.ResourceUtils; +import com.mapbox.geojson.Feature; +import com.mapbox.geojson.FeatureCollection; +import com.mapbox.geojson.Point; + +import org.hamcrest.Matcher; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.io.IOException; + +import timber.log.Timber; + +import static android.support.test.espresso.Espresso.onView; +import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; +import static android.support.test.espresso.matcher.ViewMatchers.withId; + +/** + * Tests for {@link GeoJsonSource} + */ +@RunWith(AndroidJUnit4.class) +public class GeoJsonSourceTests extends BaseActivityTest { + + @Override + protected Class getActivityClass() { + return RuntimeStyleTestActivity.class; + } + + @Test + public void testFeatureCollection() throws Exception { + validateTestSetup(); + onView(withId(R.id.mapView)).perform(new BaseViewAction() { + + @Override + public void perform(UiController uiController, View view) { + GeoJsonSource source = null; + try { + source = new GeoJsonSource("source", FeatureCollection + .fromJson(ResourceUtils.readRawResource(rule.getActivity(), R.raw.test_feature_collection))); + } catch (IOException exception) { + Timber.e(exception); + } + mapboxMap.addSource(source); + mapboxMap.addLayer(new CircleLayer("layer", source.getId())); + } + }); + } + + @Test + public void testPointGeometry() { + validateTestSetup(); + onView(withId(R.id.mapView)).perform(new BaseViewAction() { + + @Override + public void perform(UiController uiController, View view) { + GeoJsonSource source = new GeoJsonSource("source", Point.fromLngLat(0d, 0d)); + mapboxMap.addSource(source); + + mapboxMap.addLayer(new CircleLayer("layer", source.getId())); + } + + }); + } + + @Test + public void testFeatureProperties() throws IOException { + validateTestSetup(); + onView(withId(R.id.mapView)).perform(new BaseViewAction() { + + @Override + public void perform(UiController uiController, View view) { + GeoJsonSource source = null; + try { + source = new GeoJsonSource("source", + ResourceUtils.readRawResource(rule.getActivity(), R.raw.test_feature_properties)); + } catch (IOException exception) { + Timber.e(exception); + } + mapboxMap.addSource(source); + + mapboxMap.addLayer(new CircleLayer("layer", source.getId())); + } + + }); + } + + @Test + public void testPointFeature() { + testFeatureFromResource(R.raw.test_point_feature); + } + + @Test + public void testLineStringFeature() { + testFeatureFromResource(R.raw.test_line_string_feature); + } + + @Test + public void testPolygonFeature() { + testFeatureFromResource(R.raw.test_polygon_feature); + } + + @Test + public void testPolygonWithHoleFeature() { + testFeatureFromResource(R.raw.test_polygon_with_hole_feature); + } + + @Test + public void testMultiPointFeature() { + testFeatureFromResource(R.raw.test_multi_point_feature); + } + + @Test + public void testMultiLineStringFeature() { + testFeatureFromResource(R.raw.test_multi_line_string_feature); + } + + @Test + public void testMultiPolygonFeature() { + testFeatureFromResource(R.raw.test_multi_polygon_feature); + } + + protected void testFeatureFromResource(final @RawRes int resource) { + validateTestSetup(); + onView(withId(R.id.mapView)).perform(new BaseViewAction() { + + @Override + public void perform(UiController uiController, View view) { + GeoJsonSource source = new GeoJsonSource("source"); + mapboxMap.addSource(source); + Layer layer = new CircleLayer("layer", source.getId()); + mapboxMap.addLayer(layer); + + try { + source.setGeoJson(Feature.fromJson(ResourceUtils.readRawResource(rule.getActivity(), resource))); + } catch (IOException exception) { + Timber.e(exception); + } + + mapboxMap.removeLayer(layer); + mapboxMap.removeSource(source); + } + + }); + } + + public abstract class BaseViewAction implements ViewAction { + + @Override + public Matcher<View> getConstraints() { + return isDisplayed(); + } + + @Override + public String getDescription() { + return getClass().getSimpleName(); + } + + } +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/style/HeatmapLayerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/style/HeatmapLayerTest.java new file mode 100644 index 0000000000..2889d1ccae --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/style/HeatmapLayerTest.java @@ -0,0 +1,240 @@ +// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. + +package com.mapbox.mapboxsdk.maps.style; + +import android.graphics.Color; +import android.support.test.runner.AndroidJUnit4; + +import timber.log.Timber; + +import com.mapbox.mapboxsdk.style.expressions.Expression; +import com.mapbox.mapboxsdk.style.layers.HeatmapLayer; +import com.mapbox.mapboxsdk.maps.activity.BaseActivityTest; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static com.mapbox.mapboxsdk.style.expressions.Expression.*; +import static com.mapbox.mapboxsdk.maps.action.MapboxMapAction.invoke; +import static org.junit.Assert.*; +import static com.mapbox.mapboxsdk.style.layers.Property.*; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.*; + +import com.mapbox.mapboxsdk.style.layers.TransitionOptions; +import com.mapbox.mapboxsdk.maps.activity.espresso.EspressoTestActivity; + +/** + * Basic smoke tests for HeatmapLayer + */ +@RunWith(AndroidJUnit4.class) +public class HeatmapLayerTest extends BaseActivityTest { + + private HeatmapLayer layer; + + @Override + protected Class getActivityClass() { + return EspressoTestActivity.class; + } + + private void setupLayer() { + Timber.i("Retrieving layer"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { + Timber.i("Adding layer"); + layer = new HeatmapLayer("my-layer", "composite"); + layer.setSourceLayer("composite"); + mapboxMap.addLayer(layer); + // Layer reference is now stale, get new reference + layer = mapboxMap.getLayerAs("my-layer"); + } + }); + } + + @Test + public void testSetVisibility() { + validateTestSetup(); + setupLayer(); + Timber.i("Visibility"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Get initial + assertEquals(layer.getVisibility().getValue(), VISIBLE); + + // Set + layer.setProperties(visibility(NONE)); + assertEquals(layer.getVisibility().getValue(), NONE); + }); + } + + @Test + public void testSourceLayer() { + validateTestSetup(); + setupLayer(); + Timber.i("SourceLayer"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Get initial + assertEquals(layer.getSourceLayer(), "composite"); + + // Set + final String sourceLayer = "test"; + layer.setSourceLayer(sourceLayer); + assertEquals(layer.getSourceLayer(), sourceLayer); + }); + } + + @Test + public void testFilter() { + validateTestSetup(); + setupLayer(); + Timber.i("Filter"); + invoke(mapboxMap, (uiController, mapboxMap1) -> { + assertNotNull(layer); + + // Get initial + assertEquals(layer.getFilter(), null); + + // Set + Expression filter = eq(get("undefined"), literal(1.0)); + layer.setFilter(filter); + assertEquals(layer.getFilter().toString(), filter.toString()); + }); + } + + + + @Test + public void testHeatmapRadiusTransition() { + validateTestSetup(); + setupLayer(); + Timber.i("heatmap-radiusTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setHeatmapRadiusTransition(options); + assertEquals(layer.getHeatmapRadiusTransition(), options); + }); + } + + @Test + public void testHeatmapRadiusAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("heatmap-radius"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(heatmapRadius(0.3f)); + assertEquals((Float) layer.getHeatmapRadius().getValue(), (Float) 0.3f); + }); + } + + @Test + public void testHeatmapRadiusAsExpression() { + validateTestSetup(); + setupLayer(); + Timber.i("heatmap-radius-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + Expression expression = number(Expression.get("undefined")); + layer.setProperties(heatmapRadius(expression)); + assertEquals(layer.getHeatmapRadius().getExpression(), expression); + }); + } + + + @Test + public void testHeatmapWeightAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("heatmap-weight"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(heatmapWeight(0.3f)); + assertEquals((Float) layer.getHeatmapWeight().getValue(), (Float) 0.3f); + }); + } + + @Test + public void testHeatmapWeightAsExpression() { + validateTestSetup(); + setupLayer(); + Timber.i("heatmap-weight-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + Expression expression = number(Expression.get("undefined")); + layer.setProperties(heatmapWeight(expression)); + assertEquals(layer.getHeatmapWeight().getExpression(), expression); + }); + } + + + @Test + public void testHeatmapIntensityTransition() { + validateTestSetup(); + setupLayer(); + Timber.i("heatmap-intensityTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setHeatmapIntensityTransition(options); + assertEquals(layer.getHeatmapIntensityTransition(), options); + }); + } + + @Test + public void testHeatmapIntensityAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("heatmap-intensity"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(heatmapIntensity(0.3f)); + assertEquals((Float) layer.getHeatmapIntensity().getValue(), (Float) 0.3f); + }); + } + + @Test + public void testHeatmapOpacityTransition() { + validateTestSetup(); + setupLayer(); + Timber.i("heatmap-opacityTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setHeatmapOpacityTransition(options); + assertEquals(layer.getHeatmapOpacityTransition(), options); + }); + } + + @Test + public void testHeatmapOpacityAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("heatmap-opacity"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(heatmapOpacity(0.3f)); + assertEquals((Float) layer.getHeatmapOpacity().getValue(), (Float) 0.3f); + }); + } +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/style/HillshadeLayerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/style/HillshadeLayerTest.java new file mode 100644 index 0000000000..f4d42a2b55 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/style/HillshadeLayerTest.java @@ -0,0 +1,255 @@ +// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. + +package com.mapbox.mapboxsdk.maps.style; + +import android.graphics.Color; +import android.support.test.runner.AndroidJUnit4; + +import timber.log.Timber; + +import com.mapbox.mapboxsdk.style.expressions.Expression; +import com.mapbox.mapboxsdk.style.layers.HillshadeLayer; +import com.mapbox.mapboxsdk.maps.activity.BaseActivityTest; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static com.mapbox.mapboxsdk.style.expressions.Expression.*; +import static com.mapbox.mapboxsdk.maps.action.MapboxMapAction.invoke; +import static org.junit.Assert.*; +import static com.mapbox.mapboxsdk.style.layers.Property.*; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.*; + +import com.mapbox.mapboxsdk.style.layers.TransitionOptions; +import com.mapbox.mapboxsdk.maps.activity.espresso.EspressoTestActivity; + +/** + * Basic smoke tests for HillshadeLayer + */ +@RunWith(AndroidJUnit4.class) +public class HillshadeLayerTest extends BaseActivityTest { + + private HillshadeLayer layer; + + @Override + protected Class getActivityClass() { + return EspressoTestActivity.class; + } + + private void setupLayer() { + Timber.i("Retrieving layer"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { + Timber.i("Adding layer"); + layer = new HillshadeLayer("my-layer", "composite"); + layer.setSourceLayer("composite"); + mapboxMap.addLayer(layer); + // Layer reference is now stale, get new reference + layer = mapboxMap.getLayerAs("my-layer"); + } + }); + } + + @Test + public void testSetVisibility() { + validateTestSetup(); + setupLayer(); + Timber.i("Visibility"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Get initial + assertEquals(layer.getVisibility().getValue(), VISIBLE); + + // Set + layer.setProperties(visibility(NONE)); + assertEquals(layer.getVisibility().getValue(), NONE); + }); + } + + @Test + public void testHillshadeIlluminationDirectionAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("hillshade-illumination-direction"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(hillshadeIlluminationDirection(0.3f)); + assertEquals((Float) layer.getHillshadeIlluminationDirection().getValue(), (Float) 0.3f); + }); + } + + @Test + public void testHillshadeIlluminationAnchorAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("hillshade-illumination-anchor"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(hillshadeIlluminationAnchor(HILLSHADE_ILLUMINATION_ANCHOR_MAP)); + assertEquals((String) layer.getHillshadeIlluminationAnchor().getValue(), (String) HILLSHADE_ILLUMINATION_ANCHOR_MAP); + }); + } + + @Test + public void testHillshadeExaggerationTransition() { + validateTestSetup(); + setupLayer(); + Timber.i("hillshade-exaggerationTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setHillshadeExaggerationTransition(options); + assertEquals(layer.getHillshadeExaggerationTransition(), options); + }); + } + + @Test + public void testHillshadeExaggerationAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("hillshade-exaggeration"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(hillshadeExaggeration(0.3f)); + assertEquals((Float) layer.getHillshadeExaggeration().getValue(), (Float) 0.3f); + }); + } + + @Test + public void testHillshadeShadowColorTransition() { + validateTestSetup(); + setupLayer(); + Timber.i("hillshade-shadow-colorTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setHillshadeShadowColorTransition(options); + assertEquals(layer.getHillshadeShadowColorTransition(), options); + }); + } + + @Test + public void testHillshadeShadowColorAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("hillshade-shadow-color"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(hillshadeShadowColor("rgba(0, 0, 0, 1)")); + assertEquals((String) layer.getHillshadeShadowColor().getValue(), (String) "rgba(0, 0, 0, 1)"); + }); + } + + @Test + public void testHillshadeShadowColorAsIntConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("hillshade-shadow-color"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(hillshadeShadowColor(Color.RED)); + assertEquals(layer.getHillshadeShadowColorAsInt(), Color.RED); + }); + } + + @Test + public void testHillshadeHighlightColorTransition() { + validateTestSetup(); + setupLayer(); + Timber.i("hillshade-highlight-colorTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setHillshadeHighlightColorTransition(options); + assertEquals(layer.getHillshadeHighlightColorTransition(), options); + }); + } + + @Test + public void testHillshadeHighlightColorAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("hillshade-highlight-color"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(hillshadeHighlightColor("rgba(0, 0, 0, 1)")); + assertEquals((String) layer.getHillshadeHighlightColor().getValue(), (String) "rgba(0, 0, 0, 1)"); + }); + } + + @Test + public void testHillshadeHighlightColorAsIntConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("hillshade-highlight-color"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(hillshadeHighlightColor(Color.RED)); + assertEquals(layer.getHillshadeHighlightColorAsInt(), Color.RED); + }); + } + + @Test + public void testHillshadeAccentColorTransition() { + validateTestSetup(); + setupLayer(); + Timber.i("hillshade-accent-colorTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setHillshadeAccentColorTransition(options); + assertEquals(layer.getHillshadeAccentColorTransition(), options); + }); + } + + @Test + public void testHillshadeAccentColorAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("hillshade-accent-color"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(hillshadeAccentColor("rgba(0, 0, 0, 1)")); + assertEquals((String) layer.getHillshadeAccentColor().getValue(), (String) "rgba(0, 0, 0, 1)"); + }); + } + + @Test + public void testHillshadeAccentColorAsIntConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("hillshade-accent-color"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(hillshadeAccentColor(Color.RED)); + assertEquals(layer.getHillshadeAccentColorAsInt(), Color.RED); + }); + } +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/style/ImageTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/style/ImageTest.java new file mode 100644 index 0000000000..83b70045a6 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/style/ImageTest.java @@ -0,0 +1,49 @@ +package com.mapbox.mapboxsdk.maps.style; + +import android.graphics.Bitmap; +import android.graphics.drawable.BitmapDrawable; +import android.graphics.drawable.Drawable; +import android.support.test.runner.AndroidJUnit4; + +import com.mapbox.mapboxsdk.testapp.R; +import com.mapbox.mapboxsdk.maps.action.MapboxMapAction; +import com.mapbox.mapboxsdk.maps.activity.BaseActivityTest; +import com.mapbox.mapboxsdk.maps.activity.style.RuntimeStyleTestActivity; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +/** + * CRUD tests around Image + */ +@RunWith(AndroidJUnit4.class) +public class ImageTest extends BaseActivityTest { + + private static final String IMAGE_ID = "test.image"; + + @Override + protected Class getActivityClass() { + return RuntimeStyleTestActivity.class; + } + + @Test + public void testAddGetImage() { + validateTestSetup(); + MapboxMapAction.invoke(mapboxMap, (uiController, mapboxMap) -> { + Drawable drawable = rule.getActivity().getResources().getDrawable(R.drawable.ic_launcher_round); + assertTrue(drawable instanceof BitmapDrawable); + + Bitmap bitmapSet = ((BitmapDrawable) drawable).getBitmap(); + mapboxMap.addImage(IMAGE_ID, bitmapSet); + + Bitmap bitmapGet = mapboxMap.getImage(IMAGE_ID); + assertTrue(bitmapGet.sameAs(bitmapSet)); + + mapboxMap.removeImage(IMAGE_ID); + assertNull(mapboxMap.getImage(IMAGE_ID)); + }); + } +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/style/LightTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/style/LightTest.java new file mode 100644 index 0000000000..cf049a50ea --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/style/LightTest.java @@ -0,0 +1,172 @@ +package com.mapbox.mapboxsdk.maps.style; + +import android.graphics.Color; +import android.support.test.espresso.UiController; +import android.support.test.espresso.ViewAction; +import android.support.test.runner.AndroidJUnit4; +import android.view.View; + +import com.mapbox.mapboxsdk.style.light.Light; +import com.mapbox.mapboxsdk.style.expressions.Expression; +import com.mapbox.mapboxsdk.style.layers.FillExtrusionLayer; +import com.mapbox.mapboxsdk.style.layers.TransitionOptions; +import com.mapbox.mapboxsdk.style.light.Position; +import com.mapbox.mapboxsdk.testapp.R; +import com.mapbox.mapboxsdk.maps.activity.BaseActivityTest; +import com.mapbox.mapboxsdk.maps.activity.style.FillExtrusionStyleTestActivity; + +import timber.log.Timber; + +import org.hamcrest.Matcher; +import org.junit.Test; +import org.junit.runner.RunWith; + +import static android.support.test.espresso.Espresso.onView; +import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; +import static android.support.test.espresso.matcher.ViewMatchers.withId; +import static com.mapbox.mapboxsdk.style.expressions.Expression.eq; +import static com.mapbox.mapboxsdk.style.layers.Property.ANCHOR_MAP; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillExtrusionBase; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillExtrusionColor; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillExtrusionHeight; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillExtrusionOpacity; + +import static com.mapbox.mapboxsdk.maps.action.MapboxMapAction.invoke; +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertNotNull; + +@RunWith(AndroidJUnit4.class) +public class LightTest extends BaseActivityTest { + + private Light light; + + @Test + public void testAnchor() { + validateTestSetup(); + setupLight(); + Timber.i("anchor"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(light); + // Set and Get + light.setAnchor(ANCHOR_MAP); + assertEquals("Anchor should match", ANCHOR_MAP, light.getAnchor()); + }); + } + + @Test + public void testPositionTransition() { + validateTestSetup(); + setupLight(); + Timber.i("positionTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(light); + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + light.setPositionTransition(options); + assertEquals("Transition options should match", options, light.getPositionTransition()); + }); + } + + @Test + public void testPosition() { + validateTestSetup(); + setupLight(); + Timber.i("position"); + invoke(mapboxMap,(uiController, mapboxMap) -> { + assertNotNull(light); + // Set and Get + Position position = new Position(1, 2, 3); + light.setPosition(position); + assertEquals("Position should match", position, light.getPosition()); + }); + } + + @Test + public void testColorTransition() { + validateTestSetup(); + setupLight(); + Timber.i("colorTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(light); + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + light.setColorTransition(options); + assertEquals("Transition options should match", options, light.getColorTransition()); + }); + } + + @Test + public void testColor() { + validateTestSetup(); + setupLight(); + Timber.i("color"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(light); + // Set and Get + light.setColor("rgba(0, 0, 0, 1)"); + assertEquals("Color should match", "rgba(0, 0, 0, 1)".replaceAll("\\s+", ""), light.getColor()); + }); + } + + @Test + public void testIntensityTransition() { + validateTestSetup(); + setupLight(); + Timber.i("intensityTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(light); + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + light.setIntensityTransition(options); + assertEquals("Transition options should match", options, light.getIntensityTransition()); + }); + } + + @Test + public void testIntensity() { + validateTestSetup(); + setupLight(); + Timber.i("intensity"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(light); + // Set and Get + light.setIntensity(0.3f); + assertEquals("Intensity should match", 0.3f, light.getIntensity()); + }); + } + + private void setupLight() { + onView(withId(R.id.mapView)).perform(new ViewAction() { + @Override + public Matcher<View> getConstraints() { + return isDisplayed(); + } + + @Override + public String getDescription() { + return getClass().getSimpleName(); + } + + @Override + public void perform(UiController uiController, View view) { + light = mapboxMap.getLight(); + FillExtrusionLayer fillExtrusionLayer = new FillExtrusionLayer("3d-buildings", "composite"); + fillExtrusionLayer.setSourceLayer("building"); + fillExtrusionLayer.setFilter(eq(Expression.get("extrude"), "true")); + fillExtrusionLayer.setMinZoom(15); + fillExtrusionLayer.setProperties( + fillExtrusionColor(Color.LTGRAY), + fillExtrusionHeight(Expression.get("height")), + fillExtrusionBase(Expression.get("min_height")), + fillExtrusionOpacity(0.6f) + ); + mapboxMap.addLayer(fillExtrusionLayer); + } + }); + } + + @Override + protected Class getActivityClass() { + return FillExtrusionStyleTestActivity.class; + } +}
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/style/LineLayerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/style/LineLayerTest.java new file mode 100644 index 0000000000..6598a3bf8e --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/style/LineLayerTest.java @@ -0,0 +1,548 @@ +// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. + +package com.mapbox.mapboxsdk.maps.style; + +import android.graphics.Color; +import android.support.test.runner.AndroidJUnit4; + +import timber.log.Timber; + +import com.mapbox.mapboxsdk.style.expressions.Expression; +import com.mapbox.mapboxsdk.style.layers.LineLayer; +import com.mapbox.mapboxsdk.maps.activity.BaseActivityTest; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static com.mapbox.mapboxsdk.style.expressions.Expression.*; +import static com.mapbox.mapboxsdk.maps.action.MapboxMapAction.invoke; +import static org.junit.Assert.*; +import static com.mapbox.mapboxsdk.style.layers.Property.*; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.*; + +import com.mapbox.mapboxsdk.style.layers.TransitionOptions; +import com.mapbox.mapboxsdk.maps.activity.espresso.EspressoTestActivity; + +/** + * Basic smoke tests for LineLayer + */ +@RunWith(AndroidJUnit4.class) +public class LineLayerTest extends BaseActivityTest { + + private LineLayer layer; + + @Override + protected Class getActivityClass() { + return EspressoTestActivity.class; + } + + private void setupLayer() { + Timber.i("Retrieving layer"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { + Timber.i("Adding layer"); + layer = new LineLayer("my-layer", "composite"); + layer.setSourceLayer("composite"); + mapboxMap.addLayer(layer); + // Layer reference is now stale, get new reference + layer = mapboxMap.getLayerAs("my-layer"); + } + }); + } + + @Test + public void testSetVisibility() { + validateTestSetup(); + setupLayer(); + Timber.i("Visibility"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Get initial + assertEquals(layer.getVisibility().getValue(), VISIBLE); + + // Set + layer.setProperties(visibility(NONE)); + assertEquals(layer.getVisibility().getValue(), NONE); + }); + } + + @Test + public void testSourceLayer() { + validateTestSetup(); + setupLayer(); + Timber.i("SourceLayer"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Get initial + assertEquals(layer.getSourceLayer(), "composite"); + + // Set + final String sourceLayer = "test"; + layer.setSourceLayer(sourceLayer); + assertEquals(layer.getSourceLayer(), sourceLayer); + }); + } + + @Test + public void testFilter() { + validateTestSetup(); + setupLayer(); + Timber.i("Filter"); + invoke(mapboxMap, (uiController, mapboxMap1) -> { + assertNotNull(layer); + + // Get initial + assertEquals(layer.getFilter(), null); + + // Set + Expression filter = eq(get("undefined"), literal(1.0)); + layer.setFilter(filter); + assertEquals(layer.getFilter().toString(), filter.toString()); + }); + } + + + + @Test + public void testLineCapAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("line-cap"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(lineCap(LINE_CAP_BUTT)); + assertEquals((String) layer.getLineCap().getValue(), (String) LINE_CAP_BUTT); + }); + } + + @Test + public void testLineJoinAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("line-join"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(lineJoin(LINE_JOIN_BEVEL)); + assertEquals((String) layer.getLineJoin().getValue(), (String) LINE_JOIN_BEVEL); + }); + } + + @Test + public void testLineJoinAsExpression() { + validateTestSetup(); + setupLayer(); + Timber.i("line-join-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + Expression expression = string(Expression.get("undefined")); + layer.setProperties(lineJoin(expression)); + assertEquals(layer.getLineJoin().getExpression(), expression); + }); + } + + + @Test + public void testLineMiterLimitAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("line-miter-limit"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(lineMiterLimit(0.3f)); + assertEquals((Float) layer.getLineMiterLimit().getValue(), (Float) 0.3f); + }); + } + + @Test + public void testLineRoundLimitAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("line-round-limit"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(lineRoundLimit(0.3f)); + assertEquals((Float) layer.getLineRoundLimit().getValue(), (Float) 0.3f); + }); + } + + @Test + public void testLineOpacityTransition() { + validateTestSetup(); + setupLayer(); + Timber.i("line-opacityTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setLineOpacityTransition(options); + assertEquals(layer.getLineOpacityTransition(), options); + }); + } + + @Test + public void testLineOpacityAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("line-opacity"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(lineOpacity(0.3f)); + assertEquals((Float) layer.getLineOpacity().getValue(), (Float) 0.3f); + }); + } + + @Test + public void testLineOpacityAsExpression() { + validateTestSetup(); + setupLayer(); + Timber.i("line-opacity-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + Expression expression = number(Expression.get("undefined")); + layer.setProperties(lineOpacity(expression)); + assertEquals(layer.getLineOpacity().getExpression(), expression); + }); + } + + + @Test + public void testLineColorTransition() { + validateTestSetup(); + setupLayer(); + Timber.i("line-colorTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setLineColorTransition(options); + assertEquals(layer.getLineColorTransition(), options); + }); + } + + @Test + public void testLineColorAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("line-color"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(lineColor("rgba(0, 0, 0, 1)")); + assertEquals((String) layer.getLineColor().getValue(), (String) "rgba(0, 0, 0, 1)"); + }); + } + + @Test + public void testLineColorAsExpression() { + validateTestSetup(); + setupLayer(); + Timber.i("line-color-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + Expression expression = toColor(Expression.get("undefined")); + layer.setProperties(lineColor(expression)); + assertEquals(layer.getLineColor().getExpression(), expression); + }); + } + + + @Test + public void testLineColorAsIntConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("line-color"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(lineColor(Color.RED)); + assertEquals(layer.getLineColorAsInt(), Color.RED); + }); + } + + @Test + public void testLineTranslateTransition() { + validateTestSetup(); + setupLayer(); + Timber.i("line-translateTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setLineTranslateTransition(options); + assertEquals(layer.getLineTranslateTransition(), options); + }); + } + + @Test + public void testLineTranslateAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("line-translate"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(lineTranslate(new Float[] {0f, 0f})); + assertEquals((Float[]) layer.getLineTranslate().getValue(), (Float[]) new Float[] {0f, 0f}); + }); + } + + @Test + public void testLineTranslateAnchorAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("line-translate-anchor"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(lineTranslateAnchor(LINE_TRANSLATE_ANCHOR_MAP)); + assertEquals((String) layer.getLineTranslateAnchor().getValue(), (String) LINE_TRANSLATE_ANCHOR_MAP); + }); + } + + @Test + public void testLineWidthTransition() { + validateTestSetup(); + setupLayer(); + Timber.i("line-widthTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setLineWidthTransition(options); + assertEquals(layer.getLineWidthTransition(), options); + }); + } + + @Test + public void testLineWidthAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("line-width"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(lineWidth(0.3f)); + assertEquals((Float) layer.getLineWidth().getValue(), (Float) 0.3f); + }); + } + + @Test + public void testLineWidthAsExpression() { + validateTestSetup(); + setupLayer(); + Timber.i("line-width-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + Expression expression = number(Expression.get("undefined")); + layer.setProperties(lineWidth(expression)); + assertEquals(layer.getLineWidth().getExpression(), expression); + }); + } + + + @Test + public void testLineGapWidthTransition() { + validateTestSetup(); + setupLayer(); + Timber.i("line-gap-widthTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setLineGapWidthTransition(options); + assertEquals(layer.getLineGapWidthTransition(), options); + }); + } + + @Test + public void testLineGapWidthAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("line-gap-width"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(lineGapWidth(0.3f)); + assertEquals((Float) layer.getLineGapWidth().getValue(), (Float) 0.3f); + }); + } + + @Test + public void testLineGapWidthAsExpression() { + validateTestSetup(); + setupLayer(); + Timber.i("line-gap-width-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + Expression expression = number(Expression.get("undefined")); + layer.setProperties(lineGapWidth(expression)); + assertEquals(layer.getLineGapWidth().getExpression(), expression); + }); + } + + + @Test + public void testLineOffsetTransition() { + validateTestSetup(); + setupLayer(); + Timber.i("line-offsetTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setLineOffsetTransition(options); + assertEquals(layer.getLineOffsetTransition(), options); + }); + } + + @Test + public void testLineOffsetAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("line-offset"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(lineOffset(0.3f)); + assertEquals((Float) layer.getLineOffset().getValue(), (Float) 0.3f); + }); + } + + @Test + public void testLineBlurTransition() { + validateTestSetup(); + setupLayer(); + Timber.i("line-blurTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setLineBlurTransition(options); + assertEquals(layer.getLineBlurTransition(), options); + }); + } + + @Test + public void testLineBlurAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("line-blur"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(lineBlur(0.3f)); + assertEquals((Float) layer.getLineBlur().getValue(), (Float) 0.3f); + }); + } + + @Test + public void testLineBlurAsExpression() { + validateTestSetup(); + setupLayer(); + Timber.i("line-blur-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + Expression expression = number(Expression.get("undefined")); + layer.setProperties(lineBlur(expression)); + assertEquals(layer.getLineBlur().getExpression(), expression); + }); + } + + + @Test + public void testLineDasharrayTransition() { + validateTestSetup(); + setupLayer(); + Timber.i("line-dasharrayTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setLineDasharrayTransition(options); + assertEquals(layer.getLineDasharrayTransition(), options); + }); + } + + @Test + public void testLineDasharrayAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("line-dasharray"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(lineDasharray(new Float[] {})); + assertEquals((Float[]) layer.getLineDasharray().getValue(), (Float[]) new Float[] {}); + }); + } + + @Test + public void testLinePatternTransition() { + validateTestSetup(); + setupLayer(); + Timber.i("line-patternTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setLinePatternTransition(options); + assertEquals(layer.getLinePatternTransition(), options); + }); + } + + @Test + public void testLinePatternAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("line-pattern"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(linePattern("pedestrian-polygon")); + assertEquals((String) layer.getLinePattern().getValue(), (String) "pedestrian-polygon"); + }); + } +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/style/RasterLayerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/style/RasterLayerTest.java new file mode 100644 index 0000000000..594ceddcd7 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/style/RasterLayerTest.java @@ -0,0 +1,271 @@ +// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. + +package com.mapbox.mapboxsdk.maps.style; + +import android.graphics.Color; +import android.support.test.runner.AndroidJUnit4; + +import timber.log.Timber; + +import com.mapbox.mapboxsdk.style.expressions.Expression; +import com.mapbox.mapboxsdk.style.layers.RasterLayer; +import com.mapbox.mapboxsdk.maps.activity.BaseActivityTest; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static com.mapbox.mapboxsdk.style.expressions.Expression.*; +import static com.mapbox.mapboxsdk.maps.action.MapboxMapAction.invoke; +import static org.junit.Assert.*; +import static com.mapbox.mapboxsdk.style.layers.Property.*; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.*; + +import com.mapbox.mapboxsdk.style.layers.TransitionOptions; +import com.mapbox.mapboxsdk.maps.activity.espresso.EspressoTestActivity; + +/** + * Basic smoke tests for RasterLayer + */ +@RunWith(AndroidJUnit4.class) +public class RasterLayerTest extends BaseActivityTest { + + private RasterLayer layer; + + @Override + protected Class getActivityClass() { + return EspressoTestActivity.class; + } + + private void setupLayer() { + Timber.i("Retrieving layer"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { + Timber.i("Adding layer"); + layer = new RasterLayer("my-layer", "composite"); + layer.setSourceLayer("composite"); + mapboxMap.addLayer(layer); + // Layer reference is now stale, get new reference + layer = mapboxMap.getLayerAs("my-layer"); + } + }); + } + + @Test + public void testSetVisibility() { + validateTestSetup(); + setupLayer(); + Timber.i("Visibility"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Get initial + assertEquals(layer.getVisibility().getValue(), VISIBLE); + + // Set + layer.setProperties(visibility(NONE)); + assertEquals(layer.getVisibility().getValue(), NONE); + }); + } + + @Test + public void testRasterOpacityTransition() { + validateTestSetup(); + setupLayer(); + Timber.i("raster-opacityTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setRasterOpacityTransition(options); + assertEquals(layer.getRasterOpacityTransition(), options); + }); + } + + @Test + public void testRasterOpacityAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("raster-opacity"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(rasterOpacity(0.3f)); + assertEquals((Float) layer.getRasterOpacity().getValue(), (Float) 0.3f); + }); + } + + @Test + public void testRasterHueRotateTransition() { + validateTestSetup(); + setupLayer(); + Timber.i("raster-hue-rotateTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setRasterHueRotateTransition(options); + assertEquals(layer.getRasterHueRotateTransition(), options); + }); + } + + @Test + public void testRasterHueRotateAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("raster-hue-rotate"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(rasterHueRotate(0.3f)); + assertEquals((Float) layer.getRasterHueRotate().getValue(), (Float) 0.3f); + }); + } + + @Test + public void testRasterBrightnessMinTransition() { + validateTestSetup(); + setupLayer(); + Timber.i("raster-brightness-minTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setRasterBrightnessMinTransition(options); + assertEquals(layer.getRasterBrightnessMinTransition(), options); + }); + } + + @Test + public void testRasterBrightnessMinAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("raster-brightness-min"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(rasterBrightnessMin(0.3f)); + assertEquals((Float) layer.getRasterBrightnessMin().getValue(), (Float) 0.3f); + }); + } + + @Test + public void testRasterBrightnessMaxTransition() { + validateTestSetup(); + setupLayer(); + Timber.i("raster-brightness-maxTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setRasterBrightnessMaxTransition(options); + assertEquals(layer.getRasterBrightnessMaxTransition(), options); + }); + } + + @Test + public void testRasterBrightnessMaxAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("raster-brightness-max"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(rasterBrightnessMax(0.3f)); + assertEquals((Float) layer.getRasterBrightnessMax().getValue(), (Float) 0.3f); + }); + } + + @Test + public void testRasterSaturationTransition() { + validateTestSetup(); + setupLayer(); + Timber.i("raster-saturationTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setRasterSaturationTransition(options); + assertEquals(layer.getRasterSaturationTransition(), options); + }); + } + + @Test + public void testRasterSaturationAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("raster-saturation"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(rasterSaturation(0.3f)); + assertEquals((Float) layer.getRasterSaturation().getValue(), (Float) 0.3f); + }); + } + + @Test + public void testRasterContrastTransition() { + validateTestSetup(); + setupLayer(); + Timber.i("raster-contrastTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setRasterContrastTransition(options); + assertEquals(layer.getRasterContrastTransition(), options); + }); + } + + @Test + public void testRasterContrastAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("raster-contrast"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(rasterContrast(0.3f)); + assertEquals((Float) layer.getRasterContrast().getValue(), (Float) 0.3f); + }); + } + + @Test + public void testRasterResamplingAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("raster-resampling"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(rasterResampling(RASTER_RESAMPLING_LINEAR)); + assertEquals((String) layer.getRasterResampling().getValue(), (String) RASTER_RESAMPLING_LINEAR); + }); + } + + @Test + public void testRasterFadeDurationAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("raster-fade-duration"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(rasterFadeDuration(0.3f)); + assertEquals((Float) layer.getRasterFadeDuration().getValue(), (Float) 0.3f); + }); + } +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/style/RuntimeStyleTests.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/style/RuntimeStyleTests.java new file mode 100644 index 0000000000..ab5dca8b75 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/style/RuntimeStyleTests.java @@ -0,0 +1,378 @@ +package com.mapbox.mapboxsdk.maps.style; + +import android.graphics.Color; +import android.graphics.PointF; +import android.support.test.espresso.Espresso; +import android.support.test.espresso.UiController; +import android.support.test.espresso.ViewAction; +import android.support.test.runner.AndroidJUnit4; +import android.view.View; + +import com.mapbox.mapboxsdk.style.layers.CannotAddLayerException; +import com.mapbox.mapboxsdk.style.layers.CircleLayer; +import com.mapbox.mapboxsdk.style.layers.FillLayer; +import com.mapbox.mapboxsdk.style.layers.Layer; +import com.mapbox.mapboxsdk.style.layers.LineLayer; +import com.mapbox.mapboxsdk.style.layers.Property; +import com.mapbox.mapboxsdk.style.layers.PropertyFactory; +import com.mapbox.mapboxsdk.style.sources.CannotAddSourceException; +import com.mapbox.mapboxsdk.style.sources.GeoJsonSource; +import com.mapbox.mapboxsdk.style.sources.RasterSource; +import com.mapbox.mapboxsdk.style.sources.Source; +import com.mapbox.mapboxsdk.style.sources.VectorSource; +import com.mapbox.mapboxsdk.testapp.R; +import com.mapbox.mapboxsdk.maps.activity.BaseActivityTest; +import com.mapbox.mapboxsdk.maps.activity.style.RuntimeStyleTestActivity; + +import junit.framework.Assert; + +import org.hamcrest.Matcher; +import org.junit.After; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.net.MalformedURLException; +import java.net.URL; +import java.util.List; + +import timber.log.Timber; + +import static android.support.test.espresso.Espresso.onView; +import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; +import static android.support.test.espresso.matcher.ViewMatchers.withId; +import static com.mapbox.mapboxsdk.maps.action.MapboxMapAction.invoke; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + * Basic smoke tests for Layer and Source + */ +@RunWith(AndroidJUnit4.class) +public class RuntimeStyleTests extends BaseActivityTest { + + @Override + protected Class getActivityClass() { + return RuntimeStyleTestActivity.class; + } + + @Test + public void testListLayers() { + validateTestSetup(); + onView(withId(R.id.mapView)).perform(new BaseViewAction() { + + @Override + public void perform(UiController uiController, View view) { + List<Layer> layers = mapboxMap.getLayers(); + assertNotNull(layers); + assertTrue(layers.size() > 0); + for (Layer layer : layers) { + assertNotNull(layer); + } + } + + }); + } + + @Test + public void testGetAddRemoveLayer() { + validateTestSetup(); + onView(withId(R.id.mapView)).perform(new AddRemoveLayerAction()); + } + + @Test + public void testAddLayerAbove() { + validateTestSetup(); + onView(withId(R.id.mapView)).perform(new BaseViewAction() { + @Override + public void perform(UiController uiController, View view) { + List<Layer> layers = mapboxMap.getLayers(); + Source source = mapboxMap.getSources().get(0); + + // Test inserting with invalid above-id + try { + mapboxMap.addLayerAbove(new CircleLayer("invalid-id-layer-test", source.getId()), "no-such-layer-here-man"); + fail("Should have thrown exception"); + } catch (CannotAddLayerException ex) { + // Yeah + assertNotNull(ex.getMessage()); + } + + // Insert as last + CircleLayer last = new CircleLayer("this is the last one", source.getId()); + mapboxMap.addLayerAbove(last, layers.get(layers.size() - 1).getId()); + layers = mapboxMap.getLayers(); + assertEquals(last.getId(), layers.get(layers.size() - 1).getId()); + + // Insert + CircleLayer second = new CircleLayer("this is the second one", source.getId()); + mapboxMap.addLayerAbove(second, layers.get(0).getId()); + layers = mapboxMap.getLayers(); + assertEquals(second.getId(), layers.get(1).getId()); + } + }); + } + + @Test + public void testRemoveLayerAt() { + validateTestSetup(); + onView(withId(R.id.mapView)).perform(new BaseViewAction() { + + @Override + public void perform(UiController uiController, View view) { + // Remove by index + Layer firstLayer = mapboxMap.getLayers().get(0); + Layer removed = mapboxMap.removeLayerAt(0); + assertNotNull(removed); + assertNotNull(removed.getId()); + assertEquals(firstLayer.getId(), removed.getId()); + + // Test remove by index bounds checks + Timber.i("Remove layer at index > size"); + assertNull(mapboxMap.removeLayerAt(Integer.MAX_VALUE)); + } + }); + } + + public void testAddLayerAt() { + validateTestSetup(); + onView(withId(R.id.mapView)).perform(new BaseViewAction() { + @Override + public void perform(UiController uiController, View view) { + List<Layer> layers = mapboxMap.getLayers(); + Source source = mapboxMap.getSources().get(0); + + // Test inserting out of range + try { + mapboxMap.addLayerAt(new CircleLayer("invalid-id-layer-test", source.getId()), layers.size()); + fail("Should have thrown exception"); + } catch (CannotAddLayerException ex) { + // Yeah + assertNotNull(ex.getMessage()); + } + + // Insert at current last position + CircleLayer last = new CircleLayer("this is the last one", source.getId()); + mapboxMap.addLayerAt(last, layers.size() - 1); + layers = mapboxMap.getLayers(); + assertEquals(last.getId(), layers.get(layers.size() - 2).getId()); + + // Insert at start + CircleLayer second = new CircleLayer("this is the first one", source.getId()); + mapboxMap.addLayerAt(second, 0); + layers = mapboxMap.getLayers(); + assertEquals(second.getId(), layers.get(0).getId()); + } + }); + } + + + @Test + public void testListSources() { + validateTestSetup(); + onView(withId(R.id.mapView)).perform(new BaseViewAction() { + + @Override + public void perform(UiController uiController, View view) { + List<Source> sources = mapboxMap.getSources(); + assertNotNull(sources); + assertTrue(sources.size() > 0); + for (Source source : sources) { + assertNotNull(source); + } + } + + }); + } + + @Test + public void testAddRemoveSource() { + validateTestSetup(); + invoke(mapboxMap, (uiController, mapboxMap) -> { + mapboxMap.addSource(new VectorSource("my-source", "mapbox://mapbox.mapbox-terrain-v2")); + mapboxMap.removeSource("my-source"); + + // Add initial source + mapboxMap.addSource(new VectorSource("my-source", "mapbox://mapbox.mapbox-terrain-v2")); + + // Remove + Source mySource = mapboxMap.removeSource("my-source"); + assertNotNull(mySource); + assertNull(mapboxMap.getLayer("my-source")); + + // Add + Source source = new VectorSource("my-source", "mapbox://mapbox.mapbox-terrain-v2"); + mapboxMap.addSource(source); + + // Remove, preserving the reference + mapboxMap.removeSource(source); + + // Re-add the reference... + mapboxMap.addSource(source); + + // Ensure it's there + Assert.assertNotNull(mapboxMap.getSource(source.getId())); + + // Test adding a duplicate source + try { + Source source2 = new VectorSource("my-source", "mapbox://mapbox.mapbox-terrain-v2"); + mapboxMap.addSource(source2); + fail("Should not have been allowed to add a source with a duplicate id"); + } catch (CannotAddSourceException cannotAddSourceException) { + // OK + } + }); + + } + + @Test + public void testVectorSourceUrlGetter() { + validateTestSetup(); + invoke(mapboxMap, (uiController, mapboxMap) -> { + VectorSource source = new VectorSource("my-source", "mapbox://mapbox.mapbox-terrain-v2"); + mapboxMap.addSource(source); + assertEquals("mapbox://mapbox.mapbox-terrain-v2", source.getUrl()); + }); + } + + @Test + public void testRasterSourceUrlGetter() { + validateTestSetup(); + invoke(mapboxMap, (uiController, mapboxMap) -> { + RasterSource source = new RasterSource("my-source", "mapbox://mapbox.mapbox-terrain-v2"); + mapboxMap.addSource(source); + assertEquals("mapbox://mapbox.mapbox-terrain-v2", source.getUrl()); + }); + } + + @Test + public void testGeoJsonSourceUrlGetter() throws MalformedURLException { + validateTestSetup(); + invoke(mapboxMap, (uiController, mapboxMap) -> { + GeoJsonSource source = new GeoJsonSource("my-source"); + mapboxMap.addSource(source); + assertNull(source.getUrl()); + try { + source.setUrl(new URL("http://mapbox.com/my-file.json")); + } catch (MalformedURLException exception) { + fail(); + } + assertEquals("http://mapbox.com/my-file.json", source.getUrl()); + }); + } + + @Test + public void testRemoveSourceInUse() { + validateTestSetup(); + + onView(withId(R.id.mapView)).perform(new BaseViewAction() { + + @Override + public void perform(UiController uiController, View view) { + mapboxMap.addSource(new VectorSource("my-source", "mapbox://mapbox.mapbox-terrain-v2")); + mapboxMap.addLayer(new LineLayer("my-layer", "my-source")); + mapboxMap.removeSource("my-source"); + assertNotNull(mapboxMap.getSource("my-source")); + } + + }); + } + + @Test + public void testRemoveNonExistingSource() { + invoke(mapboxMap, (uiController, mapboxMap) -> mapboxMap.removeSource("source")); + } + + @Test + public void testRemoveNonExistingLayer() { + invoke(mapboxMap, (uiController, mapboxMap) -> { + mapboxMap.removeLayer("layer"); + mapboxMap.removeLayerAt(mapboxMap.getLayers().size() + 1); + mapboxMap.removeLayerAt(-1); + }); + } + + /** + * https://github.com/mapbox/mapbox-gl-native/issues/7973 + */ + @Test + public void testQueryRenderedFeaturesInputHandling() { + validateTestSetup(); + onView(withId(R.id.mapView)).perform(new BaseViewAction() { + + @Override + public void perform(UiController uiController, View view) { + String[] layerIds = new String[600]; + for (int i = 0; i < layerIds.length; i++) { + layerIds[i] = "layer-" + i; + } + mapboxMap.queryRenderedFeatures(new PointF(100, 100), layerIds); + } + + }); + } + + private class AddRemoveLayerAction extends BaseViewAction { + + @Override + public void perform(UiController uiController, View view) { + // Get initial + assertNotNull(mapboxMap.getLayer("building")); + + // Remove + Layer building = mapboxMap.removeLayer("building"); + assertNotNull(building); + assertNull(mapboxMap.getLayer("building")); + + // Add + FillLayer layer = new FillLayer("building", "composite"); + layer.setSourceLayer("building"); + mapboxMap.addLayer(layer); + assertNotNull(mapboxMap.getLayer("building")); + + // Assure the reference still works + layer.setProperties(PropertyFactory.visibility(Property.VISIBLE)); + + // Remove, preserving the reference + mapboxMap.removeLayer(layer); + + // Property setters should still work + layer.setProperties(PropertyFactory.fillColor(Color.RED)); + + // Re-add the reference... + mapboxMap.addLayer(layer); + + // Ensure it's there + Assert.assertNotNull(mapboxMap.getLayer(layer.getId())); + + // Test adding a duplicate layer + try { + mapboxMap.addLayer(new FillLayer("building", "composite")); + fail("Should not have been allowed to add a layer with a duplicate id"); + } catch (CannotAddLayerException cannotAddLayerException) { + // OK + } + } + } + + @After + public void unregisterIntentServiceIdlingResource() { + Espresso.unregisterIdlingResources(idlingResource); + } + + public abstract class BaseViewAction implements ViewAction { + + @Override + public Matcher<View> getConstraints() { + return isDisplayed(); + } + + @Override + public String getDescription() { + return getClass().getSimpleName(); + } + + } +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/style/RuntimeStyleTimingTests.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/style/RuntimeStyleTimingTests.java new file mode 100644 index 0000000000..a138b06f4d --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/style/RuntimeStyleTimingTests.java @@ -0,0 +1,27 @@ +package com.mapbox.mapboxsdk.maps.style; + +import android.support.test.runner.AndroidJUnit4; + +import com.mapbox.mapboxsdk.maps.activity.BaseActivityTest; +import com.mapbox.mapboxsdk.maps.activity.style.RuntimeStyleTimingTestActivity; + +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * Basic smoke tests for adding Layer and Source as early as possible (in onCreate) + */ +@RunWith(AndroidJUnit4.class) +public class RuntimeStyleTimingTests extends BaseActivityTest { + + @Override + protected Class getActivityClass() { + return RuntimeStyleTimingTestActivity.class; + } + + @Test + public void testGetAddRemoveLayer() { + validateTestSetup(); + // We're good if it didn't crash + } +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/style/StyleLoaderTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/style/StyleLoaderTest.java new file mode 100644 index 0000000000..ef009f5ef3 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/style/StyleLoaderTest.java @@ -0,0 +1,77 @@ +package com.mapbox.mapboxsdk.maps.style; + + +import android.support.test.espresso.UiController; + +import com.mapbox.mapboxsdk.maps.MapView; +import com.mapbox.mapboxsdk.maps.MapboxMap; +import com.mapbox.mapboxsdk.testapp.R; +import com.mapbox.mapboxsdk.maps.action.MapboxMapAction; +import com.mapbox.mapboxsdk.maps.activity.BaseActivityTest; +import com.mapbox.mapboxsdk.maps.activity.espresso.EspressoTestActivity; +import com.mapbox.mapboxsdk.maps.utils.ResourceUtils; + +import org.junit.Test; + +import java.io.IOException; + +import static com.mapbox.mapboxsdk.maps.action.MapboxMapAction.invoke; +import static org.junit.Assert.assertEquals; + +/** + * Tests around style loading + */ +public class StyleLoaderTest extends BaseActivityTest { + + + @Override + protected Class getActivityClass() { + return EspressoTestActivity.class; + } + + @Test + public void testSetGetStyleJsonString() throws Exception { + validateTestSetup(); + invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { + @Override + public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { + try { + String expected = ResourceUtils.readRawResource(rule.getActivity(), R.raw.local_style); + mapboxMap.setStyleJson(expected); + String actual = mapboxMap.getStyleJson(); + assertEquals("Style json should match", expected, actual); + } catch (IOException exception) { + exception.printStackTrace(); + } + } + }); + } + + @Test + public void testDefaultStyleLoadWithActivityLifecycleChange() throws Exception { + validateTestSetup(); + invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { + @Override + public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { + try { + String expected = ResourceUtils.readRawResource(rule.getActivity(), R.raw.local_style); + mapboxMap.setStyleJson(expected); + + // fake activity stop/start + MapView mapView = (MapView) rule.getActivity().findViewById(R.id.mapView); + mapView.onPause(); + mapView.onStop(); + + mapView.onStart(); + mapView.onResume(); + + String actual = mapboxMap.getStyleJson(); + assertEquals("Style URL should be empty", "", mapboxMap.getStyleUrl()); + assertEquals("Style json should match", expected, actual); + } catch (IOException exception) { + exception.printStackTrace(); + } + } + }); + } +}
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/style/SymbolLayerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/style/SymbolLayerTest.java new file mode 100644 index 0000000000..08116c06b3 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/style/SymbolLayerTest.java @@ -0,0 +1,1395 @@ +// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. + +package com.mapbox.mapboxsdk.maps.style; + +import android.graphics.Color; +import android.support.test.runner.AndroidJUnit4; + +import timber.log.Timber; + +import com.mapbox.mapboxsdk.style.expressions.Expression; +import com.mapbox.mapboxsdk.style.layers.SymbolLayer; +import com.mapbox.mapboxsdk.maps.activity.BaseActivityTest; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static com.mapbox.mapboxsdk.style.expressions.Expression.*; +import static com.mapbox.mapboxsdk.maps.action.MapboxMapAction.invoke; +import static org.junit.Assert.*; +import static com.mapbox.mapboxsdk.style.layers.Property.*; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.*; + +import com.mapbox.mapboxsdk.style.layers.TransitionOptions; +import com.mapbox.mapboxsdk.maps.activity.espresso.EspressoTestActivity; + +/** + * Basic smoke tests for SymbolLayer + */ +@RunWith(AndroidJUnit4.class) +public class SymbolLayerTest extends BaseActivityTest { + + private SymbolLayer layer; + + @Override + protected Class getActivityClass() { + return EspressoTestActivity.class; + } + + private void setupLayer() { + Timber.i("Retrieving layer"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { + Timber.i("Adding layer"); + layer = new SymbolLayer("my-layer", "composite"); + layer.setSourceLayer("composite"); + mapboxMap.addLayer(layer); + // Layer reference is now stale, get new reference + layer = mapboxMap.getLayerAs("my-layer"); + } + }); + } + + @Test + public void testSetVisibility() { + validateTestSetup(); + setupLayer(); + Timber.i("Visibility"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Get initial + assertEquals(layer.getVisibility().getValue(), VISIBLE); + + // Set + layer.setProperties(visibility(NONE)); + assertEquals(layer.getVisibility().getValue(), NONE); + }); + } + + @Test + public void testSourceLayer() { + validateTestSetup(); + setupLayer(); + Timber.i("SourceLayer"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Get initial + assertEquals(layer.getSourceLayer(), "composite"); + + // Set + final String sourceLayer = "test"; + layer.setSourceLayer(sourceLayer); + assertEquals(layer.getSourceLayer(), sourceLayer); + }); + } + + @Test + public void testFilter() { + validateTestSetup(); + setupLayer(); + Timber.i("Filter"); + invoke(mapboxMap, (uiController, mapboxMap1) -> { + assertNotNull(layer); + + // Get initial + assertEquals(layer.getFilter(), null); + + // Set + Expression filter = eq(get("undefined"), literal(1.0)); + layer.setFilter(filter); + assertEquals(layer.getFilter().toString(), filter.toString()); + }); + } + + + + @Test + public void testSymbolPlacementAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("symbol-placement"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(symbolPlacement(SYMBOL_PLACEMENT_POINT)); + assertEquals((String) layer.getSymbolPlacement().getValue(), (String) SYMBOL_PLACEMENT_POINT); + }); + } + + @Test + public void testSymbolSpacingAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("symbol-spacing"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(symbolSpacing(0.3f)); + assertEquals((Float) layer.getSymbolSpacing().getValue(), (Float) 0.3f); + }); + } + + @Test + public void testSymbolAvoidEdgesAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("symbol-avoid-edges"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(symbolAvoidEdges(true)); + assertEquals((Boolean) layer.getSymbolAvoidEdges().getValue(), (Boolean) true); + }); + } + + @Test + public void testIconAllowOverlapAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("icon-allow-overlap"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(iconAllowOverlap(true)); + assertEquals((Boolean) layer.getIconAllowOverlap().getValue(), (Boolean) true); + }); + } + + @Test + public void testIconIgnorePlacementAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("icon-ignore-placement"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(iconIgnorePlacement(true)); + assertEquals((Boolean) layer.getIconIgnorePlacement().getValue(), (Boolean) true); + }); + } + + @Test + public void testIconOptionalAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("icon-optional"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(iconOptional(true)); + assertEquals((Boolean) layer.getIconOptional().getValue(), (Boolean) true); + }); + } + + @Test + public void testIconRotationAlignmentAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("icon-rotation-alignment"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(iconRotationAlignment(ICON_ROTATION_ALIGNMENT_MAP)); + assertEquals((String) layer.getIconRotationAlignment().getValue(), (String) ICON_ROTATION_ALIGNMENT_MAP); + }); + } + + @Test + public void testIconSizeAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("icon-size"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(iconSize(0.3f)); + assertEquals((Float) layer.getIconSize().getValue(), (Float) 0.3f); + }); + } + + @Test + public void testIconSizeAsExpression() { + validateTestSetup(); + setupLayer(); + Timber.i("icon-size-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + Expression expression = number(Expression.get("undefined")); + layer.setProperties(iconSize(expression)); + assertEquals(layer.getIconSize().getExpression(), expression); + }); + } + + + @Test + public void testIconTextFitAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("icon-text-fit"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(iconTextFit(ICON_TEXT_FIT_NONE)); + assertEquals((String) layer.getIconTextFit().getValue(), (String) ICON_TEXT_FIT_NONE); + }); + } + + @Test + public void testIconTextFitPaddingAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("icon-text-fit-padding"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(iconTextFitPadding(new Float[] {0f, 0f, 0f, 0f})); + assertEquals((Float[]) layer.getIconTextFitPadding().getValue(), (Float[]) new Float[] {0f, 0f, 0f, 0f}); + }); + } + + @Test + public void testIconImageAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("icon-image"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(iconImage("undefined")); + assertEquals((String) layer.getIconImage().getValue(), (String) "undefined"); + }); + } + + @Test + public void testIconImageAsExpression() { + validateTestSetup(); + setupLayer(); + Timber.i("icon-image-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + Expression expression = string(Expression.get("undefined")); + layer.setProperties(iconImage(expression)); + assertEquals(layer.getIconImage().getExpression(), expression); + }); + } + + + @Test + public void testIconRotateAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("icon-rotate"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(iconRotate(0.3f)); + assertEquals((Float) layer.getIconRotate().getValue(), (Float) 0.3f); + }); + } + + @Test + public void testIconRotateAsExpression() { + validateTestSetup(); + setupLayer(); + Timber.i("icon-rotate-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + Expression expression = number(Expression.get("undefined")); + layer.setProperties(iconRotate(expression)); + assertEquals(layer.getIconRotate().getExpression(), expression); + }); + } + + + @Test + public void testIconPaddingAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("icon-padding"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(iconPadding(0.3f)); + assertEquals((Float) layer.getIconPadding().getValue(), (Float) 0.3f); + }); + } + + @Test + public void testIconKeepUprightAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("icon-keep-upright"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(iconKeepUpright(true)); + assertEquals((Boolean) layer.getIconKeepUpright().getValue(), (Boolean) true); + }); + } + + @Test + public void testIconOffsetAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("icon-offset"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(iconOffset(new Float[] {0f, 0f})); + assertEquals((Float[]) layer.getIconOffset().getValue(), (Float[]) new Float[] {0f, 0f}); + }); + } + + @Test + public void testIconAnchorAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("icon-anchor"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(iconAnchor(ICON_ANCHOR_CENTER)); + assertEquals((String) layer.getIconAnchor().getValue(), (String) ICON_ANCHOR_CENTER); + }); + } + + @Test + public void testIconAnchorAsExpression() { + validateTestSetup(); + setupLayer(); + Timber.i("icon-anchor-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + Expression expression = string(Expression.get("undefined")); + layer.setProperties(iconAnchor(expression)); + assertEquals(layer.getIconAnchor().getExpression(), expression); + }); + } + + + @Test + public void testIconPitchAlignmentAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("icon-pitch-alignment"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(iconPitchAlignment(ICON_PITCH_ALIGNMENT_MAP)); + assertEquals((String) layer.getIconPitchAlignment().getValue(), (String) ICON_PITCH_ALIGNMENT_MAP); + }); + } + + @Test + public void testTextPitchAlignmentAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("text-pitch-alignment"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(textPitchAlignment(TEXT_PITCH_ALIGNMENT_MAP)); + assertEquals((String) layer.getTextPitchAlignment().getValue(), (String) TEXT_PITCH_ALIGNMENT_MAP); + }); + } + + @Test + public void testTextRotationAlignmentAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("text-rotation-alignment"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(textRotationAlignment(TEXT_ROTATION_ALIGNMENT_MAP)); + assertEquals((String) layer.getTextRotationAlignment().getValue(), (String) TEXT_ROTATION_ALIGNMENT_MAP); + }); + } + + @Test + public void testTextFieldAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("text-field"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(textField("")); + assertEquals((String) layer.getTextField().getValue(), (String) ""); + }); + } + + @Test + public void testTextFieldAsExpression() { + validateTestSetup(); + setupLayer(); + Timber.i("text-field-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + Expression expression = string(Expression.get("undefined")); + layer.setProperties(textField(expression)); + assertEquals(layer.getTextField().getExpression(), expression); + }); + } + + + @Test + public void testTextFontAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("text-font"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(textFont(new String[]{"Open Sans Regular", "Arial Unicode MS Regular"})); + assertEquals((String[]) layer.getTextFont().getValue(), (String[]) new String[]{"Open Sans Regular", "Arial Unicode MS Regular"}); + }); + } + + @Test + public void testTextSizeAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("text-size"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(textSize(0.3f)); + assertEquals((Float) layer.getTextSize().getValue(), (Float) 0.3f); + }); + } + + @Test + public void testTextSizeAsExpression() { + validateTestSetup(); + setupLayer(); + Timber.i("text-size-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + Expression expression = number(Expression.get("undefined")); + layer.setProperties(textSize(expression)); + assertEquals(layer.getTextSize().getExpression(), expression); + }); + } + + + @Test + public void testTextMaxWidthAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("text-max-width"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(textMaxWidth(0.3f)); + assertEquals((Float) layer.getTextMaxWidth().getValue(), (Float) 0.3f); + }); + } + + @Test + public void testTextMaxWidthAsExpression() { + validateTestSetup(); + setupLayer(); + Timber.i("text-max-width-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + Expression expression = number(Expression.get("undefined")); + layer.setProperties(textMaxWidth(expression)); + assertEquals(layer.getTextMaxWidth().getExpression(), expression); + }); + } + + + @Test + public void testTextLineHeightAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("text-line-height"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(textLineHeight(0.3f)); + assertEquals((Float) layer.getTextLineHeight().getValue(), (Float) 0.3f); + }); + } + + @Test + public void testTextLetterSpacingAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("text-letter-spacing"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(textLetterSpacing(0.3f)); + assertEquals((Float) layer.getTextLetterSpacing().getValue(), (Float) 0.3f); + }); + } + + @Test + public void testTextLetterSpacingAsExpression() { + validateTestSetup(); + setupLayer(); + Timber.i("text-letter-spacing-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + Expression expression = number(Expression.get("undefined")); + layer.setProperties(textLetterSpacing(expression)); + assertEquals(layer.getTextLetterSpacing().getExpression(), expression); + }); + } + + + @Test + public void testTextJustifyAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("text-justify"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(textJustify(TEXT_JUSTIFY_LEFT)); + assertEquals((String) layer.getTextJustify().getValue(), (String) TEXT_JUSTIFY_LEFT); + }); + } + + @Test + public void testTextJustifyAsExpression() { + validateTestSetup(); + setupLayer(); + Timber.i("text-justify-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + Expression expression = string(Expression.get("undefined")); + layer.setProperties(textJustify(expression)); + assertEquals(layer.getTextJustify().getExpression(), expression); + }); + } + + + @Test + public void testTextAnchorAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("text-anchor"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(textAnchor(TEXT_ANCHOR_CENTER)); + assertEquals((String) layer.getTextAnchor().getValue(), (String) TEXT_ANCHOR_CENTER); + }); + } + + @Test + public void testTextAnchorAsExpression() { + validateTestSetup(); + setupLayer(); + Timber.i("text-anchor-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + Expression expression = string(Expression.get("undefined")); + layer.setProperties(textAnchor(expression)); + assertEquals(layer.getTextAnchor().getExpression(), expression); + }); + } + + + @Test + public void testTextMaxAngleAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("text-max-angle"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(textMaxAngle(0.3f)); + assertEquals((Float) layer.getTextMaxAngle().getValue(), (Float) 0.3f); + }); + } + + @Test + public void testTextRotateAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("text-rotate"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(textRotate(0.3f)); + assertEquals((Float) layer.getTextRotate().getValue(), (Float) 0.3f); + }); + } + + @Test + public void testTextRotateAsExpression() { + validateTestSetup(); + setupLayer(); + Timber.i("text-rotate-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + Expression expression = number(Expression.get("undefined")); + layer.setProperties(textRotate(expression)); + assertEquals(layer.getTextRotate().getExpression(), expression); + }); + } + + + @Test + public void testTextPaddingAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("text-padding"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(textPadding(0.3f)); + assertEquals((Float) layer.getTextPadding().getValue(), (Float) 0.3f); + }); + } + + @Test + public void testTextKeepUprightAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("text-keep-upright"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(textKeepUpright(true)); + assertEquals((Boolean) layer.getTextKeepUpright().getValue(), (Boolean) true); + }); + } + + @Test + public void testTextTransformAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("text-transform"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(textTransform(TEXT_TRANSFORM_NONE)); + assertEquals((String) layer.getTextTransform().getValue(), (String) TEXT_TRANSFORM_NONE); + }); + } + + @Test + public void testTextTransformAsExpression() { + validateTestSetup(); + setupLayer(); + Timber.i("text-transform-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + Expression expression = string(Expression.get("undefined")); + layer.setProperties(textTransform(expression)); + assertEquals(layer.getTextTransform().getExpression(), expression); + }); + } + + + @Test + public void testTextOffsetAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("text-offset"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(textOffset(new Float[] {0f, 0f})); + assertEquals((Float[]) layer.getTextOffset().getValue(), (Float[]) new Float[] {0f, 0f}); + }); + } + + @Test + public void testTextAllowOverlapAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("text-allow-overlap"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(textAllowOverlap(true)); + assertEquals((Boolean) layer.getTextAllowOverlap().getValue(), (Boolean) true); + }); + } + + @Test + public void testTextIgnorePlacementAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("text-ignore-placement"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(textIgnorePlacement(true)); + assertEquals((Boolean) layer.getTextIgnorePlacement().getValue(), (Boolean) true); + }); + } + + @Test + public void testTextOptionalAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("text-optional"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(textOptional(true)); + assertEquals((Boolean) layer.getTextOptional().getValue(), (Boolean) true); + }); + } + + @Test + public void testIconOpacityTransition() { + validateTestSetup(); + setupLayer(); + Timber.i("icon-opacityTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setIconOpacityTransition(options); + assertEquals(layer.getIconOpacityTransition(), options); + }); + } + + @Test + public void testIconOpacityAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("icon-opacity"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(iconOpacity(0.3f)); + assertEquals((Float) layer.getIconOpacity().getValue(), (Float) 0.3f); + }); + } + + @Test + public void testIconOpacityAsExpression() { + validateTestSetup(); + setupLayer(); + Timber.i("icon-opacity-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + Expression expression = number(Expression.get("undefined")); + layer.setProperties(iconOpacity(expression)); + assertEquals(layer.getIconOpacity().getExpression(), expression); + }); + } + + + @Test + public void testIconColorTransition() { + validateTestSetup(); + setupLayer(); + Timber.i("icon-colorTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setIconColorTransition(options); + assertEquals(layer.getIconColorTransition(), options); + }); + } + + @Test + public void testIconColorAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("icon-color"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(iconColor("rgba(0, 0, 0, 1)")); + assertEquals((String) layer.getIconColor().getValue(), (String) "rgba(0, 0, 0, 1)"); + }); + } + + @Test + public void testIconColorAsExpression() { + validateTestSetup(); + setupLayer(); + Timber.i("icon-color-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + Expression expression = toColor(Expression.get("undefined")); + layer.setProperties(iconColor(expression)); + assertEquals(layer.getIconColor().getExpression(), expression); + }); + } + + + @Test + public void testIconColorAsIntConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("icon-color"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(iconColor(Color.RED)); + assertEquals(layer.getIconColorAsInt(), Color.RED); + }); + } + + @Test + public void testIconHaloColorTransition() { + validateTestSetup(); + setupLayer(); + Timber.i("icon-halo-colorTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setIconHaloColorTransition(options); + assertEquals(layer.getIconHaloColorTransition(), options); + }); + } + + @Test + public void testIconHaloColorAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("icon-halo-color"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(iconHaloColor("rgba(0, 0, 0, 1)")); + assertEquals((String) layer.getIconHaloColor().getValue(), (String) "rgba(0, 0, 0, 1)"); + }); + } + + @Test + public void testIconHaloColorAsExpression() { + validateTestSetup(); + setupLayer(); + Timber.i("icon-halo-color-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + Expression expression = toColor(Expression.get("undefined")); + layer.setProperties(iconHaloColor(expression)); + assertEquals(layer.getIconHaloColor().getExpression(), expression); + }); + } + + + @Test + public void testIconHaloColorAsIntConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("icon-halo-color"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(iconHaloColor(Color.RED)); + assertEquals(layer.getIconHaloColorAsInt(), Color.RED); + }); + } + + @Test + public void testIconHaloWidthTransition() { + validateTestSetup(); + setupLayer(); + Timber.i("icon-halo-widthTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setIconHaloWidthTransition(options); + assertEquals(layer.getIconHaloWidthTransition(), options); + }); + } + + @Test + public void testIconHaloWidthAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("icon-halo-width"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(iconHaloWidth(0.3f)); + assertEquals((Float) layer.getIconHaloWidth().getValue(), (Float) 0.3f); + }); + } + + @Test + public void testIconHaloWidthAsExpression() { + validateTestSetup(); + setupLayer(); + Timber.i("icon-halo-width-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + Expression expression = number(Expression.get("undefined")); + layer.setProperties(iconHaloWidth(expression)); + assertEquals(layer.getIconHaloWidth().getExpression(), expression); + }); + } + + + @Test + public void testIconHaloBlurTransition() { + validateTestSetup(); + setupLayer(); + Timber.i("icon-halo-blurTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setIconHaloBlurTransition(options); + assertEquals(layer.getIconHaloBlurTransition(), options); + }); + } + + @Test + public void testIconHaloBlurAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("icon-halo-blur"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(iconHaloBlur(0.3f)); + assertEquals((Float) layer.getIconHaloBlur().getValue(), (Float) 0.3f); + }); + } + + @Test + public void testIconHaloBlurAsExpression() { + validateTestSetup(); + setupLayer(); + Timber.i("icon-halo-blur-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + Expression expression = number(Expression.get("undefined")); + layer.setProperties(iconHaloBlur(expression)); + assertEquals(layer.getIconHaloBlur().getExpression(), expression); + }); + } + + + @Test + public void testIconTranslateTransition() { + validateTestSetup(); + setupLayer(); + Timber.i("icon-translateTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setIconTranslateTransition(options); + assertEquals(layer.getIconTranslateTransition(), options); + }); + } + + @Test + public void testIconTranslateAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("icon-translate"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(iconTranslate(new Float[] {0f, 0f})); + assertEquals((Float[]) layer.getIconTranslate().getValue(), (Float[]) new Float[] {0f, 0f}); + }); + } + + @Test + public void testIconTranslateAnchorAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("icon-translate-anchor"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(iconTranslateAnchor(ICON_TRANSLATE_ANCHOR_MAP)); + assertEquals((String) layer.getIconTranslateAnchor().getValue(), (String) ICON_TRANSLATE_ANCHOR_MAP); + }); + } + + @Test + public void testTextOpacityTransition() { + validateTestSetup(); + setupLayer(); + Timber.i("text-opacityTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setTextOpacityTransition(options); + assertEquals(layer.getTextOpacityTransition(), options); + }); + } + + @Test + public void testTextOpacityAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("text-opacity"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(textOpacity(0.3f)); + assertEquals((Float) layer.getTextOpacity().getValue(), (Float) 0.3f); + }); + } + + @Test + public void testTextOpacityAsExpression() { + validateTestSetup(); + setupLayer(); + Timber.i("text-opacity-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + Expression expression = number(Expression.get("undefined")); + layer.setProperties(textOpacity(expression)); + assertEquals(layer.getTextOpacity().getExpression(), expression); + }); + } + + + @Test + public void testTextColorTransition() { + validateTestSetup(); + setupLayer(); + Timber.i("text-colorTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setTextColorTransition(options); + assertEquals(layer.getTextColorTransition(), options); + }); + } + + @Test + public void testTextColorAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("text-color"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(textColor("rgba(0, 0, 0, 1)")); + assertEquals((String) layer.getTextColor().getValue(), (String) "rgba(0, 0, 0, 1)"); + }); + } + + @Test + public void testTextColorAsExpression() { + validateTestSetup(); + setupLayer(); + Timber.i("text-color-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + Expression expression = toColor(Expression.get("undefined")); + layer.setProperties(textColor(expression)); + assertEquals(layer.getTextColor().getExpression(), expression); + }); + } + + + @Test + public void testTextColorAsIntConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("text-color"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(textColor(Color.RED)); + assertEquals(layer.getTextColorAsInt(), Color.RED); + }); + } + + @Test + public void testTextHaloColorTransition() { + validateTestSetup(); + setupLayer(); + Timber.i("text-halo-colorTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setTextHaloColorTransition(options); + assertEquals(layer.getTextHaloColorTransition(), options); + }); + } + + @Test + public void testTextHaloColorAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("text-halo-color"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(textHaloColor("rgba(0, 0, 0, 1)")); + assertEquals((String) layer.getTextHaloColor().getValue(), (String) "rgba(0, 0, 0, 1)"); + }); + } + + @Test + public void testTextHaloColorAsExpression() { + validateTestSetup(); + setupLayer(); + Timber.i("text-halo-color-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + Expression expression = toColor(Expression.get("undefined")); + layer.setProperties(textHaloColor(expression)); + assertEquals(layer.getTextHaloColor().getExpression(), expression); + }); + } + + + @Test + public void testTextHaloColorAsIntConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("text-halo-color"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(textHaloColor(Color.RED)); + assertEquals(layer.getTextHaloColorAsInt(), Color.RED); + }); + } + + @Test + public void testTextHaloWidthTransition() { + validateTestSetup(); + setupLayer(); + Timber.i("text-halo-widthTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setTextHaloWidthTransition(options); + assertEquals(layer.getTextHaloWidthTransition(), options); + }); + } + + @Test + public void testTextHaloWidthAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("text-halo-width"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(textHaloWidth(0.3f)); + assertEquals((Float) layer.getTextHaloWidth().getValue(), (Float) 0.3f); + }); + } + + @Test + public void testTextHaloWidthAsExpression() { + validateTestSetup(); + setupLayer(); + Timber.i("text-halo-width-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + Expression expression = number(Expression.get("undefined")); + layer.setProperties(textHaloWidth(expression)); + assertEquals(layer.getTextHaloWidth().getExpression(), expression); + }); + } + + + @Test + public void testTextHaloBlurTransition() { + validateTestSetup(); + setupLayer(); + Timber.i("text-halo-blurTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setTextHaloBlurTransition(options); + assertEquals(layer.getTextHaloBlurTransition(), options); + }); + } + + @Test + public void testTextHaloBlurAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("text-halo-blur"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(textHaloBlur(0.3f)); + assertEquals((Float) layer.getTextHaloBlur().getValue(), (Float) 0.3f); + }); + } + + @Test + public void testTextHaloBlurAsExpression() { + validateTestSetup(); + setupLayer(); + Timber.i("text-halo-blur-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + Expression expression = number(Expression.get("undefined")); + layer.setProperties(textHaloBlur(expression)); + assertEquals(layer.getTextHaloBlur().getExpression(), expression); + }); + } + + + @Test + public void testTextTranslateTransition() { + validateTestSetup(); + setupLayer(); + Timber.i("text-translateTransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.setTextTranslateTransition(options); + assertEquals(layer.getTextTranslateTransition(), options); + }); + } + + @Test + public void testTextTranslateAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("text-translate"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(textTranslate(new Float[] {0f, 0f})); + assertEquals((Float[]) layer.getTextTranslate().getValue(), (Float[]) new Float[] {0f, 0f}); + }); + } + + @Test + public void testTextTranslateAnchorAsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("text-translate-anchor"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(textTranslateAnchor(TEXT_TRANSLATE_ANCHOR_MAP)); + assertEquals((String) layer.getTextTranslateAnchor().getValue(), (String) TEXT_TRANSLATE_ANCHOR_MAP); + }); + } +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/style/layer.junit.ejs b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/style/layer.junit.ejs new file mode 100644 index 0000000000..575f64e809 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/style/layer.junit.ejs @@ -0,0 +1,191 @@ +<% + const type = locals.type; + const properties = locals.properties; +-%> +// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. + +package com.mapbox.mapboxsdk.testapp.style; + +import android.graphics.Color; +import android.support.test.runner.AndroidJUnit4; + +import timber.log.Timber; + +import com.mapbox.mapboxsdk.style.expressions.Expression; +import com.mapbox.mapboxsdk.style.layers.<%- camelize(type) %>Layer; +import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static com.mapbox.mapboxsdk.style.expressions.Expression.*; +import static com.mapbox.mapboxsdk.testapp.action.MapboxMapAction.invoke; +import static org.junit.Assert.*; +import static com.mapbox.mapboxsdk.style.layers.Property.*; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.*; + +import com.mapbox.mapboxsdk.style.layers.TransitionOptions; +import com.mapbox.mapboxsdk.testapp.activity.espresso.EspressoTestActivity; + +/** + * Basic smoke tests for <%- camelize(type) %>Layer + */ +@RunWith(AndroidJUnit4.class) +public class <%- camelize(type) %>LayerTest extends BaseActivityTest { + + private <%- camelize(type) %>Layer layer; + + @Override + protected Class getActivityClass() { + return EspressoTestActivity.class; + } + + private void setupLayer() { +<% if (type === 'background') { -%> + Timber.i("Retrieving layer"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + layer = mapboxMap.getLayerAs("background"); + }); +<% } else { -%> + Timber.i("Retrieving layer"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { + Timber.i("Adding layer"); + layer = new <%- camelize(type) %>Layer("my-layer", "composite"); + layer.setSourceLayer("composite"); + mapboxMap.addLayer(layer); + // Layer reference is now stale, get new reference + layer = mapboxMap.getLayerAs("my-layer"); + } + }); +<% } -%> + } + + @Test + public void testSetVisibility() { + validateTestSetup(); + setupLayer(); + Timber.i("Visibility"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Get initial + assertEquals(layer.getVisibility().getValue(), VISIBLE); + + // Set + layer.setProperties(visibility(NONE)); + assertEquals(layer.getVisibility().getValue(), NONE); + }); + } +<% if (!(type === 'background' || type === 'raster' || type === 'hillshade')) { -%> + + @Test + public void testSourceLayer() { + validateTestSetup(); + setupLayer(); + Timber.i("SourceLayer"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Get initial + assertEquals(layer.getSourceLayer(), "composite"); + + // Set + final String sourceLayer = "test"; + layer.setSourceLayer(sourceLayer); + assertEquals(layer.getSourceLayer(), sourceLayer); + }); + } + + @Test + public void testFilter() { + validateTestSetup(); + setupLayer(); + Timber.i("Filter"); + invoke(mapboxMap, (uiController, mapboxMap1) -> { + assertNotNull(layer); + + // Get initial + assertEquals(layer.getFilter(), null); + + // Set + Expression filter = eq(get("undefined"), literal(1.0)); + layer.setFilter(filter); + assertEquals(layer.getFilter().toString(), filter.toString()); + }); + } + + +<% } -%> +<% for (const property of properties) { -%> +<% if (property.name != 'heatmap-color') { -%> +<% if (property.transition) { -%> + + @Test + public void test<%- camelize(property.name) %>Transition() { + validateTestSetup(); + setupLayer(); + Timber.i("<%- property.name %>TransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + layer.set<%- camelize(property.name) %>Transition(options); + assertEquals(layer.get<%- camelize(property.name) %>Transition(), options); + }); + } +<% } -%> + + @Test + public void test<%- camelize(property.name) %>AsConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("<%- property.name %>"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(<%- camelizeWithLeadingLowercase(property.name) %>(<%- defaultValueJava(property) %>)); + assertEquals((<%- propertyType(property) %>) layer.get<%- camelize(property.name) %>().getValue(), (<%- propertyType(property) %>) <%- defaultValueJava(property) %>); + }); + } +<% if (property['property-type'] === 'data-driven' || property['property-type'] === 'cross-faded-data-driven') { -%> +<% if (!(property.name.endsWith("-font")||property.name.endsWith("-offset"))) { -%> + + @Test + public void test<%- camelize(property.name) %>AsExpression() { + validateTestSetup(); + setupLayer(); + Timber.i("<%- property.name %>-expression"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + Expression expression = <%- defaultExpressionJava(property) %>(Expression.get("undefined")); + layer.setProperties(<%- camelizeWithLeadingLowercase(property.name) %>(expression)); + assertEquals(layer.get<%- camelize(property.name) %>().getExpression(), expression); + }); + } + +<% } -%> +<% } -%> +<% if (property.type == 'color') { -%> + + @Test + public void test<%- camelize(property.name) %>AsIntConstant() { + validateTestSetup(); + setupLayer(); + Timber.i("<%- property.name %>"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(layer); + + // Set and Get + layer.setProperties(<%- camelizeWithLeadingLowercase(property.name) %>(Color.RED)); + assertEquals(layer.get<%- camelize(property.name) %>AsInt(), Color.RED); + }); + } +<% } -%> +<% } -%> +<% } -%> +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/style/light.junit.ejs b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/style/light.junit.ejs new file mode 100644 index 0000000000..c35168bb7a --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/style/light.junit.ejs @@ -0,0 +1,132 @@ +<% + const properties = locals.properties; +-%> +package com.mapbox.mapboxsdk.testapp.style; + +import android.graphics.Color; +import android.support.test.espresso.UiController; +import android.support.test.espresso.ViewAction; +import android.support.test.runner.AndroidJUnit4; +import android.view.View; + +import com.mapbox.mapboxsdk.style.light.Light; +import com.mapbox.mapboxsdk.style.expressions.Expression; +import com.mapbox.mapboxsdk.style.layers.FillExtrusionLayer; +import com.mapbox.mapboxsdk.style.layers.TransitionOptions; +import com.mapbox.mapboxsdk.style.light.Position; +import com.mapbox.mapboxsdk.testapp.R; +import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest; +import com.mapbox.mapboxsdk.testapp.activity.style.FillExtrusionStyleTestActivity; + +import timber.log.Timber; + +import org.hamcrest.Matcher; +import org.junit.Test; +import org.junit.runner.RunWith; + +import static android.support.test.espresso.Espresso.onView; +import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; +import static android.support.test.espresso.matcher.ViewMatchers.withId; +import static com.mapbox.mapboxsdk.style.expressions.Expression.eq; +import static com.mapbox.mapboxsdk.style.layers.Property.ANCHOR_MAP; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillExtrusionBase; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillExtrusionColor; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillExtrusionHeight; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillExtrusionOpacity; + +import static com.mapbox.mapboxsdk.testapp.action.MapboxMapAction.invoke; +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertNotNull; + +@RunWith(AndroidJUnit4.class) +public class LightTest extends BaseActivityTest { + + private Light light; +<% for (const property of properties) { -%> +<% if (property.transition) { -%> + + @Test + public void test<%- camelize(property.name) %>Transition() { + validateTestSetup(); + setupLight(); + Timber.i("<%- property.name %>TransitionOptions"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(light); + // Set and Get + TransitionOptions options = new TransitionOptions(300, 100); + light.set<%- camelize(property.name) %>Transition(options); + assertEquals("Transition options should match", options, light.get<%- camelize(property.name) %>Transition()); + }); + } +<% } -%> +<% if (property.name == "position") { -%> + + @Test + public void test<%- camelize(property.name) %>() { + validateTestSetup(); + setupLight(); + Timber.i("<%- property.name %>"); + invoke(mapboxMap,(uiController, mapboxMap) -> { + assertNotNull(light); + // Set and Get + Position position = new Position(1, 2, 3); + light.set<%- camelize(property.name) %>(position); + assertEquals("Position should match", position, light.get<%- camelize(property.name) %>()); + }); + } +<% } else { -%> + + @Test + public void test<%- camelize(property.name) %>() { + validateTestSetup(); + setupLight(); + Timber.i("<%- property.name %>"); + invoke(mapboxMap, (uiController, mapboxMap) -> { + assertNotNull(light); + // Set and Get + light.set<%- camelize(property.name) %>(<%- defaultValueJava(property) %>); +<% if (property.name == 'color') { -%> + assertEquals("<%- camelize(property.name) %> should match", <%- defaultValueJava(property) %>.replaceAll("\\s+", ""), light.get<%- camelize(property.name) %>()); +<% } else { -%> + assertEquals("<%- camelize(property.name) %> should match", <%- defaultValueJava(property) %>, light.get<%- camelize(property.name) %>()); +<% } -%> + }); + } +<% } -%> +<% } -%> + + private void setupLight() { + onView(withId(R.id.mapView)).perform(new ViewAction() { + @Override + public Matcher<View> getConstraints() { + return isDisplayed(); + } + + @Override + public String getDescription() { + return getClass().getSimpleName(); + } + + @Override + public void perform(UiController uiController, View view) { + light = mapboxMap.getLight(); + FillExtrusionLayer fillExtrusionLayer = new FillExtrusionLayer("3d-buildings", "composite"); + fillExtrusionLayer.setSourceLayer("building"); + fillExtrusionLayer.setFilter(eq(Expression.get("extrude"), "true")); + fillExtrusionLayer.setMinZoom(15); + fillExtrusionLayer.setProperties( + fillExtrusionColor(Color.LTGRAY), + fillExtrusionHeight(Expression.get("height")), + fillExtrusionBase(Expression.get("min_height")), + fillExtrusionOpacity(0.6f) + ); + mapboxMap.addLayer(fillExtrusionLayer); + } + }); + } + + @Override + protected Class getActivityClass() { + return FillExtrusionStyleTestActivity.class; + } +}
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/utils/DrawerUtils.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/utils/DrawerUtils.java new file mode 100644 index 0000000000..85f9a4fa3b --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/utils/DrawerUtils.java @@ -0,0 +1,29 @@ +package com.mapbox.mapboxsdk.maps.utils; + +import android.support.annotation.StringRes; +import android.support.test.espresso.Espresso; +import android.support.test.espresso.action.ViewActions; +import android.support.test.espresso.matcher.ViewMatchers; + +import com.mapbox.mapboxsdk.testapp.R; + +import org.hamcrest.Matchers; + +import static android.support.test.espresso.Espresso.onView; +import static android.support.test.espresso.action.ViewActions.click; +import static android.support.test.espresso.matcher.ViewMatchers.withContentDescription; + +public class DrawerUtils { + + private static final String HOME_BUTTON_STRING = "Navigate up"; + + public static void openDrawer() { + onView(withContentDescription(HOME_BUTTON_STRING)).perform(click()); + } + + public static void clickItem(@StringRes int txtId) { + Espresso.onView(Matchers.allOf(ViewMatchers.withId(R.id.design_menu_item_text), + ViewMatchers.hasSibling(ViewMatchers.withText(txtId)))).perform(ViewActions.click()); + } + +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/utils/GestureUtils.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/utils/GestureUtils.java new file mode 100644 index 0000000000..a9b8dfa475 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/utils/GestureUtils.java @@ -0,0 +1,15 @@ +package com.mapbox.mapboxsdk.maps.utils; + +import android.support.annotation.IdRes; + +import static android.support.test.espresso.Espresso.onView; +import static android.support.test.espresso.action.ViewActions.doubleClick; +import static android.support.test.espresso.matcher.ViewMatchers.withId; + +public class GestureUtils { + + public static void doubleClickGesture(@IdRes int id) { + onView(withId(id)).perform(doubleClick()); + } + +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/utils/OnMapReadyIdlingResource.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/utils/OnMapReadyIdlingResource.java new file mode 100644 index 0000000000..aa08f99c1e --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/utils/OnMapReadyIdlingResource.java @@ -0,0 +1,58 @@ +package com.mapbox.mapboxsdk.maps.utils; + +import android.app.Activity; +import android.os.Handler; +import android.support.annotation.WorkerThread; +import android.support.test.espresso.IdlingResource; + +import com.mapbox.mapboxsdk.maps.MapView; +import com.mapbox.mapboxsdk.maps.MapboxMap; +import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; + +import java.lang.reflect.Field; + +public class OnMapReadyIdlingResource implements IdlingResource, OnMapReadyCallback { + + private MapboxMap mapboxMap; + private IdlingResource.ResourceCallback resourceCallback; + + @WorkerThread + public OnMapReadyIdlingResource(Activity activity) { + new Handler(activity.getMainLooper()).post(() -> { + try { + Field field = activity.getClass().getDeclaredField("mapView"); + field.setAccessible(true); + ((MapView) field.get(activity)).getMapAsync(OnMapReadyIdlingResource.this); + } catch (Exception err) { + throw new RuntimeException(err); + } + }); + } + + @Override + public String getName() { + return getClass().getSimpleName(); + } + + @Override + public boolean isIdleNow() { + return mapboxMap != null; + } + + @Override + public void registerIdleTransitionCallback(ResourceCallback resourceCallback) { + this.resourceCallback = resourceCallback; + } + + public MapboxMap getMapboxMap() { + return mapboxMap; + } + + @Override + public void onMapReady(MapboxMap mapboxMap) { + this.mapboxMap = mapboxMap; + if (resourceCallback != null) { + resourceCallback.onTransitionToIdle(); + } + } +}
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/utils/SnapshotterIdlingResource.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/utils/SnapshotterIdlingResource.java new file mode 100644 index 0000000000..a42dcb5309 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/utils/SnapshotterIdlingResource.java @@ -0,0 +1,38 @@ +package com.mapbox.mapboxsdk.maps.utils; + +import android.support.test.espresso.IdlingResource; + +import com.mapbox.mapboxsdk.maps.activity.render.RenderTestActivity; + +public class SnapshotterIdlingResource implements IdlingResource, RenderTestActivity.OnRenderTestCompletionListener { + + private IdlingResource.ResourceCallback resourceCallback; + private boolean isSnapshotReady; + + public SnapshotterIdlingResource(RenderTestActivity activity) { + activity.setOnRenderTestCompletionListener(this); + } + + @Override + public String getName() { + return "SnapshotterIdlingResource"; + } + + @Override + public boolean isIdleNow() { + return isSnapshotReady; + } + + @Override + public void registerIdleTransitionCallback(ResourceCallback resourceCallback) { + this.resourceCallback = resourceCallback; + } + + @Override + public void onFinish() { + isSnapshotReady = true; + if (resourceCallback != null) { + resourceCallback.onTransitionToIdle(); + } + } +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/utils/TestConstants.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/utils/TestConstants.java new file mode 100644 index 0000000000..ca2a227592 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/utils/TestConstants.java @@ -0,0 +1,18 @@ +package com.mapbox.mapboxsdk.maps.utils; + +import com.mapbox.mapboxsdk.constants.MapboxConstants; + +public class TestConstants { + + public static final long ANIMATION_TEST_TIME = MapboxConstants.ANIMATION_DURATION * 2; + + public static final double LAT_LNG_DELTA_LARGE = 0.01; + public static final double LAT_LNG_DELTA = 0.001; + public static final double BEARING_DELTA = 0.01; + public static final double TILT_DELTA = 0.01; + public static final double ZOOM_DELTA = 0.01; + + public static final String TEXT_MARKER_TEXT = "Text"; + public static final String TEXT_MARKER_TITLE = "Marker"; + public static final String TEXT_MARKER_SNIPPET = "Snippet"; +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/utils/ViewUtils.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/utils/ViewUtils.java new file mode 100644 index 0000000000..ec39b578cf --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/utils/ViewUtils.java @@ -0,0 +1,22 @@ +package com.mapbox.mapboxsdk.maps.utils; + +import android.support.annotation.IdRes; + +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.withId; + +public class ViewUtils { + + public static void clickView(@IdRes int viewRes) { + onView(withId(viewRes)) + .perform(click()); + } + + public static void checkViewIsDisplayed(int id) { + onView(withId(id)) + .check(matches(isDisplayed())); + } +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/widgets/AttributionTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/widgets/AttributionTest.java new file mode 100644 index 0000000000..bfb698e5b7 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/widgets/AttributionTest.java @@ -0,0 +1,215 @@ +package com.mapbox.mapboxsdk.maps.widgets; + +import android.app.Instrumentation; +import android.content.Intent; +import android.net.Uri; +import android.support.test.espresso.UiController; +import android.support.test.espresso.ViewAction; +import android.support.test.espresso.intent.Intents; +import android.text.Html; +import android.text.SpannableStringBuilder; +import android.text.TextUtils; +import android.text.style.URLSpan; +import android.view.View; + +import com.mapbox.mapboxsdk.maps.MapboxMap; +import com.mapbox.mapboxsdk.style.sources.Source; +import com.mapbox.mapboxsdk.testapp.R; +import com.mapbox.mapboxsdk.maps.activity.BaseActivityTest; +import com.mapbox.mapboxsdk.maps.activity.espresso.EspressoTestActivity; + +import org.hamcrest.Matcher; +import org.junit.After; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +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.assertion.ViewAssertions.matches; +import static android.support.test.espresso.intent.Intents.intended; +import static android.support.test.espresso.intent.Intents.intending; +import static android.support.test.espresso.intent.matcher.IntentMatchers.hasAction; +import static android.support.test.espresso.intent.matcher.IntentMatchers.hasData; +import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; +import static android.support.test.espresso.matcher.ViewMatchers.withId; +import static android.support.test.espresso.matcher.ViewMatchers.withText; +import static org.hamcrest.CoreMatchers.allOf; +import static org.hamcrest.CoreMatchers.anything; +import static org.hamcrest.core.IsNot.not; + +public class AttributionTest extends BaseActivityTest { + + private URLSpan[] urlSpans; + + @Override + protected Class getActivityClass() { + return EspressoTestActivity.class; + } + + @Before + public void beforeTest() { + super.beforeTest(); + Intents.init(); + } + + @Test + public void testDisabled() { + validateTestSetup(); + + // Default + onView(withId(R.id.attributionView)).check(matches(isDisplayed())); + + // Disabled + onView(withId(R.id.attributionView)) + .perform(new DisableAction(mapboxMap)) + .check(matches(not(isDisplayed()))); + } + + @Test + @Ignore + public void testMapboxStreetsMapboxAttributionLink() { + validateTestSetup(); + if (urlSpans == null) { + buildUrlSpans(); + } + + // click on View to open dialog + onView(withId(R.id.attributionView)).perform(click()); + onView(withText(R.string.mapbox_attributionsDialogTitle)).check(matches(isDisplayed())); + + // test for trigger url intent + Matcher<Intent> expectedIntent = allOf(hasAction(Intent.ACTION_VIEW), hasData(Uri.parse(urlSpans[0].getURL()))); + intending(expectedIntent).respondWith(new Instrumentation.ActivityResult(0, null)); + + // click item and test for url + onData(anything()).inAdapterView(withId(R.id.select_dialog_listview)).atPosition(0).perform(click()); + intended(expectedIntent); + } + + @Test + @Ignore + public void testMapboxStreetsOpenStreetMapAttributionLink() { + validateTestSetup(); + if (urlSpans == null) { + buildUrlSpans(); + } + + // click on View to open dialog + onView(withId(R.id.attributionView)).perform(click()); + onView(withText(R.string.mapbox_attributionsDialogTitle)).check(matches(isDisplayed())); + + // test for trigger url intent + Matcher<Intent> expectedIntent = allOf(hasAction(Intent.ACTION_VIEW), hasData(Uri.parse(urlSpans[1].getURL()))); + intending(expectedIntent).respondWith(new Instrumentation.ActivityResult(0, null)); + + // click item and test for url + onData(anything()).inAdapterView(withId(R.id.select_dialog_listview)).atPosition(1).perform(click()); + intended(expectedIntent); + } + + @Test + @Ignore + public void testImproveMapLink() { + validateTestSetup(); + if (urlSpans == null) { + buildUrlSpans(); + } + + // click on View to open dialog + onView(withId(R.id.attributionView)).perform(click()); + onView(withText(R.string.mapbox_attributionsDialogTitle)).check(matches(isDisplayed())); + + // test for trigger url intent + Matcher<Intent> expectedIntent = hasAction(Intent.ACTION_VIEW); + intending(expectedIntent).respondWith(new Instrumentation.ActivityResult(0, null)); + + // click item and test for url + onData(anything()).inAdapterView(withId(R.id.select_dialog_listview)).atPosition(2).perform(click()); + intended(expectedIntent); + } + + @Test + public void testTelemetryDialog() { + validateTestSetup(); + + // click on View to open dialog + onView(withId(R.id.attributionView)).perform(click()); + onView(withText(R.string.mapbox_attributionsDialogTitle)).check(matches(isDisplayed())); + + // click on item to open second dialog + onView(withText(R.string.mapbox_telemetrySettings)).perform(click()); + onView(withText(R.string.mapbox_attributionTelemetryTitle)).check(matches(isDisplayed())); + } + + @After + public void afterTest() { + super.afterTest(); + Intents.release(); + } + + private void buildUrlSpans() { + onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> { + for (Source source : mapboxMap.getSources()) { + String attributionSource = source.getAttribution(); + if (!TextUtils.isEmpty(attributionSource)) { + SpannableStringBuilder htmlBuilder = (SpannableStringBuilder) Html.fromHtml(attributionSource); + urlSpans = htmlBuilder.getSpans(0, htmlBuilder.length(), URLSpan.class); + } + } + })); + } + + private class DisableAction implements ViewAction { + + private MapboxMap mapboxMap; + + DisableAction(MapboxMap map) { + mapboxMap = map; + } + + @Override + public Matcher<View> getConstraints() { + return isDisplayed(); + } + + @Override + public String getDescription() { + return getClass().getSimpleName(); + } + + @Override + public void perform(UiController uiController, View view) { + mapboxMap.getUiSettings().setAttributionEnabled(false); + } + } + + private class MapboxMapAction implements ViewAction { + + private InvokeViewAction invokeViewAction; + + MapboxMapAction(InvokeViewAction invokeViewAction) { + this.invokeViewAction = invokeViewAction; + } + + @Override + public Matcher<View> getConstraints() { + return isDisplayed(); + } + + @Override + public String getDescription() { + return getClass().getSimpleName(); + } + + @Override + public void perform(UiController uiController, View view) { + invokeViewAction.onViewAction(uiController, view); + } + } + + interface InvokeViewAction { + void onViewAction(UiController uiController, View view); + } +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/widgets/CompassViewTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/widgets/CompassViewTest.java new file mode 100644 index 0000000000..d7cdd0a3c4 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/widgets/CompassViewTest.java @@ -0,0 +1,73 @@ +package com.mapbox.mapboxsdk.maps.widgets; + +import com.mapbox.mapboxsdk.camera.CameraPosition; +import com.mapbox.mapboxsdk.camera.CameraUpdateFactory; +import com.mapbox.mapboxsdk.geometry.LatLng; +import com.mapbox.mapboxsdk.testapp.R; +import com.mapbox.mapboxsdk.maps.activity.BaseActivityTest; +import com.mapbox.mapboxsdk.maps.activity.espresso.EspressoTestActivity; +import com.mapbox.mapboxsdk.maps.utils.TestConstants; + +import org.junit.Ignore; +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.assertion.ViewAssertions.matches; +import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; +import static android.support.test.espresso.matcher.ViewMatchers.withId; +import static com.mapbox.mapboxsdk.maps.action.MapboxMapAction.invoke; +import static org.hamcrest.Matchers.not; +import static org.junit.Assert.assertEquals; + +public class CompassViewTest extends BaseActivityTest { + + @Override + protected Class getActivityClass() { + return EspressoTestActivity.class; + } + + @Test + public void testDefault() { + validateTestSetup(); + onView(withId(R.id.compassView)).check(matches(not(isDisplayed()))); + } + + @Test + @Ignore + public void testVisible() { + validateTestSetup(); + invoke(mapboxMap, (uiController, mapboxMap) -> { + mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition( + new CameraPosition.Builder() + .bearing(45) + .zoom(1) + .target(new LatLng()) + .build() + )); + uiController.loopMainThreadForAtLeast(500); + }); + onView(withId(R.id.compassView)).check(matches(isDisplayed())); + } + + @Test + @Ignore + public void testClick() { + validateTestSetup(); + invoke(mapboxMap, (uiController, mapboxMap) -> mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition( + new CameraPosition.Builder() + .bearing(45) + .zoom(1) + .target(new LatLng()) + .build() + ))); + onView(withId(R.id.compassView)).perform(click()); + waitAction(); + onView(withId(R.id.compassView)).check(matches(not(isDisplayed()))); + invoke(mapboxMap, (uiController, mapboxMap) -> { + CameraPosition cameraPosition = mapboxMap.getCameraPosition(); + assertEquals("Camera bearing should face north, ", 0, cameraPosition.bearing, TestConstants.BEARING_DELTA); + }); + } +} + diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/widgets/LogoTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/widgets/LogoTest.java new file mode 100644 index 0000000000..bee605310e --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/widgets/LogoTest.java @@ -0,0 +1,66 @@ +package com.mapbox.mapboxsdk.maps.widgets; + +import android.support.test.espresso.UiController; +import android.support.test.espresso.ViewAction; +import android.view.View; + +import com.mapbox.mapboxsdk.maps.MapboxMap; +import com.mapbox.mapboxsdk.testapp.R; +import com.mapbox.mapboxsdk.maps.activity.BaseActivityTest; +import com.mapbox.mapboxsdk.maps.activity.espresso.EspressoTestActivity; + +import org.hamcrest.Matcher; +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; +import static org.hamcrest.Matchers.not; + +public class LogoTest extends BaseActivityTest { + + @Override + protected Class getActivityClass() { + return EspressoTestActivity.class; + } + + @Test + public void testDefault() { + validateTestSetup(); + onView(withId(R.id.logoView)).check(matches(isDisplayed())); + } + + @Test + public void testDisabled() { + validateTestSetup(); + + onView(withId(R.id.logoView)) + .perform(new DisableAction(mapboxMap)) + .check(matches(not(isDisplayed()))); + } + + private class DisableAction implements ViewAction { + + private MapboxMap mapboxMap; + + DisableAction(MapboxMap map) { + mapboxMap = map; + } + + @Override + public Matcher<View> getConstraints() { + return isDisplayed(); + } + + @Override + public String getDescription() { + return getClass().getSimpleName(); + } + + @Override + public void perform(UiController uiController, View view) { + mapboxMap.getUiSettings().setLogoEnabled(false); + } + } +} |