diff options
Diffstat (limited to 'odb-tests/common/ctor')
-rw-r--r-- | odb-tests/common/ctor/buildfile | 41 | ||||
-rw-r--r-- | odb-tests/common/ctor/driver.cxx | 79 | ||||
-rw-r--r-- | odb-tests/common/ctor/test.hxx | 29 | ||||
-rw-r--r-- | odb-tests/common/ctor/testscript | 33 |
4 files changed, 182 insertions, 0 deletions
diff --git a/odb-tests/common/ctor/buildfile b/odb-tests/common/ctor/buildfile new file mode 100644 index 0000000..a9892bc --- /dev/null +++ b/odb-tests/common/ctor/buildfile @@ -0,0 +1,41 @@ +# file : common/ctor/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 ctor_ \ + --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/ctor/driver.cxx b/odb-tests/common/ctor/driver.cxx new file mode 100644 index 0000000..c9b445d --- /dev/null +++ b/odb-tests/common/ctor/driver.cxx @@ -0,0 +1,79 @@ +// file : common/ctor/driver.cxx +// license : GNU GPL v2; see accompanying LICENSE file + +// Test support for persistent objects without default constructors. +// + +#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 + { + typedef odb::query<person> query; + typedef odb::result<person> result; + + unique_ptr<database> db (create_database (argc, argv)); + + person p1 ("John", "Doe", 30); + person p2 ("Jane", "Doe", 29); + person p3 ("Joe", "Dirt", 31); + + { + transaction t (db->begin ()); + + db->persist (p1); + db->persist (p2); + db->persist (p3); + + t.commit (); + } + + { + person p ("", "", 0); + + transaction t (db->begin ()); + + db->load (p1.id_, p); + + assert (p.first_ == p1.first_); + assert (p.last_ == p1.last_); + assert (p.age_ == p1.age_); + + result r (db->query<person> (query::age < 30)); + + assert (!r.empty ()); + + result::iterator i (r.begin ()); + i.load (p); + assert (p.first_ == "Jane"); + assert (p.last_ == "Doe"); + assert (p.age_ == 29); + + assert (size (r) == 1); + + t.commit (); + } + } + catch (const odb::exception& e) + { + cerr << e.what () << endl; + return 1; + } +} diff --git a/odb-tests/common/ctor/test.hxx b/odb-tests/common/ctor/test.hxx new file mode 100644 index 0000000..2a2becd --- /dev/null +++ b/odb-tests/common/ctor/test.hxx @@ -0,0 +1,29 @@ +// file : common/ctor/test.hxx +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef TEST_HXX +#define TEST_HXX + +#include <string> + +#include <odb/core.hxx> + +#pragma db object +struct person +{ + person (const std::string& first, + const std::string& last, + unsigned short age) + : first_ (first), last_ (last), age_ (age) + { + } + + #pragma db id auto + unsigned long id_; + + std::string first_; + std::string last_; + unsigned short age_; +}; + +#endif // TEST_HXX diff --git a/odb-tests/common/ctor/testscript b/odb-tests/common/ctor/testscript new file mode 100644 index 0000000..8946ddb --- /dev/null +++ b/odb-tests/common/ctor/testscript @@ -0,0 +1,33 @@ +# file : common/ctor/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; + $* +} |