diff options
Diffstat (limited to 'odb-tests/common/circular/multiple')
-rw-r--r-- | odb-tests/common/circular/multiple/.gitignore | 6 | ||||
-rw-r--r-- | odb-tests/common/circular/multiple/buildfile | 49 | ||||
-rw-r--r-- | odb-tests/common/circular/multiple/driver.cxx | 69 | ||||
-rw-r--r-- | odb-tests/common/circular/multiple/test1.hxx | 27 | ||||
-rw-r--r-- | odb-tests/common/circular/multiple/test2.hxx | 17 | ||||
-rw-r--r-- | odb-tests/common/circular/multiple/testscript | 31 |
6 files changed, 199 insertions, 0 deletions
diff --git a/odb-tests/common/circular/multiple/.gitignore b/odb-tests/common/circular/multiple/.gitignore new file mode 100644 index 0000000..5d39d39 --- /dev/null +++ b/odb-tests/common/circular/multiple/.gitignore @@ -0,0 +1,6 @@ +# ODB-generated files. +# +test1-odb.?xx +test1-odb-*.?xx +test2-odb.?xx +test2-odb-*.?xx diff --git a/odb-tests/common/circular/multiple/buildfile b/odb-tests/common/circular/multiple/buildfile new file mode 100644 index 0000000..b060cb5 --- /dev/null +++ b/odb-tests/common/circular/multiple/buildfile @@ -0,0 +1,49 @@ +# file : common/circular/multiple/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} + +hs = test1 test2 + +exe{driver}: {hxx cxx}{* -*-odb -*-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: $hs +{ + exe{driver}: {hxx ixx cxx}{$h-odb} + + <{hxx ixx cxx}{$h-odb}>: hxx{$h} libue{test-meta} + + for db: $databases + { + exe{driver}: {hxx ixx cxx}{$h-odb-$db}: include = $multi + <{hxx ixx cxx}{$h-odb-$db}>: hxx{$h} 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_m_ \ + --generate-schema \ + --generate-query \ + --schema-format embedded + +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/multiple/driver.cxx b/odb-tests/common/circular/multiple/driver.cxx new file mode 100644 index 0000000..4887ac2 --- /dev/null +++ b/odb-tests/common/circular/multiple/driver.cxx @@ -0,0 +1,69 @@ +// file : common/circular/multiple/driver.cxx +// license : GNU GPL v2; see accompanying LICENSE file + +// Test cases of circular dependencies between persistent classes, multiple +// files version. +// + +#include <memory> // std::unique_ptr +#include <iostream> + +#include <odb/database.hxx> +#include <odb/connection.hxx> +#include <odb/transaction.hxx> +#include <odb/schema-catalog.hxx> + +#include <libcommon/common.hxx> + +#include "test1.hxx" +#include "test2.hxx" + +#include "test2-odb.hxx" +#include "test1-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, false)); + + // Create the database schema. + // + { + connection_ptr c (db->connection ()); + + // Temporarily disable foreign key constraints for MySQL and SQLite. + // For these databases this is the only way to drop circularly- + // dependant tables. + // + if (db->id () == odb::id_mysql) + c->execute ("SET FOREIGN_KEY_CHECKS=0"); + else if (db->id () == odb::id_sqlite) + c->execute ("PRAGMA foreign_keys=OFF"); + + transaction t (c->begin ()); + schema_catalog::create_schema (*db); + t.commit (); + + if (db->id () == odb::id_mysql) + c->execute ("SET FOREIGN_KEY_CHECKS=1"); + else if (db->id () == odb::id_sqlite) + c->execute ("PRAGMA foreign_keys=ON"); + } + + 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/multiple/test1.hxx b/odb-tests/common/circular/multiple/test1.hxx new file mode 100644 index 0000000..36df963 --- /dev/null +++ b/odb-tests/common/circular/multiple/test1.hxx @@ -0,0 +1,27 @@ +// file : common/circular/multiple/test1.hxx +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef TEST1_HXX +#define TEST1_HXX + +#include <odb/core.hxx> + +#pragma db object +struct derived; + +#pragma db object polymorphic +struct base +{ + virtual ~base () {} + + #pragma db id + unsigned long id_; + + derived* d_; +}; + +#ifdef ODB_COMPILER +# include "test2.hxx" +#endif + +#endif // TEST1_HXX diff --git a/odb-tests/common/circular/multiple/test2.hxx b/odb-tests/common/circular/multiple/test2.hxx new file mode 100644 index 0000000..49e9ed2 --- /dev/null +++ b/odb-tests/common/circular/multiple/test2.hxx @@ -0,0 +1,17 @@ +// file : common/circular/multiple/test2.hxx +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef TEST2_HXX +#define TEST2_HXX + +#include <odb/core.hxx> + +#include "test1.hxx" + +#pragma db object +struct derived: base +{ + base* b_; +}; + +#endif // TEST2_HXX diff --git a/odb-tests/common/circular/multiple/testscript b/odb-tests/common/circular/multiple/testscript new file mode 100644 index 0000000..6a05dc6 --- /dev/null +++ b/odb-tests/common/circular/multiple/testscript @@ -0,0 +1,31 @@ +# file : common/circular/multiple/testscript +# license : GNU GPL v2; see accompanying LICENSE file + +.include ../../../database-options.testscript + +: mysql +: +if $mysql +{ + .include ../../../mysql.testscript + + $* +} + +: sqlite +: +if $sqlite +{ + .include ../../../sqlite.testscript + + $* +} + +: pgsql +: +if $pgsql +{ + .include ../../../pgsql.testscript + + $* +} |