diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2020-03-16 17:56:29 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-03-16 17:56:29 +0100 |
| commit | 6cfc2521d687e3de57fa13b0f80ef05073362571 (patch) | |
| tree | 7509a1282eea3bd939b42fbb7610aadedbb28e85 /test/unit | |
| parent | f0d6b64fee8b796ec038929187b7b725f62a5ba8 (diff) | |
| parent | 175cbad0a7ca202cefff33f240100b01752f8f73 (diff) | |
| download | PROJ-6cfc2521d687e3de57fa13b0f80ef05073362571.tar.gz PROJ-6cfc2521d687e3de57fa13b0f80ef05073362571.zip | |
Merge branch 'master' into add_proj_get_suggested_operation
Diffstat (limited to 'test/unit')
| -rw-r--r-- | test/unit/gie_self_tests.cpp | 6 | ||||
| -rw-r--r-- | test/unit/test_c_api.cpp | 42 | ||||
| -rw-r--r-- | test/unit/test_factory.cpp | 84 |
3 files changed, 120 insertions, 12 deletions
diff --git a/test/unit/gie_self_tests.cpp b/test/unit/gie_self_tests.cpp index 720c13ca..6f1b3c32 100644 --- a/test/unit/gie_self_tests.cpp +++ b/test/unit/gie_self_tests.cpp @@ -334,7 +334,6 @@ TEST(gie, info_functions) { const PJ_OPERATIONS *oper_list; const PJ_ELLPS *ellps_list; - const PJ_UNITS *unit_list; const PJ_PRIME_MERIDIANS *pm_list; char buf[40]; @@ -453,11 +452,6 @@ TEST(gie, info_functions) { ASSERT_NE(n, 0U); n = 0; - for (unit_list = proj_list_units(); unit_list->id; ++unit_list) - n++; - ASSERT_NE(n, 0U); - - n = 0; for (pm_list = proj_list_prime_meridians(); pm_list->id; ++pm_list) n++; ASSERT_NE(n, 0U); diff --git a/test/unit/test_c_api.cpp b/test/unit/test_c_api.cpp index f274af57..c984e84e 100644 --- a/test/unit/test_c_api.cpp +++ b/test/unit/test_c_api.cpp @@ -3425,6 +3425,48 @@ TEST_F(CApi, proj_get_crs_info_list_from_database) { // --------------------------------------------------------------------------- +TEST_F(CApi, proj_get_units_from_database) { + { proj_unit_list_destroy(nullptr); } + + { + auto list = proj_get_units_from_database(nullptr, nullptr, nullptr, + true, nullptr); + ASSERT_NE(list, nullptr); + ASSERT_NE(list[0], nullptr); + ASSERT_NE(list[0]->auth_name, nullptr); + ASSERT_NE(list[0]->code, nullptr); + ASSERT_NE(list[0]->name, nullptr); + proj_unit_list_destroy(list); + } + + { + int result_count = 0; + auto list = proj_get_units_from_database(nullptr, "EPSG", "linear", + false, &result_count); + ASSERT_NE(list, nullptr); + EXPECT_GT(result_count, 1); + EXPECT_EQ(list[result_count], nullptr); + bool found9001 = false; + for (int i = 0; i < result_count; i++) { + EXPECT_EQ(std::string(list[i]->auth_name), "EPSG"); + if (std::string(list[i]->code) == "9001") { + EXPECT_EQ(std::string(list[i]->name), "metre"); + EXPECT_EQ(std::string(list[i]->category), "linear"); + EXPECT_EQ(list[i]->conv_factor, 1.0); + ASSERT_NE(list[i]->proj_short_name, nullptr); + EXPECT_EQ(std::string(list[i]->proj_short_name), "m"); + EXPECT_EQ(list[i]->deprecated, 0); + found9001 = true; + } + EXPECT_EQ(list[i]->deprecated, 0); + } + EXPECT_TRUE(found9001); + proj_unit_list_destroy(list); + } +} + +// --------------------------------------------------------------------------- + TEST_F(CApi, proj_normalize_for_visualization) { { diff --git a/test/unit/test_factory.cpp b/test/unit/test_factory.cpp index c7ae458e..aee2f572 100644 --- a/test/unit/test_factory.cpp +++ b/test/unit/test_factory.cpp @@ -1401,16 +1401,18 @@ class FactoryWithTmpDatabase : public ::testing::Test { void populateWithFakeEPSG() { ASSERT_TRUE(execute("INSERT INTO unit_of_measure " - "VALUES('EPSG','9001','metre','length',1.0,0);")) + "VALUES('EPSG','9001','metre','length',1.0,NULL," + "0);")) << last_error(); ASSERT_TRUE(execute("INSERT INTO unit_of_measure " "VALUES('EPSG','9102','degree','angle',1." - "74532925199432781271e-02,0);")) + "74532925199432781271e-02,NULL,0);")) << last_error(); ASSERT_TRUE(execute( "INSERT INTO unit_of_measure VALUES('EPSG','9122','degree " "(supplier to " - "define representation)','angle',1.74532925199432781271e-02,0);")) + "define representation)','angle',1.74532925199432781271e-02,NULL," + "0);")) << last_error(); ASSERT_TRUE( execute("INSERT INTO area " @@ -1470,7 +1472,8 @@ class FactoryWithTmpDatabase : public ::testing::Test { << last_error(); ASSERT_TRUE(execute("INSERT INTO unit_of_measure " - "VALUES('EPSG','9201','unity','scale',1.0,0);")) + "VALUES('EPSG','9201','unity','scale',1.0," + "NULL,0);")) << last_error(); ASSERT_TRUE(execute( @@ -1547,7 +1550,7 @@ class FactoryWithTmpDatabase : public ::testing::Test { ASSERT_TRUE(execute( "INSERT INTO unit_of_measure VALUES('EPSG','9110','sexagesimal " - "DMS','angle',NULL,0);")) + "DMS','angle',NULL,NULL,0);")) << last_error(); ASSERT_TRUE(execute( @@ -2933,7 +2936,7 @@ TEST(factory, getCRSInfoList) { auto list = factory->getCRSInfoList(); EXPECT_GT(list.size(), 1U); bool foundEPSG = false; - bool foundIGNF = true; + bool foundIGNF = false; bool found4326 = false; for (const auto &info : list) { foundEPSG |= info.authName == "EPSG"; @@ -3023,4 +3026,73 @@ TEST(factory, getCRSInfoList) { EXPECT_TRUE(found6871); } } + +// --------------------------------------------------------------------------- + +TEST(factory, getUnitList) { + auto ctxt = DatabaseContext::create(); + { + auto factory = AuthorityFactory::create(ctxt, std::string()); + auto list = factory->getUnitList(); + EXPECT_GT(list.size(), 1U); + bool foundEPSG = false; + bool foundPROJ = false; + bool found1027 = false; + bool found1028 = false; + bool found1032 = false; + bool found1036 = false; + bool found9001 = false; + bool found9101 = false; + for (const auto &info : list) { + foundEPSG |= info.authName == "EPSG"; + foundPROJ |= info.authName == "PROJ"; + if (info.authName == "EPSG" && info.code == "1027") { + EXPECT_EQ(info.name, "millimetres per year"); + EXPECT_EQ(info.category, "linear_per_time"); + found1027 = true; + } else if (info.authName == "EPSG" && info.code == "1028") { + EXPECT_EQ(info.name, "parts per billion"); + EXPECT_EQ(info.category, "scale"); + found1028 = true; + } else if (info.authName == "EPSG" && info.code == "1032") { + EXPECT_EQ(info.name, "milliarc-seconds per year"); + EXPECT_EQ(info.category, "angular_per_time"); + found1032 = true; + } else if (info.authName == "EPSG" && info.code == "1036") { + EXPECT_EQ(info.name, "unity per second"); + EXPECT_EQ(info.category, "scale_per_time"); + found1036 = true; + } else if (info.authName == "EPSG" && info.code == "9001") { + EXPECT_EQ(info.name, "metre"); + EXPECT_EQ(info.category, "linear"); + EXPECT_EQ(info.convFactor, 1.0); + EXPECT_EQ(info.projShortName, "m"); + EXPECT_FALSE(info.deprecated); + found9001 = true; + } else if (info.authName == "EPSG" && info.code == "9101") { + EXPECT_EQ(info.name, "radian"); + EXPECT_EQ(info.category, "angular"); + EXPECT_FALSE(info.deprecated); + found9101 = true; + } + } + EXPECT_TRUE(foundEPSG); + EXPECT_TRUE(foundPROJ); + EXPECT_TRUE(found1027); + EXPECT_TRUE(found1028); + EXPECT_TRUE(found1032); + EXPECT_TRUE(found1036); + EXPECT_TRUE(found9001); + EXPECT_TRUE(found9101); + } + { + auto factory = AuthorityFactory::create(ctxt, "EPSG"); + auto list = factory->getUnitList(); + EXPECT_GT(list.size(), 1U); + for (const auto &info : list) { + EXPECT_EQ(info.authName, "EPSG"); + } + } +} + } // namespace |
