From 493c72b1f470f839ee6d9e56583c17837a9809a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Mon, 6 Jul 2015 16:29:14 +0200 Subject: [PATCH] move crc64() to test fixture --- test/annotations/sprite_atlas.cpp | 28 +++++----------------------- test/annotations/sprite_parser.cpp | 30 +++++++----------------------- test/fixtures/util.cpp | 16 ++++++++++++++++ test/fixtures/util.hpp | 3 +++ 4 files changed, 31 insertions(+), 46 deletions(-) diff --git a/test/annotations/sprite_atlas.cpp b/test/annotations/sprite_atlas.cpp index f1684ff18..c2a566f2f 100644 --- a/test/annotations/sprite_atlas.cpp +++ b/test/annotations/sprite_atlas.cpp @@ -6,24 +6,6 @@ #include #include -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wshadow" -#include -#pragma GCC diagnostic pop - -namespace { - -// 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(); -} - -} // anonymous namespace - -using namespace mbgl; - using namespace mbgl; TEST(Annotations, SpriteAtlas) { @@ -84,7 +66,7 @@ TEST(Annotations, SpriteAtlas) { EXPECT_EQ(18, metro2.pos.originalH); const size_t bytes = atlas.getTextureWidth() * atlas.getTextureHeight() * 4; - const auto hash = crc64(reinterpret_cast(atlas.getData()), bytes); + const auto hash = test::crc64(reinterpret_cast(atlas.getData()), bytes); EXPECT_EQ(0x9875FC0595489A9Fu, hash) << std::hex << hash; // util::write_file( @@ -118,7 +100,7 @@ TEST(Annotations, SpriteAtlasSize) { EXPECT_EQ(1.0f, metro.texture->pixelRatio); const size_t bytes = atlas.getTextureWidth() * atlas.getTextureHeight() * 4; - const auto hash = crc64(reinterpret_cast(atlas.getData()), bytes); + const auto hash = test::crc64(reinterpret_cast(atlas.getData()), bytes); EXPECT_EQ(0x2CDDA7DBB04D116Du, hash) << std::hex << hash; // util::write_file( @@ -152,7 +134,7 @@ TEST(Annotations, SpriteAtlasUpdates) { EXPECT_EQ(1.0f, one.texture->pixelRatio); const size_t bytes = atlas.getTextureWidth() * atlas.getTextureHeight() * 4; - const auto hash = crc64(reinterpret_cast(atlas.getData()), bytes); + const auto hash = test::crc64(reinterpret_cast(atlas.getData()), bytes); EXPECT_EQ(0x0000000000000000u, hash) << std::hex << hash; // Update sprite @@ -161,13 +143,13 @@ TEST(Annotations, SpriteAtlasUpdates) { ASSERT_EQ(newSprite, store.getSprite("one")); // Atlas texture hasn't changed yet. - const auto hash2 = crc64(reinterpret_cast(atlas.getData()), bytes); + const auto hash2 = test::crc64(reinterpret_cast(atlas.getData()), bytes); EXPECT_EQ(0x0000000000000000u, hash2) << std::hex << hash2; atlas.updateDirty(); // Now the atlas texture has changed. - const auto hash3 = crc64(reinterpret_cast(atlas.getData()), bytes); + const auto hash3 = test::crc64(reinterpret_cast(atlas.getData()), bytes); EXPECT_EQ(0x4E6D4900CD2D9149u, hash3) << std::hex << hash3; // util::write_file( diff --git a/test/annotations/sprite_parser.cpp b/test/annotations/sprite_parser.cpp index 17193273e..280a19c50 100644 --- a/test/annotations/sprite_parser.cpp +++ b/test/annotations/sprite_parser.cpp @@ -6,24 +6,8 @@ #include #include -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wshadow" -#include -#pragma GCC diagnostic pop - #include -namespace { - -// from https://gist.github.com/ArtemGr/997887 -uint64_t crc64(const std::string& str) { - boost::crc_optimal<64, 0x04C11DB7, 0, 0, false, false> crc; - crc.process_bytes(str.data(), str.size()); - return crc.checksum(); -} - -} // anonymous namespace - using namespace mbgl; TEST(Annotations, SpriteImageCreationInvalid) { @@ -63,7 +47,7 @@ TEST(Annotations, SpriteImageCreation1x) { EXPECT_EQ(18, sprite->pixelWidth); EXPECT_EQ(18, sprite->pixelHeight); EXPECT_EQ(1, sprite->pixelRatio); - EXPECT_EQ(0x7FCC5F263D1FFE16u, crc64(sprite->data)); + EXPECT_EQ(0x7FCC5F263D1FFE16u, test::crc64(sprite->data)); } { // outside image == blank @@ -74,7 +58,7 @@ TEST(Annotations, SpriteImageCreation1x) { EXPECT_EQ(16, sprite->pixelWidth); EXPECT_EQ(16, sprite->pixelHeight); EXPECT_EQ(1, sprite->pixelRatio); - EXPECT_EQ(0x0000000000000000u, crc64(sprite->data)) << std::hex << crc64(sprite->data); + EXPECT_EQ(0x0000000000000000u, test::crc64(sprite->data)) << std::hex << test::crc64(sprite->data); } { // outside image == blank @@ -85,7 +69,7 @@ TEST(Annotations, SpriteImageCreation1x) { EXPECT_EQ(16, sprite->pixelWidth); EXPECT_EQ(16, sprite->pixelHeight); EXPECT_EQ(1, sprite->pixelRatio); - EXPECT_EQ(0x0000000000000000u, crc64(sprite->data)) << std::hex << crc64(sprite->data); + EXPECT_EQ(0x0000000000000000u, test::crc64(sprite->data)) << std::hex << test::crc64(sprite->data); } } @@ -101,7 +85,7 @@ TEST(Annotations, SpriteImageCreation2x) { EXPECT_EQ(36, sprite->pixelWidth); EXPECT_EQ(36, sprite->pixelHeight); EXPECT_EQ(2, sprite->pixelRatio); - EXPECT_EQ(0x85F345098DD4F9E3u, crc64(sprite->data)); + EXPECT_EQ(0x85F345098DD4F9E3u, test::crc64(sprite->data)); } TEST(Annotations, SpriteImageCreation1_5x) { @@ -116,7 +100,7 @@ TEST(Annotations, SpriteImageCreation1_5x) { EXPECT_EQ(36, sprite->pixelWidth); EXPECT_EQ(36, sprite->pixelHeight); EXPECT_EQ(1.5, sprite->pixelRatio); - EXPECT_EQ(0x85F345098DD4F9E3u, crc64(sprite->data)); + EXPECT_EQ(0x85F345098DD4F9E3u, test::crc64(sprite->data)); // "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); @@ -126,7 +110,7 @@ TEST(Annotations, SpriteImageCreation1_5x) { EXPECT_EQ(36, sprite2->pixelWidth); EXPECT_EQ(36, sprite2->pixelHeight); EXPECT_EQ(1.5, sprite2->pixelRatio); - EXPECT_EQ(0x134A530C742DD141u, crc64(sprite2->data)); + EXPECT_EQ(0x134A530C742DD141u, test::crc64(sprite2->data)); } TEST(Annotations, SpriteParsing) { @@ -221,7 +205,7 @@ TEST(Annotations, SpriteParsing) { EXPECT_EQ(18, sprite->pixelWidth); EXPECT_EQ(18, sprite->pixelHeight); EXPECT_EQ(1, sprite->pixelRatio); - EXPECT_EQ(0xFF56F5F48F707147u, crc64(sprite->data)); + EXPECT_EQ(0xFF56F5F48F707147u, test::crc64(sprite->data)); } } diff --git a/test/fixtures/util.cpp b/test/fixtures/util.cpp index 068a3d849..7527f64f9 100644 --- a/test/fixtures/util.cpp +++ b/test/fixtures/util.cpp @@ -2,6 +2,11 @@ #include +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wshadow" +#include +#pragma GCC diagnostic pop + #include #include @@ -57,5 +62,16 @@ void stopServer(pid_t pid) { kill(pid, SIGTERM); } +// 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()); +} + } } diff --git a/test/fixtures/util.hpp b/test/fixtures/util.hpp index dd8539c84..fbee03c2d 100644 --- a/test/fixtures/util.hpp +++ b/test/fixtures/util.hpp @@ -17,6 +17,9 @@ namespace test { pid_t startServer(const char *executable); void stopServer(pid_t pid); +uint64_t crc64(const char*, size_t); +uint64_t crc64(const std::string&); + } }