diff options
Diffstat (limited to 'odb-tests/common/inheritance/transient')
-rw-r--r-- | odb-tests/common/inheritance/transient/buildfile | 41 | ||||
-rw-r--r-- | odb-tests/common/inheritance/transient/driver.cxx | 80 | ||||
-rw-r--r-- | odb-tests/common/inheritance/transient/test.hxx | 60 | ||||
-rw-r--r-- | odb-tests/common/inheritance/transient/testscript | 33 |
4 files changed, 214 insertions, 0 deletions
diff --git a/odb-tests/common/inheritance/transient/buildfile b/odb-tests/common/inheritance/transient/buildfile new file mode 100644 index 0000000..1961abc --- /dev/null +++ b/odb-tests/common/inheritance/transient/buildfile @@ -0,0 +1,41 @@ +# file : common/inheritance/transient/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 inhrt_t_ \ + --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/inheritance/transient/driver.cxx b/odb-tests/common/inheritance/transient/driver.cxx new file mode 100644 index 0000000..1caae6c --- /dev/null +++ b/odb-tests/common/inheritance/transient/driver.cxx @@ -0,0 +1,80 @@ +// file : common/inheritance/transient/driver.cxx +// license : GNU GPL v2; see accompanying LICENSE file + +// Test transient inheritance of objects, composite value types, and views. +// + +#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)); + + object o; + o.num = 1; + o.str = "abc"; + o.strs.push_back ("abc 1"); + o.strs.push_back ("abc 2"); + o.c.num = 11; + o.c.str = "comp abc"; + o.c.nums.push_back (111); + o.c.nums.push_back (112); + + // persist + // + { + transaction t (db->begin ()); + db->persist (o); + t.commit (); + } + + // load & check + // + { + transaction t (db->begin ()); + unique_ptr<object> p (db->load<object> (o.id_)); + t.commit (); + + assert (*p == o); + } + + // view + // + { + typedef odb::query<view> query; + typedef odb::result<view> result; + + transaction t (db->begin ()); + + result r (db->query<view> (query::id == o.id_)); + result::iterator i (r.begin ()); + assert (i != r.end () && i->num == o.num && i->str == o.str); + assert (++i == r.end ()); + + t.commit (); + } + } + catch (const odb::exception& e) + { + cerr << e.what () << endl; + return 1; + } +} diff --git a/odb-tests/common/inheritance/transient/test.hxx b/odb-tests/common/inheritance/transient/test.hxx new file mode 100644 index 0000000..394ee8f --- /dev/null +++ b/odb-tests/common/inheritance/transient/test.hxx @@ -0,0 +1,60 @@ +// file : common/inheritance/transient/test.hxx +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef TEST_HXX +#define TEST_HXX + +#include <string> +#include <vector> + +#include <odb/core.hxx> + +struct object; + +struct base +{ + int n; + std::vector<std::string> v; + object* p; +}; + +#pragma db value +struct comp: base +{ + unsigned int num; + std::string str; + std::vector<unsigned int> nums; + + bool + operator== (const comp& y) const + { + return num == y.num && str == y.str && nums == y.nums; + } +}; + +#pragma db object +struct object: base +{ + #pragma db id auto + unsigned int id_; + + unsigned int num; + std::string str; + std::vector<std::string> strs; + comp c; + + bool + operator== (const object& y) const + { + return num == y.num && str == y.str && strs == y.strs && c == y.c; + } +}; + +#pragma db view object(object) +struct view: base +{ + unsigned int num; + std::string str; +}; + +#endif // TEST_HXX diff --git a/odb-tests/common/inheritance/transient/testscript b/odb-tests/common/inheritance/transient/testscript new file mode 100644 index 0000000..bce91de --- /dev/null +++ b/odb-tests/common/inheritance/transient/testscript @@ -0,0 +1,33 @@ +# file : common/inheritance/transient/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; + $* +} |