summaryrefslogtreecommitdiff
path: root/test/sprite
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2017-04-20 12:28:35 +0200
committerKonstantin Käfer <mail@kkaefer.com>2017-04-24 10:42:47 +0200
commit59055cf403cab60496fcc8e7cbf06874fa55bb8b (patch)
tree7e74c6ba3fa9c2cc1930811302e8b93b48ab1687 /test/sprite
parent197f0ca6b418a27412bfcc7e891ab80949fd8833 (diff)
downloadqtlocation-mapboxgl-59055cf403cab60496fcc8e7cbf06874fa55bb8b.tar.gz
[core] Move Sprite parsing to thread pool
Diffstat (limited to 'test/sprite')
-rw-r--r--test/sprite/sprite_atlas.test.cpp8
-rw-r--r--test/sprite/sprite_parser.test.cpp24
2 files changed, 19 insertions, 13 deletions
diff --git a/test/sprite/sprite_atlas.test.cpp b/test/sprite/sprite_atlas.test.cpp
index 2335165715..fc0219efb9 100644
--- a/test/sprite/sprite_atlas.test.cpp
+++ b/test/sprite/sprite_atlas.test.cpp
@@ -9,6 +9,7 @@
#include <mbgl/util/io.hpp>
#include <mbgl/util/image.hpp>
#include <mbgl/util/run_loop.hpp>
+#include <mbgl/util/default_thread_pool.hpp>
#include <mbgl/util/string.hpp>
#include <utility>
@@ -22,7 +23,7 @@ TEST(SpriteAtlas, Basic) {
util::read_file("test/fixtures/annotations/emerald.json"));
SpriteAtlas atlas({ 63, 112 }, 1);
- atlas.setSprites(spriteParseResult.get<Sprites>());
+ atlas.setSprites(spriteParseResult);
EXPECT_EQ(1.0f, atlas.getPixelRatio());
EXPECT_EQ(63u, atlas.getSize().width);
@@ -77,7 +78,7 @@ TEST(SpriteAtlas, Size) {
util::read_file("test/fixtures/annotations/emerald.json"));
SpriteAtlas atlas({ 63, 112 }, 1.4);
- atlas.setSprites(spriteParseResult.get<Sprites>());
+ atlas.setSprites(spriteParseResult);
EXPECT_DOUBLE_EQ(1.4f, atlas.getPixelRatio());
EXPECT_EQ(63u, atlas.getSize().width);
@@ -270,6 +271,7 @@ public:
util::RunLoop loop;
StubFileSource fileSource;
StubStyleObserver observer;
+ ThreadPool threadPool { 1 };
SpriteAtlas spriteAtlas{ { 32, 32 }, 1 };
void run() {
@@ -277,7 +279,7 @@ public:
Log::setObserver(std::make_unique<Log::NullObserver>());
spriteAtlas.setObserver(&observer);
- spriteAtlas.load("test/fixtures/resources/sprite", fileSource);
+ spriteAtlas.load("test/fixtures/resources/sprite", threadPool, fileSource);
loop.run();
}
diff --git a/test/sprite/sprite_parser.test.cpp b/test/sprite/sprite_parser.test.cpp
index d634df1c1a..18b4b2a749 100644
--- a/test/sprite/sprite_parser.test.cpp
+++ b/test/sprite/sprite_parser.test.cpp
@@ -198,7 +198,7 @@ TEST(Sprite, 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).get<Sprites>();
+ const auto images = parseSprite(image_1x, json_1x);
std::set<std::string> names;
std::transform(images.begin(), images.end(), std::inserter(names, names.begin()),
@@ -294,10 +294,14 @@ TEST(Sprite, SpriteParsingInvalidJSON) {
const auto image_1x = util::read_file("test/fixtures/annotations/emerald.png");
const auto json_1x = R"JSON({ "image": " })JSON";
- const auto error = parseSprite(image_1x, json_1x).get<std::exception_ptr>();
-
- EXPECT_EQ(util::toString(error),
- std::string("Failed to parse JSON: Missing a closing quotation mark in string. at offset 14"));
+ try {
+ parseSprite(image_1x, json_1x);
+ FAIL() << "Expected exception";
+ } catch (std::runtime_error& err) {
+ EXPECT_STREQ(
+ "Failed to parse JSON: Missing a closing quotation mark in string. at offset 14",
+ err.what());
+ }
}
TEST(Sprite, SpriteParsingEmptyImage) {
@@ -306,7 +310,7 @@ TEST(Sprite, 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).get<Sprites>();
+ const auto images = parseSprite(image_1x, json_1x);
EXPECT_EQ(0u, images.size());
EXPECT_EQ(1u, log.count({
@@ -323,7 +327,7 @@ TEST(Sprite, 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).get<Sprites>();
+ const auto images = parseSprite(image_1x, json_1x);
EXPECT_EQ(1u, images.size());
}
@@ -333,7 +337,7 @@ TEST(Sprite, 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).get<Sprites>();
+ const auto images = parseSprite(image_1x, json_1x);
EXPECT_EQ(0u, images.size());
EXPECT_EQ(1u, log.count({
@@ -356,7 +360,7 @@ TEST(Sprite, 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).get<Sprites>();
+ const auto images = parseSprite(image_1x, json_1x);
EXPECT_EQ(0u, images.size());
EXPECT_EQ(1u, log.count({
@@ -379,7 +383,7 @@ TEST(Sprite, 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).get<Sprites>();
+ const auto images = parseSprite(image_1x, json_1x);
EXPECT_EQ(0u, images.size());
EXPECT_EQ(1u, log.count({