diff options
Diffstat (limited to 'test/unit')
| -rw-r--r-- | test/unit/gie_self_tests.cpp | 78 | ||||
| -rw-r--r-- | test/unit/test_io.cpp | 35 |
2 files changed, 91 insertions, 22 deletions
diff --git a/test/unit/gie_self_tests.cpp b/test/unit/gie_self_tests.cpp index 67a44fe5..8b90a22d 100644 --- a/test/unit/gie_self_tests.cpp +++ b/test/unit/gie_self_tests.cpp @@ -49,24 +49,11 @@ TEST( gie, cart_selftest ) { PJ_COORD a, b, obs[2]; PJ_COORD coord[2]; - PJ_INFO info; - PJ_PROJ_INFO pj_info; - PJ_GRID_INFO grid_info; - PJ_INIT_INFO init_info; - - PJ_FACTORS factors; - - const PJ_OPERATIONS *oper_list; - const PJ_ELLPS *ellps_list; - const PJ_UNITS *unit_list; - const PJ_PRIME_MERIDIANS *pm_list; - int err; size_t n, sz; double dist, h, t; const char * const args[3] = {"proj=utm", "zone=32", "ellps=GRS80"}; char arg[50] = {"+proj=utm; +zone=32; +ellps=GRS80"}; - char buf[40]; /* An utm projection on the GRS80 ellipsoid */ P = proj_create (PJ_DEFAULT_CTX, arg); @@ -246,10 +233,32 @@ TEST( gie, cart_selftest ) { /* Clean up after proj_trans_* tests */ proj_destroy (P); +} + +// --------------------------------------------------------------------------- + +class gieTest : public ::testing::Test { + + static void DummyLogFunction(void *, int, const char *) {} + + protected: + void SetUp() override { + m_ctxt = proj_context_create(); + proj_log_func(m_ctxt, nullptr, DummyLogFunction); + } + void TearDown() override { proj_context_destroy(m_ctxt); } + + PJ_CONTEXT *m_ctxt = nullptr; +}; + +// --------------------------------------------------------------------------- + +TEST_F( gieTest, proj_create_crs_to_crs ) { /* test proj_create_crs_to_crs() */ - P = proj_create_crs_to_crs(PJ_DEFAULT_CTX, "epsg:25832", "epsg:25833", NULL); + auto P = proj_create_crs_to_crs(PJ_DEFAULT_CTX, "epsg:25832", "epsg:25833", NULL); ASSERT_TRUE( P != nullptr ); + PJ_COORD a, b; a.xy.x = 700000.0; a.xy.y = 6000000.0; @@ -257,14 +266,39 @@ TEST( gie, cart_selftest ) { b.xy.y = 5999669.3036037628; a = proj_trans(P, PJ_FWD, a); - ASSERT_LE(dist, 1e-7); + EXPECT_NEAR( a.xy.x, b.xy.x, 1e-9); + EXPECT_NEAR( a.xy.y, b.xy.y, 1e-9); proj_destroy(P); - /* let's make sure that only entries in init-files results in a usable PJ */ + /* we can also allow PROJ strings as a usable PJ */ P = proj_create_crs_to_crs(PJ_DEFAULT_CTX, "proj=utm +zone=32 +datum=WGS84", "proj=utm +zone=33 +datum=WGS84", NULL); - ASSERT_TRUE( P == nullptr ); + ASSERT_TRUE( P != nullptr ); proj_destroy(P); + EXPECT_TRUE( proj_create_crs_to_crs(m_ctxt, "invalid", "EPSG:25833", NULL) == nullptr ); + EXPECT_TRUE( proj_create_crs_to_crs(m_ctxt, "EPSG:25832", "invalid", NULL) == nullptr ); +} + +// --------------------------------------------------------------------------- + +TEST( gie, info_functions ) { + PJ_INFO info; + PJ_PROJ_INFO pj_info; + PJ_GRID_INFO grid_info; + PJ_INIT_INFO init_info; + + PJ_FACTORS factors; + + const PJ_OPERATIONS *oper_list; + const PJ_ELLPS *ellps_list; + const PJ_UNITS *unit_list; + const PJ_PRIME_MERIDIANS *pm_list; + + char buf[40]; + PJ *P; + char arg[50] = {"+proj=utm; +zone=32; +ellps=GRS80"}; + PJ_COORD a; + /* ********************************************************************** */ /* Test info functions */ /* ********************************************************************** */ @@ -345,7 +379,7 @@ TEST( gie, cart_selftest ) { proj_destroy(P); /* Check that proj_list_* functions work by looping through them */ - n = 0; + size_t n = 0; for (oper_list = proj_list_operations(); oper_list->id; ++oper_list) n++; ASSERT_NE(n, 0U); @@ -361,11 +395,15 @@ TEST( gie, cart_selftest ) { for (pm_list = proj_list_prime_meridians(); pm_list->id; ++pm_list) n++; ASSERT_NE(n, 0U); +} + +// --------------------------------------------------------------------------- +TEST( gie, io_predicates ) { /* check io-predicates */ /* angular in on fwd, linear out */ - P = proj_create (PJ_DEFAULT_CTX, "+proj=cart +ellps=GRS80"); + auto P = proj_create (PJ_DEFAULT_CTX, "+proj=cart +ellps=GRS80"); ASSERT_TRUE( P != nullptr ); ASSERT_TRUE(proj_angular_input (P, PJ_FWD)); ASSERT_FALSE(proj_angular_input (P, PJ_INV)); @@ -425,7 +463,7 @@ TEST( gie, cart_selftest ) { /* Test that pj_fwd* and pj_inv* returns NaNs when receiving NaN input */ P = proj_create(PJ_DEFAULT_CTX, "+proj=merc"); ASSERT_TRUE( P != nullptr ); - a = proj_coord(NAN, NAN, NAN, NAN); + auto a = proj_coord(NAN, NAN, NAN, NAN); a = proj_trans(P, PJ_FWD, a); ASSERT_TRUE ( ( std::isnan(a.v[0]) && std::isnan(a.v[1]) && std::isnan(a.v[2]) && std::isnan(a.v[3]) ) ); diff --git a/test/unit/test_io.cpp b/test/unit/test_io.cpp index 6ccd5578..99f58739 100644 --- a/test/unit/test_io.cpp +++ b/test/unit/test_io.cpp @@ -7448,12 +7448,43 @@ TEST(io, projparse_projected_title) { TEST(io, projparse_init) { + // Not allowed in non-compatibillity mode + EXPECT_THROW(PROJStringParser().createFromPROJString("init=epsg:4326"), + ParsingException); + + { + // EPSG:4326 is normally latitude-longitude order with degree, + // but in compatibillity mode it will be long-lat radian + auto dbContext = DatabaseContext::create(); + auto obj = createFromUserInput("init=epsg:4326", dbContext, true); + auto crs = nn_dynamic_pointer_cast<GeographicCRS>(obj); + ASSERT_TRUE(crs != nullptr); + EXPECT_TRUE(crs->coordinateSystem()->isEquivalentTo( + EllipsoidalCS::createLongitudeLatitude(UnitOfMeasure::RADIAN) + .get())); + } + + { + // EPSG:3040 is normally northing-easting order, but in compatibillity + // mode it will be easting-northing + auto dbContext = DatabaseContext::create(); + auto obj = createFromUserInput("init=epsg:3040", dbContext, true); + auto crs = nn_dynamic_pointer_cast<ProjectedCRS>(obj); + ASSERT_TRUE(crs != nullptr); + EXPECT_TRUE(crs->coordinateSystem()->isEquivalentTo( + CartesianCS::createEastingNorthing(UnitOfMeasure::METRE).get())); + } + { - auto obj = PROJStringParser().createFromPROJString("init=epsg:4326"); + auto obj = + PROJStringParser().createFromPROJString("init=ITRF2000:ITRF2005"); auto co = nn_dynamic_pointer_cast<CoordinateOperation>(obj); ASSERT_TRUE(co != nullptr); EXPECT_EQ(co->exportToPROJString(PROJStringFormatter::create().get()), - "+init=epsg:4326"); + "+proj=helmert +x=-0.0001 +y=0.0008 +z=0.0058 +rx=0 +ry=0 " + "+rz=0 +s=-0.0004 +dx=0.0002 +dy=-0.0001 +dz=0.0018 +drx=0 " + "+dry=0 +drz=0 +ds=-8e-06 +t_epoch=2000 " + "+convention=position_vector"); } { |
