summaryrefslogtreecommitdiff
path: root/odb-tests/boost/common/optional
diff options
context:
space:
mode:
Diffstat (limited to 'odb-tests/boost/common/optional')
-rw-r--r--odb-tests/boost/common/optional/buildfile44
-rw-r--r--odb-tests/boost/common/optional/driver.cxx76
-rw-r--r--odb-tests/boost/common/optional/test.hxx31
-rw-r--r--odb-tests/boost/common/optional/testscript53
4 files changed, 204 insertions, 0 deletions
diff --git a/odb-tests/boost/common/optional/buildfile b/odb-tests/boost/common/optional/buildfile
new file mode 100644
index 0000000..3e07b95
--- /dev/null
+++ b/odb-tests/boost/common/optional/buildfile
@@ -0,0 +1,44 @@
+# file : boost/common/optional/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-optional%lib{boost_optional}
+
+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_optional_ \
+ --profile boost/optional \
+ --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/boost/common/optional/driver.cxx b/odb-tests/boost/common/optional/driver.cxx
new file mode 100644
index 0000000..b256032
--- /dev/null
+++ b/odb-tests/boost/common/optional/driver.cxx
@@ -0,0 +1,76 @@
+// file : boost/common/optional/driver.cxx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+// Test boost::optional persistence.
+//
+
+#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 o1 (1);
+ object o2 (2);
+ o2.str = "abc";
+
+ transaction t (db->begin ());
+ db->persist (o1);
+ db->persist (o2);
+ t.commit ();
+ }
+
+ {
+ transaction t (db->begin ());
+ unique_ptr<object> o1 (db->load<object> (1));
+ unique_ptr<object> o2 (db->load<object> (2));
+ t.commit ();
+
+ assert (!o1->str);
+ assert (o2->str && *o2->str == "abc");
+ }
+
+ {
+ typedef odb::query<object> query;
+ typedef odb::result<object> result;
+
+ transaction t (db->begin ());
+
+ {
+ result r (db->query<object> (query::str.is_null ()));
+ assert (!r.empty ());
+ }
+
+ {
+ result r (db->query<object> (query::str == "abc"));
+ assert (!r.empty ());
+ }
+
+ t.commit ();
+ }
+ }
+ catch (const odb::exception& e)
+ {
+ cerr << e.what () << endl;
+ return 1;
+ }
+}
diff --git a/odb-tests/boost/common/optional/test.hxx b/odb-tests/boost/common/optional/test.hxx
new file mode 100644
index 0000000..65d951e
--- /dev/null
+++ b/odb-tests/boost/common/optional/test.hxx
@@ -0,0 +1,31 @@
+// file : boost/common/optional/test.hxx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef TEST_HXX
+#define TEST_HXX
+
+#include <string>
+
+#include <boost/optional.hpp>
+
+#include <odb/core.hxx>
+
+#pragma db object
+struct object
+{
+ object (unsigned long id)
+ : id_ (id)
+ {
+ }
+
+ object ()
+ {
+ }
+
+ #pragma db id
+ unsigned long id_;
+
+ boost::optional<std::string> str;
+};
+
+#endif // TEST_HXX
diff --git a/odb-tests/boost/common/optional/testscript b/odb-tests/boost/common/optional/testscript
new file mode 100644
index 0000000..b24c252
--- /dev/null
+++ b/odb-tests/boost/common/optional/testscript
@@ -0,0 +1,53 @@
+# file : boost/common/optional/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;
+ $*
+}