Skip to content

Commit fcb95bb

Browse files
Add alternative test image
1 parent 4d155a3 commit fcb95bb

File tree

5 files changed

+51
-8
lines changed

5 files changed

+51
-8
lines changed
5.07 KB
Loading

test/include/mbgl/test/util.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,12 @@ void checkImage(const std::string& base,
7474
double imageThreshold = 0,
7575
double pixelThreshold = 0);
7676

77+
void checkImages(const std::vector<std::string>& possibleExpected,
78+
const PremultipliedImage& actual,
79+
double imageThreshold = 0,
80+
double pixelThreshold = 0);
81+
82+
double getImageDiff(const std::string& base, const PremultipliedImage& actual, double pixelThreshold = 0);
83+
7784
} // namespace test
7885
} // namespace mbgl

test/src/mbgl/test/util.cpp

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,44 @@
99
#pragma warning(disable : 4244)
1010
#endif
1111

12+
#include <gmock/gmock-matchers.h>
13+
#include <gmock/gmock-more-matchers.h>
1214
#include <mapbox/pixelmatch.hpp>
1315

1416
#ifdef _MSC_VER
1517
#pragma warning(pop)
1618
#endif
1719

20+
using namespace ::testing;
21+
1822
namespace mbgl {
1923
namespace test {
2024

2125
void checkImage(const std::string& base,
2226
const PremultipliedImage& actual,
2327
double imageThreshold,
2428
double pixelThreshold) {
29+
EXPECT_LE(getImageDiff(base, actual, pixelThreshold), imageThreshold);
30+
}
31+
32+
void checkImages(const std::vector<std::string>& possibleExpected,
33+
const PremultipliedImage& actual,
34+
double imageThreshold,
35+
double pixelThreshold) {
36+
std::vector<double> diffs(0.0, possibleExpected.size());
37+
38+
for (const auto& expected : possibleExpected) {
39+
diffs.push_back(getImageDiff(expected, actual, pixelThreshold));
40+
}
41+
42+
EXPECT_THAT(diffs, Contains(Le(imageThreshold)));
43+
}
44+
45+
double getImageDiff(const std::string& base, const PremultipliedImage& actual, double pixelThreshold) {
2546
#if !TEST_READ_ONLY
2647
if (getenv("UPDATE")) {
2748
util::write_file(base + "/expected.png", encodePNG(actual));
28-
return;
49+
return 0.0;
2950
}
3051
#endif
3152

@@ -44,7 +65,9 @@ void checkImage(const std::string& base,
4465
util::write_file(base + "/actual.png", encodePNG(actual));
4566
#endif
4667

47-
ASSERT_EQ(expected.size, actual.size);
68+
if (expected.size != actual.size) {
69+
return 1.0;
70+
}
4871

4972
uint64_t pixels = mapbox::pixelmatch(actual.data.get(),
5073
expected.data.get(),
@@ -53,11 +76,11 @@ void checkImage(const std::string& base,
5376
diff.data.get(),
5477
pixelThreshold);
5578

56-
EXPECT_LE(static_cast<double>(pixels) / (expected.size.width * expected.size.height), imageThreshold);
57-
5879
#if !TEST_READ_ONLY
5980
util::write_file(base + "/diff.png", encodePNG(diff));
6081
#endif
82+
83+
return static_cast<double>(pixels) / (expected.size.width * expected.size.height);
6184
}
6285

6386
} // namespace test

test/tile/tile_lod.test.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,21 @@ class TileLODTest {
6666
map.getStyle().addLayer(std::move(layer));
6767
}
6868

69-
void checkImage(std::string name, uint32_t expectedTileCount) {
70-
const std::string imageDir = "test/fixtures/tile_lod/" + name;
69+
void checkImage(std::string image, uint32_t expectedTileCount) {
70+
checkImages(std::vector<std::string>{image}, expectedTileCount);
71+
}
7172

72-
test::checkImage(imageDir, frontend.render(map).image, 0.0002, 0.1);
73+
void checkImages(std::vector<std::string> images, uint32_t expectedTileCount) {
74+
const auto result = frontend.render(map);
7375

7476
// check this after frontend.render()
7577
EXPECT_EQ(tileCount, expectedTileCount);
78+
79+
std::transform(images.begin(), images.end(), images.begin(), [](const auto& img) {
80+
return "test/fixtures/tile_lod/" + img;
81+
});
82+
83+
test::checkImages(images, result.image, 0.0002, 0.01);
7684
}
7785
};
7886

@@ -113,7 +121,12 @@ TEST(TileLOD, pitchThreshold) {
113121
test.tileCount = 0;
114122

115123
test.map.jumpTo(CameraOptions().withPitch(pitch + 1.0));
116-
test.checkImage("pitchThreshold", 22);
124+
test.checkImages(
125+
{
126+
"pitchThreshold-line",
127+
"pitchThreshold-polyline",
128+
},
129+
22);
117130
}
118131

119132
TEST(TileLOD, scale) {

0 commit comments

Comments
 (0)