1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
#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("test", PremultipliedImage({ 0, 16 }), 2.0);
FAIL() << "Expected exception";
} catch (util::StyleImageException& ex) {
EXPECT_STREQ("dimensions may not be zero", ex.what());
}
}
TEST(StyleImage, ZeroHeight) {
try {
style::Image("test", PremultipliedImage({ 16, 0 }), 2.0);
FAIL() << "Expected exception";
} catch (util::StyleImageException& ex) {
EXPECT_STREQ("dimensions may not be zero", ex.what());
}
}
TEST(StyleImage, ZeroRatio) {
try {
style::Image("test", PremultipliedImage({ 16, 16 }), 0.0);
FAIL() << "Expected exception";
} catch (util::StyleImageException& ex) {
EXPECT_STREQ("pixelRatio may not be <= 0", ex.what());
}
}
TEST(StyleImage, Retina) {
style::Image image("test", PremultipliedImage({ 32, 24 }), 2.0);
EXPECT_EQ(32u, image.getImage().size.width);
EXPECT_EQ(24u, image.getImage().size.height);
EXPECT_EQ(2, image.getPixelRatio());
}
TEST(StyleImage, FractionalRatio) {
style::Image image("test", PremultipliedImage({ 20, 12 }), 1.5);
EXPECT_EQ(20u, image.getImage().size.width);
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());
}
|