From 59055cf403cab60496fcc8e7cbf06874fa55bb8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Thu, 20 Apr 2017 12:28:35 +0200 Subject: [core] Move Sprite parsing to thread pool --- test/sprite/sprite_atlas.test.cpp | 8 +++++--- test/sprite/sprite_parser.test.cpp | 24 ++++++++++++++---------- test/style/source.test.cpp | 2 +- test/style/style.test.cpp | 13 +++++++++---- test/style/style_layer.test.cpp | 4 +++- test/tile/annotation_tile.test.cpp | 2 +- test/tile/geojson_tile.test.cpp | 2 +- test/tile/raster_tile.test.cpp | 2 +- test/tile/vector_tile.test.cpp | 2 +- 9 files changed, 36 insertions(+), 23 deletions(-) (limited to 'test') 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 #include #include +#include #include #include @@ -22,7 +23,7 @@ TEST(SpriteAtlas, Basic) { util::read_file("test/fixtures/annotations/emerald.json")); SpriteAtlas atlas({ 63, 112 }, 1); - atlas.setSprites(spriteParseResult.get()); + 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()); + 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()); 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(); + const auto images = parseSprite(image_1x, json_1x); std::set 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(); - - 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(); + 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(); + 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(); + 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(); + 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(); + const auto images = parseSprite(image_1x, json_1x); EXPECT_EQ(0u, images.size()); EXPECT_EQ(1u, log.count({ diff --git a/test/style/source.test.cpp b/test/style/source.test.cpp index f637f1ccde..24ddba8aaf 100644 --- a/test/style/source.test.cpp +++ b/test/style/source.test.cpp @@ -38,7 +38,7 @@ public: TransformState transformState; ThreadPool threadPool { 1 }; AnnotationManager annotationManager { 1.0 }; - style::Style style { fileSource, 1.0 }; + style::Style style { threadPool, fileSource, 1.0 }; style::UpdateParameters updateParameters { 1.0, diff --git a/test/style/style.test.cpp b/test/style/style.test.cpp index b49058420e..f87e31cce2 100644 --- a/test/style/style.test.cpp +++ b/test/style/style.test.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include @@ -16,8 +17,9 @@ using namespace mbgl::style; TEST(Style, UnusedSource) { util::RunLoop loop; + ThreadPool threadPool{ 1 }; StubFileSource fileSource; - Style style { fileSource, 1.0 }; + Style style { threadPool, fileSource, 1.0 }; auto now = Clock::now(); @@ -53,8 +55,9 @@ TEST(Style, UnusedSource) { TEST(Style, UnusedSourceActiveViaClassUpdate) { util::RunLoop loop; + ThreadPool threadPool{ 1 }; StubFileSource fileSource; - Style style { fileSource, 1.0 }; + Style style { threadPool, fileSource, 1.0 }; style.setJSON(util::read_file("test/fixtures/resources/style-unused-sources.json")); EXPECT_TRUE(style.addClass("visible")); @@ -86,8 +89,9 @@ TEST(Style, UnusedSourceActiveViaClassUpdate) { TEST(Style, Properties) { util::RunLoop loop; + ThreadPool threadPool{ 1 }; StubFileSource fileSource; - Style style { fileSource, 1.0 }; + Style style { threadPool, fileSource, 1.0 }; style.setJSON(R"STYLE({"name": "Test"})STYLE"); ASSERT_EQ("Test", style.getName()); @@ -120,8 +124,9 @@ TEST(Style, Properties) { TEST(Style, DuplicateSource) { util::RunLoop loop; + ThreadPool threadPool{ 1 }; StubFileSource fileSource; - Style style { fileSource, 1.0 }; + Style style { threadPool, fileSource, 1.0 }; style.setJSON(util::read_file("test/fixtures/resources/style-unused-sources.json")); diff --git a/test/style/style_layer.test.cpp b/test/style/style_layer.test.cpp index 10b88c53d4..657dc24a70 100644 --- a/test/style/style_layer.test.cpp +++ b/test/style/style_layer.test.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -279,8 +280,9 @@ TEST(Layer, DuplicateLayer) { util::RunLoop loop; // Setup style + ThreadPool threadPool{ 1 }; StubFileSource fileSource; - Style style { fileSource, 1.0 }; + Style style { threadPool, fileSource, 1.0 }; style.setJSON(util::read_file("test/fixtures/resources/style-unused-sources.json")); // Add initial layer diff --git a/test/tile/annotation_tile.test.cpp b/test/tile/annotation_tile.test.cpp index cba2b61b59..032f918068 100644 --- a/test/tile/annotation_tile.test.cpp +++ b/test/tile/annotation_tile.test.cpp @@ -24,7 +24,7 @@ public: util::RunLoop loop; ThreadPool threadPool { 1 }; AnnotationManager annotationManager { 1.0 }; - style::Style style { fileSource, 1.0 }; + style::Style style { threadPool, fileSource, 1.0 }; style::UpdateParameters updateParameters { 1.0, diff --git a/test/tile/geojson_tile.test.cpp b/test/tile/geojson_tile.test.cpp index 920e946a2b..e2a026b560 100644 --- a/test/tile/geojson_tile.test.cpp +++ b/test/tile/geojson_tile.test.cpp @@ -24,7 +24,7 @@ public: util::RunLoop loop; ThreadPool threadPool { 1 }; AnnotationManager annotationManager { 1.0 }; - style::Style style { fileSource, 1.0 }; + style::Style style { threadPool, fileSource, 1.0 }; Tileset tileset { { "https://example.com" }, { 0, 22 }, "none" }; style::UpdateParameters updateParameters { diff --git a/test/tile/raster_tile.test.cpp b/test/tile/raster_tile.test.cpp index d0252555ac..1d1e7d746e 100644 --- a/test/tile/raster_tile.test.cpp +++ b/test/tile/raster_tile.test.cpp @@ -20,7 +20,7 @@ public: util::RunLoop loop; ThreadPool threadPool { 1 }; AnnotationManager annotationManager { 1.0 }; - style::Style style { fileSource, 1.0 }; + style::Style style { threadPool, fileSource, 1.0 }; Tileset tileset { { "https://example.com" }, { 0, 22 }, "none" }; style::UpdateParameters updateParameters { diff --git a/test/tile/vector_tile.test.cpp b/test/tile/vector_tile.test.cpp index 0f43645d49..fc6e9b3a6d 100644 --- a/test/tile/vector_tile.test.cpp +++ b/test/tile/vector_tile.test.cpp @@ -26,7 +26,7 @@ public: util::RunLoop loop; ThreadPool threadPool { 1 }; AnnotationManager annotationManager { 1.0 }; - style::Style style { fileSource, 1.0 }; + style::Style style { threadPool, fileSource, 1.0 }; Tileset tileset { { "https://example.com" }, { 0, 22 }, "none" }; style::UpdateParameters updateParameters { -- cgit v1.2.1