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
|
#include <mbgl/test/util.hpp>
#include <mbgl/test/stub_file_source.hpp>
#include <mbgl/style/style.hpp>
#include <mbgl/source/source.hpp>
#include <mbgl/util/io.hpp>
using namespace mbgl;
TEST(Style, UnusedSource) {
util::RunLoop loop;
StubFileSource fileSource;
Style style { fileSource, 1.0 };
auto now = Clock::now();
style.setJSON(util::read_file("test/fixtures/resources/style-unused-sources.json"), "");
style.cascade(now, MapMode::Still);
style.recalculate(0, now, MapMode::Still);
Source *usedSource = style.getSource("usedsource");
EXPECT_TRUE(usedSource);
EXPECT_TRUE(usedSource->isLoaded());
Source *unusedSource = style.getSource("unusedsource");
EXPECT_TRUE(unusedSource);
EXPECT_FALSE(unusedSource->isLoaded());
}
TEST(Style, UnusedSourceActiveViaClassUpdate) {
util::RunLoop loop;
StubFileSource fileSource;
Style style { fileSource, 1.0 };
style.setJSON(util::read_file("test/fixtures/resources/style-unused-sources.json"), "");
EXPECT_TRUE(style.addClass("visible"));
EXPECT_TRUE(style.hasClass("visible"));
auto now = Clock::now();
style.cascade(now, MapMode::Still);
style.recalculate(0, now, MapMode::Still);
Source *unusedSource = style.getSource("unusedsource");
EXPECT_TRUE(unusedSource);
EXPECT_TRUE(unusedSource->isLoaded());
// Style classes should be cleared upon new style load.
style.setJSON(util::read_file("test/fixtures/resources/style-unused-sources.json"), "");
EXPECT_FALSE(style.hasClass("visible"));
now = Clock::now();
style.cascade(now, MapMode::Still);
style.recalculate(0, now, MapMode::Still);
unusedSource = style.getSource("unusedsource");
EXPECT_TRUE(unusedSource);
EXPECT_FALSE(unusedSource->isLoaded());
}
|