summaryrefslogtreecommitdiff
path: root/odb-tests/common/object
diff options
context:
space:
mode:
Diffstat (limited to 'odb-tests/common/object')
-rw-r--r--odb-tests/common/object/buildfile41
-rw-r--r--odb-tests/common/object/driver.cxx84
-rw-r--r--odb-tests/common/object/test.hxx49
-rw-r--r--odb-tests/common/object/testscript53
4 files changed, 227 insertions, 0 deletions
diff --git a/odb-tests/common/object/buildfile b/odb-tests/common/object/buildfile
new file mode 100644
index 0000000..cb56aee
--- /dev/null
+++ b/odb-tests/common/object/buildfile
@@ -0,0 +1,41 @@
+# file : common/object/buildfile
+# license : GNU GPL v2; see accompanying LICENSE file
+
+import libodb = libodb%lib{odb}
+
+libs =
+
+for db: $databases
+ import libs += libodb-$db%lib{odb-$db}
+
+import libs += lib{common}
+
+exe{driver}: {hxx cxx}{* -*-odb -*-odb-*} {hxx ixx cxx}{test-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
+
+<{hxx ixx cxx}{test-odb}>: hxx{test} libue{test-meta}
+
+for db: $databases
+{
+ exe{driver}: {hxx ixx cxx}{test-odb-$db}: include = $multi
+ <{hxx ixx cxx}{test-odb-$db}>: hxx{test} libue{test-meta}
+}
+
+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 object_ \
+ --generate-schema \
+ --generate-query
+
+cxx.poptions =+ "-I$out_base" "-I$src_base"
+
+# Testscript's run-time prerequisites.
+#
+exe{driver}: ../../alias{database-client}: include = adhoc
diff --git a/odb-tests/common/object/driver.cxx b/odb-tests/common/object/driver.cxx
new file mode 100644
index 0000000..1c29417
--- /dev/null
+++ b/odb-tests/common/object/driver.cxx
@@ -0,0 +1,84 @@
+// file : common/object/driver.cxx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+// Test persistent classes.
+//
+
+#include <memory> // std::unique_ptr
+#include <iostream>
+
+#include <odb/database.hxx>
+#include <odb/transaction.hxx>
+
+#include <libcommon/common.hxx>
+
+#include "test.hxx"
+#include "test-odb.hxx"
+
+#undef NDEBUG
+#include <cassert>
+
+using namespace std;
+using namespace odb::core;
+
+int
+main (int argc, char* argv[])
+{
+ try
+ {
+ unique_ptr<database> db (create_database (argc, argv));
+
+ // Test persistent class template instantiation.
+ //
+ {
+ using namespace test1;
+
+ pair_object po;
+ po.second = "abc";
+
+ derived d;
+ d.x = "abc";
+ d.n = 123;
+
+ // persist
+ //
+ {
+ transaction t (db->begin ());
+ db->persist<pair_object> (po);
+ db->persist (d);
+ t.commit ();
+ }
+
+ // load & check
+ //
+ {
+ transaction t (db->begin ());
+ unique_ptr<pair_object> po1 (db->load<pair_object> (po.first));
+ unique_ptr<derived> d1 (db->load<derived> (d.id));
+ t.commit ();
+
+ assert (po == *po1);
+
+ assert (d.x == d1->x);
+ assert (d.n == d1->n);
+ }
+
+ // Test the API confusion.
+ //
+ {
+ transaction t (db->begin ());
+ db->update<pair_object> (po);
+ db->reload<pair_object> (po);
+ db->erase<pair_object> (po);
+
+ db->query<pair_object> ();
+ t.commit ();
+ }
+ }
+ }
+ catch (const odb::exception& e)
+ {
+ cerr << e.what () << endl;
+ return 1;
+ }
+}
diff --git a/odb-tests/common/object/test.hxx b/odb-tests/common/object/test.hxx
new file mode 100644
index 0000000..87bac91
--- /dev/null
+++ b/odb-tests/common/object/test.hxx
@@ -0,0 +1,49 @@
+// file : common/object/test.hxx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef TEST_HXX
+#define TEST_HXX
+
+#include <string>
+#include <utility> // std::pair
+
+#include <odb/core.hxx>
+
+// Test persistent class template instantiation.
+//
+#pragma db namespace table("t1_")
+namespace test1
+{
+ typedef std::pair<unsigned long, std::string> pair_object;
+ #pragma db object(pair_object)
+ #pragma db member(pair_object::first) id auto
+
+ #pragma db object abstract
+ struct base_data
+ {
+ #pragma db id auto
+ unsigned long id;
+ };
+
+ template <typename T>
+ struct base: base_data
+ {
+ T x;
+ };
+
+ typedef base<std::string> base_derived;
+ #pragma db object(base_derived) abstract
+
+ #pragma db object
+ struct derived: base_derived
+ {
+ int n;
+ };
+
+ // Test instantiation in order to "see" id, etc.
+ //
+ typedef base<int> int_base;
+ #pragma db object(int_base)
+}
+
+#endif // TEST_HXX
diff --git a/odb-tests/common/object/testscript b/odb-tests/common/object/testscript
new file mode 100644
index 0000000..45737c1
--- /dev/null
+++ b/odb-tests/common/object/testscript
@@ -0,0 +1,53 @@
+# file : common/object/testscript
+# license : GNU GPL v2; see accompanying LICENSE file
+
+.include ../../database-options.testscript
+
+: mysql
+:
+if $mysql
+{
+ .include ../../mysql.testscript
+
+ $create_schema;
+ $*
+}
+
+: sqlite
+:
+if $sqlite
+{
+ .include ../../sqlite.testscript
+
+ $*
+}
+
+: pgsql
+:
+if $pgsql
+{
+ .include ../../pgsql.testscript
+
+ $create_schema;
+ $*
+}
+
+: oracle
+:
+if $oracle
+{
+ .include ../../oracle.testscript
+
+ $create_schema;
+ $*
+}
+
+: mssql
+:
+if $mssql
+{
+ .include ../../mssql.testscript
+
+ $create_schema;
+ $*
+}