diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2016-10-26 15:22:31 -0700 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2016-10-27 18:30:58 -0700 |
commit | 62b56b799a7d4fcd1a8f151eed878054b862da5b (patch) | |
tree | 34d510a69f9dd1bca30e9b137feffbd1eb6495d0 /test/sprite | |
parent | ef8017198ce8f0bd79ba5a5ed31e35a16e3433bb (diff) | |
download | qtlocation-mapboxgl-62b56b799a7d4fcd1a8f151eed878054b862da5b.tar.gz |
[core] change std::array<uint16_t, 2> to mbgl::Size
Diffstat (limited to 'test/sprite')
-rw-r--r-- | test/sprite/sprite_atlas.test.cpp | 44 | ||||
-rw-r--r-- | test/sprite/sprite_image.test.cpp | 18 | ||||
-rw-r--r-- | test/sprite/sprite_parser.test.cpp | 32 |
3 files changed, 47 insertions, 47 deletions
diff --git a/test/sprite/sprite_atlas.test.cpp b/test/sprite/sprite_atlas.test.cpp index f84e17cbcf..231e2b1246 100644 --- a/test/sprite/sprite_atlas.test.cpp +++ b/test/sprite/sprite_atlas.test.cpp @@ -26,7 +26,7 @@ auto imageFromAtlas(const SpriteAtlas& atlas) { auto data = std::make_unique<uint8_t[]>(bytes); const auto src = reinterpret_cast<const uint8_t*>(atlas.getData()); std::copy(src, src + bytes, data.get()); - return PremultipliedImage{ atlas.getTextureWidth(), atlas.getTextureHeight(), std::move(data) }; + return PremultipliedImage{ { atlas.getTextureWidth(), atlas.getTextureHeight() }, std::move(data) }; } } // namespace @@ -56,8 +56,8 @@ TEST(SpriteAtlas, Basic) { EXPECT_EQ(20, metro.pos.h); EXPECT_EQ(18, metro.spriteImage->getWidth()); EXPECT_EQ(18, metro.spriteImage->getHeight()); - EXPECT_EQ(18u, metro.spriteImage->image.width); - EXPECT_EQ(18u, metro.spriteImage->image.height); + EXPECT_EQ(18u, metro.spriteImage->image.size.width); + EXPECT_EQ(18u, metro.spriteImage->image.size.height); EXPECT_EQ(1.0f, metro.spriteImage->pixelRatio); EXPECT_TRUE(atlas.getData()); @@ -110,8 +110,8 @@ TEST(SpriteAtlas, Size) { EXPECT_EQ(16, metro.pos.h); EXPECT_EQ(18, metro.spriteImage->getWidth()); EXPECT_EQ(18, metro.spriteImage->getHeight()); - EXPECT_EQ(18u, metro.spriteImage->image.width); - EXPECT_EQ(18u, metro.spriteImage->image.height); + EXPECT_EQ(18u, metro.spriteImage->image.size.width); + EXPECT_EQ(18u, metro.spriteImage->image.size.height); EXPECT_EQ(1.0f, metro.spriteImage->pixelRatio); EXPECT_EQ(readImage("test/fixtures/annotations/result-spriteatlassize.png"), @@ -127,7 +127,7 @@ TEST(SpriteAtlas, Updates) { EXPECT_EQ(32, atlas.getTextureWidth()); EXPECT_EQ(32, atlas.getTextureHeight()); - atlas.setSprite("one", std::make_shared<SpriteImage>(PremultipliedImage(16, 12), 1)); + atlas.setSprite("one", std::make_shared<SpriteImage>(PremultipliedImage({ 16, 12 }), 1)); auto one = *atlas.getImage("one", SpritePatternMode::Single); EXPECT_EQ(0, one.pos.x); EXPECT_EQ(0, one.pos.y); @@ -135,16 +135,16 @@ TEST(SpriteAtlas, Updates) { EXPECT_EQ(16, one.pos.h); EXPECT_EQ(16, one.spriteImage->getWidth()); EXPECT_EQ(12, one.spriteImage->getHeight()); - EXPECT_EQ(16u, one.spriteImage->image.width); - EXPECT_EQ(12u, one.spriteImage->image.height); + EXPECT_EQ(16u, one.spriteImage->image.size.width); + EXPECT_EQ(12u, one.spriteImage->image.size.height); EXPECT_EQ(1.0f, one.spriteImage->pixelRatio); EXPECT_EQ(readImage("test/fixtures/annotations/result-spriteatlas-empty.png"), imageFromAtlas(atlas)); // Update sprite - PremultipliedImage image2(16, 12); - for (size_t i = 0; i < image2.size(); i++) { + PremultipliedImage image2({ 16, 12 }); + for (size_t i = 0; i < image2.bytes(); i++) { image2.data.get()[i] = 255; } auto newSprite = std::make_shared<SpriteImage>(std::move(image2), 1); @@ -165,9 +165,9 @@ TEST(SpriteAtlas, Updates) { TEST(SpriteAtlas, AddRemove) { FixtureLog log; - const auto sprite1 = std::make_shared<SpriteImage>(PremultipliedImage(16, 16), 2); - const auto sprite2 = std::make_shared<SpriteImage>(PremultipliedImage(16, 16), 2); - const auto sprite3 = std::make_shared<SpriteImage>(PremultipliedImage(16, 16), 2); + const auto sprite1 = std::make_shared<SpriteImage>(PremultipliedImage({ 16, 16 }), 2); + const auto sprite2 = std::make_shared<SpriteImage>(PremultipliedImage({ 16, 16 }), 2); + const auto sprite3 = std::make_shared<SpriteImage>(PremultipliedImage({ 16, 16 }), 2); SpriteAtlas atlas(32, 32, 1); @@ -210,7 +210,7 @@ TEST(SpriteAtlas, AddRemove) { TEST(SpriteAtlas, OtherPixelRatio) { FixtureLog log; - const auto sprite1 = std::make_shared<SpriteImage>(PremultipliedImage(8, 8), 1); + const auto sprite1 = std::make_shared<SpriteImage>(PremultipliedImage({ 8, 8 }), 1); SpriteAtlas atlas(32, 32, 1); @@ -219,8 +219,8 @@ TEST(SpriteAtlas, OtherPixelRatio) { } TEST(SpriteAtlas, Multiple) { - const auto sprite1 = std::make_shared<SpriteImage>(PremultipliedImage(16, 16), 2); - const auto sprite2 = std::make_shared<SpriteImage>(PremultipliedImage(16, 16), 2); + const auto sprite1 = std::make_shared<SpriteImage>(PremultipliedImage({ 16, 16 }), 2); + const auto sprite2 = std::make_shared<SpriteImage>(PremultipliedImage({ 16, 16 }), 2); SpriteAtlas atlas(32, 32, 1); @@ -232,8 +232,8 @@ TEST(SpriteAtlas, Multiple) { TEST(SpriteAtlas, Replace) { FixtureLog log; - const auto sprite1 = std::make_shared<SpriteImage>(PremultipliedImage(16, 16), 2); - const auto sprite2 = std::make_shared<SpriteImage>(PremultipliedImage(16, 16), 2); + const auto sprite1 = std::make_shared<SpriteImage>(PremultipliedImage({ 16, 16 }), 2); + const auto sprite2 = std::make_shared<SpriteImage>(PremultipliedImage({ 16, 16 }), 2); SpriteAtlas atlas(32, 32, 1); @@ -246,10 +246,10 @@ TEST(SpriteAtlas, Replace) { TEST(SpriteAtlas, ReplaceWithDifferentDimensions) { FixtureLog log; - PremultipliedImage image(16, 16); - PremultipliedImage image2(18, 18); - const auto sprite1 = std::make_shared<SpriteImage>(PremultipliedImage(16, 16), 2); - const auto sprite2 = std::make_shared<SpriteImage>(PremultipliedImage(18, 18), 2); + PremultipliedImage image({ 16, 16 }); + PremultipliedImage image2({ 18, 18 }); + const auto sprite1 = std::make_shared<SpriteImage>(PremultipliedImage({ 16, 16 }), 2); + const auto sprite2 = std::make_shared<SpriteImage>(PremultipliedImage({ 18, 18 }), 2); SpriteAtlas atlas(32, 32, 1); diff --git a/test/sprite/sprite_image.test.cpp b/test/sprite/sprite_image.test.cpp index f8982826a3..97a37513ac 100644 --- a/test/sprite/sprite_image.test.cpp +++ b/test/sprite/sprite_image.test.cpp @@ -7,7 +7,7 @@ using namespace mbgl; TEST(Sprite, SpriteImageZeroWidth) { - PremultipliedImage image(0, 16); + PremultipliedImage image({ 0, 16 }); try { SpriteImage(std::move(image), 2.0); FAIL() << "Expected exception"; @@ -17,7 +17,7 @@ TEST(Sprite, SpriteImageZeroWidth) { } TEST(Sprite, SpriteImageZeroHeight) { - PremultipliedImage image(16, 0); + PremultipliedImage image({ 16, 0 }); try { SpriteImage(std::move(image), 2.0); FAIL() << "Expected exception"; @@ -27,7 +27,7 @@ TEST(Sprite, SpriteImageZeroHeight) { } TEST(Sprite, SpriteImageZeroRatio) { - PremultipliedImage image(16, 16); + PremultipliedImage image({ 16, 16 }); try { SpriteImage(std::move(image), 0.0); FAIL() << "Expected exception"; @@ -37,21 +37,21 @@ TEST(Sprite, SpriteImageZeroRatio) { } TEST(Sprite, SpriteImage) { - PremultipliedImage image(32, 24); + PremultipliedImage image({ 32, 24 }); SpriteImage sprite(std::move(image), 2.0); EXPECT_EQ(16, sprite.getWidth()); - EXPECT_EQ(32u, sprite.image.width); + EXPECT_EQ(32u, sprite.image.size.width); EXPECT_EQ(12, sprite.getHeight()); - EXPECT_EQ(24u, sprite.image.height); + EXPECT_EQ(24u, sprite.image.size.height); EXPECT_EQ(2, sprite.pixelRatio); } TEST(Sprite, SpriteImageFractionalRatio) { - PremultipliedImage image(20, 12); + PremultipliedImage image({ 20, 12 }); SpriteImage sprite(std::move(image), 1.5); EXPECT_EQ(float(20.0 / 1.5), sprite.getWidth()); - EXPECT_EQ(20u, sprite.image.width); + EXPECT_EQ(20u, sprite.image.size.width); EXPECT_EQ(float(12.0 / 1.5), sprite.getHeight()); - EXPECT_EQ(12u, sprite.image.height); + EXPECT_EQ(12u, sprite.image.size.height); EXPECT_EQ(1.5, sprite.pixelRatio); } diff --git a/test/sprite/sprite_parser.test.cpp b/test/sprite/sprite_parser.test.cpp index 8d32d081bf..7bedf7bc28 100644 --- a/test/sprite/sprite_parser.test.cpp +++ b/test/sprite/sprite_parser.test.cpp @@ -24,8 +24,8 @@ TEST(Sprite, SpriteImageCreationInvalid) { const PremultipliedImage image_1x = decodeImage(util::read_file("test/fixtures/annotations/emerald.png")); - ASSERT_EQ(200u, image_1x.width); - ASSERT_EQ(299u, image_1x.height); + ASSERT_EQ(200u, image_1x.size.width); + ASSERT_EQ(299u, image_1x.size.height); ASSERT_EQ(nullptr, createSpriteImage(image_1x, 0, 0, 0, 16, 1, false)); // width == 0 ASSERT_EQ(nullptr, createSpriteImage(image_1x, 0, 0, 16, 0, 1, false)); // height == 0 @@ -38,8 +38,8 @@ TEST(Sprite, SpriteImageCreationInvalid) { ASSERT_EQ(nullptr, createSpriteImage(image_1x, 0, 0, 16, 1025, 1, false)); // too tall ASSERT_EQ(nullptr, createSpriteImage(image_1x, -1, 0, 16, 16, 1, false)); // srcX < 0 ASSERT_EQ(nullptr, createSpriteImage(image_1x, 0, -1, 16, 16, 1, false)); // srcY < 0 - ASSERT_EQ(nullptr, createSpriteImage(image_1x, 0, 0, image_1x.width + 1, 16, 1, false)); // right edge out of bounds - ASSERT_EQ(nullptr, createSpriteImage(image_1x, 0, 0, 16, image_1x.height + 1, 1, false)); // bottom edge out of bounds + ASSERT_EQ(nullptr, createSpriteImage(image_1x, 0, 0, image_1x.size.width + 1, 16, 1, false)); // right edge out of bounds + ASSERT_EQ(nullptr, createSpriteImage(image_1x, 0, 0, 16, image_1x.size.height + 1, 1, false)); // bottom edge out of bounds EXPECT_EQ(13u, log.count({ EventSeverity::Error, @@ -52,16 +52,16 @@ TEST(Sprite, SpriteImageCreationInvalid) { TEST(Sprite, SpriteImageCreation1x) { const PremultipliedImage image_1x = decodeImage(util::read_file("test/fixtures/annotations/emerald.png")); - ASSERT_EQ(200u, image_1x.width); - ASSERT_EQ(299u, image_1x.height); + ASSERT_EQ(200u, image_1x.size.width); + ASSERT_EQ(299u, image_1x.size.height); { // "museum_icon":{"x":177,"y":187,"width":18,"height":18,"pixelRatio":1,"sdf":false} const auto sprite = createSpriteImage(image_1x, 177, 187, 18, 18, 1, false); ASSERT_TRUE(sprite.get()); EXPECT_EQ(18, sprite->getWidth()); EXPECT_EQ(18, sprite->getHeight()); - EXPECT_EQ(18u, sprite->image.width); - EXPECT_EQ(18u, sprite->image.height); + EXPECT_EQ(18u, sprite->image.size.width); + EXPECT_EQ(18u, sprite->image.size.height); EXPECT_EQ(1, sprite->pixelRatio); EXPECT_EQ(readImage("test/fixtures/annotations/result-spriteimagecreation1x-museum.png"), sprite->image); @@ -76,8 +76,8 @@ TEST(Sprite, SpriteImageCreation2x) { ASSERT_TRUE(sprite.get()); EXPECT_EQ(18, sprite->getWidth()); EXPECT_EQ(18, sprite->getHeight()); - EXPECT_EQ(36u, sprite->image.width); - EXPECT_EQ(36u, sprite->image.height); + EXPECT_EQ(36u, sprite->image.size.width); + EXPECT_EQ(36u, sprite->image.size.height); EXPECT_EQ(2, sprite->pixelRatio); EXPECT_EQ(readImage("test/fixtures/annotations/result-spriteimagecreation2x.png"), sprite->image); @@ -91,8 +91,8 @@ TEST(Sprite, SpriteImageCreation1_5x) { ASSERT_TRUE(sprite.get()); EXPECT_EQ(24, sprite->getWidth()); EXPECT_EQ(24, sprite->getHeight()); - EXPECT_EQ(36u, sprite->image.width); - EXPECT_EQ(36u, sprite->image.height); + EXPECT_EQ(36u, sprite->image.size.width); + EXPECT_EQ(36u, sprite->image.size.height); EXPECT_EQ(1.5, sprite->pixelRatio); EXPECT_EQ(readImage("test/fixtures/annotations/result-spriteimagecreation1_5x-museum.png"), sprite->image); @@ -102,8 +102,8 @@ TEST(Sprite, SpriteImageCreation1_5x) { ASSERT_TRUE(sprite2.get()); EXPECT_EQ(float(35 / 1.5), sprite2->getWidth()); EXPECT_EQ(float(35 / 1.5), sprite2->getHeight()); - EXPECT_EQ(35u, sprite2->image.width); - EXPECT_EQ(35u, sprite2->image.height); + EXPECT_EQ(35u, sprite2->image.size.width); + EXPECT_EQ(35u, sprite2->image.size.height); EXPECT_EQ(1.5, sprite2->pixelRatio); EXPECT_EQ(readImage("test/fixtures/annotations/result-spriteimagecreation1_5x-hospital.png"), sprite2->image); @@ -198,8 +198,8 @@ TEST(Sprite, SpriteParsing) { auto sprite = images.find("generic-metro")->second; EXPECT_EQ(18, sprite->getWidth()); EXPECT_EQ(18, sprite->getHeight()); - EXPECT_EQ(18u, sprite->image.width); - EXPECT_EQ(18u, sprite->image.height); + EXPECT_EQ(18u, sprite->image.size.width); + EXPECT_EQ(18u, sprite->image.size.height); EXPECT_EQ(1, sprite->pixelRatio); EXPECT_EQ(readImage("test/fixtures/annotations/result-spriteparsing.png"), sprite->image); } |