summaryrefslogtreecommitdiff
path: root/odb-tests/common/circular/single
diff options
context:
space:
mode:
Diffstat (limited to 'odb-tests/common/circular/single')
-rw-r--r--odb-tests/common/circular/single/buildfile41
-rw-r--r--odb-tests/common/circular/single/driver.cxx40
-rw-r--r--odb-tests/common/circular/single/test.hxx28
-rw-r--r--odb-tests/common/circular/single/testscript33
4 files changed, 142 insertions, 0 deletions
diff --git a/odb-tests/common/circular/single/buildfile b/odb-tests/common/circular/single/buildfile
new file mode 100644
index 0000000..740ce91
--- /dev/null
+++ b/odb-tests/common/circular/single/buildfile
@@ -0,0 +1,41 @@
+# file : common/circular/single/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 circular_s_ \
+ --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/circular/single/driver.cxx b/odb-tests/common/circular/single/driver.cxx
new file mode 100644
index 0000000..9bcb135
--- /dev/null
+++ b/odb-tests/common/circular/single/driver.cxx
@@ -0,0 +1,40 @@
+// file : common/circular/single/driver.cxx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+// Test cases of circular dependencies between persistent classes, single
+// file version.
+//
+
+#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));
+
+ query<base> bq (query<base>::d->id != 0);
+ query<derived> dq (query<derived>::b->id != 0);
+ }
+ catch (const odb::exception& e)
+ {
+ cerr << e.what () << endl;
+ return 1;
+ }
+}
diff --git a/odb-tests/common/circular/single/test.hxx b/odb-tests/common/circular/single/test.hxx
new file mode 100644
index 0000000..7f95dea
--- /dev/null
+++ b/odb-tests/common/circular/single/test.hxx
@@ -0,0 +1,28 @@
+// file : common/circular/single/test.hxx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef TEST_HXX
+#define TEST_HXX
+
+#include <odb/core.hxx>
+
+struct derived;
+
+#pragma db object polymorphic
+struct base
+{
+ virtual ~base () {}
+
+ #pragma db id
+ unsigned long id_;
+
+ derived* d_;
+};
+
+#pragma db object
+struct derived: base
+{
+ base* b_;
+};
+
+#endif // TEST_HXX
diff --git a/odb-tests/common/circular/single/testscript b/odb-tests/common/circular/single/testscript
new file mode 100644
index 0000000..b870306
--- /dev/null
+++ b/odb-tests/common/circular/single/testscript
@@ -0,0 +1,33 @@
+# file : common/circular/single/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;
+ $*
+}