summaryrefslogtreecommitdiff
path: root/test/sprite
diff options
context:
space:
mode:
authorAnsis Brammanis <brammanis@gmail.com>2016-03-30 15:39:50 -0700
committerAnsis Brammanis <brammanis@gmail.com>2016-03-31 10:27:42 -0700
commit415ea295c512c52731a98b4a83ec804434ff0d25 (patch)
tree739a555f4351555bfabdb1220f4285a9cb6c2d16 /test/sprite
parent3f10f74a70f992f1fdbc2475b8fa3007ae3b2c5f (diff)
downloadqtlocation-mapboxgl-415ea295c512c52731a98b4a83ec804434ff0d25.tar.gz
[core] make sprite metrics checking stricter
- check that sprite metrics are within the bounds of the sprite. fix #714 - make sprite metrics problems Errors instead of Warnings - check for negative image width, height
Diffstat (limited to 'test/sprite')
-rw-r--r--test/sprite/sprite_parser.cpp43
1 files changed, 13 insertions, 30 deletions
diff --git a/test/sprite/sprite_parser.cpp b/test/sprite/sprite_parser.cpp
index 6ac155468a..318911674e 100644
--- a/test/sprite/sprite_parser.cpp
+++ b/test/sprite/sprite_parser.cpp
@@ -29,13 +29,20 @@ TEST(Sprite, SpriteImageCreationInvalid) {
ASSERT_EQ(nullptr, createSpriteImage(image_1x, 0, 0, 0, 16, 1, false)); // width == 0
ASSERT_EQ(nullptr, createSpriteImage(image_1x, 0, 0, 16, 0, 1, false)); // height == 0
+ ASSERT_EQ(nullptr, createSpriteImage(image_1x, 0, 0, -1, 16, 1, false)); // width < 0
+ ASSERT_EQ(nullptr, createSpriteImage(image_1x, 0, 0, 16, -1, 1, false)); // height < 0
ASSERT_EQ(nullptr, createSpriteImage(image_1x, 0, 0, 1, 1, 0, false)); // ratio == 0
+ ASSERT_EQ(nullptr, createSpriteImage(image_1x, 0, 0, 1, 1, -1, false)); // ratio < 0
ASSERT_EQ(nullptr, createSpriteImage(image_1x, 0, 0, 1, 1, 23, false)); // ratio too large
ASSERT_EQ(nullptr, createSpriteImage(image_1x, 0, 0, 2048, 16, 1, false)); // too wide
ASSERT_EQ(nullptr, createSpriteImage(image_1x, 0, 0, 16, 1025, 1, false)); // too tall
+ ASSERT_EQ(nullptr, createSpriteImage(image_1x, -1, 0, 16, 16, 1, false)); // srcX < 0
+ ASSERT_EQ(nullptr, createSpriteImage(image_1x, 0, -1, 16, 16, 1, false)); // srcY < 0
+ ASSERT_EQ(nullptr, createSpriteImage(image_1x, 0, 0, image_1x.width + 1, 16, 1, false)); // right edge out of bounds
+ ASSERT_EQ(nullptr, createSpriteImage(image_1x, 0, 0, 16, image_1x.height + 1, 1, false)); // bottom edge out of bounds
- EXPECT_EQ(6u, log.count({
- EventSeverity::Warning,
+ EXPECT_EQ(13u, log.count({
+ EventSeverity::Error,
Event::Sprite,
int64_t(-1),
"Can't create sprite with invalid metrics",
@@ -59,30 +66,6 @@ TEST(Sprite, SpriteImageCreation1x) {
EXPECT_EQ(readImage("test/fixtures/annotations/result-spriteimagecreation1x-museum.png"),
sprite->image);
}
-
- { // outside image == blank
- const auto sprite = createSpriteImage(image_1x, 200, 0, 16, 16, 1, false);
- ASSERT_TRUE(sprite.get());
- EXPECT_EQ(16, sprite->getWidth());
- EXPECT_EQ(16, sprite->getHeight());
- EXPECT_EQ(16, sprite->image.width);
- EXPECT_EQ(16, sprite->image.height);
- EXPECT_EQ(1, sprite->pixelRatio);
- EXPECT_EQ(readImage("test/fixtures/annotations/result-spriteimagecreation1x-blank.png"),
- sprite->image);
- }
-
- { // outside image == blank
- const auto sprite = createSpriteImage(image_1x, 0, 300, 16, 16, 1, false);
- ASSERT_TRUE(sprite.get());
- EXPECT_EQ(16, sprite->getWidth());
- EXPECT_EQ(16, sprite->getHeight());
- EXPECT_EQ(16, sprite->image.width);
- EXPECT_EQ(16, sprite->image.height);
- EXPECT_EQ(1, sprite->pixelRatio);
- EXPECT_EQ(readImage("test/fixtures/annotations/result-spriteimagecreation1x-blank.png"),
- sprite->image);
- }
}
TEST(Sprite, SpriteImageCreation2x) {
@@ -242,7 +225,7 @@ TEST(Sprite, SpriteParsingEmptyImage) {
EXPECT_EQ(0u, images.size());
EXPECT_EQ(1u, log.count({
- EventSeverity::Warning,
+ EventSeverity::Error,
Event::Sprite,
int64_t(-1),
"Can't create sprite with invalid metrics",
@@ -275,7 +258,7 @@ TEST(Sprite, SpriteParsingWidthTooBig) {
"Value of 'width' must be an integer between 0 and 65535",
}));
EXPECT_EQ(1u, log.count({
- EventSeverity::Warning,
+ EventSeverity::Error,
Event::Sprite,
int64_t(-1),
"Can't create sprite with invalid metrics",
@@ -298,7 +281,7 @@ TEST(Sprite, SpriteParsingNegativeWidth) {
"Value of 'width' must be an integer between 0 and 65535",
}));
EXPECT_EQ(1u, log.count({
- EventSeverity::Warning,
+ EventSeverity::Error,
Event::Sprite,
int64_t(-1),
"Can't create sprite with invalid metrics",
@@ -315,7 +298,7 @@ TEST(Sprite, SpriteParsingNullRatio) {
EXPECT_EQ(0u, images.size());
EXPECT_EQ(1u, log.count({
- EventSeverity::Warning,
+ EventSeverity::Error,
Event::Sprite,
int64_t(-1),
"Can't create sprite with invalid metrics",