summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2017-04-11 17:07:25 +0300
committerJohn Firebaugh <john.firebaugh@gmail.com>2017-04-14 12:33:13 -0700
commit2f4d162debd7e4accfc0b20360058304dce40801 (patch)
tree276894e2ccfa67874dbe6ecf263330d6b35007ad /test
parent8877452ec36d01a753221998f31b67700e595d54 (diff)
downloadqtlocation-mapboxgl-2f4d162debd7e4accfc0b20360058304dce40801.tar.gz
[core] Tighten geo.hpp ctors
Diffstat (limited to 'test')
-rw-r--r--test/map/transform.test.cpp6
-rw-r--r--test/util/geo.test.cpp69
-rw-r--r--test/util/projection.test.cpp10
3 files changed, 76 insertions, 9 deletions
diff --git a/test/map/transform.test.cpp b/test/map/transform.test.cpp
index 8a86598a1d..accf7d293c 100644
--- a/test/map/transform.test.cpp
+++ b/test/map/transform.test.cpp
@@ -471,14 +471,12 @@ TEST(Transform, DefaultTransform) {
// 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);
+ ASSERT_TRUE(false) << "Should throw";
} catch (...) {
- pass = true;
+ ASSERT_TRUE(size.isEmpty());
}
- ASSERT_TRUE(pass) << "Expected to throw";
}
Size validSize { max, max };
diff --git a/test/util/geo.test.cpp b/test/util/geo.test.cpp
index 3f625f21fa..3dfa8e1cca 100644
--- a/test/util/geo.test.cpp
+++ b/test/util/geo.test.cpp
@@ -6,6 +6,75 @@
using namespace mbgl;
+TEST(LatLng, InvalidLatLng) {
+ try {
+ LatLng { NAN };
+ ASSERT_TRUE(false) << "should throw";
+ } catch (const std::domain_error& error) {
+ ASSERT_EQ(std::string(error.what()), "latitude must not be NaN");
+ }
+ try {
+ LatLng { 0, NAN };
+ ASSERT_TRUE(false) << "should throw";
+ } catch (const std::domain_error& error) {
+ ASSERT_EQ(std::string(error.what()), "longitude must not be NaN");
+ }
+ try {
+ LatLng { 91.0 };
+ ASSERT_TRUE(false) << "should throw";
+ } catch (const std::domain_error& error) {
+ ASSERT_EQ(std::string(error.what()), "latitude must be between -90 and 90");
+ }
+ try {
+ LatLng { 0, std::numeric_limits<double>::infinity() };
+ ASSERT_TRUE(false) << "should throw";
+ } catch (const std::domain_error& error) {
+ ASSERT_EQ(std::string(error.what()), "longitude must not be infinite");
+ }
+}
+
+TEST(ProjectedMeters, InvalidProjectedMeters) {
+ try {
+ ProjectedMeters { NAN };
+ ASSERT_TRUE(false) << "should throw";
+ } catch (const std::domain_error& error) {
+ ASSERT_EQ(std::string(error.what()), "northing must not be NaN");
+ }
+ try {
+ ProjectedMeters { 0, NAN };
+ ASSERT_TRUE(false) << "should throw";
+ } catch (const std::domain_error& error) {
+ ASSERT_EQ(std::string(error.what()), "easting must not be NaN");
+ }
+}
+
+TEST(EdgeInsets, InvalidEdgeInsets) {
+ try {
+ EdgeInsets { NAN };
+ ASSERT_TRUE(false) << "should throw";
+ } catch (const std::domain_error& error) {
+ ASSERT_EQ(std::string(error.what()), "top must not be NaN");
+ }
+ try {
+ EdgeInsets { 0, NAN };
+ ASSERT_TRUE(false) << "should throw";
+ } catch (const std::domain_error& error) {
+ ASSERT_EQ(std::string(error.what()), "left must not be NaN");
+ }
+ try {
+ EdgeInsets { 0, 0, NAN };
+ ASSERT_TRUE(false) << "should throw";
+ } catch (const std::domain_error& error) {
+ ASSERT_EQ(std::string(error.what()), "bottom must not be NaN");
+ }
+ try {
+ EdgeInsets { 0, 0, 0, NAN };
+ ASSERT_TRUE(false) << "should throw";
+ } catch (const std::domain_error& error) {
+ ASSERT_EQ(std::string(error.what()), "right must not be NaN");
+ }
+}
+
TEST(LatLngBounds, World) {
auto result = LatLngBounds::world();
ASSERT_DOUBLE_EQ(-90, result.south());
diff --git a/test/util/projection.test.cpp b/test/util/projection.test.cpp
index b0fa0bd060..9f27fe3d14 100644
--- a/test/util/projection.test.cpp
+++ b/test/util/projection.test.cpp
@@ -38,18 +38,18 @@ TEST(Projection, MetersPerPixelAtLatitude) {
TEST(Projection, ProjectedMeters) {
auto latLng = LatLng {};
auto projectedMeters = Projection::projectedMetersForLatLng(latLng);
- EXPECT_EQ(projectedMeters.northing, projectedMeters.easting);
+ EXPECT_EQ(projectedMeters.northing(), projectedMeters.easting());
EXPECT_EQ(latLng, Projection::latLngForProjectedMeters(projectedMeters));
const auto southWest = LatLng { -util::LATITUDE_MAX, -util::LONGITUDE_MAX };
projectedMeters = Projection::projectedMetersForLatLng(southWest);
- EXPECT_DOUBLE_EQ(projectedMeters.northing, -20037508.342789274);
- EXPECT_DOUBLE_EQ(projectedMeters.easting, -20037508.342789244);
+ EXPECT_DOUBLE_EQ(projectedMeters.northing(), -20037508.342789274);
+ EXPECT_DOUBLE_EQ(projectedMeters.easting(), -20037508.342789244);
const auto northEast = LatLng { util::LATITUDE_MAX, util::LONGITUDE_MAX };
projectedMeters = Projection::projectedMetersForLatLng(northEast);
- EXPECT_DOUBLE_EQ(projectedMeters.northing, 20037508.342789274);
- EXPECT_DOUBLE_EQ(projectedMeters.easting, 20037508.342789244);
+ EXPECT_DOUBLE_EQ(projectedMeters.northing(), 20037508.342789274);
+ EXPECT_DOUBLE_EQ(projectedMeters.easting(), 20037508.342789244);
projectedMeters = ProjectedMeters { std::numeric_limits<double>::lowest(), std::numeric_limits<double>::lowest() };
latLng = Projection::latLngForProjectedMeters(projectedMeters);