summaryrefslogtreecommitdiff
path: root/test/style/conversion/tileset.test.cpp
blob: f92ed46786e8aa8898b2dee6c0116c9454bf29d2 (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
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
#include <mbgl/test/util.hpp>

#include <mbgl/style/conversion/json.hpp>
#include <mbgl/style/conversion/tileset.hpp>

#include <mbgl/util/logging.hpp>

using namespace mbgl;
using namespace mbgl::style::conversion;

TEST(Tileset, Empty) {
    Error error;
    mbgl::optional<Tileset> converted = convertJSON<Tileset>("{}", error);
    EXPECT_FALSE((bool) converted);
}

TEST(Tileset, ErrorHandling) {
    Error error;
    mbgl::optional<Tileset> converted = convertJSON<Tileset>(R"JSON({
        "tiles": "should not be a string"
    })JSON", error);
    EXPECT_FALSE((bool) converted);
}

TEST(Tileset, InvalidBounds) {
    {
        Error error;
        mbgl::optional<Tileset> converted = convertJSON<Tileset>(R"JSON({
            "tiles": ["http://mytiles"],
            "bounds": [73, -180, -73, -120]
        })JSON", error);

        EXPECT_FALSE((bool) converted);
    }
    {
        Error error;
        mbgl::optional<Tileset> converted = convertJSON<Tileset>(R"JSON({
            "tiles": ["http://mytiles"],
            "bounds": [-120]
        })JSON", error);

        EXPECT_FALSE((bool) converted);
    }
    {
        Error error;
        mbgl::optional<Tileset> converted = convertJSON<Tileset>(R"JSON({
            "tiles": ["http://mytiles"],
            "bounds": "should not be a string"
        })JSON", error);

        EXPECT_FALSE((bool) converted);
    }
}

TEST(Tileset, ValidWorldBounds) {
    Error error;
    mbgl::optional<Tileset> converted = convertJSON<Tileset>(R"JSON({
        "tiles": ["http://mytiles"],
        "bounds": [-180, -90, 180, 90]
    })JSON", error);
    EXPECT_TRUE((bool) converted);
    EXPECT_EQ(converted->bounds, LatLngBounds::hull({90, -180}, {-90, 180}));
}

TEST(Tileset, PointBounds) {
    Error error;
    mbgl::optional<Tileset> converted = convertJSON<Tileset>(R"JSON({
        "tiles": ["http://mytiles"],
        "bounds": [0, 0, 0, 0]
    })JSON", error);
    EXPECT_TRUE((bool) converted);
    EXPECT_EQ(converted->bounds, LatLngBounds::hull({0, 0}, {0, 0}));
}

TEST(Tileset, BoundsAreClamped) {
    Error error;
    mbgl::optional<Tileset> converted = convertJSON<Tileset>(R"JSON({
        "tiles": ["http://mytiles"],
        "bounds": [-181.0000005,-90.000000006,180.00000000000006,91]
    })JSON", error);
    EXPECT_TRUE((bool) converted);
    EXPECT_EQ(converted->bounds, LatLngBounds::hull({90, -180}, {-90, 180}));
}

TEST(Tileset, FullConversion) {
    Error error;
    Tileset converted = *convertJSON<Tileset>(R"JSON({
        "tiles": ["http://mytiles"],
        "scheme": "xyz",
        "minzoom": 1,
        "maxzoom": 2,
        "attribution": "mapbox",
        "bounds": [-180, -73, -120, 73]
    })JSON", error);

    EXPECT_EQ(converted.tiles[0], "http://mytiles");
    EXPECT_EQ(converted.scheme, Tileset::Scheme::XYZ);
    EXPECT_EQ(converted.zoomRange.min, 1);
    EXPECT_EQ(converted.zoomRange.max, 2);
    EXPECT_EQ(converted.attribution, "mapbox");
    EXPECT_EQ(converted.bounds, LatLngBounds::hull({73, -180}, {-73, -120}));
}