diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/cli/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | test/cli/Makefile.am | 8 | ||||
| -rwxr-xr-x | test/cli/testinvproj | 55 | ||||
| -rw-r--r-- | test/cli/testinvproj_out.dist | 1 | ||||
| -rwxr-xr-x | test/cli/testproj | 2 | ||||
| -rwxr-xr-x | test/fuzzers/build.sh | 16 | ||||
| -rw-r--r-- | test/unit/test_crs.cpp | 88 | ||||
| -rw-r--r-- | test/unit/test_io.cpp | 31 | ||||
| -rw-r--r-- | test/unit/test_operation.cpp | 17 |
9 files changed, 215 insertions, 5 deletions
diff --git a/test/cli/CMakeLists.txt b/test/cli/CMakeLists.txt index 0f86ca3d..b136b05d 100644 --- a/test/cli/CMakeLists.txt +++ b/test/cli/CMakeLists.txt @@ -3,12 +3,14 @@ # set(CS2CS_BIN "cs2cs") set(PROJ_BIN "proj") +set(INVPROJ_BIN "invproj") set(PROJINFO_BIN "projinfo") set(CCT_BIN "cct") set(PROJSYNC_BIN "projsync") proj_add_test_script_sh("test27" PROJ_BIN) proj_add_test_script_sh("test83" PROJ_BIN) proj_add_test_script_sh("testproj" PROJ_BIN) +proj_add_test_script_sh("testinvproj" INVPROJ_BIN) proj_add_test_script_sh("testvarious" CS2CS_BIN) proj_add_test_script_sh("testdatumfile" CS2CS_BIN) proj_add_test_script_sh("testIGNF" CS2CS_BIN) diff --git a/test/cli/Makefile.am b/test/cli/Makefile.am index 46d9d36c..bc840738 100644 --- a/test/cli/Makefile.am +++ b/test/cli/Makefile.am @@ -3,6 +3,7 @@ PROJ_LIB = ../../data/for_tests THIS_DIR = $(top_srcdir)/test/cli EXEPATH = ../../src PROJEXE = $(EXEPATH)/proj +INVPROJEXE = $(EXEPATH)/invproj CS2CSEXE = $(EXEPATH)/cs2cs PROJINFOEXE = $(EXEPATH)/projinfo CCTEXE = $(EXEPATH)/cct @@ -12,6 +13,7 @@ PROJSYNC_EXE = $(EXEPATH)/projsync TEST27 = $(THIS_DIR)/test27 TEST83 = $(THIS_DIR)/test83 TESTPROJ = $(THIS_DIR)/testproj +TESTINVPROJ = $(THIS_DIR)/testinvproj TESTNTV2 = $(THIS_DIR)/testntv2 TESTVARIOUS = $(THIS_DIR)/testvarious TESTFLAKY = $(THIS_DIR)/testflaky @@ -28,6 +30,7 @@ EXTRA_DIST = pj_out27.dist pj_out83.dist td_out.dist \ testprojinfo testprojinfo_out.dist \ testcct testcct_out.dist \ testproj testproj_out.dist \ + testinvproj testinvproj_out.dist \ test_projsync \ CMakeLists.txt @@ -43,6 +46,9 @@ test83-check: testproj-check: PROJ_LIB=$(PROJ_LIB) $(TESTPROJ) $(PROJEXE) +testinvproj-check: + PROJ_LIB=$(PROJ_LIB) $(TESTINVPROJ) $(INVPROJEXE) + testvarious-check: PROJ_SKIP_READ_USER_WRITABLE_DIRECTORY=YES PROJ_LIB=$(PROJ_LIB) $(TESTVARIOUS) $(CS2CSEXE) @@ -67,4 +73,4 @@ testprojsync-check: echo "Skipping testprojsync-check" endif -check-local: testprojinfo-check test27-check test83-check testproj-check testvarious-check testdatumfile-check testign-check testntv2-check testcct-check testprojsync-check +check-local: testprojinfo-check test27-check test83-check testproj-check testinvproj-check testvarious-check testdatumfile-check testign-check testntv2-check testcct-check testprojsync-check diff --git a/test/cli/testinvproj b/test/cli/testinvproj new file mode 100755 index 00000000..878fd118 --- /dev/null +++ b/test/cli/testinvproj @@ -0,0 +1,55 @@ +: +# Script to test invproj exe +# +TEST_CLI_DIR=`dirname $0` +EXE=$1 + +usage() +{ + echo "Usage: ${0} <path to 'invproj' program>" + echo + exit 1 +} + +if test -z "${EXE}"; then + EXE=../../src/invproj +fi + +if test ! -x ${EXE}; then + echo "*** ERROR: Can not find '${EXE}' program!" + exit 1 +fi + +if test -z "${PROJ_LIB}"; then + export PROJ_LIB="`dirname $0`/../../data" +fi + +echo "============================================" +echo "Running ${0} using ${EXE}:" +echo "============================================" + +OUT=testinvproj_out +# +echo "doing tests into file ${OUT}, please wait" +# +$EXE +proj=tmerc +ellps=GRS80 -E -f '%.3f' >${OUT} <<EOF +146339.48 5431555.61 +EOF + +# +# do 'diff' with distribution results +echo "diff ${OUT} with testinvproj_out.dist" +diff -u -b ${OUT} ${TEST_CLI_DIR}/testinvproj_out.dist +if [ $? -ne 0 ] ; then + echo "" + echo "PROBLEMS HAVE OCCURRED" + echo "test file ${OUT} saved" + echo + exit 100 +else + echo "TEST OK" + echo "test file ${OUT} removed" + echo + /bin/rm -f ${OUT} + exit 0 +fi diff --git a/test/cli/testinvproj_out.dist b/test/cli/testinvproj_out.dist new file mode 100644 index 00000000..6b52306f --- /dev/null +++ b/test/cli/testinvproj_out.dist @@ -0,0 +1 @@ +146339.48 5431555.61 2.000 49.000 diff --git a/test/cli/testproj b/test/cli/testproj index 8686224e..d03932fb 100755 --- a/test/cli/testproj +++ b/test/cli/testproj @@ -12,7 +12,7 @@ usage() } if test -z "${EXE}"; then - EXE=../../src/cs2cs + EXE=../../src/proj fi if test ! -x ${EXE}; then diff --git a/test/fuzzers/build.sh b/test/fuzzers/build.sh index 54909fea..25c43fa2 100755 --- a/test/fuzzers/build.sh +++ b/test/fuzzers/build.sh @@ -50,10 +50,20 @@ make -j$(nproc) make install cd .. -./autogen.sh -SQLITE3_CFLAGS=-I/usr/include SQLITE3_LIBS=-lsqlite3 TIFF_CFLAGS=-I$SRC/install/include TIFF_LIBS="-L$SRC/install/lib -ltiff" ./configure --disable-shared --with-curl=$SRC/install/bin/curl-config +mkdir build +cd build +cmake .. -DBUILD_SHARED_LIBS:BOOL=OFF \ + -DCURL_INCLUDE_DIR:PATH="$SRC/install/include" \ + -DCURL_LIBRARY_RELEASE:FILEPATH="$SRC/install/lib/libcurl.a" \ + -DTIFF_INCLUDE_DIR:PATH="$SRC/install/include" \ + -DTIFF_LIBRARY_RELEASE:FILEPATH="$SRC/install/lib/libtiff.a" \ + -DCMAKE_INSTALL_PREFIX=$SRC/install \ + -DBUILD_APPS:BOOL=OFF \ + -DBUILD_TESTING:BOOL=OFF make clean -s make -j$(nproc) -s +make install +cd .. EXTRA_LIBS="-lpthread -Wl,-Bstatic -lsqlite3 -L$SRC/install/lib -ltiff -lcurl -lssl -lcrypto -lz -Wl,-Bdynamic" @@ -66,7 +76,7 @@ build_fuzzer() echo "Building fuzzer $fuzzerName" $CXX $CXXFLAGS -std=c++11 -fvisibility=hidden -Isrc -Iinclude \ $sourceFilename $* -o $OUT/$fuzzerName \ - $LIB_FUZZING_ENGINE src/.libs/libproj.a $EXTRA_LIBS + $LIB_FUZZING_ENGINE "$SRC/install/lib/libproj.a" $EXTRA_LIBS } build_fuzzer proj_crs_to_crs_fuzzer test/fuzzers/proj_crs_to_crs_fuzzer.cpp diff --git a/test/unit/test_crs.cpp b/test/unit/test_crs.cpp index 987ffe1b..500ff4a4 100644 --- a/test/unit/test_crs.cpp +++ b/test/unit/test_crs.cpp @@ -747,6 +747,77 @@ TEST(crs, EPSG_4268_geogcrs_deprecated_as_WKT1_GDAL) { // --------------------------------------------------------------------------- +TEST(crs, ESRI_104971_as_WKT1_ESRI_with_database) { + auto dbContext = DatabaseContext::create(); + auto factory = AuthorityFactory::create(dbContext, "ESRI"); + auto crs = factory->createCoordinateReferenceSystem("104971"); + WKTFormatterNNPtr f(WKTFormatter::create( + WKTFormatter::Convention::WKT1_ESRI, DatabaseContext::create())); + // Check that the _(Sphere) suffix is preserved + EXPECT_EQ(crs->exportToWKT(f.get()), + "GEOGCS[\"Mars_2000_(Sphere)\",DATUM[\"Mars_2000_(Sphere)\"," + "SPHEROID[\"Mars_2000_(Sphere)\",3396190.0,0.0]]," + "PRIMEM[\"Reference_Meridian\",0.0]," + "UNIT[\"Degree\",0.0174532925199433]]"); +} + +// --------------------------------------------------------------------------- + +TEST(crs, + implicit_compound_ESRI_104024_plus_115844_as_WKT1_ESRI_with_database) { + auto dbContext = DatabaseContext::create(); + auto obj = createFromUserInput("ESRI:104024+115844", dbContext); + auto crs = nn_dynamic_pointer_cast<GeographicCRS>(obj); + ASSERT_TRUE(crs != nullptr); + EXPECT_EQ(crs->coordinateSystem()->axisList().size(), 3U); + WKTFormatterNNPtr f(WKTFormatter::create( + WKTFormatter::Convention::WKT1_ESRI, DatabaseContext::create())); + // Situation where there is no EPSG official name + EXPECT_EQ(crs->exportToWKT(f.get()), + "GEOGCS[\"California_SRS_Epoch_2017.50_(NAD83)\"," + "DATUM[\"California_SRS_Epoch_2017.50_(NAD83)\"," + "SPHEROID[\"GRS_1980\",6378137.0,298.257222101]]," + "PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]]," + "VERTCS[\"California_SRS_Epoch_2017.50_(NAD83)\"," + "DATUM[\"California_SRS_Epoch_2017.50_(NAD83)\"," + "SPHEROID[\"GRS_1980\",6378137.0,298.257222101]]," + "PARAMETER[\"Vertical_Shift\",0.0]," + "PARAMETER[\"Direction\",1.0],UNIT[\"Meter\",1.0]]"); +} + +// --------------------------------------------------------------------------- + +TEST(crs, implicit_compound_ESRI_104971_to_3D_as_WKT1_ESRI_with_database) { + auto dbContext = DatabaseContext::create(); + auto factory = AuthorityFactory::create(dbContext, "ESRI"); + auto crs = factory->createGeographicCRS("104971")->promoteTo3D( + std::string(), dbContext); + WKTFormatterNNPtr f(WKTFormatter::create( + WKTFormatter::Convention::WKT1_ESRI, DatabaseContext::create())); + // Situation where there is no ESRI vertical CRS, but the GEOGCS does exist + // This will be only partly recognized by ESRI software. + // See https://github.com/OSGeo/PROJ/issues/2757 + const char *wkt = "GEOGCS[\"Mars_2000_(Sphere)\"," + "DATUM[\"Mars_2000_(Sphere)\"," + "SPHEROID[\"Mars_2000_(Sphere)\",3396190.0,0.0]]," + "PRIMEM[\"Reference_Meridian\",0.0]," + "UNIT[\"Degree\",0.0174532925199433]]," + "VERTCS[\"Mars_2000_(Sphere)\"," + "DATUM[\"Mars_2000_(Sphere)\"," + "SPHEROID[\"Mars_2000_(Sphere)\",3396190.0,0.0]]," + "PARAMETER[\"Vertical_Shift\",0.0]," + "PARAMETER[\"Direction\",1.0]," + "UNIT[\"Meter\",1.0]]"; + EXPECT_EQ(crs->exportToWKT(f.get()), wkt); + + auto obj2 = WKTParser().attachDatabaseContext(dbContext).createFromWKT(wkt); + auto crs2 = nn_dynamic_pointer_cast<GeographicCRS>(obj2); + ASSERT_TRUE(crs2 != nullptr); + EXPECT_EQ(crs2->coordinateSystem()->axisList().size(), 3U); +} + +// --------------------------------------------------------------------------- + TEST(crs, IAU_1000_as_WKT2) { auto dbContext = DatabaseContext::create(); auto factory = AuthorityFactory::create(dbContext, "IAU_2015"); @@ -3877,6 +3948,23 @@ TEST(crs, verticalCRS_down_as_WKT1_ESRI) { // --------------------------------------------------------------------------- +TEST(crs, verticalCRS_ESRI_115834_as_WKT1_ESRI_with_database) { + auto dbContext = DatabaseContext::create(); + auto factory = AuthorityFactory::create(dbContext, "ESRI"); + auto crs = factory->createCoordinateReferenceSystem("115834"); + WKTFormatterNNPtr f(WKTFormatter::create( + WKTFormatter::Convention::WKT1_ESRI, DatabaseContext::create())); + // Check that the parentheses in the VERTCS and DATUM names are preserved + EXPECT_EQ(crs->exportToWKT(f.get()), + "VERTCS[\"NAD83(CSRS)v5\"," + "DATUM[\"North_American_Datum_of_1983_(CSRS)_version_5\"," + "SPHEROID[\"GRS_1980\",6378137.0,298.257222101]]," + "PARAMETER[\"Vertical_Shift\",0.0]," + "PARAMETER[\"Direction\",1.0],UNIT[\"Meter\",1.0]]"); +} + +// --------------------------------------------------------------------------- + TEST(crs, verticalCRS_identify_db) { auto dbContext = DatabaseContext::create(); auto factory = AuthorityFactory::create(dbContext, "EPSG"); diff --git a/test/unit/test_io.cpp b/test/unit/test_io.cpp index 4e888f2c..196552d4 100644 --- a/test/unit/test_io.cpp +++ b/test/unit/test_io.cpp @@ -6394,6 +6394,37 @@ TEST(wkt_parse, wkt1_oracle) { // --------------------------------------------------------------------------- +TEST(wkt_parse, wkt1_lcc_1sp_without_1sp_suffix) { + // WKT from Trimble + auto wkt = "PROJCS[\"TWM-Madison Co LDP\"," + "GEOGCS[\"WGS 1984\"," + "DATUM[\"WGS 1984\"," + "SPHEROID[\"World Geodetic System 1984\"," + "6378137,298.257223563]]," + "PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]]," + "UNIT[\"Degree\",0.01745329251994," + "AUTHORITY[\"EPSG\",\"9102\"]]," + "AXIS[\"Long\",EAST],AXIS[\"Lat\",NORTH]]," + "PROJECTION[\"Lambert_Conformal_Conic\"]," + "PARAMETER[\"False_Easting\",103000.0000035]," + "PARAMETER[\"False_Northing\",79000.00007055]," + "PARAMETER[\"Latitude_Of_Origin\",38.83333333333]," + "PARAMETER[\"Central_Meridian\",-89.93333333333]," + "PARAMETER[\"Scale_Factor\",1.000019129]," + "UNIT[\"Foot_US\",0.3048006096012,AUTHORITY[\"EPSG\",\"9003\"]]," + "AXIS[\"East\",EAST],AXIS[\"North\",NORTH]]"; + + auto dbContext = DatabaseContext::create(); + auto obj = WKTParser().attachDatabaseContext(dbContext).createFromWKT(wkt); + auto crs = nn_dynamic_pointer_cast<ProjectedCRS>(obj); + ASSERT_TRUE(crs != nullptr); + + EXPECT_EQ(crs->derivingConversion()->method()->nameStr(), + "Lambert Conic Conformal (1SP)"); +} + +// --------------------------------------------------------------------------- + TEST(wkt_parse, invalid) { EXPECT_THROW(WKTParser().createFromWKT(""), ParsingException); EXPECT_THROW(WKTParser().createFromWKT("A"), ParsingException); diff --git a/test/unit/test_operation.cpp b/test/unit/test_operation.cpp index f76647e2..0e27aa9b 100644 --- a/test/unit/test_operation.cpp +++ b/test/unit/test_operation.cpp @@ -5429,6 +5429,20 @@ TEST(operation, normalizeForVisualization) { auto authFactory = AuthorityFactory::create(DatabaseContext::create(), "EPSG"); + const auto checkThroughWKTRoundtrip = [](const CoordinateOperationNNPtr + &opRef) { + auto wkt = opRef->exportToWKT( + WKTFormatter::create(WKTFormatter::Convention::WKT2_2019).get()); + auto objFromWkt = WKTParser().createFromWKT(wkt); + auto opFromWkt = + nn_dynamic_pointer_cast<CoordinateOperation>(objFromWkt); + ASSERT_TRUE(opFromWkt != nullptr); + EXPECT_TRUE(opRef->_isEquivalentTo(opFromWkt.get())); + EXPECT_EQ( + opFromWkt->exportToPROJString(PROJStringFormatter::create().get()), + opRef->exportToPROJString(PROJStringFormatter::create().get())); + }; + // Source(geographic) must be inverted { auto src = authFactory->createCoordinateReferenceSystem("4326"); @@ -5443,6 +5457,7 @@ TEST(operation, normalizeForVisualization) { "+proj=pipeline " "+step +proj=unitconvert +xy_in=deg +xy_out=rad " "+step +proj=utm +zone=31 +ellps=WGS84"); + checkThroughWKTRoundtrip(opNormalized); } // Target(geographic) must be inverted @@ -5459,6 +5474,7 @@ TEST(operation, normalizeForVisualization) { "+proj=pipeline " "+step +inv +proj=utm +zone=31 +ellps=WGS84 " "+step +proj=unitconvert +xy_in=rad +xy_out=deg"); + checkThroughWKTRoundtrip(opNormalized); } // Source(geographic) and target(projected) must be inverted @@ -5475,6 +5491,7 @@ TEST(operation, normalizeForVisualization) { "+proj=pipeline " "+step +proj=unitconvert +xy_in=deg +xy_out=rad " "+step +proj=utm +zone=28 +ellps=GRS80"); + checkThroughWKTRoundtrip(opNormalized); } // No inversion |
