[test] remove crc64 and compare images
boost's crc64 breaks on iOS
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <algorithm>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
@@ -26,6 +27,12 @@ public:
|
||||
height(h),
|
||||
data(std::move(data_)) {}
|
||||
|
||||
bool operator==(const Image& rhs) const {
|
||||
return width == rhs.width && height == rhs.height &&
|
||||
std::equal(data.get(), data.get() + size(), rhs.data.get(),
|
||||
rhs.data.get() + rhs.size());
|
||||
}
|
||||
|
||||
size_t stride() const { return width * 4; }
|
||||
size_t size() const { return width * height * 4; }
|
||||
|
||||
|
||||
BIN
test/fixtures/annotations/result-spriteatlas-empty.png
vendored
Normal file
|
After Width: | Height: | Size: 110 B |
BIN
test/fixtures/annotations/result-spriteatlas-updated.png
vendored
Normal file
|
After Width: | Height: | Size: 135 B |
BIN
test/fixtures/annotations/result-spriteatlas.png
vendored
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
BIN
test/fixtures/annotations/result-spriteatlassize.png
vendored
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
BIN
test/fixtures/annotations/result-spriteimagecreation1_5x-hospital.png
vendored
Normal file
|
After Width: | Height: | Size: 838 B |
BIN
test/fixtures/annotations/result-spriteimagecreation1_5x-museum.png
vendored
Normal file
|
After Width: | Height: | Size: 918 B |
BIN
test/fixtures/annotations/result-spriteimagecreation1x-blank.png
vendored
Normal file
|
After Width: | Height: | Size: 91 B |
BIN
test/fixtures/annotations/result-spriteimagecreation1x-museum.png
vendored
Normal file
|
After Width: | Height: | Size: 647 B |
BIN
test/fixtures/annotations/result-spriteimagecreation2x.png
vendored
Normal file
|
After Width: | Height: | Size: 918 B |
BIN
test/fixtures/annotations/result-spriteparsing.png
vendored
Normal file
|
After Width: | Height: | Size: 730 B |
21
test/fixtures/util.cpp
vendored
@@ -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) {
|
||||
|
||||
4
test/fixtures/util.hpp
vendored
@@ -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,
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||