[android] "format" expression support
This commit is contained in:
committed by
Łukasz Paczos
parent
78a1c30e80
commit
12b4969454
@@ -161,7 +161,6 @@ public class CircleLayerTest extends BaseActivityTest {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testCircleColorTransition() {
|
||||
validateTestSetup();
|
||||
@@ -206,7 +205,6 @@ public class CircleLayerTest extends BaseActivityTest {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testCircleColorAsIntConstant() {
|
||||
validateTestSetup();
|
||||
@@ -265,7 +263,6 @@ public class CircleLayerTest extends BaseActivityTest {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testCircleOpacityTransition() {
|
||||
validateTestSetup();
|
||||
@@ -310,7 +307,6 @@ public class CircleLayerTest extends BaseActivityTest {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testCircleTranslateTransition() {
|
||||
validateTestSetup();
|
||||
@@ -426,7 +422,6 @@ public class CircleLayerTest extends BaseActivityTest {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testCircleStrokeColorTransition() {
|
||||
validateTestSetup();
|
||||
@@ -471,7 +466,6 @@ public class CircleLayerTest extends BaseActivityTest {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testCircleStrokeColorAsIntConstant() {
|
||||
validateTestSetup();
|
||||
@@ -529,5 +523,4 @@ public class CircleLayerTest extends BaseActivityTest {
|
||||
assertEquals(layer.getCircleStrokeOpacity().getExpression(), expression);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,16 +1,22 @@
|
||||
package com.mapbox.mapboxsdk.testapp.style;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.support.test.espresso.UiController;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
|
||||
import com.mapbox.geojson.Feature;
|
||||
import com.mapbox.geojson.Point;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.style.expressions.Expression;
|
||||
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.SymbolLayer;
|
||||
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;
|
||||
import com.mapbox.mapboxsdk.style.sources.Source;
|
||||
import com.mapbox.mapboxsdk.style.types.Formatted;
|
||||
import com.mapbox.mapboxsdk.style.types.FormattedSection;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest;
|
||||
import com.mapbox.mapboxsdk.testapp.activity.espresso.EspressoTestActivity;
|
||||
@@ -24,13 +30,18 @@ import java.io.IOException;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.FormatOption.fontScale;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.FormatOption.textFont;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.collator;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.eq;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.exponential;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.format;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.formatEntry;
|
||||
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.number;
|
||||
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;
|
||||
@@ -43,9 +54,11 @@ import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleColor;
|
||||
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.style.layers.PropertyFactory.textField;
|
||||
import static com.mapbox.mapboxsdk.testapp.action.MapboxMapAction.invoke;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class ExpressionTest extends BaseActivityTest {
|
||||
@@ -220,7 +233,6 @@ public class ExpressionTest extends BaseActivityTest {
|
||||
@Test
|
||||
public void testCollatorExpression() {
|
||||
validateTestSetup();
|
||||
setupStyle();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
LatLng latLng = new LatLng(51, 17);
|
||||
|
||||
@@ -265,6 +277,254 @@ public class ExpressionTest extends BaseActivityTest {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstFormatExpressionNoParams() {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
LatLng latLng = new LatLng(51, 17);
|
||||
mapboxMap.addSource(new GeoJsonSource("source", Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude())));
|
||||
SymbolLayer layer = new SymbolLayer("layer", "source");
|
||||
mapboxMap.addLayer(layer);
|
||||
|
||||
Expression expression = format(
|
||||
formatEntry("test")
|
||||
);
|
||||
layer.setProperties(textField(expression));
|
||||
waitForLayer(uiController, mapboxMap, latLng);
|
||||
assertFalse(mapboxMap.queryRenderedFeatures(mapboxMap.getProjection().toScreenLocation(latLng), "layer")
|
||||
.isEmpty());
|
||||
|
||||
assertNull(layer.getTextField().getExpression());
|
||||
assertEquals("test", layer.getTextField().getValue());
|
||||
|
||||
Formatted expected = new Formatted(new FormattedSection[] {
|
||||
new FormattedSection("test", 1.0f)
|
||||
});
|
||||
assertNull(layer.getFormattedTextField().getExpression());
|
||||
assertEquals(expected, layer.getFormattedTextField().getValue());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstFormatExpressionFontScaleParam() {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
LatLng latLng = new LatLng(51, 17);
|
||||
mapboxMap.addSource(new GeoJsonSource("source", Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude())));
|
||||
SymbolLayer layer = new SymbolLayer("layer", "source");
|
||||
mapboxMap.addLayer(layer);
|
||||
|
||||
Expression expression = format(
|
||||
formatEntry("test", fontScale(1.75))
|
||||
);
|
||||
layer.setProperties(textField(expression));
|
||||
waitForLayer(uiController, mapboxMap, latLng);
|
||||
assertFalse(mapboxMap.queryRenderedFeatures(mapboxMap.getProjection().toScreenLocation(latLng), "layer")
|
||||
.isEmpty());
|
||||
|
||||
assertNull(layer.getTextField().getExpression());
|
||||
assertEquals("test", layer.getTextField().getValue());
|
||||
|
||||
Formatted expected = new Formatted(new FormattedSection[] {
|
||||
new FormattedSection("test", 1.75f)
|
||||
});
|
||||
assertNull(layer.getFormattedTextField().getExpression());
|
||||
assertEquals(expected, layer.getFormattedTextField().getValue());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstFormatExpressionTextFontParam() {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
LatLng latLng = new LatLng(51, 17);
|
||||
mapboxMap.addSource(new GeoJsonSource("source", Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude())));
|
||||
SymbolLayer layer = new SymbolLayer("layer", "source");
|
||||
mapboxMap.addLayer(layer);
|
||||
|
||||
Expression expression = format(
|
||||
formatEntry(
|
||||
literal("test"), fontScale(1.0), textFont(new String[] {"DIN Offc Pro Regular", "Arial Unicode MS Regular"})
|
||||
)
|
||||
);
|
||||
layer.setProperties(textField(expression));
|
||||
waitForLayer(uiController, mapboxMap, latLng);
|
||||
assertFalse(mapboxMap.queryRenderedFeatures(mapboxMap.getProjection().toScreenLocation(latLng), "layer")
|
||||
.isEmpty());
|
||||
|
||||
assertNull(layer.getTextField().getExpression());
|
||||
assertEquals("test", layer.getTextField().getValue());
|
||||
|
||||
Formatted expected = new Formatted(new FormattedSection[] {
|
||||
new FormattedSection("test", 1.0f,
|
||||
new String[] {"DIN Offc Pro Regular", "Arial Unicode MS Regular"})
|
||||
});
|
||||
assertNull(layer.getFormattedTextField().getExpression());
|
||||
assertEquals(expected, layer.getFormattedTextField().getValue());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstFormatExpressionAllParams() {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
LatLng latLng = new LatLng(51, 17);
|
||||
mapboxMap.addSource(new GeoJsonSource("source", Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude())));
|
||||
SymbolLayer layer = new SymbolLayer("layer", "source");
|
||||
mapboxMap.addLayer(layer);
|
||||
|
||||
Expression expression = format(
|
||||
formatEntry(
|
||||
"test", fontScale(0.5), textFont(new String[] {"DIN Offc Pro Regular", "Arial Unicode MS Regular"})
|
||||
)
|
||||
);
|
||||
layer.setProperties(textField(expression));
|
||||
waitForLayer(uiController, mapboxMap, latLng);
|
||||
assertFalse(mapboxMap.queryRenderedFeatures(mapboxMap.getProjection().toScreenLocation(latLng), "layer")
|
||||
.isEmpty());
|
||||
|
||||
assertNull(layer.getTextField().getExpression());
|
||||
assertEquals("test", layer.getTextField().getValue());
|
||||
|
||||
Formatted expected = new Formatted(new FormattedSection[] {
|
||||
new FormattedSection("test", 0.5f, new String[] {"DIN Offc Pro Regular", "Arial Unicode MS Regular"})});
|
||||
assertNull(layer.getFormattedTextField().getExpression());
|
||||
assertEquals(expected, layer.getFormattedTextField().getValue());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstFormatExpressionMultipleInputs() {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
LatLng latLng = new LatLng(51, 17);
|
||||
mapboxMap.addSource(new GeoJsonSource("source", Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude())));
|
||||
SymbolLayer layer = new SymbolLayer("layer", "source");
|
||||
mapboxMap.addLayer(layer);
|
||||
|
||||
Expression expression = format(
|
||||
formatEntry(
|
||||
"test", fontScale(1.5), textFont(new String[] {"DIN Offc Pro Regular", "Arial Unicode MS Regular"})
|
||||
),
|
||||
formatEntry("\ntest2", fontScale(2))
|
||||
);
|
||||
layer.setProperties(textField(expression));
|
||||
waitForLayer(uiController, mapboxMap, latLng);
|
||||
assertFalse(mapboxMap.queryRenderedFeatures(mapboxMap.getProjection().toScreenLocation(latLng), "layer")
|
||||
.isEmpty());
|
||||
|
||||
assertNull(layer.getTextField().getExpression());
|
||||
assertEquals("test\ntest2", layer.getTextField().getValue());
|
||||
|
||||
Formatted expected = new Formatted(new FormattedSection[] {
|
||||
new FormattedSection("test", 1.5f, new String[] {"DIN Offc Pro Regular", "Arial Unicode MS Regular"}),
|
||||
new FormattedSection("\ntest2", 2f),
|
||||
});
|
||||
assertNull(layer.getFormattedTextField().getExpression());
|
||||
assertEquals(expected, layer.getFormattedTextField().getValue());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVariableFormatExpression() {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
LatLng latLng = new LatLng(51, 17);
|
||||
Feature feature = Feature.fromGeometry(Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude()));
|
||||
feature.addStringProperty("test_property", "test");
|
||||
feature.addNumberProperty("test_property_number", 1.5);
|
||||
mapboxMap.addSource(new GeoJsonSource("source", feature));
|
||||
SymbolLayer layer = new SymbolLayer("layer", "source");
|
||||
mapboxMap.addLayer(layer);
|
||||
|
||||
Expression expression = format(
|
||||
formatEntry(
|
||||
get("test_property"),
|
||||
fontScale(number(get("test_property_number"))),
|
||||
textFont(new String[] {"Arial Unicode MS Regular", "DIN Offc Pro Regular"})
|
||||
)
|
||||
);
|
||||
layer.setProperties(textField(expression));
|
||||
waitForLayer(uiController, mapboxMap, latLng);
|
||||
assertFalse(mapboxMap.queryRenderedFeatures(mapboxMap.getProjection().toScreenLocation(latLng), "layer")
|
||||
.isEmpty());
|
||||
|
||||
assertEquals(expression, layer.getTextField().getExpression());
|
||||
assertNull(layer.getTextField().getValue());
|
||||
|
||||
assertEquals(expression, layer.getFormattedTextField().getExpression());
|
||||
assertNull(layer.getFormattedTextField().getValue());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVariableFormatExpressionMultipleInputs() {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
LatLng latLng = new LatLng(51, 17);
|
||||
Feature feature = Feature.fromGeometry(Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude()));
|
||||
feature.addStringProperty("test_property", "test");
|
||||
feature.addNumberProperty("test_property_number", 1.5);
|
||||
mapboxMap.addSource(new GeoJsonSource("source", feature));
|
||||
SymbolLayer layer = new SymbolLayer("layer", "source");
|
||||
mapboxMap.addLayer(layer);
|
||||
|
||||
Expression expression = format(
|
||||
formatEntry(
|
||||
get("test_property"),
|
||||
fontScale(1.25),
|
||||
textFont(new String[] {"Arial Unicode MS Regular", "DIN Offc Pro Regular"})
|
||||
),
|
||||
formatEntry("\ntest2", fontScale(2))
|
||||
);
|
||||
layer.setProperties(textField(expression));
|
||||
waitForLayer(uiController, mapboxMap, latLng);
|
||||
assertFalse(mapboxMap.queryRenderedFeatures(mapboxMap.getProjection().toScreenLocation(latLng), "layer")
|
||||
.isEmpty());
|
||||
|
||||
assertEquals(expression, layer.getTextField().getExpression());
|
||||
assertNull(layer.getTextField().getValue());
|
||||
|
||||
assertEquals(expression, layer.getFormattedTextField().getExpression());
|
||||
assertNull(layer.getFormattedTextField().getValue());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormatExpressionPlainTextCoercion() {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
LatLng latLng = new LatLng(51, 17);
|
||||
mapboxMap.addSource(new GeoJsonSource("source", Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude())));
|
||||
SymbolLayer layer = new SymbolLayer("layer", "source");
|
||||
mapboxMap.addLayer(layer);
|
||||
|
||||
layer.setProperties(textField("test"));
|
||||
waitForLayer(uiController, mapboxMap, latLng);
|
||||
assertFalse(mapboxMap.queryRenderedFeatures(mapboxMap.getProjection().toScreenLocation(latLng), "layer")
|
||||
.isEmpty());
|
||||
|
||||
assertNull(layer.getTextField().getExpression());
|
||||
assertEquals("test", layer.getTextField().getValue());
|
||||
|
||||
assertNull(layer.getFormattedTextField().getExpression());
|
||||
Formatted expected = new Formatted(new FormattedSection[] {new FormattedSection("test", 1.0f)});
|
||||
assertEquals(expected, layer.getFormattedTextField().getValue());
|
||||
});
|
||||
}
|
||||
|
||||
private static final long WAIT_TIMEOUT = 5000;
|
||||
private static final long WAIT_DELAY = 150;
|
||||
|
||||
private static void waitForLayer(UiController uiController, MapboxMap mapboxMap, LatLng latLng) {
|
||||
int i = 0;
|
||||
while (mapboxMap.queryRenderedFeatures(mapboxMap.getProjection().toScreenLocation(latLng), "layer").isEmpty()) {
|
||||
i++;
|
||||
assertFalse("Waiting for layer timed out", i * WAIT_DELAY > WAIT_TIMEOUT);
|
||||
uiController.loopMainThreadForAtLeast(WAIT_DELAY);
|
||||
}
|
||||
}
|
||||
|
||||
private void setupStyle() {
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
// Add a source
|
||||
|
||||
@@ -190,7 +190,6 @@ public class FillExtrusionLayerTest extends BaseActivityTest {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testFillExtrusionColorAsIntConstant() {
|
||||
validateTestSetup();
|
||||
@@ -292,7 +291,6 @@ public class FillExtrusionLayerTest extends BaseActivityTest {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testFillExtrusionHeightTransition() {
|
||||
validateTestSetup();
|
||||
@@ -337,7 +335,6 @@ public class FillExtrusionLayerTest extends BaseActivityTest {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testFillExtrusionBaseTransition() {
|
||||
validateTestSetup();
|
||||
@@ -381,5 +378,4 @@ public class FillExtrusionLayerTest extends BaseActivityTest {
|
||||
assertEquals(layer.getFillExtrusionBase().getExpression(), expression);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -175,7 +175,6 @@ public class FillLayerTest extends BaseActivityTest {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testFillColorTransition() {
|
||||
validateTestSetup();
|
||||
@@ -220,7 +219,6 @@ public class FillLayerTest extends BaseActivityTest {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testFillColorAsIntConstant() {
|
||||
validateTestSetup();
|
||||
@@ -279,7 +277,6 @@ public class FillLayerTest extends BaseActivityTest {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testFillOutlineColorAsIntConstant() {
|
||||
validateTestSetup();
|
||||
@@ -380,5 +377,4 @@ public class FillLayerTest extends BaseActivityTest {
|
||||
assertEquals(layer.getFillPattern().getExpression(), expression);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -161,7 +161,6 @@ public class HeatmapLayerTest extends BaseActivityTest {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testHeatmapWeightAsConstant() {
|
||||
validateTestSetup();
|
||||
@@ -191,7 +190,6 @@ public class HeatmapLayerTest extends BaseActivityTest {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testHeatmapIntensityTransition() {
|
||||
validateTestSetup();
|
||||
|
||||
@@ -160,7 +160,6 @@ public class LineLayerTest extends BaseActivityTest {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testLineMiterLimitAsConstant() {
|
||||
validateTestSetup();
|
||||
@@ -233,7 +232,6 @@ public class LineLayerTest extends BaseActivityTest {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testLineColorTransition() {
|
||||
validateTestSetup();
|
||||
@@ -278,7 +276,6 @@ public class LineLayerTest extends BaseActivityTest {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testLineColorAsIntConstant() {
|
||||
validateTestSetup();
|
||||
@@ -380,7 +377,6 @@ public class LineLayerTest extends BaseActivityTest {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testLineGapWidthTransition() {
|
||||
validateTestSetup();
|
||||
@@ -425,7 +421,6 @@ public class LineLayerTest extends BaseActivityTest {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testLineOffsetTransition() {
|
||||
validateTestSetup();
|
||||
@@ -499,7 +494,6 @@ public class LineLayerTest extends BaseActivityTest {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testLineDasharrayTransition() {
|
||||
validateTestSetup();
|
||||
@@ -572,5 +566,4 @@ public class LineLayerTest extends BaseActivityTest {
|
||||
assertEquals(layer.getLinePattern().getExpression(), expression);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ import timber.log.Timber;
|
||||
|
||||
import com.mapbox.mapboxsdk.style.expressions.Expression;
|
||||
import com.mapbox.mapboxsdk.style.layers.SymbolLayer;
|
||||
import com.mapbox.mapboxsdk.style.types.Formatted;
|
||||
import com.mapbox.mapboxsdk.style.types.FormattedSection;
|
||||
import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -258,7 +260,6 @@ public class SymbolLayerTest extends BaseActivityTest {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testIconTextFitAsConstant() {
|
||||
validateTestSetup();
|
||||
@@ -319,7 +320,6 @@ public class SymbolLayerTest extends BaseActivityTest {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testIconRotateAsConstant() {
|
||||
validateTestSetup();
|
||||
@@ -349,7 +349,6 @@ public class SymbolLayerTest extends BaseActivityTest {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testIconPaddingAsConstant() {
|
||||
validateTestSetup();
|
||||
@@ -421,7 +420,6 @@ public class SymbolLayerTest extends BaseActivityTest {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testIconPitchAlignmentAsConstant() {
|
||||
validateTestSetup();
|
||||
@@ -477,8 +475,28 @@ public class SymbolLayerTest extends BaseActivityTest {
|
||||
assertEquals((String) layer.getTextField().getValue(), (String) "");
|
||||
|
||||
layer.setProperties(textField("{token}"));
|
||||
assertEquals(layer.getTextField().getExpression(),
|
||||
Expression.format(Expression.toString(Expression.get("token"))));
|
||||
assertEquals(layer.getTextField().getExpression(), Expression.format(Expression.formatEntry(Expression.toString(Expression.get("token")))));
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormattedTextFieldAsConstant() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("text-field-formatted");
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
Formatted expected = new Formatted(new FormattedSection[] {
|
||||
new FormattedSection("", 1.0)
|
||||
});
|
||||
|
||||
// Set and Get
|
||||
layer.setProperties(textField(""));
|
||||
assertEquals(layer.getFormattedTextField().getValue(), expected/*(String) ""*/);
|
||||
|
||||
layer.setProperties(textField("{token}"));
|
||||
assertEquals(layer.getFormattedTextField().getExpression(), Expression.format(Expression.formatEntry(Expression.toString(Expression.get("token")))));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -491,12 +509,26 @@ public class SymbolLayerTest extends BaseActivityTest {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
Expression expression = Expression.format(string(Expression.get("undefined")));
|
||||
Expression expression = string(Expression.get("undefined"));
|
||||
layer.setProperties(textField(expression));
|
||||
assertEquals(layer.getTextField().getExpression(), expression);
|
||||
assertEquals(layer.getTextField().getExpression(), Expression.format(Expression.formatEntry(expression)));
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormattedTextFieldAsExpression() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("text-field-formatted-expression");
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
Expression expression = string(Expression.get("undefined"));
|
||||
layer.setProperties(textField(expression));
|
||||
assertEquals(layer.getFormattedTextField().getExpression(), Expression.format(Expression.formatEntry(Expression.string(Expression.get("undefined")))));
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTextFontAsConstant() {
|
||||
@@ -541,7 +573,6 @@ public class SymbolLayerTest extends BaseActivityTest {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testTextMaxWidthAsConstant() {
|
||||
validateTestSetup();
|
||||
@@ -571,7 +602,6 @@ public class SymbolLayerTest extends BaseActivityTest {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testTextLineHeightAsConstant() {
|
||||
validateTestSetup();
|
||||
@@ -615,7 +645,6 @@ public class SymbolLayerTest extends BaseActivityTest {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testTextJustifyAsConstant() {
|
||||
validateTestSetup();
|
||||
@@ -645,7 +674,6 @@ public class SymbolLayerTest extends BaseActivityTest {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testTextAnchorAsConstant() {
|
||||
validateTestSetup();
|
||||
@@ -675,7 +703,6 @@ public class SymbolLayerTest extends BaseActivityTest {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testTextMaxAngleAsConstant() {
|
||||
validateTestSetup();
|
||||
@@ -719,7 +746,6 @@ public class SymbolLayerTest extends BaseActivityTest {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testTextPaddingAsConstant() {
|
||||
validateTestSetup();
|
||||
@@ -777,7 +803,6 @@ public class SymbolLayerTest extends BaseActivityTest {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testTextOffsetAsConstant() {
|
||||
validateTestSetup();
|
||||
@@ -878,7 +903,6 @@ public class SymbolLayerTest extends BaseActivityTest {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testIconColorTransition() {
|
||||
validateTestSetup();
|
||||
@@ -923,7 +947,6 @@ public class SymbolLayerTest extends BaseActivityTest {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testIconColorAsIntConstant() {
|
||||
validateTestSetup();
|
||||
@@ -982,7 +1005,6 @@ public class SymbolLayerTest extends BaseActivityTest {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testIconHaloColorAsIntConstant() {
|
||||
validateTestSetup();
|
||||
@@ -1041,7 +1063,6 @@ public class SymbolLayerTest extends BaseActivityTest {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testIconHaloBlurTransition() {
|
||||
validateTestSetup();
|
||||
@@ -1086,7 +1107,6 @@ public class SymbolLayerTest extends BaseActivityTest {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testIconTranslateTransition() {
|
||||
validateTestSetup();
|
||||
@@ -1174,7 +1194,6 @@ public class SymbolLayerTest extends BaseActivityTest {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testTextColorTransition() {
|
||||
validateTestSetup();
|
||||
@@ -1219,7 +1238,6 @@ public class SymbolLayerTest extends BaseActivityTest {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testTextColorAsIntConstant() {
|
||||
validateTestSetup();
|
||||
@@ -1278,7 +1296,6 @@ public class SymbolLayerTest extends BaseActivityTest {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testTextHaloColorAsIntConstant() {
|
||||
validateTestSetup();
|
||||
@@ -1337,7 +1354,6 @@ public class SymbolLayerTest extends BaseActivityTest {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testTextHaloBlurTransition() {
|
||||
validateTestSetup();
|
||||
@@ -1382,7 +1398,6 @@ public class SymbolLayerTest extends BaseActivityTest {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testTextTranslateTransition() {
|
||||
validateTestSetup();
|
||||
|
||||
@@ -13,6 +13,10 @@ import timber.log.Timber;
|
||||
|
||||
import com.mapbox.mapboxsdk.style.expressions.Expression;
|
||||
import com.mapbox.mapboxsdk.style.layers.<%- camelize(type) %>Layer;
|
||||
<% if (type === 'symbol') { -%>
|
||||
import com.mapbox.mapboxsdk.style.types.Formatted;
|
||||
import com.mapbox.mapboxsdk.style.types.FormattedSection;
|
||||
<% } -%>
|
||||
import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -166,14 +170,38 @@ public class <%- camelize(type) %>LayerTest extends BaseActivityTest {
|
||||
|
||||
layer.setProperties(<%- camelizeWithLeadingLowercase(property.name) %>("{token}"));
|
||||
<% if (property.type === 'formatted') { -%>
|
||||
assertEquals(layer.get<%- camelize(property.name) %>().getExpression(),
|
||||
Expression.format(Expression.toString(Expression.get("token"))));
|
||||
<% } else { -%>
|
||||
assertEquals(layer.getTextField().getExpression(), Expression.format(Expression.formatEntry(Expression.toString(Expression.get("token")))));
|
||||
<% } else {-%>
|
||||
assertEquals(layer.get<%- camelize(property.name) %>().getExpression(), Expression.toString(Expression.get("token")));
|
||||
<% } -%>
|
||||
<% } -%>
|
||||
});
|
||||
}
|
||||
<% if (property.name === 'text-field' && property.type === 'formatted') { -%>
|
||||
|
||||
@Test
|
||||
public void testFormatted<%- camelize(property.name) %>AsConstant() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("<%- property.name %>-formatted");
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
Formatted expected = new Formatted(new FormattedSection[] {
|
||||
new FormattedSection("", 1.0)
|
||||
});
|
||||
|
||||
// Set and Get
|
||||
layer.setProperties(<%- camelizeWithLeadingLowercase(property.name) %>(<%- defaultValueJava(property) %>));
|
||||
assertEquals(layer.getFormatted<%- camelize(property.name) %>().getValue(), expected/*(<%- propertyType(property) %>) <%- defaultValueJava(property) %>*/);
|
||||
<% if (property.tokens) { -%>
|
||||
|
||||
layer.setProperties(<%- camelizeWithLeadingLowercase(property.name) %>("{token}"));
|
||||
assertEquals(layer.getFormattedTextField().getExpression(), Expression.format(Expression.formatEntry(Expression.toString(Expression.get("token")))));
|
||||
<% } -%>
|
||||
});
|
||||
}
|
||||
<% } -%>
|
||||
<% if (property['property-type'] === 'data-driven' || property['property-type'] === 'cross-faded-data-driven') { -%>
|
||||
<% if (!(property.name.endsWith("-font")||property.name.endsWith("-offset"))) { -%>
|
||||
|
||||
@@ -186,16 +214,32 @@ public class <%- camelize(type) %>LayerTest extends BaseActivityTest {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
<% if (property.type === 'formatted') { -%>
|
||||
Expression expression = Expression.format(<%- defaultExpressionJava(property) %>(Expression.get("undefined")));
|
||||
<% } else { -%>
|
||||
Expression expression = <%- defaultExpressionJava(property) %>(Expression.get("undefined"));
|
||||
<% } -%>
|
||||
layer.setProperties(<%- camelizeWithLeadingLowercase(property.name) %>(expression));
|
||||
<% if (property.type === 'formatted') { -%>
|
||||
assertEquals(layer.getTextField().getExpression(), Expression.format(Expression.formatEntry(expression)));
|
||||
<% } else { -%>
|
||||
assertEquals(layer.get<%- camelize(property.name) %>().getExpression(), expression);
|
||||
<% } -%>
|
||||
});
|
||||
}
|
||||
<% if (property.name === 'text-field' && property.type === 'formatted') { -%>
|
||||
|
||||
@Test
|
||||
public void testFormatted<%- camelize(property.name) %>AsExpression() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("<%- property.name %>-formatted-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.getFormattedTextField().getExpression(), Expression.format(Expression.formatEntry(Expression.string(Expression.get("undefined")))));
|
||||
});
|
||||
}
|
||||
<% } -%>
|
||||
<% } -%>
|
||||
<% } -%>
|
||||
<% if (property.type == 'color') { -%>
|
||||
|
||||
Reference in New Issue
Block a user