diff options
author | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2019-05-29 16:06:56 +0300 |
---|---|---|
committer | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2019-06-04 15:28:00 +0300 |
commit | a9abc43510b4206ffa9c54c3d4c9aa2ed0d1cfce (patch) | |
tree | fc7aa8330560a1beac6b3866b2b838477795e6e4 /test | |
parent | c0e5632001a0eb656857fed6fa8fb9e42d3e205e (diff) | |
download | qtlocation-mapboxgl-a9abc43510b4206ffa9c54c3d4c9aa2ed0d1cfce.tar.gz |
[core] Introduce PatternAtlas
Diffstat (limited to 'test')
-rw-r--r-- | test/renderer/image_manager.test.cpp | 47 | ||||
-rw-r--r-- | test/renderer/pattern_atlas.test.cpp | 82 | ||||
-rw-r--r-- | test/test-files.json | 1 |
3 files changed, 86 insertions, 44 deletions
diff --git a/test/renderer/image_manager.test.cpp b/test/renderer/image_manager.test.cpp index 443a8539b6..0b72578c35 100644 --- a/test/renderer/image_manager.test.cpp +++ b/test/renderer/image_manager.test.cpp @@ -28,51 +28,10 @@ TEST(ImageManager, Basic) { util::read_file("test/fixtures/annotations/emerald.json")); for (auto& image : images) { imageManager.addImage(image->baseImpl); + auto* stored = imageManager.getImage(image->getID()); + ASSERT_TRUE(stored); + EXPECT_EQ(image->getImage().size, stored->image.size); } - - auto metro = *imageManager.getPattern("metro"); - EXPECT_EQ(1, metro.tl()[0]); - EXPECT_EQ(1, metro.tl()[1]); - EXPECT_EQ(19, metro.br()[0]); - EXPECT_EQ(19, metro.br()[1]); - EXPECT_EQ(18, metro.displaySize()[0]); - EXPECT_EQ(18, metro.displaySize()[1]); - EXPECT_EQ(1.0f, metro.pixelRatio); - EXPECT_EQ(imageManager.getPixelSize(), imageManager.getAtlasImage().size); - - test::checkImage("test/fixtures/image_manager/basic", imageManager.getAtlasImage()); -} - -TEST(ImageManager, Updates) { - ImageManager imageManager; - - PremultipliedImage imageA({ 16, 12 }); - imageA.fill(255); - imageManager.addImage(makeMutable<style::Image::Impl>("one", std::move(imageA), 1)); - - auto a = *imageManager.getPattern("one"); - EXPECT_EQ(1, a.tl()[0]); - EXPECT_EQ(1, a.tl()[1]); - EXPECT_EQ(17, a.br()[0]); - EXPECT_EQ(13, a.br()[1]); - EXPECT_EQ(16, a.displaySize()[0]); - EXPECT_EQ(12, a.displaySize()[1]); - EXPECT_EQ(1.0f, a.pixelRatio); - test::checkImage("test/fixtures/image_manager/updates_before", imageManager.getAtlasImage()); - - PremultipliedImage imageB({ 5, 5 }); - imageA.fill(200); - imageManager.updateImage(makeMutable<style::Image::Impl>("one", std::move(imageB), 1)); - - auto b = *imageManager.getPattern("one"); - EXPECT_EQ(1, b.tl()[0]); - EXPECT_EQ(1, b.tl()[1]); - EXPECT_EQ(6, b.br()[0]); - EXPECT_EQ(6, b.br()[1]); - EXPECT_EQ(5, b.displaySize()[0]); - EXPECT_EQ(5, b.displaySize()[1]); - EXPECT_EQ(1.0f, b.pixelRatio); - test::checkImage("test/fixtures/image_manager/updates_after", imageManager.getAtlasImage()); } TEST(ImageManager, AddRemove) { diff --git a/test/renderer/pattern_atlas.test.cpp b/test/renderer/pattern_atlas.test.cpp new file mode 100644 index 0000000000..2a19e463bd --- /dev/null +++ b/test/renderer/pattern_atlas.test.cpp @@ -0,0 +1,82 @@ +#include <mbgl/test/util.hpp> +#include <mbgl/test/fixture_log_observer.hpp> +#include <mbgl/test/stub_style_observer.hpp> + +#include <mbgl/renderer/pattern_atlas.hpp> +#include <mbgl/sprite/sprite_parser.hpp> +#include <mbgl/style/image_impl.hpp> +#include <mbgl/util/io.hpp> +#include <mbgl/util/image.hpp> +#include <mbgl/util/run_loop.hpp> +#include <mbgl/util/string.hpp> + +#include <utility> + +using namespace mbgl; + +TEST(PatternAtlas, Basic) { + FixtureLog log; + PatternAtlas patternAtlas; + + auto images = parseSprite(util::read_file("test/fixtures/annotations/emerald.png"), + util::read_file("test/fixtures/annotations/emerald.json")); + for (auto& image : images) { + if (image->getID() == "metro") { + ASSERT_TRUE(patternAtlas.addPattern(*image->baseImpl)); + } + } + auto found = patternAtlas.getPattern("metro"); + ASSERT_TRUE(found); + + auto metro = *found; + EXPECT_EQ(1, metro.tl()[0]); + EXPECT_EQ(1, metro.tl()[1]); + EXPECT_EQ(19, metro.br()[0]); + EXPECT_EQ(19, metro.br()[1]); + EXPECT_EQ(18, metro.displaySize()[0]); + EXPECT_EQ(18, metro.displaySize()[1]); + EXPECT_EQ(1.0f, metro.pixelRatio); + EXPECT_EQ(patternAtlas.getPixelSize(), patternAtlas.getAtlasImageForTests().size); + + test::checkImage("test/fixtures/image_manager/basic", patternAtlas.getAtlasImageForTests()); +} + +TEST(PatternAtlas, Updates) { + PatternAtlas patternAtlas; + + PremultipliedImage imageA({ 16, 12 }); + imageA.fill(255); + + auto added = patternAtlas.addPattern(*makeMutable<style::Image::Impl>("one", std::move(imageA), 1)); + ASSERT_TRUE(added); + auto found = patternAtlas.getPattern("one"); + ASSERT_TRUE(found); + EXPECT_EQ(added->textureRect, found->textureRect); + + auto a = *found; + EXPECT_EQ(1, a.tl()[0]); + EXPECT_EQ(1, a.tl()[1]); + EXPECT_EQ(17, a.br()[0]); + EXPECT_EQ(13, a.br()[1]); + EXPECT_EQ(16, a.displaySize()[0]); + EXPECT_EQ(12, a.displaySize()[1]); + EXPECT_EQ(1.0f, a.pixelRatio); + test::checkImage("test/fixtures/image_manager/updates_before", patternAtlas.getAtlasImageForTests()); + + auto imageB = makeMutable<style::Image::Impl>("one", PremultipliedImage({ 5, 5 }), 1); + EXPECT_FALSE(patternAtlas.addPattern(*imageB)); // Already added. + + patternAtlas.removePattern("one"); + ASSERT_FALSE(patternAtlas.getPattern("one")); + EXPECT_TRUE(patternAtlas.addPattern(*imageB)); + + auto b = *patternAtlas.getPattern("one"); + EXPECT_EQ(1, b.tl()[0]); + EXPECT_EQ(1, b.tl()[1]); + EXPECT_EQ(6, b.br()[0]); + EXPECT_EQ(6, b.br()[1]); + EXPECT_EQ(5, b.displaySize()[0]); + EXPECT_EQ(5, b.displaySize()[1]); + EXPECT_EQ(1.0f, b.pixelRatio); + test::checkImage("test/fixtures/image_manager/updates_after", patternAtlas.getAtlasImageForTests()); +} diff --git a/test/test-files.json b/test/test-files.json index 6ed78d4e61..e46f833269 100644 --- a/test/test-files.json +++ b/test/test-files.json @@ -26,6 +26,7 @@ "test/programs/symbol_program.test.cpp", "test/renderer/backend_scope.test.cpp", "test/renderer/image_manager.test.cpp", + "test/renderer/pattern_atlas.test.cpp", "test/sprite/sprite_loader.test.cpp", "test/sprite/sprite_parser.test.cpp", "test/src/mbgl/test/fixture_log_observer.cpp", |