summaryrefslogtreecommitdiff
path: root/test/style
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2019-12-09 15:09:42 +0100
committerAlexander Shalamov <alexander.shalamov@mapbox.com>2020-01-15 15:02:11 +0200
commit62b0f4cde289e5918c41d5b69b0a03baa6821862 (patch)
tree2042319da9abd756564dcbba7812d4868a177800 /test/style
parent4b171cccf1c4012f8962b022f86c4ac8d73f09df (diff)
downloadqtlocation-mapboxgl-62b0f4cde289e5918c41d5b69b0a03baa6821862.tar.gz
[core] Add stretches and content to style::Image
Diffstat (limited to 'test/style')
-rw-r--r--test/style/style_image.test.cpp85
1 files changed, 79 insertions, 6 deletions
diff --git a/test/style/style_image.test.cpp b/test/style/style_image.test.cpp
index e49bf37582..75dafb9938 100644
--- a/test/style/style_image.test.cpp
+++ b/test/style/style_image.test.cpp
@@ -10,8 +10,8 @@ TEST(StyleImage, ZeroWidth) {
try {
style::Image("test", PremultipliedImage({ 0, 16 }), 2.0);
FAIL() << "Expected exception";
- } catch (util::SpriteImageException& ex) {
- EXPECT_STREQ("Sprite image dimensions may not be zero", ex.what());
+ } catch (util::StyleImageException& ex) {
+ EXPECT_STREQ("dimensions may not be zero", ex.what());
}
}
@@ -19,8 +19,8 @@ TEST(StyleImage, ZeroHeight) {
try {
style::Image("test", PremultipliedImage({ 16, 0 }), 2.0);
FAIL() << "Expected exception";
- } catch (util::SpriteImageException& ex) {
- EXPECT_STREQ("Sprite image dimensions may not be zero", ex.what());
+ } catch (util::StyleImageException& ex) {
+ EXPECT_STREQ("dimensions may not be zero", ex.what());
}
}
@@ -28,8 +28,8 @@ TEST(StyleImage, ZeroRatio) {
try {
style::Image("test", PremultipliedImage({ 16, 16 }), 0.0);
FAIL() << "Expected exception";
- } catch (util::SpriteImageException& ex) {
- EXPECT_STREQ("Sprite pixelRatio may not be <= 0", ex.what());
+ } catch (util::StyleImageException& ex) {
+ EXPECT_STREQ("pixelRatio may not be <= 0", ex.what());
}
}
@@ -46,3 +46,76 @@ TEST(StyleImage, FractionalRatio) {
EXPECT_EQ(12u, image.getImage().size.height);
EXPECT_EQ(1.5, image.getPixelRatio());
}
+
+TEST(StyleImage, InvalidStretchX) {
+ // out of left bound
+ try {
+ style::Image("test", PremultipliedImage({16, 16}), 1, {{-1, 3}});
+ FAIL() << "Expected exception";
+ } catch (util::StyleImageException& ex) {
+ EXPECT_STREQ("stretchX is out of bounds or overlapping", ex.what());
+ }
+
+ // overlapping
+ try {
+ style::Image("test", PremultipliedImage({16, 16}), 1, {{0, 3}, {2., 4.}});
+ FAIL() << "Expected exception";
+ } catch (util::StyleImageException& ex) {
+ EXPECT_STREQ("stretchX is out of bounds or overlapping", ex.what());
+ }
+}
+
+TEST(StyleImage, InvalidStretchY) {
+ // out of bottom bound
+ try {
+ style::Image("test", PremultipliedImage({16, 16}), 1, {}, {{14, 20}});
+ FAIL() << "Expected exception";
+ } catch (util::StyleImageException& ex) {
+ EXPECT_STREQ("stretchX is out of bounds or overlapping", ex.what());
+ }
+
+ // must be sorted
+ try {
+ style::Image("test", PremultipliedImage({16, 16}), 1, {}, {{4, 8}, {2, 3}});
+ FAIL() << "Expected exception";
+ } catch (util::StyleImageException& ex) {
+ EXPECT_STREQ("stretchX is out of bounds or overlapping", ex.what());
+ }
+}
+
+TEST(StyleImage, InvalidContent) {
+ // bottom right out of bounds
+ try {
+ style::Image("test", PremultipliedImage({16, 16}), 1, {}, {}, style::ImageContent{0, 0, 24, 28});
+ FAIL() << "Expected exception";
+ } catch (util::StyleImageException& ex) {
+ EXPECT_STREQ("content area is invalid", ex.what());
+ }
+
+ // bottom right < top left
+ try {
+ style::Image("test", PremultipliedImage({16, 16}), 1, {}, {}, style::ImageContent{14, 14, 12, 10});
+ FAIL() << "Expected exception";
+ } catch (util::StyleImageException& ex) {
+ EXPECT_STREQ("content area is invalid", ex.what());
+ }
+
+ // top left out of bounds
+ try {
+ style::Image("test", PremultipliedImage({16, 16}), 1, {}, {}, style::ImageContent{-2, -8, 12, 10});
+ FAIL() << "Expected exception";
+ } catch (util::StyleImageException& ex) {
+ EXPECT_STREQ("content area is invalid", ex.what());
+ }
+}
+
+TEST(StyleImage, StretchContent) {
+ style::Image image(
+ "test", PremultipliedImage({16, 16}), 1, {{2, 14}}, {{0, 4}, {12, 16}}, style::ImageContent{2, 2, 14, 14});
+ EXPECT_EQ(16u, image.getImage().size.width);
+ EXPECT_EQ(16u, image.getImage().size.height);
+ EXPECT_EQ(1.0, image.getPixelRatio());
+ EXPECT_EQ((style::ImageStretches{{2, 14}}), image.getStretchX());
+ EXPECT_EQ((style::ImageStretches{{0, 4}, {12, 16}}), image.getStretchY());
+ EXPECT_EQ((style::ImageContent{2, 2, 14, 14}), image.getContent());
+}