summaryrefslogtreecommitdiff
path: root/test/sprite
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2016-02-17 15:53:14 +0100
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-03-22 11:56:01 -0700
commit1dd81d9776baf9b9ef61b05d29f7acbb0f2a1508 (patch)
treeded904ed0a8b2d9cb0f3f784d683162e5917e99f /test/sprite
parentc608803ca95e833c9312c0f1cd622594224d5458 (diff)
downloadqtlocation-mapboxgl-1dd81d9776baf9b9ef61b05d29f7acbb0f2a1508.tar.gz
[test] remove crc64 and compare images
boost's crc64 breaks on iOS
Diffstat (limited to 'test/sprite')
-rw-r--r--test/sprite/sprite_atlas.cpp50
-rw-r--r--test/sprite/sprite_parser.cpp28
2 files changed, 46 insertions, 32 deletions
diff --git a/test/sprite/sprite_atlas.cpp b/test/sprite/sprite_atlas.cpp
index d9a8c5c720..81abbae933 100644
--- a/test/sprite/sprite_atlas.cpp
+++ b/test/sprite/sprite_atlas.cpp
@@ -9,6 +9,22 @@
using namespace mbgl;
+namespace {
+
+auto readImage(const std::string& name) {
+ return decodeImage(util::read_file(name));
+}
+
+auto imageFromAtlas(const SpriteAtlas& atlas) {
+ const size_t bytes = atlas.getTextureWidth() * atlas.getTextureHeight() * 4;
+ 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) };
+}
+
+} // namespace
+
TEST(Sprite, SpriteAtlas) {
FixtureLog log;
@@ -67,13 +83,7 @@ TEST(Sprite, SpriteAtlas) {
EXPECT_EQ(20, metro2.pos.w);
EXPECT_EQ(20, metro2.pos.h);
- const size_t bytes = atlas.getTextureWidth() * atlas.getTextureHeight() * 4;
- const auto hash = test::crc64(reinterpret_cast<const char*>(atlas.getData()), bytes);
- EXPECT_EQ(11868256915183397177u, hash) << std::hex << hash;
-
- // util::write_file(
- // "test/fixtures/annotations/atlas1.png",
- // util::compress_png(atlas.getTextureWidth(), atlas.getTextureHeight(), atlas.getData()));
+ EXPECT_EQ(readImage("test/fixtures/annotations/result-spriteatlas.png"), imageFromAtlas(atlas));
}
TEST(Sprite, SpriteAtlasSize) {
@@ -102,13 +112,8 @@ TEST(Sprite, SpriteAtlasSize) {
EXPECT_EQ(18, metro.spriteImage->image.height);
EXPECT_EQ(1.0f, metro.spriteImage->pixelRatio);
- const size_t bytes = atlas.getTextureWidth() * atlas.getTextureHeight() * 4;
- const auto hash = test::crc64(reinterpret_cast<const char*>(atlas.getData()), bytes);
- EXPECT_EQ(18324190582232646342u, hash) << std::hex << hash;
-
- // util::write_file(
- // "test/fixtures/annotations/atlas2.png",
- // util::compress_png(atlas.getTextureWidth(), atlas.getTextureHeight(), atlas.getData()));
+ EXPECT_EQ(readImage("test/fixtures/annotations/result-spriteatlassize.png"),
+ imageFromAtlas(atlas));
}
TEST(Sprite, SpriteAtlasUpdates) {
@@ -134,9 +139,8 @@ TEST(Sprite, SpriteAtlasUpdates) {
EXPECT_EQ(12, one.spriteImage->image.height);
EXPECT_EQ(1.0f, one.spriteImage->pixelRatio);
- const size_t bytes = atlas.getTextureWidth() * atlas.getTextureHeight() * 4;
- const auto hash = test::crc64(reinterpret_cast<const char*>(atlas.getData()), bytes);
- EXPECT_EQ(0x0000000000000000u, hash) << std::hex << hash;
+ EXPECT_EQ(readImage("test/fixtures/annotations/result-spriteatlas-empty.png"),
+ imageFromAtlas(atlas));
// Update sprite
PremultipliedImage image2(16, 12);
@@ -148,16 +152,12 @@ TEST(Sprite, SpriteAtlasUpdates) {
ASSERT_EQ(newSprite, store.getSprite("one"));
// Atlas texture hasn't changed yet.
- const auto hash2 = test::crc64(reinterpret_cast<const char*>(atlas.getData()), bytes);
- EXPECT_EQ(0x0000000000000000u, hash2) << std::hex << hash2;
+ EXPECT_EQ(readImage("test/fixtures/annotations/result-spriteatlas-empty.png"),
+ imageFromAtlas(atlas));
atlas.updateDirty();
// Now the atlas texture has changed.
- const auto hash3 = test::crc64(reinterpret_cast<const char*>(atlas.getData()), bytes);
- EXPECT_EQ(0x4E6D4900CD2D9149u, hash3) << std::hex << hash3;
-
- // util::write_file(
- // "test/fixtures/annotations/atlas3.png",
- // util::compress_png(atlas.getTextureWidth(), atlas.getTextureHeight(), atlas.getData()));
+ EXPECT_EQ(readImage("test/fixtures/annotations/result-spriteatlas-updated.png"),
+ imageFromAtlas(atlas));
}
diff --git a/test/sprite/sprite_parser.cpp b/test/sprite/sprite_parser.cpp
index 54c013e936..177662db43 100644
--- a/test/sprite/sprite_parser.cpp
+++ b/test/sprite/sprite_parser.cpp
@@ -11,6 +11,14 @@
using namespace mbgl;
+namespace {
+
+auto readImage(const std::string& name) {
+ return decodeImage(util::read_file(name));
+}
+
+} // namespace
+
TEST(Sprite, SpriteImageCreationInvalid) {
FixtureLog log;
@@ -48,7 +56,8 @@ TEST(Sprite, SpriteImageCreation1x) {
EXPECT_EQ(18, sprite->image.width);
EXPECT_EQ(18, sprite->image.height);
EXPECT_EQ(1, sprite->pixelRatio);
- EXPECT_EQ(0x7FCC5F263D1FFE16u, test::crc64(sprite->image));
+ EXPECT_EQ(readImage("test/fixtures/annotations/result-spriteimagecreation1x-museum.png"),
+ sprite->image);
}
{ // outside image == blank
@@ -59,7 +68,8 @@ TEST(Sprite, SpriteImageCreation1x) {
EXPECT_EQ(16, sprite->image.width);
EXPECT_EQ(16, sprite->image.height);
EXPECT_EQ(1, sprite->pixelRatio);
- EXPECT_EQ(0x0000000000000000u, test::crc64(sprite->image)) << std::hex << test::crc64(sprite->image);
+ EXPECT_EQ(readImage("test/fixtures/annotations/result-spriteimagecreation1x-blank.png"),
+ sprite->image);
}
{ // outside image == blank
@@ -70,7 +80,8 @@ TEST(Sprite, SpriteImageCreation1x) {
EXPECT_EQ(16, sprite->image.width);
EXPECT_EQ(16, sprite->image.height);
EXPECT_EQ(1, sprite->pixelRatio);
- EXPECT_EQ(0x0000000000000000u, test::crc64(sprite->image)) << std::hex << test::crc64(sprite->image);
+ EXPECT_EQ(readImage("test/fixtures/annotations/result-spriteimagecreation1x-blank.png"),
+ sprite->image);
}
}
@@ -85,7 +96,8 @@ TEST(Sprite, SpriteImageCreation2x) {
EXPECT_EQ(36, sprite->image.width);
EXPECT_EQ(36, sprite->image.height);
EXPECT_EQ(2, sprite->pixelRatio);
- EXPECT_EQ(0x85F345098DD4F9E3u, test::crc64(sprite->image));
+ EXPECT_EQ(readImage("test/fixtures/annotations/result-spriteimagecreation2x.png"),
+ sprite->image);
}
TEST(Sprite, SpriteImageCreation1_5x) {
@@ -99,7 +111,8 @@ TEST(Sprite, SpriteImageCreation1_5x) {
EXPECT_EQ(36, sprite->image.width);
EXPECT_EQ(36, sprite->image.height);
EXPECT_EQ(1.5, sprite->pixelRatio);
- EXPECT_EQ(0x85F345098DD4F9E3u, test::crc64(sprite->image));
+ EXPECT_EQ(readImage("test/fixtures/annotations/result-spriteimagecreation1_5x-museum.png"),
+ sprite->image);
// "hospital_icon":{"x":314,"y":518,"width":36,"height":36,"pixelRatio":2,"sdf":false}
const auto sprite2 = createSpriteImage(image_2x, 314, 518, 35, 35, 1.5, false);
@@ -109,7 +122,8 @@ TEST(Sprite, SpriteImageCreation1_5x) {
EXPECT_EQ(35, sprite2->image.width);
EXPECT_EQ(35, sprite2->image.height);
EXPECT_EQ(1.5, sprite2->pixelRatio);
- EXPECT_EQ(14312995667113444493u, test::crc64(sprite2->image));
+ EXPECT_EQ(readImage("test/fixtures/annotations/result-spriteimagecreation1_5x-hospital.png"),
+ sprite2->image);
}
TEST(Sprite, SpriteParsing) {
@@ -204,7 +218,7 @@ TEST(Sprite, SpriteParsing) {
EXPECT_EQ(18, sprite->image.width);
EXPECT_EQ(18, sprite->image.height);
EXPECT_EQ(1, sprite->pixelRatio);
- EXPECT_EQ(0xFF56F5F48F707147u, test::crc64(sprite->image));
+ EXPECT_EQ(readImage("test/fixtures/annotations/result-spriteparsing.png"), sprite->image);
}
}