summaryrefslogtreecommitdiff
path: root/odb-tests/evolution/version
diff options
context:
space:
mode:
Diffstat (limited to 'odb-tests/evolution/version')
-rw-r--r--odb-tests/evolution/version/buildfile63
-rw-r--r--odb-tests/evolution/version/driver.cxx23
-rw-r--r--odb-tests/evolution/version/testscript54
3 files changed, 131 insertions, 9 deletions
diff --git a/odb-tests/evolution/version/buildfile b/odb-tests/evolution/version/buildfile
new file mode 100644
index 0000000..f11559f
--- /dev/null
+++ b/odb-tests/evolution/version/buildfile
@@ -0,0 +1,63 @@
+# file : evolution/version/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 libs = libodb-$db%lib{odb-$db}
+import libs += lib{common}
+
+hdrs = test1 test2 test3
+
+exe{driver}: {hxx cxx}{* -*-odb} testscript
+
+# Introduce the metadata library target to make sure the libodb library is
+# resolved for the odb_compile ad hoc rule (see build/root.build for details).
+#
+libue{test-meta}: $libodb
+
+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} $libs
+
+# 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_version_ \
+ --schema-version-table evo_version_sv \
+ --generate-schema \
+ --generate-query \
+ --at-once \
+ --changelog $out_base/model.xml
+
+<{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/version/driver.cxx b/odb-tests/evolution/version/driver.cxx
index 236c9b4..cc1b4b9 100644
--- a/odb-tests/evolution/version/driver.cxx
+++ b/odb-tests/evolution/version/driver.cxx
@@ -4,22 +4,24 @@
// Test schema version access via the database instance.
//
-#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_version_sv");
+
bool embedded (schema_catalog::exists (*db));
// 1 - base version
@@ -87,7 +92,7 @@ main (int argc, char* argv[])
{
transaction t (db->begin ());
- auto_ptr<object1> o1 (db->load<object1> (1));
+ unique_ptr<object1> o1 (db->load<object1> (1));
object2 o2 (1);
o2.num = o1->num;
db->persist (o2);
@@ -118,7 +123,7 @@ main (int argc, char* argv[])
{
transaction t (db->begin ());
- auto_ptr<object2> o2 (db->load<object2> (1));
+ unique_ptr<object2> o2 (db->load<object2> (1));
assert (o2->num == 123);
t.commit ();
}
@@ -131,9 +136,9 @@ main (int argc, char* argv[])
transaction t (db->begin ());
#ifdef DATABASE_ORACLE
- db->execute ("DROP TABLE \"schema_version\"");
+ db->execute ("DROP TABLE \"evo_version_sv\"");
#else
- db->execute ("DROP TABLE schema_version");
+ db->execute ("DROP TABLE evo_version_sv");
#endif
t.commit ();
}
diff --git a/odb-tests/evolution/version/testscript b/odb-tests/evolution/version/testscript
new file mode 100644
index 0000000..1a41b2d
--- /dev/null
+++ b/odb-tests/evolution/version/testscript
@@ -0,0 +1,54 @@
+# file : evolution/version/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
+}