summaryrefslogtreecommitdiff
path: root/test/style
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2017-04-21 14:52:19 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2017-04-24 15:52:28 -0700
commit5dd98df50ba1210b1eef0d8d6655713a725f2995 (patch)
treeb289bb3cbad5d1c3076816f4891a057d6089fc93 /test/style
parent6f708ac5458fe332e25ca398431928b7ff5ba404 (diff)
downloadqtlocation-mapboxgl-5dd98df50ba1210b1eef0d8d6655713a725f2995.tar.gz
[all] Rationalize style::Image
A style has a collection of images, just as it has collections of sources and layers. * Name things appropriately * Use std::unique_ptr
Diffstat (limited to 'test/style')
-rw-r--r--test/style/style_image.test.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/test/style/style_image.test.cpp b/test/style/style_image.test.cpp
new file mode 100644
index 0000000000..319120df83
--- /dev/null
+++ b/test/style/style_image.test.cpp
@@ -0,0 +1,52 @@
+#include <mbgl/test/util.hpp>
+
+#include <mbgl/style/image.hpp>
+#include <mbgl/util/image.hpp>
+#include <mbgl/util/exception.hpp>
+
+using namespace mbgl;
+
+TEST(StyleImage, ZeroWidth) {
+ try {
+ style::Image(PremultipliedImage({ 0, 16 }), 2.0);
+ FAIL() << "Expected exception";
+ } catch (util::SpriteImageException& ex) {
+ EXPECT_STREQ("Sprite image dimensions may not be zero", ex.what());
+ }
+}
+
+TEST(StyleImage, ZeroHeight) {
+ try {
+ style::Image(PremultipliedImage({ 16, 0 }), 2.0);
+ FAIL() << "Expected exception";
+ } catch (util::SpriteImageException& ex) {
+ EXPECT_STREQ("Sprite image dimensions may not be zero", ex.what());
+ }
+}
+
+TEST(StyleImage, ZeroRatio) {
+ try {
+ style::Image(PremultipliedImage({ 16, 16 }), 0.0);
+ FAIL() << "Expected exception";
+ } catch (util::SpriteImageException& ex) {
+ EXPECT_STREQ("Sprite pixelRatio may not be <= 0", ex.what());
+ }
+}
+
+TEST(StyleImage, Retina) {
+ style::Image image(PremultipliedImage({ 32, 24 }), 2.0);
+ EXPECT_EQ(16, image.getWidth());
+ EXPECT_EQ(32u, image.image.size.width);
+ EXPECT_EQ(12, image.getHeight());
+ EXPECT_EQ(24u, image.image.size.height);
+ EXPECT_EQ(2, image.pixelRatio);
+}
+
+TEST(StyleImage, FractionalRatio) {
+ style::Image image(PremultipliedImage({ 20, 12 }), 1.5);
+ EXPECT_EQ(float(20.0 / 1.5), image.getWidth());
+ EXPECT_EQ(20u, image.image.size.width);
+ EXPECT_EQ(float(12.0 / 1.5), image.getHeight());
+ EXPECT_EQ(12u, image.image.size.height);
+ EXPECT_EQ(1.5, image.pixelRatio);
+}