diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2017-10-16 15:40:07 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2017-10-16 17:14:19 -0700 |
commit | 12f78fc8747332a3d54763c9b0cc2e794eefb4f8 (patch) | |
tree | fb10590f6605226a16dc528965ba541ff9371ec4 /test/style/conversion | |
parent | b8654b3b04599988f1f7a519853e98d4ca54cfd0 (diff) | |
download | qtlocation-mapboxgl-12f78fc8747332a3d54763c9b0cc2e794eefb4f8.tar.gz |
[core] Use convertJSON instead of RapidJSON directly
Diffstat (limited to 'test/style/conversion')
-rw-r--r-- | test/style/conversion/function.test.cpp | 10 | ||||
-rw-r--r-- | test/style/conversion/geojson_options.test.cpp | 39 | ||||
-rw-r--r-- | test/style/conversion/layer.test.cpp | 8 | ||||
-rw-r--r-- | test/style/conversion/light.test.cpp | 7 |
4 files changed, 21 insertions, 43 deletions
diff --git a/test/style/conversion/function.test.cpp b/test/style/conversion/function.test.cpp index 1eff94d939..9e8a6b3a7f 100644 --- a/test/style/conversion/function.test.cpp +++ b/test/style/conversion/function.test.cpp @@ -1,10 +1,8 @@ #include <mbgl/test/util.hpp> -#include <mbgl/style/conversion.hpp> -#include <mbgl/style/rapidjson_conversion.hpp> +#include <mbgl/style/conversion/json.hpp> #include <mbgl/style/conversion/constant.hpp> #include <mbgl/style/conversion/function.hpp> -#include <mbgl/util/rapidjson.hpp> using namespace mbgl; using namespace mbgl::style; @@ -13,10 +11,8 @@ using namespace mbgl::style::conversion; 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 parseFunction = [&](const std::string& json) { + return convertJSON<CameraFunction<float>>(json, error); }; auto fn1 = parseFunction(R"({"stops":[]})"); diff --git a/test/style/conversion/geojson_options.test.cpp b/test/style/conversion/geojson_options.test.cpp index a798ad6559..4c5a0c9aa4 100644 --- a/test/style/conversion/geojson_options.test.cpp +++ b/test/style/conversion/geojson_options.test.cpp @@ -1,8 +1,7 @@ #include <mbgl/test/util.hpp> -#include <mbgl/style/conversion.hpp> +#include <mbgl/style/conversion/json.hpp> #include <mbgl/style/conversion/geojson_options.hpp> -#include <mbgl/test/conversion_stubs.hpp> #include <mbgl/util/logging.hpp> @@ -10,26 +9,22 @@ using namespace mbgl::style; using namespace mbgl::style::conversion; TEST(GeoJSONOptions, Basic) { - ValueMap map; - Value raw(map); Error error; - mbgl::optional<GeoJSONOptions> converted = convert<GeoJSONOptions>(raw, error); + mbgl::optional<GeoJSONOptions> converted = convertJSON<GeoJSONOptions>("{}", error); ASSERT_TRUE((bool) converted); } TEST(GeoJSONOptions, ErrorHandling) { - ValueMap map {{"maxzoom", std::string{"should not be a string"}}}; - Value raw(map); Error error; - mbgl::optional<GeoJSONOptions> converted = convert<GeoJSONOptions>(raw, error); + mbgl::optional<GeoJSONOptions> converted = convertJSON<GeoJSONOptions>(R"JSON({ + "maxzoom": "should not be a string" + })JSON", error); ASSERT_FALSE((bool) converted); } TEST(GeoJSONOptions, RetainsDefaults) { - ValueMap map; - Value raw(map); Error error; - GeoJSONOptions converted = *convert<GeoJSONOptions>(raw, error); + GeoJSONOptions converted = *convertJSON<GeoJSONOptions>("{}", error); GeoJSONOptions defaults; // GeoJSON-VT @@ -44,22 +39,16 @@ TEST(GeoJSONOptions, RetainsDefaults) { ASSERT_EQ(converted.clusterMaxZoom, defaults.clusterMaxZoom); } - TEST(GeoJSONOptions, FullConversion) { - ValueMap map { - // GeoJSON-VT - {"maxzoom", 1.0f}, - {"buffer", 2.0f}, - {"tolerance", 3.0f}, - - // Supercluster - {"cluster", true}, - {"clusterRadius", 4.0f}, - {"clusterMaxZoom", 5.0f} - }; - Value raw(map); Error error; - GeoJSONOptions converted = *convert<GeoJSONOptions>(raw, error); + GeoJSONOptions converted = *convertJSON<GeoJSONOptions>(R"JSON({ + "maxzoom": 1, + "buffer": 2, + "tolerance": 3, + "cluster": true, + "clusterRadius": 4, + "clusterMaxZoom": 5 + })JSON", error); // GeoJSON-VT ASSERT_EQ(converted.minzoom, 0); diff --git a/test/style/conversion/layer.test.cpp b/test/style/conversion/layer.test.cpp index d51d7d33e2..33cd329999 100644 --- a/test/style/conversion/layer.test.cpp +++ b/test/style/conversion/layer.test.cpp @@ -1,10 +1,8 @@ #include <mbgl/test/util.hpp> -#include <mbgl/style/conversion.hpp> -#include <mbgl/style/rapidjson_conversion.hpp> +#include <mbgl/style/conversion/json.hpp> #include <mbgl/style/conversion/layer.hpp> #include <mbgl/style/layers/background_layer_impl.hpp> -#include <mbgl/util/rapidjson.hpp> using namespace mbgl; using namespace mbgl::style; @@ -12,10 +10,8 @@ using namespace mbgl::style::conversion; using namespace std::literals::chrono_literals; std::unique_ptr<Layer> parseLayer(const std::string& src) { - JSDocument doc; - doc.Parse<0>(src); Error error; - return std::move(*convert<std::unique_ptr<Layer>, JSValue>(doc, error)); + return std::move(*convertJSON<std::unique_ptr<Layer>>(src, error)); } TEST(StyleConversion, LayerTransition) { diff --git a/test/style/conversion/light.test.cpp b/test/style/conversion/light.test.cpp index 28e22b3550..67e48c942e 100644 --- a/test/style/conversion/light.test.cpp +++ b/test/style/conversion/light.test.cpp @@ -1,11 +1,10 @@ #include <mbgl/test/util.hpp> #include <mbgl/style/conversion.hpp> -#include <mbgl/style/rapidjson_conversion.hpp> +#include <mbgl/style/conversion/json.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> @@ -19,9 +18,7 @@ TEST(StyleConversion, Light) { Error error; auto parseLight = [&](const std::string& src) { - JSDocument doc; - doc.Parse<0>(src); - return convert<Light>(doc, error); + return convertJSON<Light>(src, error); }; { |