diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2016-02-17 15:53:14 +0100 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2016-03-22 11:56:01 -0700 |
commit | 1dd81d9776baf9b9ef61b05d29f7acbb0f2a1508 (patch) | |
tree | ded904ed0a8b2d9cb0f3f784d683162e5917e99f /test | |
parent | c608803ca95e833c9312c0f1cd622594224d5458 (diff) | |
download | qtlocation-mapboxgl-1dd81d9776baf9b9ef61b05d29f7acbb0f2a1508.tar.gz |
[test] remove crc64 and compare images
boost's crc64 breaks on iOS
Diffstat (limited to 'test')
14 files changed, 46 insertions, 57 deletions
diff --git a/test/fixtures/annotations/result-spriteatlas-empty.png b/test/fixtures/annotations/result-spriteatlas-empty.png Binary files differnew file mode 100644 index 0000000000..effcd38f1e --- /dev/null +++ b/test/fixtures/annotations/result-spriteatlas-empty.png diff --git a/test/fixtures/annotations/result-spriteatlas-updated.png b/test/fixtures/annotations/result-spriteatlas-updated.png Binary files differnew file mode 100644 index 0000000000..3c850c0a25 --- /dev/null +++ b/test/fixtures/annotations/result-spriteatlas-updated.png diff --git a/test/fixtures/annotations/result-spriteatlas.png b/test/fixtures/annotations/result-spriteatlas.png Binary files differnew file mode 100644 index 0000000000..e886e060fe --- /dev/null +++ b/test/fixtures/annotations/result-spriteatlas.png diff --git a/test/fixtures/annotations/result-spriteatlassize.png b/test/fixtures/annotations/result-spriteatlassize.png Binary files differnew file mode 100644 index 0000000000..d9ae7dab47 --- /dev/null +++ b/test/fixtures/annotations/result-spriteatlassize.png diff --git a/test/fixtures/annotations/result-spriteimagecreation1_5x-hospital.png b/test/fixtures/annotations/result-spriteimagecreation1_5x-hospital.png Binary files differnew file mode 100644 index 0000000000..529b3fe2b4 --- /dev/null +++ b/test/fixtures/annotations/result-spriteimagecreation1_5x-hospital.png diff --git a/test/fixtures/annotations/result-spriteimagecreation1_5x-museum.png b/test/fixtures/annotations/result-spriteimagecreation1_5x-museum.png Binary files differnew file mode 100644 index 0000000000..96cebabc95 --- /dev/null +++ b/test/fixtures/annotations/result-spriteimagecreation1_5x-museum.png diff --git a/test/fixtures/annotations/result-spriteimagecreation1x-blank.png b/test/fixtures/annotations/result-spriteimagecreation1x-blank.png Binary files differnew file mode 100644 index 0000000000..7613586672 --- /dev/null +++ b/test/fixtures/annotations/result-spriteimagecreation1x-blank.png diff --git a/test/fixtures/annotations/result-spriteimagecreation1x-museum.png b/test/fixtures/annotations/result-spriteimagecreation1x-museum.png Binary files differnew file mode 100644 index 0000000000..3f45c7de2b --- /dev/null +++ b/test/fixtures/annotations/result-spriteimagecreation1x-museum.png diff --git a/test/fixtures/annotations/result-spriteimagecreation2x.png b/test/fixtures/annotations/result-spriteimagecreation2x.png Binary files differnew file mode 100644 index 0000000000..96cebabc95 --- /dev/null +++ b/test/fixtures/annotations/result-spriteimagecreation2x.png diff --git a/test/fixtures/annotations/result-spriteparsing.png b/test/fixtures/annotations/result-spriteparsing.png Binary files differnew file mode 100644 index 0000000000..ba5840cdf7 --- /dev/null +++ b/test/fixtures/annotations/result-spriteparsing.png diff --git a/test/fixtures/util.cpp b/test/fixtures/util.cpp index 5617b15e8b..0829fe72d8 100644 --- a/test/fixtures/util.cpp +++ b/test/fixtures/util.cpp @@ -8,11 +8,6 @@ #include <mapbox/pixelmatch.hpp> -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wshadow" -#include <boost/crc.hpp> -#pragma GCC diagnostic pop - #include <csignal> #include <future> @@ -90,22 +85,6 @@ Server::~Server() { } } - -// from https://gist.github.com/ArtemGr/997887 -uint64_t crc64(const char* data, size_t size) { - boost::crc_optimal<64, 0x04C11DB7, 0, 0, false, false> crc; - crc.process_bytes(data, size); - return crc.checksum(); -} - -uint64_t crc64(const std::string& str) { - return crc64(str.data(), str.size()); -} - -uint64_t crc64(const PremultipliedImage &image) { - return crc64(reinterpret_cast<const char*>(image.data.get()), image.size()); -} - PremultipliedImage render(Map& map) { std::promise<PremultipliedImage> promise; map.renderStill([&](std::exception_ptr, PremultipliedImage&& image) { diff --git a/test/fixtures/util.hpp b/test/fixtures/util.hpp index 2e27e5bf0f..911f2073b5 100644 --- a/test/fixtures/util.hpp +++ b/test/fixtures/util.hpp @@ -31,10 +31,6 @@ private: int fd = -1; }; -uint64_t crc64(const char*, size_t); -uint64_t crc64(const std::string&); -uint64_t crc64(const PremultipliedImage&); - PremultipliedImage render(Map&); void checkImage(const std::string& base, 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); } } |