summaryrefslogtreecommitdiff
path: root/test/map
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2017-04-03 17:07:17 +0300
committerBruno de Oliveira Abinader <bruno@mapbox.com>2017-04-10 18:01:28 +0300
commite5aa4d70cd7b39302ddf1ec4df240a14accfb474 (patch)
tree8e8595f32fa4f30316e68f533ee4dd289adf11fb /test/map
parent76edc6ee69ec9a8aaa0b0207aed06f257ff5fd83 (diff)
downloadqtlocation-mapboxgl-e5aa4d70cd7b39302ddf1ec4df240a14accfb474.tar.gz
[core] Updated Size::isEmpty and TransformState::valid checks
Diffstat (limited to 'test/map')
-rw-r--r--test/map/transform.test.cpp81
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);
}