summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorThiago Marcos P. Santos <thiago@mapbox.com>2015-07-09 15:57:15 +0300
committerThiago Marcos P. Santos <thiago@mapbox.com>2015-07-10 10:48:46 +0300
commit0ee9f21c56a69513ba2dce3108f5540afb045c6d (patch)
tree0bbb6f5e3d029dbf53a29257dfd87f0a4ddbe5a2 /test
parentf64ba789105c0193ced0da4507120fc03b684aba (diff)
downloadqtlocation-mapboxgl-0ee9f21c56a69513ba2dce3108f5540afb045c6d.tar.gz
Report Sprite parsing errors to Observers
Parsing errors will be reported to Observers. In practice this will bubble all the way to the Map object. This will make possible to identify possible corrupted data instead of rendering without sprites like we do in case of semantic errors.
Diffstat (limited to 'test')
-rw-r--r--test/annotations/sprite_atlas.cpp13
-rw-r--r--test/annotations/sprite_parser.cpp27
2 files changed, 18 insertions, 22 deletions
diff --git a/test/annotations/sprite_atlas.cpp b/test/annotations/sprite_atlas.cpp
index 16140b0517..0eece6c47c 100644
--- a/test/annotations/sprite_atlas.cpp
+++ b/test/annotations/sprite_atlas.cpp
@@ -12,9 +12,11 @@ using namespace mbgl;
TEST(Annotations, SpriteAtlas) {
FixtureLog log;
+ auto spriteParseResult = parseSprite(util::read_file("test/fixtures/annotations/emerald.png"),
+ util::read_file("test/fixtures/annotations/emerald.json"));
+
SpriteStore store;
- store.setSprites(parseSprite(util::read_file("test/fixtures/annotations/emerald.png"),
- util::read_file("test/fixtures/annotations/emerald.json")));
+ store.setSprites(spriteParseResult.get<Sprites>());
SpriteAtlas atlas(63, 112, 1, store);
@@ -85,9 +87,12 @@ TEST(Annotations, SpriteAtlas) {
}
TEST(Annotations, SpriteAtlasSize) {
+ auto spriteParseResult = parseSprite(util::read_file("test/fixtures/annotations/emerald.png"),
+ util::read_file("test/fixtures/annotations/emerald.json"));
+
SpriteStore store;
- store.setSprites(parseSprite(util::read_file("test/fixtures/annotations/emerald.png"),
- util::read_file("test/fixtures/annotations/emerald.json")));
+ store.setSprites(spriteParseResult.get<Sprites>());
+
SpriteAtlas atlas(63, 112, 1.4, store);
EXPECT_DOUBLE_EQ(1.4f, atlas.getPixelRatio());
diff --git a/test/annotations/sprite_parser.cpp b/test/annotations/sprite_parser.cpp
index 280a19c50a..7033152581 100644
--- a/test/annotations/sprite_parser.cpp
+++ b/test/annotations/sprite_parser.cpp
@@ -117,7 +117,7 @@ TEST(Annotations, SpriteParsing) {
const auto image_1x = util::read_file("test/fixtures/annotations/emerald.png");
const auto json_1x = util::read_file("test/fixtures/annotations/emerald.json");
- const auto images = parseSprite(image_1x, json_1x);
+ const auto images = parseSprite(image_1x, json_1x).get<Sprites>();
std::set<std::string> names;
std::transform(images.begin(), images.end(), std::inserter(names, names.begin()),
@@ -210,22 +210,13 @@ TEST(Annotations, SpriteParsing) {
}
TEST(Annotations, SpriteParsingInvalidJSON) {
- FixtureLog log;
-
const auto image_1x = util::read_file("test/fixtures/annotations/emerald.png");
const auto json_1x = R"JSON({ "image": " })JSON";
- const auto images = parseSprite(image_1x, json_1x);
- EXPECT_EQ(0u, images.size());
+ const auto error = parseSprite(image_1x, json_1x).get<std::string>();
- EXPECT_EQ(
- 1u,
- log.count({
- EventSeverity::Warning,
- Event::Sprite,
- int64_t(-1),
- "Failed to parse JSON: lacks ending quotation before the end of string at offset 10",
- }));
+ EXPECT_EQ(error,
+ std::string("Failed to parse JSON: lacks ending quotation before the end of string at offset 10"));
}
TEST(Annotations, SpriteParsingEmptyImage) {
@@ -234,7 +225,7 @@ TEST(Annotations, SpriteParsingEmptyImage) {
const auto image_1x = util::read_file("test/fixtures/annotations/emerald.png");
const auto json_1x = R"JSON({ "image": {} })JSON";
- const auto images = parseSprite(image_1x, json_1x);
+ const auto images = parseSprite(image_1x, json_1x).get<Sprites>();
EXPECT_EQ(0u, images.size());
EXPECT_EQ(1u, log.count({
@@ -251,7 +242,7 @@ TEST(Annotations, SpriteParsingSimpleWidthHeight) {
const auto image_1x = util::read_file("test/fixtures/annotations/emerald.png");
const auto json_1x = R"JSON({ "image": { "width": 32, "height": 32 } })JSON";
- const auto images = parseSprite(image_1x, json_1x);
+ const auto images = parseSprite(image_1x, json_1x).get<Sprites>();
EXPECT_EQ(1u, images.size());
}
@@ -261,7 +252,7 @@ TEST(Annotations, SpriteParsingWidthTooBig) {
const auto image_1x = util::read_file("test/fixtures/annotations/emerald.png");
const auto json_1x = R"JSON({ "image": { "width": 65536, "height": 32 } })JSON";
- const auto images = parseSprite(image_1x, json_1x);
+ const auto images = parseSprite(image_1x, json_1x).get<Sprites>();
EXPECT_EQ(0u, images.size());
EXPECT_EQ(1u, log.count({
@@ -284,7 +275,7 @@ TEST(Annotations, SpriteParsingNegativeWidth) {
const auto image_1x = util::read_file("test/fixtures/annotations/emerald.png");
const auto json_1x = R"JSON({ "image": { "width": -1, "height": 32 } })JSON";
- const auto images = parseSprite(image_1x, json_1x);
+ const auto images = parseSprite(image_1x, json_1x).get<Sprites>();
EXPECT_EQ(0u, images.size());
EXPECT_EQ(1u, log.count({
@@ -307,7 +298,7 @@ TEST(Annotations, SpriteParsingNullRatio) {
const auto image_1x = util::read_file("test/fixtures/annotations/emerald.png");
const auto json_1x = R"JSON({ "image": { "width": 32, "height": 32, "pixelRatio": 0 } })JSON";
- const auto images = parseSprite(image_1x, json_1x);
+ const auto images = parseSprite(image_1x, json_1x).get<Sprites>();
EXPECT_EQ(0u, images.size());
EXPECT_EQ(1u, log.count({