summaryrefslogtreecommitdiff
path: root/test/style/style_image.test.cpp
blob: e49bf37582f0f506eb7bce3f95af8f71bf4eda92 (plain)
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
#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::SpriteImageException& ex) {
        EXPECT_STREQ("Sprite image dimensions may not be zero", ex.what());
    }
}

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());
    }
}

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());
    }
}

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());
}