diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/map/transform.test.cpp | 81 |
1 files changed, 58 insertions, 23 deletions
diff --git a/test/map/transform.test.cpp b/test/map/transform.test.cpp index 40f94e4f7c..a8869b41bf 100644 --- a/test/map/transform.test.cpp +++ b/test/map/transform.test.cpp @@ -461,41 +461,76 @@ TEST(Transform, Camera) { } TEST(Transform, DefaultTransform) { - Transform transform; + struct TransformObserver : public mbgl::MapObserver { + void onCameraWillChange(MapObserver::CameraChangeMode) final { + cameraWillChangeCallback(); + }; + + void onCameraDidChange(MapObserver::CameraChangeMode) final { + cameraDidChangeCallback(); + }; + + std::function<void()> cameraWillChangeCallback; + std::function<void()> cameraDidChangeCallback; + }; + + uint32_t cameraWillChangeCount = 0; + uint32_t cameraDidChangeCount = 0; + + TransformObserver observer; + observer.cameraWillChangeCallback = [&cameraWillChangeCount]() { cameraWillChangeCount++; }; + observer.cameraDidChangeCallback = [&cameraDidChangeCount]() { cameraDidChangeCount++; }; + + Transform transform(observer); const TransformState& state = transform.getState(); + ASSERT_FALSE(state.valid()); LatLng nullIsland, latLng = {}; ScreenCoordinate center, point = {}; const uint32_t min = 0; const uint32_t max = 65535; - auto testConversions = [&](const LatLng& coord, const ScreenCoordinate& screenCoord) { - latLng = state.screenCoordinateToLatLng(center); - ASSERT_NEAR(latLng.latitude(), coord.latitude(), 0.000001); - ASSERT_NEAR(latLng.longitude(), coord.longitude(), 0.000001); - point = state.latLngToScreenCoordinate(nullIsland); - ASSERT_DOUBLE_EQ(point.x, screenCoord.x); - ASSERT_DOUBLE_EQ(point.y, screenCoord.y); - }; - - testConversions(nullIsland, center); + // Cannot assign invalid sizes. + std::vector<Size> invalidSizes = { {}, { min, max }, { max, min } }; + for (const Size& size : invalidSizes) { + ASSERT_TRUE(size.isEmpty()); + bool pass = false; + try { + transform.resize(size); + } catch (...) { + pass = true; + } + ASSERT_TRUE(pass) << "Expected to throw"; + } - // Cannot assign the current size. - ASSERT_FALSE(transform.resize({})); + Size validSize { max, max }; + ASSERT_FALSE(validSize.isEmpty()); - ASSERT_TRUE(transform.resize({ min, max })); - testConversions(nullIsland, center); + try { + transform.resize(validSize); + ASSERT_EQ(cameraWillChangeCount, 1u); + ASSERT_EQ(cameraDidChangeCount, 1u); + } catch (...) { + ASSERT_TRUE(false) << "Should not throw"; + } - ASSERT_TRUE(transform.resize({ max, min })); - testConversions(nullIsland, center); + ASSERT_TRUE(state.valid()); - ASSERT_TRUE(transform.resize({ min, min })); - testConversions(nullIsland, center); + // Double resize + try { + transform.resize(validSize); + ASSERT_EQ(cameraWillChangeCount, 1u); + ASSERT_EQ(cameraDidChangeCount, 1u); + } catch (...) { + ASSERT_TRUE(false) << "Should not throw"; + } center = { max / 2., max / 2. }; + latLng = state.screenCoordinateToLatLng(center); + ASSERT_NEAR(latLng.latitude(), nullIsland.latitude(), 1e-5); + ASSERT_NEAR(latLng.longitude(), nullIsland.longitude(), 1e-5); - // Double resize - ASSERT_TRUE(transform.resize({ max, max })); - ASSERT_FALSE(transform.resize({ max, max })); - testConversions(nullIsland, center); + point = state.latLngToScreenCoordinate(nullIsland); + ASSERT_DOUBLE_EQ(point.x, center.x); + ASSERT_DOUBLE_EQ(point.y, center.y); } |