summaryrefslogtreecommitdiff
path: root/test/annotations/sprite_image.cpp
blob: 30542778fd8787bc4a01273480debb60c65aa7e4 (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "../fixtures/util.hpp"

#include <mbgl/annotation/sprite_image.hpp>
#include <mbgl/util/exception.hpp>

using namespace mbgl;

TEST(Annotations, SpriteImageZeroWidth) {
    try {
        SpriteImage(0, 16, 2, "");
        FAIL() << "Expected exception";
    } catch (util::SpriteImageException& ex) {
        EXPECT_STREQ("Sprite image dimensions may not be zero", ex.what());
    }
}

TEST(Annotations, SpriteImageZeroHeight) {
    try {
        SpriteImage(16, 0, 2, "");
        FAIL() << "Expected exception";
    } catch (util::SpriteImageException& ex) {
        EXPECT_STREQ("Sprite image dimensions may not be zero", ex.what());
    }
}

TEST(Annotations, SpriteImageZeroRatio) {
    try {
        SpriteImage(16, 16, 0, "");
        FAIL() << "Expected exception";
    } catch (util::SpriteImageException& ex) {
        EXPECT_STREQ("Sprite image dimensions may not be zero", ex.what());
    }
}

TEST(Annotations, SpriteImageMismatchedData) {
    try {
        SpriteImage(16, 16, 2, "");
        FAIL() << "Expected exception";
    } catch (util::SpriteImageException& ex) {
        EXPECT_STREQ("Sprite image pixel count mismatch", ex.what());
    }
}

TEST(Annotations, SpriteImage) {
    std::string pixels(32 * 24 * 4, '\0');
    SpriteImage sprite(16, 12, 2, std::move(pixels));
    EXPECT_EQ(16, sprite.width);
    EXPECT_EQ(32, sprite.pixelWidth);
    EXPECT_EQ(12, sprite.height);
    EXPECT_EQ(24, sprite.pixelHeight);
    EXPECT_EQ(2, sprite.ratio);
    EXPECT_EQ(32u * 24 * 4, sprite.data.size());
}

TEST(Annotations, SpriteImageFractionalRatio) {
    std::string pixels(20 * 12 * 4, '\0');
    SpriteImage sprite(13, 8, 1.5, std::move(pixels));
    EXPECT_EQ(13, sprite.width);
    EXPECT_EQ(20, sprite.pixelWidth);
    EXPECT_EQ(8, sprite.height);
    EXPECT_EQ(12, sprite.pixelHeight);
    EXPECT_EQ(1.5, sprite.ratio);
    EXPECT_EQ(20u * 12 * 4, sprite.data.size());
}