diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2024-02-02 18:37:48 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2024-02-07 16:21:33 +0300 |
commit | 567871f6803756cec9eb0793ad937579d4864c51 (patch) | |
tree | d23718571621b63b0bc795992b9462dd4dd9107d /odb-tests/evolution/add-foreign-key | |
parent | 01bf760a937cc80901dac5b14fa8d165761ebd11 (diff) |
Add evolution tests to odb-tests
Also clean up some buildfiles and manifests.
Diffstat (limited to 'odb-tests/evolution/add-foreign-key')
-rw-r--r-- | odb-tests/evolution/add-foreign-key/buildfile | 64 | ||||
-rw-r--r-- | odb-tests/evolution/add-foreign-key/driver.cxx | 19 | ||||
-rw-r--r-- | odb-tests/evolution/add-foreign-key/model.hxx | 2 | ||||
-rw-r--r-- | odb-tests/evolution/add-foreign-key/testscript | 54 |
4 files changed, 131 insertions, 8 deletions
diff --git a/odb-tests/evolution/add-foreign-key/buildfile b/odb-tests/evolution/add-foreign-key/buildfile new file mode 100644 index 0000000..0fe5468 --- /dev/null +++ b/odb-tests/evolution/add-foreign-key/buildfile @@ -0,0 +1,64 @@ +# file : evolution/add-foreign-key/buildfile +# license : GNU GPL v2; see accompanying LICENSE file + +if ($build.meta_operation != 'dist') + assert (!$multi) "multi-database mode is not supported by this test" + +db = ($databases[0]) + +import libodb = libodb%lib{odb} +import libodb_db = libodb-$db%lib{odb-$db} +import libcommon = lib{common} + +hdrs = test1 test2 test3 + +exe{driver}: {hxx cxx}{* -*-odb} testscript + +# Introduce the metadata library target to make sure the libodb and libcommon +# libraries are resolved for the odb_compile ad hoc rule (see build/root.build +# for details). +# +libue{test-meta}: $libodb $libcommon + +for h: $hdrs + exe{driver}: {hxx ixx cxx}{$h-odb}: hxx{$h} libue{test-meta} hxx{model} + +# Make sure testN.hxx are compiled serially since they share the changelog. +# +# @@ TODO: make order-only when supported by build2. +# +{hxx ixx cxx}{test3-odb}: {hxx ixx cxx}{test2-odb}: {hxx ixx cxx}{test1-odb} + +exe{driver}: libue{test-meta} $libodb_db + +# Specify the ODB custom options to be used by the odb_compile ad hoc rule +# (see build/root.build for details). +# +odb_options = --table-prefix evo_add_fk_ \ + --schema-version-table evo_add_fk_sv \ + --generate-schema \ + --generate-query \ + --at-once \ + --changelog $out_base/model.xml \ + --fkeys-deferrable-mode not_deferrable + +<{hxx ixx cxx}{test1-odb}>: odb_options += --init-changelog +<{hxx ixx cxx}{test2-odb}>: odb_options += --omit-create --suppress-migration + +<{hxx ixx cxx}{test3-odb}>: +{ + odb_options += --omit-create + schema_versions = 002 003 +} + +cxx.poptions =+ "-I$out_base" "-I$src_base" + +# Testscript's run-time prerequisites. +# +exe{driver}: ../../alias{database-client}: include = adhoc + +testscript@./: +{ + db = $db + schemas = $hdrs +} diff --git a/odb-tests/evolution/add-foreign-key/driver.cxx b/odb-tests/evolution/add-foreign-key/driver.cxx index 177b615..dae9a9c 100644 --- a/odb-tests/evolution/add-foreign-key/driver.cxx +++ b/odb-tests/evolution/add-foreign-key/driver.cxx @@ -4,22 +4,24 @@ // Test adding a foreign key. // -#include <memory> // std::auto_ptr -#include <cassert> +#include <memory> // std::unique_ptr #include <iostream> #include <odb/database.hxx> #include <odb/transaction.hxx> #include <odb/schema-catalog.hxx> -#include <common/config.hxx> // DATABASE_XXX -#include <common/common.hxx> +#include <libcommon/config.hxx> // DATABASE_XXX +#include <libcommon/common.hxx> #include "test2.hxx" #include "test3.hxx" #include "test2-odb.hxx" #include "test3-odb.hxx" +#undef NDEBUG +#include <cassert> + using namespace std; using namespace odb::core; @@ -28,7 +30,10 @@ main (int argc, char* argv[]) { try { - auto_ptr<database> db (create_database (argc, argv, false)); + unique_ptr<database> db (create_database (argc, argv, false)); + + db->schema_version_table ("evo_add_fk_sv"); + bool embedded (schema_catalog::exists (*db)); // 1 - base version @@ -83,7 +88,7 @@ main (int argc, char* argv[]) // { transaction t (db->begin ()); - auto_ptr<object> p (db->load<object> (1)); + unique_ptr<object> p (db->load<object> (1)); assert (p->o1 == 0 && p->o2 == 0); @@ -122,7 +127,7 @@ main (int argc, char* argv[]) { transaction t (db->begin ()); - auto_ptr<object> p (db->load<object> (1)); + unique_ptr<object> p (db->load<object> (1)); assert (p->o1->id_ == 1); assert (p->o2->id_ == 1); t.commit (); diff --git a/odb-tests/evolution/add-foreign-key/model.hxx b/odb-tests/evolution/add-foreign-key/model.hxx index f5fe26d..17cd85f 100644 --- a/odb-tests/evolution/add-foreign-key/model.hxx +++ b/odb-tests/evolution/add-foreign-key/model.hxx @@ -9,7 +9,7 @@ #include <odb/core.hxx> -#include <common/config.hxx> // DATABASE_XXX +#include <libcommon/config.hxx> // DATABASE_XXX #pragma db model version(1, MODEL_VERSION) diff --git a/odb-tests/evolution/add-foreign-key/testscript b/odb-tests/evolution/add-foreign-key/testscript new file mode 100644 index 0000000..5447082 --- /dev/null +++ b/odb-tests/evolution/add-foreign-key/testscript @@ -0,0 +1,54 @@ +# file : evolution/add-foreign-key/testscript +# license : GNU GPL v2; see accompanying LICENSE file + +.include ../../database-options.testscript +.include ../../$db-schema.testscript + +test.arguments += $($(db)_options) + +: basics +: +if! $sqlite +{ + ss =; # Schema modification base file names. + + # Drop everything. + # + for s: $schemas + ss =+ $s + end; + + # Add base schema. + # + ss += test3-002-pre test3-002-post; + + # Add migration. + # + ss += test3-003-pre test3-003-post; + + # Run tests. + # + for s: $ss + f = $out_base/"$s".sql + + if $mysql + cat $f | $create_schema_cmd + elif $pgsql + $create_schema_cmd -f $f + end + + if ($s == 'test3-002-post') + $* 1 + elif ($s == 'test3-003-pre') + $* 2 + elif ($s == 'test3-003-post') + $* 3 + end + end +} +else +{ + $* 1 &odb-test.db; + $* 2; + $* 3 +} |