summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorLauren Budorick <lauren@mapbox.com>2017-04-27 15:56:55 -0700
committerGitHub <noreply@github.com>2017-04-27 15:56:55 -0700
commitf6e79d70735361438655f279c8699a786d25458c (patch)
treecc01ae7aba097bae4aa84beb12ac6b8f34f4d51a /test
parent839ad87f37a4880804fb4c79157d998ac59954b5 (diff)
downloadqtlocation-mapboxgl-f6e79d70735361438655f279c8699a786d25458c.tar.gz
[core] Render fill-extrusion layers (#8431)
Diffstat (limited to 'test')
-rw-r--r--test/fixtures/style_parser/line-translate.info.json2
-rw-r--r--test/style/conversion/light.test.cpp101
-rw-r--r--test/style/paint_property.test.cpp39
-rw-r--r--test/util/position.test.cpp49
-rw-r--r--test/util/tile_cover.test.cpp5
5 files changed, 174 insertions, 22 deletions
diff --git a/test/fixtures/style_parser/line-translate.info.json b/test/fixtures/style_parser/line-translate.info.json
index 16df094290..26df77609b 100644
--- a/test/fixtures/style_parser/line-translate.info.json
+++ b/test/fixtures/style_parser/line-translate.info.json
@@ -1,7 +1,7 @@
{
"default": {
"log": [
- [1, "WARNING", "ParseStyle", "value must be an array of two numbers"]
+ [1, "WARNING", "ParseStyle", "value must be an array of 2 numbers"]
]
}
}
diff --git a/test/style/conversion/light.test.cpp b/test/style/conversion/light.test.cpp
new file mode 100644
index 0000000000..da0fd3054a
--- /dev/null
+++ b/test/style/conversion/light.test.cpp
@@ -0,0 +1,101 @@
+#include <mbgl/test/util.hpp>
+
+#include <mbgl/style/conversion.hpp>
+#include <mbgl/style/rapidjson_conversion.hpp>
+#include <mbgl/style/conversion/constant.hpp>
+#include <mbgl/style/conversion/light.hpp>
+#include <mbgl/style/position.hpp>
+#include <mbgl/util/rapidjson.hpp>
+#include <mbgl/util/color.hpp>
+#include <mbgl/util/chrono.hpp>
+
+#include <array>
+
+using namespace mbgl;
+using namespace mbgl::style;
+using namespace mbgl::style::conversion;
+
+TEST(StyleConversion, Light) {
+ Error error;
+
+ auto parseLight = [&](const std::string& src) {
+ JSDocument doc;
+ doc.Parse<0>(src);
+ return convert<Light>(doc, error);
+ };
+
+ {
+ auto light = parseLight("{}");
+ ASSERT_TRUE((bool) light);
+ }
+
+ {
+ auto light = parseLight("{\"color\":{\"stops\":[[14,\"blue\"],[16,\"red\"]]},\"intensity\":0.3,\"position\":[3,90,90]}");
+ ASSERT_TRUE((bool) light);
+
+ ASSERT_TRUE(light->get<LightAnchor>().value.isUndefined());
+ ASSERT_FALSE(light->get<LightAnchor>().value.isConstant());
+ ASSERT_FALSE(light->get<LightAnchor>().value.isCameraFunction());
+
+ ASSERT_FALSE(light->get<LightIntensity>().value.isUndefined());
+ ASSERT_TRUE(light->get<LightIntensity>().value.isConstant());
+ ASSERT_EQ(light->get<LightIntensity>().value.asConstant(), 0.3f);
+ ASSERT_FALSE(light->get<LightAnchor>().value.isCameraFunction());
+
+ ASSERT_FALSE(light->get<LightColor>().value.isUndefined());
+ ASSERT_FALSE(light->get<LightColor>().value.isConstant());
+ ASSERT_TRUE(light->get<LightColor>().value.isCameraFunction());
+
+ ASSERT_FALSE(light->get<LightPosition>().value.isUndefined());
+ ASSERT_TRUE(light->get<LightPosition>().value.isConstant());
+ std::array<float, 3> expected{{ 3, 90, 90 }};
+ ASSERT_EQ(light->get<LightPosition>().value.asConstant(), mbgl::style::Position({ expected }));
+ ASSERT_FALSE(light->get<LightPosition>().value.isCameraFunction());
+ }
+
+ {
+ auto light = parseLight("{\"color\":\"blue\",\"intensity\":0.3,\"color-transition\":{\"duration\":1000}}");
+ ASSERT_TRUE((bool) light);
+
+ ASSERT_FALSE(light->get<LightColor>().value.isUndefined());
+ ASSERT_TRUE(light->get<LightColor>().value.isConstant());
+ ASSERT_FALSE(light->get<LightColor>().value.isCameraFunction());
+ ASSERT_EQ(light->get<LightColor>().transition.duration, mbgl::Duration(mbgl::Milliseconds(1000)));
+ ASSERT_FALSE((bool) light->get<LightColor>().transition.delay);
+ }
+
+ {
+ auto light = parseLight("{\"intensity\":false}");
+
+ ASSERT_FALSE((bool) light);
+ ASSERT_EQ("value must be a number", error.message);
+ }
+
+ {
+ auto light = parseLight("{\"intensity\":{\"stops\":[[15,\"red\"],[17,\"blue\"]]}}");
+
+ ASSERT_FALSE((bool) light);
+ ASSERT_EQ("value must be a number", error.message);
+ }
+
+ {
+ auto light = parseLight("{\"color\":5}");
+
+ ASSERT_FALSE((bool) light);
+ ASSERT_EQ("value must be a string", error.message);
+ }
+
+ {
+ auto light = parseLight("{\"position\":[0,5]}");
+
+ ASSERT_FALSE((bool) light);
+ ASSERT_EQ("value must be an array of 3 numbers", error.message);
+ }
+
+ {
+ auto light = parseLight("{\"anchor\":\"something\"}");
+
+ ASSERT_FALSE((bool) light);
+ ASSERT_EQ("value must be a valid enumeration value", error.message);
+ }
+}
diff --git a/test/style/paint_property.test.cpp b/test/style/paint_property.test.cpp
index 39d31068c1..15a0796f21 100644
--- a/test/style/paint_property.test.cpp
+++ b/test/style/paint_property.test.cpp
@@ -1,12 +1,13 @@
#include <mbgl/test/util.hpp>
#include <mbgl/style/paint_property.hpp>
+#include <mbgl/style/transitioning_property.hpp>
using namespace mbgl;
using namespace mbgl::style;
using namespace std::literals::chrono_literals;
-float evaluate(UnevaluatedPaintProperty<PropertyValue<float>>& property, Duration delta = Duration::zero()) {
+float evaluate(TransitioningProperty<PropertyValue<float>>& property, Duration delta = Duration::zero()) {
PropertyEvaluationParameters parameters {
0,
TimePoint::min() + delta,
@@ -22,7 +23,7 @@ float evaluate(UnevaluatedPaintProperty<PropertyValue<float>>& property, Duratio
return property.evaluate(evaluator, parameters.now);
}
-PossiblyEvaluatedPropertyValue<float> evaluate(UnevaluatedPaintProperty<DataDrivenPropertyValue<float>>& property, Duration delta = Duration::zero()) {
+PossiblyEvaluatedPropertyValue<float> evaluate(TransitioningProperty<DataDrivenPropertyValue<float>>& property, Duration delta = Duration::zero()) {
PropertyEvaluationParameters parameters {
0,
TimePoint::min() + delta,
@@ -38,15 +39,15 @@ PossiblyEvaluatedPropertyValue<float> evaluate(UnevaluatedPaintProperty<DataDriv
return property.evaluate(evaluator, parameters.now);
}
-TEST(UnevaluatedPaintProperty, EvaluateDefaultValue) {
- UnevaluatedPaintProperty<PropertyValue<float>> property;
+TEST(TransitioningProperty, EvaluateDefaultValue) {
+ TransitioningProperty<PropertyValue<float>> property;
ASSERT_EQ(0.0f, evaluate(property));
}
-TEST(UnevaluatedPaintProperty, EvaluateUntransitionedConstant) {
- UnevaluatedPaintProperty<PropertyValue<float>> property {
+TEST(TransitioningProperty, EvaluateUntransitionedConstant) {
+ TransitioningProperty<PropertyValue<float>> property {
PropertyValue<float>(1.0f),
- UnevaluatedPaintProperty<PropertyValue<float>>(),
+ TransitioningProperty<PropertyValue<float>>(),
TransitionOptions(),
TimePoint::min()
};
@@ -54,18 +55,18 @@ TEST(UnevaluatedPaintProperty, EvaluateUntransitionedConstant) {
ASSERT_EQ(1.0f, evaluate(property));
}
-TEST(UnevaluatedPaintProperty, EvaluateTransitionedConstantWithoutDelay) {
+TEST(TransitioningProperty, EvaluateTransitionedConstantWithoutDelay) {
TransitionOptions transition;
transition.duration = { 1000ms };
- UnevaluatedPaintProperty<PropertyValue<float>> t0 {
+ TransitioningProperty<PropertyValue<float>> t0 {
PropertyValue<float>(0.0f),
- UnevaluatedPaintProperty<PropertyValue<float>>(),
+ TransitioningProperty<PropertyValue<float>>(),
TransitionOptions(),
TimePoint::min()
};
- UnevaluatedPaintProperty<PropertyValue<float>> t1 {
+ TransitioningProperty<PropertyValue<float>> t1 {
PropertyValue<float>(1.0f),
t0,
transition,
@@ -77,19 +78,19 @@ TEST(UnevaluatedPaintProperty, EvaluateTransitionedConstantWithoutDelay) {
ASSERT_FLOAT_EQ(1.0f, evaluate(t1, 1500ms));
}
-TEST(UnevaluatedPaintProperty, EvaluateTransitionedConstantWithDelay) {
+TEST(TransitioningProperty, EvaluateTransitionedConstantWithDelay) {
TransitionOptions transition;
transition.delay = { 1000ms };
transition.duration = { 1000ms };
- UnevaluatedPaintProperty<PropertyValue<float>> t0 {
+ TransitioningProperty<PropertyValue<float>> t0 {
PropertyValue<float>(0.0f),
- UnevaluatedPaintProperty<PropertyValue<float>>(),
+ TransitioningProperty<PropertyValue<float>>(),
TransitionOptions(),
TimePoint::min()
};
- UnevaluatedPaintProperty<PropertyValue<float>> t1 {
+ TransitioningProperty<PropertyValue<float>> t1 {
PropertyValue<float>(1.0f),
t0,
transition,
@@ -103,14 +104,14 @@ TEST(UnevaluatedPaintProperty, EvaluateTransitionedConstantWithDelay) {
ASSERT_FLOAT_EQ(1.0f, evaluate(t1, 2500ms));
}
-TEST(UnevaluatedPaintProperty, EvaluateDataDrivenValue) {
+TEST(TransitioningProperty, EvaluateDataDrivenValue) {
TransitionOptions transition;
transition.delay = { 1000ms };
transition.duration = { 1000ms };
- UnevaluatedPaintProperty<DataDrivenPropertyValue<float>> t0 {
+ TransitioningProperty<DataDrivenPropertyValue<float>> t0 {
DataDrivenPropertyValue<float>(0.0f),
- UnevaluatedPaintProperty<DataDrivenPropertyValue<float>>(),
+ TransitioningProperty<DataDrivenPropertyValue<float>>(),
TransitionOptions(),
TimePoint::min()
};
@@ -120,7 +121,7 @@ TEST(UnevaluatedPaintProperty, EvaluateDataDrivenValue) {
IdentityStops<float>()
};
- UnevaluatedPaintProperty<DataDrivenPropertyValue<float>> t1 {
+ TransitioningProperty<DataDrivenPropertyValue<float>> t1 {
DataDrivenPropertyValue<float>(sourceFunction),
t0,
transition,
diff --git a/test/util/position.test.cpp b/test/util/position.test.cpp
new file mode 100644
index 0000000000..938a08dded
--- /dev/null
+++ b/test/util/position.test.cpp
@@ -0,0 +1,49 @@
+#include <mbgl/test/util.hpp>
+
+#include <mbgl/style/types.hpp>
+#include <mbgl/style/position.hpp>
+#include <mbgl/util/constants.hpp>
+
+using namespace mbgl;
+using namespace style;
+
+void expectArrayEQ(std::array<float, 3> got, std::array<float, 3> expected) {
+ for (int i = 0; i < 3; i++) {
+ EXPECT_NEAR(got[i], expected[i], 0.00001);
+ }
+};
+
+void expectArrayNE(std::array<float, 3> got, std::array<float, 3> expected) {
+ short eq = 0;
+ for (int i = 0; i < 3; i++) {
+ if (got[i] == expected[i]) {
+ eq++;
+ }
+ }
+ EXPECT_NE(eq, 3);
+};
+
+Position createPosition(std::array<float, 3> pos) {
+ return Position(pos);
+}
+
+TEST(Position, Calculations) {
+ std::array<float, 3> spherical{{ 2, 10, 270 }};
+
+ Position position(spherical);
+
+ expectArrayNE(position.getCartesian(), spherical);
+ expectArrayEQ(position.getSpherical(), spherical);
+
+ expectArrayEQ(position.getCartesian(), {{ 0.34729638695716858, -1.9696154594421387, 2.384976127700611e-08 }});
+
+ expectArrayNE(createPosition({{ 2, 30, 10 }}).getSpherical(), createPosition({{ 2, 30, 370 }}).getSpherical());
+ expectArrayEQ(createPosition({{ 2, 30, 10 }}).getCartesian(), createPosition({{ 2, 30, 370 }}).getCartesian());
+
+ std::array<float, 3> newSpherical = {{ 1, 80, 270 }};
+ position.set(newSpherical);
+
+ expectArrayNE(position.getSpherical(), spherical);
+ expectArrayNE(position.getCartesian(), {{ 0.34729638695716858, -1.9696154594421387, 2.384976127700611e-08 }});
+ expectArrayEQ(position.getCartesian(), {{ 0.98480772972106934, -0.17364829778671265, 1.1924880638503055e-08 }});
+}
diff --git a/test/util/tile_cover.test.cpp b/test/util/tile_cover.test.cpp
index 809b7df9f2..c746e6dab5 100644
--- a/test/util/tile_cover.test.cpp
+++ b/test/util/tile_cover.test.cpp
@@ -31,12 +31,13 @@ TEST(TileCover, Pitch) {
Transform transform;
transform.resize({ 512, 512 });
// slightly offset center so that tile order is better defined
- transform.setLatLng({ 0.01, -0.01 });
+ transform.setLatLng({ 0.1, -0.1 });
transform.setZoom(2);
+ transform.setAngle(5.0);
transform.setPitch(40.0 * M_PI / 180.0);
EXPECT_EQ((std::vector<UnwrappedTileID>{
- { 2, 1, 1 }, { 2, 1, 2 }, { 2, 2, 1 }, { 2, 2, 2 },
+ { 2, 1, 2 }, { 2, 1, 1 }, { 2, 2, 2 }, { 2, 2, 1 }, { 2, 3, 2 }
}),
util::tileCover(transform.getState(), 2));
}