summaryrefslogtreecommitdiff
path: root/test/fixtures
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2015-11-20 14:55:49 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2015-11-25 15:57:37 -0800
commited5eb9edc1458692bf6ff71d5ec95a7d3400318f (patch)
treec60c536731f37b67a7f15abeec22ca46d7cd2f5e /test/fixtures
parent54eff4b4c108598aa30f280de312e4cc88d72368 (diff)
downloadqtlocation-mapboxgl-ed5eb9edc1458692bf6ff71d5ec95a7d3400318f.tar.gz
[test] Add pixelmatch; use in annotation tests
Diffstat (limited to 'test/fixtures')
-rw-r--r--test/fixtures/annotations/add_multiple/expected.pngbin0 -> 4589 bytes
-rw-r--r--test/fixtures/annotations/custom_icon/expected.pngbin0 -> 1300 bytes
-rw-r--r--test/fixtures/annotations/fill_annotation/expected.pngbin0 -> 1543 bytes
-rw-r--r--test/fixtures/annotations/line_annotation/expected.pngbin0 -> 2412 bytes
-rw-r--r--test/fixtures/annotations/non_immediate_add/expected.pngbin0 -> 1543 bytes
-rw-r--r--test/fixtures/annotations/point_annotation/expected.pngbin0 -> 4273 bytes
-rw-r--r--test/fixtures/annotations/remove_point/expected.pngbin0 -> 1238 bytes
-rw-r--r--test/fixtures/annotations/remove_shape/expected.pngbin0 -> 1238 bytes
-rw-r--r--test/fixtures/annotations/style_sourced_shape_annotation/expected.pngbin0 -> 1538 bytes
-rw-r--r--test/fixtures/annotations/switch_style/expected.pngbin0 -> 4273 bytes
-rw-r--r--test/fixtures/util.cpp60
-rw-r--r--test/fixtures/util.hpp9
12 files changed, 69 insertions, 0 deletions
diff --git a/test/fixtures/annotations/add_multiple/expected.png b/test/fixtures/annotations/add_multiple/expected.png
new file mode 100644
index 0000000000..deedf84330
--- /dev/null
+++ b/test/fixtures/annotations/add_multiple/expected.png
Binary files differ
diff --git a/test/fixtures/annotations/custom_icon/expected.png b/test/fixtures/annotations/custom_icon/expected.png
new file mode 100644
index 0000000000..924e4df403
--- /dev/null
+++ b/test/fixtures/annotations/custom_icon/expected.png
Binary files differ
diff --git a/test/fixtures/annotations/fill_annotation/expected.png b/test/fixtures/annotations/fill_annotation/expected.png
new file mode 100644
index 0000000000..30f6f1eb59
--- /dev/null
+++ b/test/fixtures/annotations/fill_annotation/expected.png
Binary files differ
diff --git a/test/fixtures/annotations/line_annotation/expected.png b/test/fixtures/annotations/line_annotation/expected.png
new file mode 100644
index 0000000000..067027f1d1
--- /dev/null
+++ b/test/fixtures/annotations/line_annotation/expected.png
Binary files differ
diff --git a/test/fixtures/annotations/non_immediate_add/expected.png b/test/fixtures/annotations/non_immediate_add/expected.png
new file mode 100644
index 0000000000..30f6f1eb59
--- /dev/null
+++ b/test/fixtures/annotations/non_immediate_add/expected.png
Binary files differ
diff --git a/test/fixtures/annotations/point_annotation/expected.png b/test/fixtures/annotations/point_annotation/expected.png
new file mode 100644
index 0000000000..33299a2d6a
--- /dev/null
+++ b/test/fixtures/annotations/point_annotation/expected.png
Binary files differ
diff --git a/test/fixtures/annotations/remove_point/expected.png b/test/fixtures/annotations/remove_point/expected.png
new file mode 100644
index 0000000000..04f8682f88
--- /dev/null
+++ b/test/fixtures/annotations/remove_point/expected.png
Binary files differ
diff --git a/test/fixtures/annotations/remove_shape/expected.png b/test/fixtures/annotations/remove_shape/expected.png
new file mode 100644
index 0000000000..04f8682f88
--- /dev/null
+++ b/test/fixtures/annotations/remove_shape/expected.png
Binary files differ
diff --git a/test/fixtures/annotations/style_sourced_shape_annotation/expected.png b/test/fixtures/annotations/style_sourced_shape_annotation/expected.png
new file mode 100644
index 0000000000..09f48081a8
--- /dev/null
+++ b/test/fixtures/annotations/style_sourced_shape_annotation/expected.png
Binary files differ
diff --git a/test/fixtures/annotations/switch_style/expected.png b/test/fixtures/annotations/switch_style/expected.png
new file mode 100644
index 0000000000..33299a2d6a
--- /dev/null
+++ b/test/fixtures/annotations/switch_style/expected.png
Binary files differ
diff --git a/test/fixtures/util.cpp b/test/fixtures/util.cpp
index aad349d668..aa6371a4c7 100644
--- a/test/fixtures/util.cpp
+++ b/test/fixtures/util.cpp
@@ -1,6 +1,10 @@
#include "util.hpp"
#include <mbgl/platform/log.hpp>
+#include <mbgl/util/image.hpp>
+#include <mbgl/util/io.hpp>
+
+#include <mapbox/pixelmatch.hpp>
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wshadow"
@@ -81,5 +85,61 @@ uint64_t crc64(const std::string& str) {
return crc64(str.data(), str.size());
}
+UnassociatedImage unpremultiply(const PremultipliedImage& src) {
+ UnassociatedImage dst { src.width, src.height };
+ std::copy(src.data.get(), src.data.get() + src.size(), dst.data.get());
+
+ uint8_t* data = dst.data.get();
+ for (size_t i = 0; i < dst.size(); i += 4) {
+ uint8_t& r = data[i + 0];
+ uint8_t& g = data[i + 1];
+ uint8_t& b = data[i + 2];
+ uint8_t& a = data[i + 3];
+ if (a) {
+ r = (255 * r + (a / 2)) / a;
+ g = (255 * g + (a / 2)) / a;
+ b = (255 * b + (a / 2)) / a;
+ }
+ }
+
+ return std::move(dst);
+}
+
+void checkImage(const std::string& base,
+ const UnassociatedImage& actual,
+ double imageThreshold,
+ double pixelThreshold) {
+ // TODO: the pixels produced by Map::renderStill are probably actually premultiplied,
+ // but Map::renderStill produces an UnassociatedImage. This probably should be fixed;
+ // here we just hack around it by copying the pixels to a PremultipliedImage (and
+ // un-premultiplying them when updating expected.png, since encodePNG wants
+ // un-premultiplied pixels).
+ PremultipliedImage actualActual { actual.width, actual.height };
+ std::copy(actual.data.get(), actual.data.get() + actual.size(), actualActual.data.get());
+
+ if (getenv("UPDATE")) {
+ util::write_file(base + "/expected.png", encodePNG(unpremultiply(actualActual)));
+ return;
+ }
+
+ PremultipliedImage expected = decodeImage(util::read_file(base + "/expected.png"));
+ UnassociatedImage diff { expected.width, expected.height };
+
+ ASSERT_EQ(expected.width, actual.width);
+ ASSERT_EQ(expected.height, actual.height);
+
+ double pixels = mapbox::pixelmatch(actual.data.get(),
+ expected.data.get(),
+ expected.width,
+ expected.height,
+ diff.data.get(),
+ pixelThreshold);
+
+ EXPECT_LE(pixels / (expected.width * expected.height), imageThreshold);
+
+ util::write_file(base + "/actual.png", encodePNG(actual));
+ util::write_file(base + "/diff.png", encodePNG(diff));
+}
+
}
}
diff --git a/test/fixtures/util.hpp b/test/fixtures/util.hpp
index fbee03c2d1..b369979e9c 100644
--- a/test/fixtures/util.hpp
+++ b/test/fixtures/util.hpp
@@ -1,6 +1,10 @@
#ifndef MBGL_TEST_UTIL
#define MBGL_TEST_UTIL
+#include <mbgl/util/image.hpp>
+
+#include <cstdint>
+
#include <gtest/gtest.h>
#define SCOPED_TEST(name) \
@@ -20,6 +24,11 @@ void stopServer(pid_t pid);
uint64_t crc64(const char*, size_t);
uint64_t crc64(const std::string&);
+void checkImage(const std::string& base,
+ const UnassociatedImage& actual,
+ double imageThreshold = 0,
+ double pixelThreshold = 0);
+
}
}