diff --git a/geodiff/src/geodiff.cpp b/geodiff/src/geodiff.cpp index f5226dbb..3d0c11ae 100644 --- a/geodiff/src/geodiff.cpp +++ b/geodiff/src/geodiff.cpp @@ -23,7 +23,7 @@ const char *GEODIFF_version() { - return "0.2.6"; + return "0.3.0"; } void _errorLogCallback( void *pArg, int iErrCode, const char *zMsg ) diff --git a/geodiff/src/geodiffutils.cpp b/geodiff/src/geodiffutils.cpp index 74d004ac..74b68531 100644 --- a/geodiff/src/geodiffutils.cpp +++ b/geodiff/src/geodiffutils.cpp @@ -823,13 +823,17 @@ void tables( std::shared_ptr db, rtree_simple_geometry_node rtree_simple_geometry_parent rtree_simple_geometry_rowid - simple + simple (or any other name(s) of layers) sqlite_sequence */ - if ( startsWith( tableName, "gpkg_" ) ) + + // table handled by triggers trigger_*_feature_count_* + if ( startsWith( tableName, "gpkg_ogr_contents" ) ) continue; + // table handled by triggers rtree_*_geometry_* if ( startsWith( tableName, "rtree_" ) ) continue; + // internal table for AUTOINCREMENT if ( tableName == "sqlite_sequence" ) continue; diff --git a/geodiff/tests/geodiff_testutils.cpp b/geodiff/tests/geodiff_testutils.cpp index 7f29bbfc..4a9d5b70 100644 --- a/geodiff/tests/geodiff_testutils.cpp +++ b/geodiff/tests/geodiff_testutils.cpp @@ -102,13 +102,17 @@ void finalize_test() { } -bool equals( const std::string &file1, const std::string &file2 ) +bool equals( const std::string &file1, const std::string &file2, bool ignore_timestamp_change ) { std::string changeset = file1 + "_changeset.bin"; if ( GEODIFF_createChangeset( file1.c_str(), file2.c_str(), changeset.c_str() ) != GEODIFF_SUCCESS ) return false; - return ( GEODIFF_listChanges( changeset.c_str() ) == 0 ); + int expected_changes = 0; + if ( ignore_timestamp_change ) + expected_changes = 1; + + return ( GEODIFF_listChanges( changeset.c_str() ) == expected_changes ); } void makedir( const std::string &dir ) diff --git a/geodiff/tests/geodiff_testutils.hpp b/geodiff/tests/geodiff_testutils.hpp index 62701593..ad4e29eb 100644 --- a/geodiff/tests/geodiff_testutils.hpp +++ b/geodiff/tests/geodiff_testutils.hpp @@ -23,6 +23,11 @@ void finalize_test(); std::string test_file( std::string basename ); std::string tmp_file( std::string basename ); -bool equals( const std::string &file1, const std::string &file2 ); +/** + * \param ignore_timestamp_change ignore last_change in table gpkg_contents + */ +bool equals( const std::string &file1, + const std::string &file2, + bool ignore_timestamp_change = false ); #endif // GEODIFF_TESTUTILS_HPP diff --git a/geodiff/tests/test_concurrent_commits.cpp b/geodiff/tests/test_concurrent_commits.cpp index 0735f066..c4001471 100644 --- a/geodiff/tests/test_concurrent_commits.cpp +++ b/geodiff/tests/test_concurrent_commits.cpp @@ -15,7 +15,8 @@ bool _test( const std::string &expected_AB, int expected_changes_A, int expected_changes_AB, - int expected_changes_XB + int expected_changes_XB, + bool ignore_timestamp_change = false ) { makedir( pathjoin( tmpdir(), testname ) ); @@ -80,7 +81,7 @@ bool _test( // check that it equals expected result std::cout << "final file: " << patchedAB << std::endl; - return equals( patchedAB, expected_patchedAB ) ; + return equals( patchedAB, expected_patchedAB, ignore_timestamp_change ) ; } TEST( ConcurrentCommitsSqlite3Test, test_2_inserts ) @@ -95,9 +96,9 @@ TEST( ConcurrentCommitsSqlite3Test, test_2_inserts ) "inserted_1_A.gpkg", "inserted_1_B.gpkg", "merged_1_A_1_B.gpkg", - 1, - 1, - 2 + 2, + 2, + 3 ); ASSERT_TRUE( ret ); } @@ -116,9 +117,9 @@ TEST( ConcurrentCommitsSqlite3Test, test_2_edits ) "updated_A.gpkg", "updated_B.gpkg", "merged_1_A_1_B.gpkg", - 1, - 1, - 1 + 2, + 2, + 2 ); ASSERT_TRUE( ret ); } @@ -135,9 +136,9 @@ TEST( ConcurrentCommitsSqlite3Test, test_2_deletes ) "deleted_A.gpkg", "deleted_B.gpkg", "merged_A_B.gpkg", + 2, 1, - 0, - 1 + 2 ); ASSERT_TRUE( ret ); } @@ -154,9 +155,10 @@ TEST( ConcurrentCommitsSqlite3Test, test_delete_update ) "deleted_A.gpkg", "updated_B.gpkg", "deleted_A.gpkg", + 2, 1, - 0, - 1 + 2, + true ); ASSERT_TRUE( ret ); } @@ -173,9 +175,9 @@ TEST( ConcurrentCommitsSqlite3Test, test_update_delete ) "updated_A.gpkg", "deleted_B.gpkg", "deleted_B.gpkg", - 1, - 1, - 1 + 2, + 2, + 2 ); ASSERT_TRUE( ret ); } diff --git a/geodiff/tests/test_modified_scheme.cpp b/geodiff/tests/test_modified_scheme.cpp index 6e63f177..74a55e2b 100644 --- a/geodiff/tests/test_modified_scheme.cpp +++ b/geodiff/tests/test_modified_scheme.cpp @@ -85,20 +85,6 @@ TEST( ModifiedSchemeSqlite3Test, rename_attribute ) ASSERT_EQ( GEODIFF_createChangeset( base.c_str(), modified.c_str(), changeset.c_str() ), GEODIFF_UNSUPPORTED_CHANGE ); } -TEST( ModifiedSchemeSqlite3Test, retype_attribute ) -{ - std::cout << "geopackage attribute count is same, have same name, but different type" << std::endl; - std::string testname = "retype_attribute"; - makedir( pathjoin( tmpdir(), testname ) ); - - std::string base = pathjoin( testdir(), "modified_scheme", "added_attribute.gpkg" ); - std::string modified = pathjoin( testdir(), "modified_scheme", "added_attribute_different_type.gpkg" ); - std::string changeset = pathjoin( tmpdir(), testname, "changeset.bin" ); - - // this is supported since sqlite3 uses dynamic run-time typing - ASSERT_EQ( GEODIFF_createChangeset( base.c_str(), modified.c_str(), changeset.c_str() ), GEODIFF_SUCCESS ); -} - int main( int argc, char **argv ) { testing::InitGoogleTest( &argc, argv ); diff --git a/geodiff/tests/test_single_commit.cpp b/geodiff/tests/test_single_commit.cpp index 33437c77..47a16170 100644 --- a/geodiff/tests/test_single_commit.cpp +++ b/geodiff/tests/test_single_commit.cpp @@ -7,43 +7,95 @@ #include "geodiff_testutils.hpp" #include "geodiff.h" -TEST( SingleCommitSqlite3Test, test_sqlite_no_gis ) +bool _test( + const std::string &testname, + const std::string &basename, + const std::string &modifiedname, + int expected_changes, + bool ignore_timestamp_change = false +) { - std::cout << "sqlite 2 updated 1 added 1 deleted" << std::endl; - std::string testname = "pure_sqlite"; + std::cout << testname << std::endl; makedir( pathjoin( tmpdir(), testname ) ); - std::string base = pathjoin( testdir(), "base.sqlite" ); - std::string modified = pathjoin( testdir(), testname, "modified_base.sqlite" ); - std::string changeset = pathjoin( tmpdir(), testname, "changeset_base_sqlite.bin" ); - std::string changeset2 = pathjoin( tmpdir(), testname, "changeset_after_apply_base_sqlite.bin" ); - std::string patched = pathjoin( tmpdir(), testname, "patched_base_sqlite.gpkg" ); + std::string base = pathjoin( testdir(), basename ); + std::string modified = pathjoin( testdir(), modifiedname ); + std::string changeset = pathjoin( tmpdir(), testname, "changeset.bin" ); + std::string patched = pathjoin( tmpdir(), testname, "patched.gpkg" ); + + if ( GEODIFF_createChangeset( base.c_str(), modified.c_str(), changeset.c_str() ) != GEODIFF_SUCCESS ) + { + std::cout << "err GEODIFF_createChangeset" << std::endl; + return false; + } - ASSERT_EQ( GEODIFF_createChangeset( base.c_str(), modified.c_str(), changeset.c_str() ), GEODIFF_SUCCESS ); - ASSERT_EQ( GEODIFF_listChanges( changeset.c_str() ), 4 ); - ASSERT_EQ( GEODIFF_applyChangeset( base.c_str(), patched.c_str(), changeset.c_str() ), GEODIFF_SUCCESS ); + int nchanges = GEODIFF_listChanges( changeset.c_str() ); + if ( nchanges != expected_changes ) + { + std::cout << "err GEODIFF_listChanges " << nchanges << " vs " << expected_changes << std::endl; + return false; + } + + if ( GEODIFF_applyChangeset( base.c_str(), patched.c_str(), changeset.c_str() ) != GEODIFF_SUCCESS ) + { + std::cout << "err GEODIFF_applyChangeset" << std::endl; + return false; + } // check that now it is same file - ASSERT_TRUE( equals( patched, modified ) ); + if ( !equals( patched, modified, ignore_timestamp_change ) ) + { + std::cout << "err equals" << std::endl; + return false; + } + + return true; + +} + + +TEST( SingleCommitSqlite3Test, test_sqlite_no_gis ) +{ + std::cout << "sqlite 2 updated 1 added 1 deleted" << std::endl; + bool ret = _test( "pure_sqlite", + "base.sqlite", + pathjoin( "pure_sqlite", "modified_base.sqlite" ), + 4 + ); + ASSERT_TRUE( ret ); } TEST( SingleCommitSqlite3Test, geopackage ) { std::cout << "geopackage 1 updated geometry" << std::endl; - std::string testname = "1_geopackage"; - makedir( pathjoin( tmpdir(), testname ) ); - - std::string base = pathjoin( testdir(), "base.gpkg" ); - std::string modified = pathjoin( testdir(), testname, "modified_1_geom.gpkg" ); - std::string changeset = pathjoin( tmpdir(), testname, "changeset_base_gpkg.bin" ); - std::string patched = pathjoin( tmpdir(), testname, "patched_base_gpkg.gpkg" ); + bool ret = _test( "1_geopackage", + "base.gpkg", + pathjoin( "1_geopackage", "modified_1_geom.gpkg" ), + 2 + ); + ASSERT_TRUE( ret ); +} - ASSERT_EQ( GEODIFF_createChangeset( base.c_str(), modified.c_str(), changeset.c_str() ), GEODIFF_SUCCESS ); - ASSERT_EQ( GEODIFF_listChanges( changeset.c_str() ), 1 ); - ASSERT_EQ( GEODIFF_applyChangeset( base.c_str(), patched.c_str(), changeset.c_str() ), GEODIFF_SUCCESS ); +TEST( SingleCommitSqlite3Test, retype_attribute ) +{ + std::cout << "geopackage attribute count is same, have same name, but different type" << std::endl; + bool ret = _test( "retype_attribute", + pathjoin( "modified_scheme", "added_attribute.gpkg" ), + pathjoin( "modified_scheme", "added_attribute_different_type.gpkg" ), + 4 + ); + ASSERT_TRUE( ret ); +} - // check that now it is same file - ASSERT_TRUE( equals( patched, modified ) ); +TEST( SingleCommitSqlite3Test, reprojected ) +{ + std::cout << "geopackage change of crs" << std::endl; + bool ret = _test( "reprojected", + pathjoin( "modified_scheme", "reprojected.gpkg" ), + pathjoin( "modified_scheme", "reprojected2.gpkg" ), + 6 + ); + ASSERT_TRUE( ret ); } int main( int argc, char **argv ) diff --git a/geodiff/tests/testdata/base.gpkg b/geodiff/tests/testdata/base.gpkg index 282d9a8b..33499579 100644 Binary files a/geodiff/tests/testdata/base.gpkg and b/geodiff/tests/testdata/base.gpkg differ diff --git a/geodiff/tests/testdata/modified_scheme/reprojected.gpkg b/geodiff/tests/testdata/modified_scheme/reprojected.gpkg new file mode 100644 index 00000000..a4624f1d Binary files /dev/null and b/geodiff/tests/testdata/modified_scheme/reprojected.gpkg differ diff --git a/geodiff/tests/testdata/modified_scheme/reprojected2.gpkg b/geodiff/tests/testdata/modified_scheme/reprojected2.gpkg new file mode 100644 index 00000000..e0c4e077 Binary files /dev/null and b/geodiff/tests/testdata/modified_scheme/reprojected2.gpkg differ diff --git a/pygeodiff/__about__.py b/pygeodiff/__about__.py index 0ae21eaf..68561628 100644 --- a/pygeodiff/__about__.py +++ b/pygeodiff/__about__.py @@ -1,7 +1,7 @@ __title__ = 'PyGeoDiff' __description__ = 'Diff tool for geo-spatial data' __url__ = 'https://github.com/lutraconsulting/geodiff' -__version__ = '0.2.6' +__version__ = '0.3.0' __author__ = 'Peter Petrik' __author_email__ = 'zilolv@gmail.com' __maintainer__ = 'Peter Petrik' diff --git a/pygeodiff/tests/test_concurrent_commits.py b/pygeodiff/tests/test_concurrent_commits.py index 5decbb82..fbefb995 100644 --- a/pygeodiff/tests/test_concurrent_commits.py +++ b/pygeodiff/tests/test_concurrent_commits.py @@ -27,15 +27,15 @@ def test_2_inserts(self): print("create changeset base to A") self.geodiff.create_changeset(base, modifiedA, changesetbaseA) - check_nchanges(self.geodiff, changesetbaseA, 1) + check_nchanges(self.geodiff, changesetbaseA, 2) print("create changeset A to B") self.geodiff.create_rebased_changeset(base, modifiedB, changesetbaseA, changesetAB) - check_nchanges(self.geodiff, changesetAB, 1) + check_nchanges(self.geodiff, changesetAB, 2) print("apply changeset to A to get AB") self.geodiff.apply_changeset(modifiedA, patchedAB, changesetAB) print("check that then new data has both features\n") self.geodiff.create_changeset(base, patchedAB, changesetBbase) - check_nchanges(self.geodiff, changesetBbase, 2) + check_nchanges(self.geodiff, changesetBbase, 3) diff --git a/pygeodiff/tests/test_single_commit.py b/pygeodiff/tests/test_single_commit.py index 41ea1390..8774429b 100644 --- a/pygeodiff/tests/test_single_commit.py +++ b/pygeodiff/tests/test_single_commit.py @@ -53,4 +53,4 @@ def test_geopackage(self): "1_geopackage", "base.gpkg", "modified_1_geom.gpkg", - 1) + 2) diff --git a/pyproject.toml b/pyproject.toml index 75335283..4546686d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,2 +1,2 @@ [build-system] -requires = ["setuptools", "wheel", "scikit-build", "cmake", "ninja"] +requires = ["setuptools", "wheel", "scikit-build", "cmake"] diff --git a/scripts/update_version.bash b/scripts/update_version.bash new file mode 100755 index 00000000..ac6bfbb8 --- /dev/null +++ b/scripts/update_version.bash @@ -0,0 +1,8 @@ +#!/bin/bash +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +VER=$1 + +python3 $DIR/update_version.py --version $VER + + + diff --git a/setup.py b/setup.py index 70295e89..d8d0dc8d 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ #from setuptools import setup from skbuild import setup -VERSION = '0.2.6' +VERSION = '0.3.0' setup( name="pygeodiff",