transcode input strings to UTF-8 (portability)

This commit is contained in:
artemp 2016-05-24 12:16:48 +02:00
parent acb2d56f49
commit 37a8aed62d
2 changed files with 28 additions and 26 deletions

View file

@ -23,6 +23,7 @@
#include "catch.hpp" #include "catch.hpp"
#include "ds_test_util.hpp" #include "ds_test_util.hpp"
#include <mapnik/unicode.hpp>
#include <mapnik/datasource.hpp> #include <mapnik/datasource.hpp>
#include <mapnik/datasource_cache.hpp> #include <mapnik/datasource_cache.hpp>
#include <mapnik/geometry.hpp> #include <mapnik/geometry.hpp>
@ -657,6 +658,7 @@ TEST_CASE("geojson") {
SECTION("GeoJSON properties are properly expressed") SECTION("GeoJSON properties are properly expressed")
{ {
mapnik::transcoder tr("utf8");
mapnik::parameters params; mapnik::parameters params;
params["type"] = "geojson"; params["type"] = "geojson";
@ -693,21 +695,21 @@ TEST_CASE("geojson") {
auto fs = all_features(ds); auto fs = all_features(ds);
REQUIRE(bool(fs)); REQUIRE(bool(fs));
std::initializer_list<attr> attrs = { std::initializer_list<attr> attrs = {
attr{"name", mapnik::value_unicode_string(u8"Test")}, attr{"name", tr.transcode("Test")},
attr{"NOM_FR", mapnik::value_unicode_string(u8"Québec")}, attr{"NOM_FR", tr.transcode("Québec")},
attr{"boolean", mapnik::value_bool(u8"true")}, attr{"boolean", mapnik::value_bool("true")},
attr{"description", mapnik::value_unicode_string(u8"Test: \u005C")}, attr{"description", tr.transcode("Test: \u005C")},
attr{"double", mapnik::value_double(1.1)}, attr{"double", mapnik::value_double(1.1)},
attr{"int", mapnik::value_integer(1)}, attr{"int", mapnik::value_integer(1)},
attr{"object", mapnik::value_unicode_string(u8"{name:\"waka\",spaces:\"value with spaces\",int:1,double:1.1,boolean:false" attr{"object", tr.transcode("{name:\"waka\",spaces:\"value with spaces\",int:1,double:1.1,boolean:false"
u8",NOM_FR:\"Québec\",array:[\"string\",\"value with spaces\",3,1.1,null,true" ",NOM_FR:\"Québec\",array:[\"string\",\"value with spaces\",3,1.1,null,true"
u8",\"Québec\"],another_object:{name:\"nested object\"}}")}, ",\"Québec\"],another_object:{name:\"nested object\"}}")},
attr{"spaces", mapnik::value_unicode_string(u8"this has spaces")}, attr{"spaces", tr.transcode("this has spaces")},
attr{"array", mapnik::value_unicode_string(u8"[\"string\",\"value with spaces\",3,1.1,null,true," attr{"array", tr.transcode("[\"string\",\"value with spaces\",3,1.1,null,true,"
u8"\"Québec\",{name:\"object within an array\"}," "\"Québec\",{name:\"object within an array\"},"
u8"[\"array\",\"within\",\"an\",\"array\"]]")}, "[\"array\",\"within\",\"an\",\"array\"]]")},
attr{"empty_array", mapnik::value_unicode_string(u8"[]")}, attr{"empty_array", tr.transcode("[]")},
attr{"empty_object", mapnik::value_unicode_string(u8"{}")}, attr{"empty_object", tr.transcode("{}")},
}; };
auto feature = fs->next(); auto feature = fs->next();
REQUIRE(bool(feature)); REQUIRE(bool(feature));

View file

@ -51,7 +51,7 @@ bool parse_topology(std::string const& filename, mapnik::topojson::topology & to
} }
TEST_CASE("topology") TEST_CASE("topojson")
{ {
SECTION("geometry parsing") SECTION("geometry parsing")
{ {
@ -91,21 +91,21 @@ TEST_CASE("topology")
CHECK(feature); CHECK(feature);
CHECK(feature->envelope() == bbox); CHECK(feature->envelope() == bbox);
std::initializer_list<attr> attrs = { std::initializer_list<attr> attrs = {
attr{"name", mapnik::value_unicode_string(u8"Test")}, attr{"name", tr.transcode("Test")},
attr{"NOM_FR", mapnik::value_unicode_string(u8"Québec")}, attr{"NOM_FR", tr.transcode("Québec")},
attr{"boolean", mapnik::value_bool("true")}, attr{"boolean", mapnik::value_bool("true")},
attr{"description", mapnik::value_unicode_string(u8"Test: \u005C")}, attr{"description", tr.transcode("Test: \u005C")},
attr{"double", mapnik::value_double(1.1)}, attr{"double", mapnik::value_double(1.1)},
attr{"int", mapnik::value_integer(1)}, attr{"int", mapnik::value_integer(1)},
attr{"object", mapnik::value_unicode_string(u8"{name:\"waka\",spaces:\"value with spaces\",int:1,double:1.1,boolean:false" attr{"object", tr.transcode("{name:\"waka\",spaces:\"value with spaces\",int:1,double:1.1,boolean:false"
u8",NOM_FR:\"Québec\",array:[\"string\",\"value with spaces\",3,1.1,null,true" ",NOM_FR:\"Québec\",array:[\"string\",\"value with spaces\",3,1.1,null,true"
u8",\"Québec\"],another_object:{name:\"nested object\"}}")}, ",\"Québec\"],another_object:{name:\"nested object\"}}")},
attr{"spaces", mapnik::value_unicode_string(u8"this has spaces")}, attr{"spaces", tr.transcode("this has spaces")},
attr{"array", mapnik::value_unicode_string(u8"[\"string\",\"value with spaces\",3,1.1,null,true," attr{"array", tr.transcode("[\"string\",\"value with spaces\",3,1.1,null,true,"
u8"\"Québec\",{name:\"object within an array\"}," "\"Québec\",{name:\"object within an array\"},"
u8"[\"array\",\"within\",\"an\",\"array\"]]")}, "[\"array\",\"within\",\"an\",\"array\"]]")},
attr{"empty_array", mapnik::value_unicode_string(u8"[]")}, attr{"empty_array", tr.transcode("[]")},
attr{"empty_object", mapnik::value_unicode_string(u8"{}")}, attr{"empty_object", tr.transcode("{}")},
}; };
REQUIRE_ATTRIBUTES(feature, attrs); REQUIRE_ATTRIBUTES(feature, attrs);
} }