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

#include <mbgl/style/conversion.hpp>
#include <mbgl/style/rapidjson_conversion.hpp>
#include <mbgl/style/conversion/layer.hpp>
#include <mbgl/style/layers/background_layer_impl.hpp>
#include <mbgl/util/rapidjson.hpp>

using namespace mbgl;
using namespace mbgl::style;
using namespace mbgl::style::conversion;
using namespace std::literals::chrono_literals;

auto parseLayer(const std::string& src) {
    JSDocument doc;
    doc.Parse<0>(src);
    return convert<std::unique_ptr<Layer>, JSValue>(doc);
}

TEST(StyleConversion, LayerTransition) {
    auto layer = parseLayer(R"JSON({
        "type": "background",
        "id": "background",
        "paint": {
            "background-color-transition": {
                "duration": 400,
                "delay": 500
            }
        },
        "paint.class": {
            "background-color-transition": {
                "duration": 100
            }
        }
    })JSON");

    ASSERT_EQ(400ms, *(*layer)->as<BackgroundLayer>()->impl->paint.cascading
        .get<BackgroundColor>().getTransition({}).duration);
    ASSERT_EQ(500ms, *(*layer)->as<BackgroundLayer>()->impl->paint.cascading
        .get<BackgroundColor>().getTransition({}).delay);

    ASSERT_EQ(100ms, *(*layer)->as<BackgroundLayer>()->impl->paint.cascading
        .get<BackgroundColor>().getTransition({"class"}).duration);
    ASSERT_FALSE(bool((*layer)->as<BackgroundLayer>()->impl->paint.cascading
        .get<BackgroundColor>().getTransition({"class"}).delay));
}