summaryrefslogtreecommitdiff
path: root/odb-tests/boost/common/uuid
diff options
context:
space:
mode:
Diffstat (limited to 'odb-tests/boost/common/uuid')
-rw-r--r--odb-tests/boost/common/uuid/buildfile49
-rw-r--r--odb-tests/boost/common/uuid/driver.cxx71
-rw-r--r--odb-tests/boost/common/uuid/test.hxx37
-rw-r--r--odb-tests/boost/common/uuid/testscript53
4 files changed, 210 insertions, 0 deletions
diff --git a/odb-tests/boost/common/uuid/buildfile b/odb-tests/boost/common/uuid/buildfile
new file mode 100644
index 0000000..32f226c
--- /dev/null
+++ b/odb-tests/boost/common/uuid/buildfile
@@ -0,0 +1,49 @@
+# file : boost/common/uuid/buildfile
+# license : GNU GPL v2; see accompanying LICENSE file
+
+import meta_libs = libodb%lib{odb}
+import meta_libs += libodb-boost%lib{odb-boost}
+import meta_libs += libboost-uuid%lib{boost_uuid}
+
+libs =
+
+for db: $databases
+ import libs += libodb-$db%lib{odb-$db}
+
+import libs += lib{common}
+
+exe{driver}: {hxx cxx}{* -test-odb -test-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}: $meta_libs
+
+<{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 boost_uuid_ \
+ --profile boost/uuid \
+ --generate-schema \
+ --generate-query
+
+cxx.poptions =+ "-I$out_base" "-I$src_base"
+
+# @@ TMP Until https://github.com/build2-packaging/boost/issues/2 is fixed.
+#
+if ($cxx.target.class == 'windows')
+ cxx.libs += ($cxx.target.system == 'mingw32' ? -lbcrypt : bcrypt.lib)
+
+# Testscript's run-time prerequisites.
+#
+exe{driver}: ../../../alias{database-client}: include = adhoc
diff --git a/odb-tests/boost/common/uuid/driver.cxx b/odb-tests/boost/common/uuid/driver.cxx
new file mode 100644
index 0000000..8b1018f
--- /dev/null
+++ b/odb-tests/boost/common/uuid/driver.cxx
@@ -0,0 +1,71 @@
+// file : boost/common/uuid/driver.cxx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+// Test Boost UUID persistence.
+//
+
+#include <memory> // std::unique_ptr
+#include <iostream>
+
+#include <boost/uuid/uuid_generators.hpp>
+
+#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 boost::uuids;
+using namespace odb::core;
+
+int
+main (int argc, char* argv[])
+{
+ try
+ {
+ unique_ptr<database> db (create_database (argc, argv));
+
+ object o (1);
+ o.uuid_ = random_generator() ();
+ o.null_ = nil_uuid ();
+ o.zero_ = nil_uuid ();
+
+ {
+ transaction t (db->begin ());
+ db->persist (o);
+ t.commit ();
+ }
+
+ {
+ transaction t (db->begin ());
+ unique_ptr<object> p (db->load<object> (o.id_));
+ t.commit ();
+
+ assert (*p == o);
+ }
+
+ {
+ typedef odb::query<object> query;
+ typedef odb::result<object> result;
+
+ transaction t (db->begin ());
+ result r (db->query<object> (query::uuid == o.uuid_));
+ result::iterator i (r.begin ());
+ assert (i != r.end () && i->id_ == o.id_);
+ assert (++i == r.end ());
+ t.commit ();
+ }
+
+ }
+ catch (const odb::exception& e)
+ {
+ cerr << e.what () << endl;
+ return 1;
+ }
+}
diff --git a/odb-tests/boost/common/uuid/test.hxx b/odb-tests/boost/common/uuid/test.hxx
new file mode 100644
index 0000000..82ed95b
--- /dev/null
+++ b/odb-tests/boost/common/uuid/test.hxx
@@ -0,0 +1,37 @@
+// file : boost/common/uuid/test.hxx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef TEST_HXX
+#define TEST_HXX
+
+#include <boost/uuid/uuid.hpp>
+
+#include <odb/core.hxx>
+
+#pragma db object
+struct object
+{
+ object () {}
+ object (unsigned long id): id_ (id) {}
+
+ #pragma db id
+ unsigned long id_;
+
+ typedef boost::uuids::uuid uuid;
+
+ uuid uuid_;
+ uuid null_;
+
+ #pragma db not_null
+ uuid zero_;
+
+ bool operator== (const object& x) const
+ {
+ return id_ == x.id_ &&
+ uuid_ == x.uuid_ &&
+ null_ == x.null_ &&
+ zero_ == x.zero_;
+ }
+};
+
+#endif // TEST_HXX
diff --git a/odb-tests/boost/common/uuid/testscript b/odb-tests/boost/common/uuid/testscript
new file mode 100644
index 0000000..f9e6e54
--- /dev/null
+++ b/odb-tests/boost/common/uuid/testscript
@@ -0,0 +1,53 @@
+# file : boost/common/uuid/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;
+ $*
+}