From 3690108345103889b5e6de22e7f7c59ae93d6103 Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Fri, 16 Jun 2006 14:13:06 +0000 Subject: [PATCH] New regress test cases and support for loader/dumper. git-svn-id: http://svn.osgeo.org/postgis/trunk@2384 b70326c6-7e19-0410-871a-916f4a2858ee --- CHANGES | 5 +- regress/Makefile | 2 +- regress/loader/README | 10 + regress/loader/mlines2d-wkb.expected | 2 + regress/loader/mlines2d-wkt.expected | 2 + regress/loader/mlines2d.dbf | Bin 0 -> 89 bytes regress/loader/mlines2d.shp | Bin 0 -> 400 bytes regress/loader/mlines2d.shx | Bin 0 -> 116 bytes regress/loader/mlines3dm-wkb.expected | 1 + regress/loader/mlines3dm-wkt.expected | 1 + regress/loader/mlines3dm.dbf | Bin 0 -> 33 bytes regress/loader/mlines3dm.shp | Bin 0 -> 348 bytes regress/loader/mlines3dm.shx | Bin 0 -> 108 bytes regress/loader/mlines3dz-wkb.expected | 1 + regress/loader/mlines3dz-wkt.expected | 1 + regress/loader/mlines3dz.dbf | Bin 0 -> 33 bytes regress/loader/mlines3dz.shp | Bin 0 -> 420 bytes regress/loader/mlines3dz.shx | Bin 0 -> 108 bytes regress/loader/mlines4d-wkb.expected | 1 + regress/loader/mlines4d-wkt.expected | 1 + regress/loader/mlines4d.dbf | Bin 0 -> 33 bytes regress/loader/mlines4d.shp | Bin 0 -> 420 bytes regress/loader/mlines4d.shx | Bin 0 -> 108 bytes regress/run_test | 383 ++++++++++++++++++++++---- 24 files changed, 347 insertions(+), 63 deletions(-) create mode 100644 regress/loader/README create mode 100644 regress/loader/mlines2d-wkb.expected create mode 100644 regress/loader/mlines2d-wkt.expected create mode 100644 regress/loader/mlines2d.dbf create mode 100644 regress/loader/mlines2d.shp create mode 100644 regress/loader/mlines2d.shx create mode 100644 regress/loader/mlines3dm-wkb.expected create mode 100644 regress/loader/mlines3dm-wkt.expected create mode 100644 regress/loader/mlines3dm.dbf create mode 100644 regress/loader/mlines3dm.shp create mode 100644 regress/loader/mlines3dm.shx create mode 100644 regress/loader/mlines3dz-wkb.expected create mode 100644 regress/loader/mlines3dz-wkt.expected create mode 100644 regress/loader/mlines3dz.dbf create mode 100644 regress/loader/mlines3dz.shp create mode 100644 regress/loader/mlines3dz.shx create mode 100644 regress/loader/mlines4d-wkb.expected create mode 100644 regress/loader/mlines4d-wkt.expected create mode 100644 regress/loader/mlines4d.dbf create mode 100644 regress/loader/mlines4d.shp create mode 100644 regress/loader/mlines4d.shx diff --git a/CHANGES b/CHANGES index 4f49b5e7c..311846cc6 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,9 @@ PostGIS 1.1.3CVS - - BUGXFIX in affine() failing to update bounding box + - New regress test support for loader/dumper. + - BUGFIX in pgsql2shp successful return code. + - BUGFIX in shp2pgsql handling of MultiLine WKT. + - BUGFIX in affine() failing to update bounding box - WKT parser: forbidden construction of multigeometries with EMPTY elements (still supported for GEOMETRYCOLLECTION). - Added --with-proj-libdir and --with-geos-libdir configure diff --git a/regress/Makefile b/regress/Makefile index aab4083b8..cfcf14983 100644 --- a/regress/Makefile +++ b/regress/Makefile @@ -2,7 +2,7 @@ TMPDIR?=/tmp include ../Makefile.config -TESTS=regress regress_index lwgeom_regress regress_lrs removepoint setpoint simplify snaptogrid affine wkt measures +TESTS=loader/mlines2d loader/mlines3dz loader/mlines3dm loader/mlines4d regress regress_index lwgeom_regress regress_lrs removepoint setpoint simplify snaptogrid affine wkt measures ifeq ($(USE_GEOS),1) TESTS += regress_ogc regress_bdpoly diff --git a/regress/loader/README b/regress/loader/README new file mode 100644 index 000000000..e190b48c0 --- /dev/null +++ b/regress/loader/README @@ -0,0 +1,10 @@ +Fri Jun 16 15:59:14 CEST 2006 --strk; + +The ../run_test script will load a provided shapefile using both DUMP and INSERT +mode and both WKT and WKB modes. +Will compare a 'select * from loaded_table' against the provided -wkb.expected +and -wkt.expected files (we need two separate files as the WKT mode will +not support M values). +Also, the tester file will dump the loaded table and compare the resulting shapefile +with the original one (only .shp, .dbf is not compared as field sizes are not +retained, we might use a dbf viewer for that, but that's not currently implemented) diff --git a/regress/loader/mlines2d-wkb.expected b/regress/loader/mlines2d-wkb.expected new file mode 100644 index 000000000..49e4ff523 --- /dev/null +++ b/regress/loader/mlines2d-wkb.expected @@ -0,0 +1,2 @@ +1|1|01050000000200000001020000000200000000000000000000000000000000000000000000000000F03F000000000000F03F0102000000020000000000000000000840000000000000084000000000000010400000000000001040 +2|2|01050000000300000001020000000200000000000000000000000000000000000000000000000000F03F000000000000F03F0102000000020000000000000000000840000000000000084000000000000010400000000000001040010200000003000000000000000000244000000000000024400000000000001440000000000000144000000000000008400000000000000840 diff --git a/regress/loader/mlines2d-wkt.expected b/regress/loader/mlines2d-wkt.expected new file mode 100644 index 000000000..49e4ff523 --- /dev/null +++ b/regress/loader/mlines2d-wkt.expected @@ -0,0 +1,2 @@ +1|1|01050000000200000001020000000200000000000000000000000000000000000000000000000000F03F000000000000F03F0102000000020000000000000000000840000000000000084000000000000010400000000000001040 +2|2|01050000000300000001020000000200000000000000000000000000000000000000000000000000F03F000000000000F03F0102000000020000000000000000000840000000000000084000000000000010400000000000001040010200000003000000000000000000244000000000000024400000000000001440000000000000144000000000000008400000000000000840 diff --git a/regress/loader/mlines2d.dbf b/regress/loader/mlines2d.dbf new file mode 100644 index 0000000000000000000000000000000000000000..9d928dd1be8fec41f9886335914cf4811e4a9983 GIT binary patch literal 89 ocmZRMXP07PU|?`$-~p1Dz|#dT<_BVN!?_R!mx7@J0vI8f0G-DK<^TWy literal 0 HcmV?d00001 diff --git a/regress/loader/mlines2d.shp b/regress/loader/mlines2d.shp new file mode 100644 index 0000000000000000000000000000000000000000..db615cf1d7cd318df6d2825d6da8f988cda59f72 GIT binary patch literal 400 zcmZQzQ0HR64o=1*%nqcmL3L#N2dto%pUKovHKTsdS4u~Nl L4yZItABO_~j#&-k literal 0 HcmV?d00001 diff --git a/regress/loader/mlines2d.shx b/regress/loader/mlines2d.shx new file mode 100644 index 0000000000000000000000000000000000000000..8e7fe0714caad5c20d909a8e0380855119d3a9cd GIT binary patch literal 116 ocmZQzQ0HR64y;}>(mDAa#sDTtSRkKr0#8ffxjsfS3i$ z!bZT%htV7k5LGZ*0Lq8aFn7Xe5vV+jhUtURFmu7~2O16IGeGsh)WOV$nIi#}mvI09 Dl&%lO literal 0 HcmV?d00001 diff --git a/regress/loader/mlines3dm.shx b/regress/loader/mlines3dm.shx new file mode 100644 index 0000000000000000000000000000000000000000..9a00a4c6cd57452fe6320472656c574ba9499865 GIT binary patch literal 108 qcmZQzQ0HR64$NLKGcbr_mjjBbI6$OeG`hkM_7D*nkUAqEt^feDOax~D literal 0 HcmV?d00001 diff --git a/regress/loader/mlines3dz-wkb.expected b/regress/loader/mlines3dz-wkb.expected new file mode 100644 index 000000000..38289397d --- /dev/null +++ b/regress/loader/mlines3dz-wkb.expected @@ -0,0 +1 @@ +1|01050000C00300000001020000C00200000000000000000000000000000000000000000000000000F03F0000000000000000000000000000F03F000000000000F03F0000000000000040000000000000000001020000C0020000000000000000000840000000000000084000000000000008400000000000000000000000000000104000000000000010400000000000001040000000000000000001020000C00300000000000000000024400000000000002440000000000000144000000000000000000000000000001440000000000000144000000000000018400000000000000000000000000000084000000000000008400000000000001C400000000000000000 diff --git a/regress/loader/mlines3dz-wkt.expected b/regress/loader/mlines3dz-wkt.expected new file mode 100644 index 000000000..22619e3b3 --- /dev/null +++ b/regress/loader/mlines3dz-wkt.expected @@ -0,0 +1 @@ +1|01050000800300000001020000800200000000000000000000000000000000000000000000000000F03F000000000000F03F000000000000F03F0000000000000040010200008002000000000000000000084000000000000008400000000000000840000000000000104000000000000010400000000000001040010200008003000000000000000000244000000000000024400000000000001440000000000000144000000000000014400000000000001840000000000000084000000000000008400000000000001C40 diff --git a/regress/loader/mlines3dz.dbf b/regress/loader/mlines3dz.dbf new file mode 100644 index 0000000000000000000000000000000000000000..13b4aeea0f36e95f37f532ac3645bfa848df67e0 GIT binary patch literal 33 UcmZRMXP06C0!0Q!5QPD_028ACumAu6 literal 0 HcmV?d00001 diff --git a/regress/loader/mlines3dz.shp b/regress/loader/mlines3dz.shp new file mode 100644 index 0000000000000000000000000000000000000000..c2ad6cc1f81d9d068bfae1813dc37f7857916557 GIT binary patch literal 420 zcmZQzQ0HR64lcc5W?;Z2$-toE0MQ1cKiEU~GEi{{4@xou={dxh1+@zfy%>Zm_8T{GZ*F`7@q-$Juq`5pz<(%3={(ZT+I*j literal 0 HcmV?d00001 diff --git a/regress/loader/mlines3dz.shx b/regress/loader/mlines3dz.shx new file mode 100644 index 0000000000000000000000000000000000000000..10eaae9790fd134c633301766bcc8ebf12ee98b6 GIT binary patch literal 108 qcmZQzQ0HR64$NLKGce$iWMEKnfM|o!AM7D~8K^jf2PKVw^c(=lL +# +function fail () +{ + _msg="$1" + _log="$2" + + if [ -z "$_log" ]; then + echo " failed ($_msg)" + elif test "$VERBOSE" -eq "1"; then + echo " failed ($_msg: $_log)" + echo "-----------------------------------------------------------------------------" + cat $_log + echo "-----------------------------------------------------------------------------" + else + echo " failed ($_msg: $_log)" + fi + + FAIL=`expr $FAIL + 1` +} + +# +# run_simple_test +# +# Run an sql script and compare results with the given expected output +# +# SQL input is ${TEST}.sql, expected output is {$TEST}_expected +# +function run_simple_test () +{ + _sql="$1" + _expected="$2" + if [ -n "$3" ]; then + _msg="$3: " + else + _msg= + fi + + if [ ! -r "$_expected" ]; then + fail "can't read $_expected" + return 1 + fi + + + echo -n "." + + OUTFILE="${TMPDIR}/test_${RUN}_out" + TMPFILE="${TMPDIR}/test_${RUN}_tmp" + DIFFILE="${TMPDIR}/test_${RUN}_diff" + + # Use intermediate file to prevent MingW buffering problems + ${PSQL} -tA < "${TEST}.sql" ${DB} > ${TMPFILE} 2>&1 + cat ${TMPFILE} \ + | grep -v "^$" \ + | grep -v "^INSERT" \ + | grep -v "^UPDATE" \ + | grep -v "^DROP" \ + | grep -v "^CREATE" \ + | grep -v "^SET" \ + | sed 's/Infinity/inf/g;s/Inf/inf/g;s/1\.#INF/inf/g' \ + | sed 's/[eE]\([+-]\)0\{1,\}\([0-9]\{1,\}\)/e\1\2/g' \ + | sed 's/Self-intersection .*/Self-intersection/' \ + > "${OUTFILE}" + rm ${TMPFILE} + + if diff "${_expected}" "${OUTFILE}" > ${DIFFILE}; then + #SUCCESS=`expr $SUCCESS + 1` + rm "${OUTFILE}" "${DIFFILE}" # we don't need these anymore + return 0 + else + fail "${_msg}diff expected obtained" "${DIFFILE}" + rm "${OUTFILE}" # diff is enough + return 1 + fi +} + +# +# run_loader_test +# +# Load a shapefile with different methods, create a 'select *' SQL +# test and run simple test with provided expected output. +# +# SHP input is ${TEST}.shp, expected output is {$TEST}_expected +# +function run_loader_test () +{ + _tblname=loadertest + + # ON_ERROR_STOP is used by psql to return non-0 on an error + _psql_opts="--variable ON_ERROR_STOP=true" + + echo "SELECT * from ${_tblname}" > ${TEST}.sql + + + # + # Run in HEXWKB insert mode + # + + echo -n "." + + ${SHP2PGSQL} ${TEST}.shp $_tblname \ + > ${TMPDIR}/loader \ + 2> ${TMPDIR}/loader.err + + if [ $? -gt 0 ]; then + fail "running shp2pgsql" "${TMPDIR}/loader.err" + return 1 + + fi + + echo -n "." + + ${PSQL} -c "DROP table ${_tblname}" "${DB}" >> ${TMPDIR}/regress_log 2>&1 + ${PSQL} ${_psql_opts} -f ${TMPDIR}/loader "${DB}" > ${TMPDIR}/loader.err 2>&1 + if [ $? -gt 0 ]; then + fail "sourcing shp2pgsql output" "${TMPDIR}/loader.err" + return 1 + fi + + if ! run_simple_test ${TEST}.sql ${TEST}-wkb.expected "wkb insert"; then + return 1 + fi + + + # + # Run in HEXWKB dump mode + # + + echo -n "." + + ${SHP2PGSQL} -D ${TEST}.shp $_tblname \ + > ${TMPDIR}/loader \ + 2> ${TMPDIR}/loader.err + + if [ $? -gt 0 ]; then + fail "running shp2pgsql -D" "${TMPDIR}/loader.err" + return 1 + + fi + + echo -n "." + + ${PSQL} -c "DROP table ${_tblname}" "${DB}" >> ${TMPDIR}/regress_log 2>&1 + ${PSQL} ${_psql_opts} -f ${TMPDIR}/loader "${DB}" > ${TMPDIR}/loader.err 2>&1 + if [ $? -gt 0 ]; then + fail "sourcing shp2pgsql -D output" "${TMPDIR}/loader.err" + return 1 + fi + + if ! run_simple_test ${TEST}.sql ${TEST}-wkb.expected "wkb dump"; then + return 1 + fi + + ########################################################### + # + # Dump and compare. + # Do this using WKB mode, as WKT is unable to reproduce + # M values + # + + echo -n "." + + ${PGSQL2SHP} -f ${TMPDIR}/dumper ${DB} "${_tblname}" > "${TMPDIR}/dumper.err" 2>&1 + if [ $? -gt 0 ]; then + fail "dumping loaded table" "${TMPDIR}/dumper.err" + return 1 + fi + + echo -n "." + + if ! diff "${TMPDIR}"/dumper.shp "${TEST}".shp > /dev/null; then + ls -lL "${TMPDIR}"/dumper.shp "${TEST}".shp > "${TMPDIR}"/dumper.diff + fail "dumping loaded table" "${TMPDIR}/dumper.diff" + return 1 + fi + +# I'm not sure it's safe to compare indexes +# if ! diff "${TMPDIR}"/dumper.shx "${TEST}".shx; then +# ls -lL "${TMPDIR}"/dumper.shx "${TEST}".shx > "${TMPDIR}"/dumper.diff +# fail "dumping loaded table" "${TMPDIR}/dumper.diff" +# return 1 +# fi + +# Change in attribute sizes would make this fail +# if ! diff "${TMPDIR}"/dumper.dbf "${TEST}".dbf; then +# ls -lL "${TMPDIR}"/dumper.dbf "${TEST}".dbf > "${TMPDIR}"/dumper.diff +# fail "dumping loaded table" "${TMPDIR}/dumper.diff" +# return 1 +# fi + + + # + # End of dump and compare. + # + ################################################ + + echo -n "." + + ${SHP2PGSQL} -w ${TEST}.shp $_tblname \ + > ${TMPDIR}/loader \ + 2> ${TMPDIR}/loader.err + + if [ $? -gt 0 ]; then + fail "running shp2pgsql -w" "${TMPDIR}/loader.err" + return 1 + fi + + echo -n "." + + ${PSQL} -c "DROP table ${_tblname}" "${DB}" >> ${TMPDIR}/regress_log 2>&1 + ${PSQL} ${_psql_opts} -f ${TMPDIR}/loader "${DB}" > ${TMPDIR}/loader.err 2>&1 + if [ $? -gt 0 ]; then + fail "sourcing shp2pgsql -w output" "${TMPDIR}/loader.err" + return 1 + fi + + if ! run_simple_test ${TEST}.sql ${TEST}-wkt.expected "wkt insert"; then + return 1 + fi + + # + # Run in WKT dump mode + # + + echo -n "." + + ${SHP2PGSQL} -D -w ${TEST}.shp $_tblname \ + > ${TMPDIR}/loader \ + 2> ${TMPDIR}/loader.err + + if [ $? -gt 0 ]; then + fail "running shp2pgsql -D -w" "${TMPDIR}/loader.err" + return 1 + + fi + + echo -n "." + + ${PSQL} -c "DROP table ${_tblname}" "${DB}" >> ${TMPDIR}/regress_log 2>&1 + ${PSQL} ${_psql_opts} -f ${TMPDIR}/loader "${DB}" > ${TMPDIR}/loader.err 2>&1 + if [ $? -gt 0 ]; then + fail "sourcing shp2pgsql -D -w output" "${TMPDIR}/loader.err" + return 1 + fi + + if ! run_simple_test ${TEST}.sql ${TEST}-wkt.expected "wkt dump"; then + return 1 + fi + + rm ${TEST}.sql + + return 0; +} + +################################################### +# +# Parse command line opts +# +################################################### + while [ -n "$1" ]; do if test "$1" = "-v"; then @@ -50,17 +326,22 @@ if [ -z "$1" ]; then exit 1 fi +################################################### +# +# Prepare the database +# +################################################### -db_exists=`psql -l | grep -w ${DB}` +db_exists=`${PSQL} -l | grep -w ${DB}` if test -z "$db_exists"; then if test x"$OPT_CREATE" = "xyes"; then echo "Creating spatial db ${DB} " - createdb $DB > ${TMPDIR}/regress_log_$$ - createlang plpgsql $DB >> ${TMPDIR}/regress_log_$$ - psql -f lwpostgis.sql $DB >> ${TMPDIR}/regress_log_$$ 2>&1 + createdb "${DB}" > ${TMPDIR}/regress_log + createlang plpgsql "${DB}" >> ${TMPDIR}/regress_log + ${PSQL} -f lwpostgis.sql "${DB}" >> ${TMPDIR}/regress_log 2>&1 else echo "Database ${DB} does not exist" >&2 @@ -78,11 +359,11 @@ else fi fi -libver=`psql -tAc "select postgis_lib_version()" $DB` +libver=`${PSQL} -tAc "select postgis_lib_version()" "${DB}"` if [ -z "$libver" ]; then echo - echo " Something went wrong (no postgis installed in $DB)." + echo " Something went wrong (no postgis installed in ${DB})." if [ -z "$db_exists" ]; then echo " Check ${TMPDIR}/regress_log_$$ for details." else @@ -93,11 +374,17 @@ if [ -z "$libver" ]; then exit 1 fi -geosver=`psql -tAc "select postgis_geos_version()" $DB` -jtsver=`psql -tAc "select postgis_jts_version()" $DB` -projver=`psql -tAc "select postgis_proj_version()" $DB` -libbuilddate=`psql -tAc "select postgis_lib_build_date()" $DB` -pgsqlver=`psql -tAc "select version()" $DB` +################################################### +# +# Report runtime environment +# +################################################### + +geosver=`${PSQL} -tAc "select postgis_geos_version()" "${DB}"` +jtsver=`${PSQL} -tAc "select postgis_jts_version()" "${DB}"` +projver=`${PSQL} -tAc "select postgis_proj_version()" "${DB}"` +libbuilddate=`${PSQL} -tAc "select postgis_lib_build_date()" "${DB}"` +pgsqlver=`${PSQL} -tAc "select version()" "${DB}"` echo echo " $pgsqlver" @@ -112,6 +399,12 @@ if [ -n "$projver" ]; then echo " PROJ: $projver" fi +################################################### +# +# Run the tests +# +################################################### + echo echo "Running tests" echo @@ -119,78 +412,46 @@ echo RUN=0 SKIP=0 FAIL=0 -SUCCESS=0 +#SUCCESS=0 while [ -n "$1" ]; do TEST="$1"; shift; # catch a common mistake (strip trailing .sql) TEST=`echo "$TEST" | sed 's/\.sql$//'` - OUTFILE="${TMPDIR}/regress_${TEST}_out_$$" - TMPFILE="${TMPDIR}/regress_${TEST}_tmp_$$" - DIFFILE="${TMPDIR}/regress_${TEST}_diff_$$" + #printf %20s " ${TEST}" + echo -ne " ${TEST}" - printf %20s " ${TEST}: " - #echo -ne " ${TEST}:\t" + RUN=`expr $RUN + 1` - if [ ! -r "${TEST}.sql" ]; then + # Check .shp *before* .sql as loader test would + # create the .sql + if [ -r "${TEST}.shp" ]; then + if run_loader_test; then + echo " ok" + fi + elif [ -r "${TEST}.sql" ]; then + if run_simple_test ${TEST}.sql ${TEST}_expected; then + echo " ok" + fi + else echo "Skipped (can't read ${TEST}.sql)" SKIP=`expr $SKIP + 1` continue fi - if [ ! -r "${TEST}_expected" ]; then - echo " Skipped (can't read ${TEST}_expected)" - SKIP=`expr $SKIP + 1` - continue - fi - - # Use intermediate file to prevent MingW buffering problems - psql -tA < "${TEST}.sql" $DB > ${TMPFILE} 2>&1 - cat ${TMPFILE} \ - | grep -v "^$" \ - | grep -v "^INSERT" \ - | grep -v "^UPDATE" \ - | grep -v "^DROP" \ - | grep -v "^CREATE" \ - | grep -v "^SET" \ - | sed 's/Infinity/inf/g;s/Inf/inf/g;s/1\.#INF/inf/g' \ - | sed 's/[eE]\([+-]\)0\{1,\}\([0-9]\{1,\}\)/e\1\2/g' \ - | sed 's/Self-intersection .*/Self-intersection/' \ - > "${OUTFILE}" - rm ${TMPFILE} - - if diff "${TEST}_expected" "${OUTFILE}" > ${DIFFILE}; then - SUCCESS=`expr $SUCCESS + 1` - echo "Ok." - rm "${OUTFILE}" "${DIFFILE}" # we don't need these anymore - else - FAIL=`expr $FAIL + 1` - if test "$VERBOSE" -eq "1"; then - echo "Failed (diff ${DIFFILE})" - echo "-----------------------------------------------------------------------------" - echo "expected:'<' obtained:'>'" - echo "-----------------------------------------------------------------------------" - cat ${DIFFILE} - echo "-----------------------------------------------------------------------------" - else - echo "Failed (diff ${DIFFILE})" - fi - rm "${OUTFILE}" # diff is enough - fi - RUN=`expr $RUN + 1` done echo echo "Run tests: $RUN" #echo "Skipped: $SKIP" -echo "Successful: $SUCCESS" +#echo "Successful: $SUCCESS" echo "Failed: $FAIL" if test x"$OPT_DROP" = "xyes" -a x"$OPT_CREATE" = "xyes"; then sleep 1 - dropdb $DB > /dev/null + dropdb "${DB}" > /dev/null else : echo "Drop database ${DB} manually" fi