diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2017-03-07 17:00:53 -0800 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2017-03-23 13:31:13 -0700 |
commit | d7227e13a7a87cf50a4c8c1f0615fc565f5a2679 (patch) | |
tree | eda76a2da3220f3cfeec901400369cf9c8361f58 /test | |
parent | 1c757cce34344dfecc9a724034680225143f92b7 (diff) | |
download | qtlocation-mapboxgl-d7227e13a7a87cf50a4c8c1f0615fc565f5a2679.tar.gz |
[all] Replace Result<T> with optional<T> plus out Error parameter
Diffstat (limited to 'test')
-rw-r--r-- | test/style/conversion/function.test.cpp | 30 | ||||
-rw-r--r-- | test/style/conversion/geojson_options.test.cpp | 12 | ||||
-rw-r--r-- | test/style/conversion/layer.test.cpp | 13 | ||||
-rw-r--r-- | test/style/filter.test.cpp | 5 |
4 files changed, 35 insertions, 25 deletions
diff --git a/test/style/conversion/function.test.cpp b/test/style/conversion/function.test.cpp index 4dc6549c78..08637d40cb 100644 --- a/test/style/conversion/function.test.cpp +++ b/test/style/conversion/function.test.cpp @@ -10,45 +10,47 @@ using namespace mbgl; using namespace mbgl::style; using namespace mbgl::style::conversion; -auto parseFunction(const std::string& src) { - JSDocument doc; - doc.Parse<0>(src); - return convert<CameraFunction<float>, JSValue>(doc); -} - TEST(StyleConversion, Function) { + Error error; + + auto parseFunction = [&](const std::string& src) { + JSDocument doc; + doc.Parse<0>(src); + return convert<CameraFunction<float>, JSValue>(doc, error); + }; + auto fn1 = parseFunction("{\"stops\":[]}"); ASSERT_FALSE(fn1); - ASSERT_EQ("function must have at least one stop", fn1.error().message); + ASSERT_EQ("function must have at least one stop", error.message); auto fn2 = parseFunction("{\"stops\":[1]}"); ASSERT_FALSE(fn2); - ASSERT_EQ("function stop must be an array", fn2.error().message); + ASSERT_EQ("function stop must be an array", error.message); auto fn3 = parseFunction("{\"stops\":[[]]}"); ASSERT_FALSE(fn3); - ASSERT_EQ("function stop must have two elements", fn3.error().message); + ASSERT_EQ("function stop must have two elements", error.message); auto fn4 = parseFunction("{\"stops\":[[-1,-1]]}"); ASSERT_TRUE(bool(fn4)); auto fn5 = parseFunction("{\"stops\":[[0,1,2]]}"); ASSERT_FALSE(fn5); - ASSERT_EQ("function stop must have two elements", fn5.error().message); + ASSERT_EQ("function stop must have two elements", error.message); auto fn6 = parseFunction("{\"stops\":[[0,\"x\"]]}"); ASSERT_FALSE(fn6); - ASSERT_EQ("value must be a number", fn6.error().message); + ASSERT_EQ("value must be a number", error.message); auto fn7 = parseFunction("{}"); ASSERT_FALSE(fn7); - ASSERT_EQ("function value must specify stops", fn7.error().message); + ASSERT_EQ("function value must specify stops", error.message); auto fn8 = parseFunction("[]"); ASSERT_FALSE(fn8); - ASSERT_EQ("function must be an object", fn8.error().message); + ASSERT_EQ("function must be an object", error.message); auto fn9 = parseFunction("{\"stops\":[[0,0]],\"base\":false}"); ASSERT_FALSE(fn9); - ASSERT_EQ("function base must be a number", fn9.error().message); + ASSERT_EQ("function base must be a number", error.message); } diff --git a/test/style/conversion/geojson_options.test.cpp b/test/style/conversion/geojson_options.test.cpp index ddf261ea52..e6bd984f36 100644 --- a/test/style/conversion/geojson_options.test.cpp +++ b/test/style/conversion/geojson_options.test.cpp @@ -12,21 +12,24 @@ using namespace mbgl::style::conversion; TEST(GeoJSONOptions, Basic) { ValueMap map; Value raw(map); - Result<GeoJSONOptions> converted = convert<GeoJSONOptions>(raw); + Error error; + mbgl::optional<GeoJSONOptions> converted = convert<GeoJSONOptions>(raw, error); ASSERT_TRUE((bool) converted); } TEST(GeoJSONOptions, ErrorHandling) { ValueMap map {{"maxzoom", std::string{"should not be a string"}}}; Value raw(map); - Result<GeoJSONOptions> converted = convert<GeoJSONOptions>(raw); + Error error; + mbgl::optional<GeoJSONOptions> converted = convert<GeoJSONOptions>(raw, error); ASSERT_FALSE((bool) converted); } TEST(GeoJSONOptions, RetainsDefaults) { ValueMap map; Value raw(map); - GeoJSONOptions converted = *convert<GeoJSONOptions>(raw); + Error error; + GeoJSONOptions converted = *convert<GeoJSONOptions>(raw, error); GeoJSONOptions defaults; // GeoJSON-VT @@ -54,7 +57,8 @@ TEST(GeoJSONOptions, FullConversion) { {"clusterMaxZoom", 5.0f} }; Value raw(map); - GeoJSONOptions converted = *convert<GeoJSONOptions>(raw); + Error error; + GeoJSONOptions converted = *convert<GeoJSONOptions>(raw, error); // GeoJSON-VT ASSERT_EQ(converted.maxzoom, 1); diff --git a/test/style/conversion/layer.test.cpp b/test/style/conversion/layer.test.cpp index b27c1841ee..cfe2662fb8 100644 --- a/test/style/conversion/layer.test.cpp +++ b/test/style/conversion/layer.test.cpp @@ -11,10 +11,11 @@ using namespace mbgl::style; using namespace mbgl::style::conversion; using namespace std::literals::chrono_literals; -auto parseLayer(const std::string& src) { +std::unique_ptr<Layer> parseLayer(const std::string& src) { JSDocument doc; doc.Parse<0>(src); - return convert<std::unique_ptr<Layer>, JSValue>(doc); + Error error; + return std::move(*convert<std::unique_ptr<Layer>, JSValue>(doc, error)); } TEST(StyleConversion, LayerTransition) { @@ -34,13 +35,13 @@ TEST(StyleConversion, LayerTransition) { } })JSON"); - ASSERT_EQ(400ms, *(*layer)->as<BackgroundLayer>()->impl->paint.cascading + ASSERT_EQ(400ms, *layer->as<BackgroundLayer>()->impl->paint.cascading .get<BackgroundColor>().getTransition({}).duration); - ASSERT_EQ(500ms, *(*layer)->as<BackgroundLayer>()->impl->paint.cascading + ASSERT_EQ(500ms, *layer->as<BackgroundLayer>()->impl->paint.cascading .get<BackgroundColor>().getTransition({}).delay); - ASSERT_EQ(100ms, *(*layer)->as<BackgroundLayer>()->impl->paint.cascading + ASSERT_EQ(100ms, *layer->as<BackgroundLayer>()->impl->paint.cascading .get<BackgroundColor>().getTransition({"class"}).duration); - ASSERT_FALSE(bool((*layer)->as<BackgroundLayer>()->impl->paint.cascading + ASSERT_FALSE(bool(layer->as<BackgroundLayer>()->impl->paint.cascading .get<BackgroundColor>().getTransition({"class"}).delay)); } diff --git a/test/style/filter.test.cpp b/test/style/filter.test.cpp index 2f12246078..c70792d8ef 100644 --- a/test/style/filter.test.cpp +++ b/test/style/filter.test.cpp @@ -16,7 +16,10 @@ using namespace mbgl::style; Filter parse(const char * expression) { rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator> doc; doc.Parse<0>(expression); - return *conversion::convert<Filter, JSValue>(doc); + conversion::Error error; + optional<Filter> filter = conversion::convert<Filter, JSValue>(doc, error); + EXPECT_TRUE(bool(filter)); + return *filter; } Feature feature(const PropertyMap& properties, const Geometry<double>& geometry = Point<double>()) { |