summaryrefslogtreecommitdiff
path: root/odb-tests/boost/common/multi-index
diff options
context:
space:
mode:
Diffstat (limited to 'odb-tests/boost/common/multi-index')
-rw-r--r--odb-tests/boost/common/multi-index/buildfile43
-rw-r--r--odb-tests/boost/common/multi-index/driver.cxx191
-rw-r--r--odb-tests/boost/common/multi-index/test.hxx113
-rw-r--r--odb-tests/boost/common/multi-index/testscript53
4 files changed, 400 insertions, 0 deletions
diff --git a/odb-tests/boost/common/multi-index/buildfile b/odb-tests/boost/common/multi-index/buildfile
new file mode 100644
index 0000000..ff8ab37
--- /dev/null
+++ b/odb-tests/boost/common/multi-index/buildfile
@@ -0,0 +1,43 @@
+# file : boost/common/multi-index/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-multi-index%lib{boost_multi_index}
+
+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_multi_index_ \
+ --profile boost/multi-index \
+ --generate-schema
+
+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/multi-index/driver.cxx b/odb-tests/boost/common/multi-index/driver.cxx
new file mode 100644
index 0000000..68a022e
--- /dev/null
+++ b/odb-tests/boost/common/multi-index/driver.cxx
@@ -0,0 +1,191 @@
+// file : boost/common/multi-index/driver.cxx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+// Test Boost multi-index container 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[])
+{
+ {
+ using namespace odb;
+
+ assert (odb::access::container_traits<int_lst>::kind == ck_ordered);
+ assert (odb::access::container_traits<int_vec>::kind == ck_ordered);
+ assert (odb::access::container_traits<int_set>::kind == ck_set);
+
+ assert (odb::access::container_traits<int_lst_set>::kind == ck_ordered);
+ assert (odb::access::container_traits<comp_set_vec>::kind == ck_ordered);
+ assert (odb::access::container_traits<comp_set_set>::kind == ck_set);
+ }
+
+ try
+ {
+ unique_ptr<database> db (create_database (argc, argv));
+
+ for (unsigned short i (0); i < 2; ++i)
+ {
+ object empty ("empty"), med ("medium"), full ("full");
+
+ //
+ // empty
+ //
+
+ //
+ // med
+ //
+ med.il.push_back (234);
+ med.il.push_back (123);
+
+ med.iv.push_back (234);
+ med.iv.push_back (123);
+
+ med.is.insert (234);
+ med.is.insert (123);
+
+ med.ils.push_back (234);
+ med.ils.push_back (123);
+
+ med.csv.insert (comp (234, "bcd"));
+ med.csv.insert (comp (123, "abc"));
+
+ med.css.insert (comp (234, "bcd"));
+ med.css.insert (comp (123, "abc"));
+
+ //
+ // full
+ //
+ full.il.push_back (2345);
+ full.il.push_back (1234);
+ full.il.push_back (3456);
+
+ full.iv.push_back (2345);
+ full.iv.push_back (1234);
+ full.iv.push_back (3456);
+
+ full.is.insert (2345);
+ full.is.insert (1234);
+ full.is.insert (3456);
+
+ full.ils.push_back (2345);
+ full.ils.push_back (1234);
+ full.ils.push_back (3456);
+
+ full.csv.insert (comp (234, "bcde"));
+ full.csv.insert (comp (123, "abcd"));
+ full.csv.insert (comp (234, "cdef"));
+
+ full.css.insert (comp (234, "bcde"));
+ full.css.insert (comp (123, "abcd"));
+ full.css.insert (comp (234, "cdef"));
+
+ // persist
+ //
+ {
+ transaction t (db->begin ());
+ db->persist (empty);
+ db->persist (med);
+ db->persist (full);
+ t.commit ();
+ }
+
+ // load & check
+ //
+ {
+ transaction t (db->begin ());
+ unique_ptr<object> e (db->load<object> ("empty"));
+ unique_ptr<object> m (db->load<object> ("medium"));
+ unique_ptr<object> f (db->load<object> ("full"));
+ t.commit ();
+
+ assert (empty == *e);
+ assert (med == *m);
+ assert (full == *f);
+ }
+
+ // empty
+ //
+ empty.il.push_back (12);
+ empty.iv.push_back (12);
+ empty.is.insert (12);
+ empty.ils.push_back (12);
+ empty.csv.insert (comp (12, "ab"));
+ empty.css.insert (comp (12, "ab"));
+
+ // med
+ //
+ med.il.clear ();
+ med.iv.clear ();
+ med.is.clear ();
+ med.ils.clear ();
+ med.csv.clear ();
+ med.css.clear ();
+
+ // full
+ //
+ full.il.push_back (4567);
+ full.iv.push_back (4567);
+ full.is.insert (4567);
+ full.ils.push_back (4567);
+ full.csv.insert (comp (4567, "defg"));
+ full.css.insert (comp (4567, "defg"));
+
+ // update
+ //
+ {
+ transaction t (db->begin ());
+ db->update (empty);
+ db->update (med);
+ db->update (full);
+ t.commit ();
+ }
+
+ // load & check
+ //
+ {
+ transaction t (db->begin ());
+ unique_ptr<object> e (db->load<object> ("empty"));
+ unique_ptr<object> m (db->load<object> ("medium"));
+ unique_ptr<object> f (db->load<object> ("full"));
+ t.commit ();
+
+ assert (empty == *e);
+ assert (med == *m);
+ assert (full == *f);
+ }
+
+ // erase
+ //
+ if (i == 0)
+ {
+ transaction t (db->begin ());
+ db->erase<object> ("empty");
+ db->erase<object> ("medium");
+ db->erase<object> ("full");
+ t.commit ();
+ }
+ }
+ }
+ catch (const odb::exception& e)
+ {
+ cerr << e.what () << endl;
+ return 1;
+ }
+}
diff --git a/odb-tests/boost/common/multi-index/test.hxx b/odb-tests/boost/common/multi-index/test.hxx
new file mode 100644
index 0000000..22b9ea4
--- /dev/null
+++ b/odb-tests/boost/common/multi-index/test.hxx
@@ -0,0 +1,113 @@
+// file : boost/common/multi-index/test.hxx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef TEST_HXX
+#define TEST_HXX
+
+#include <boost/multi_index_container.hpp>
+#include <boost/multi_index/member.hpp>
+#include <boost/multi_index/identity.hpp>
+#include <boost/multi_index/ordered_index.hpp>
+#include <boost/multi_index/sequenced_index.hpp>
+#include <boost/multi_index/random_access_index.hpp>
+
+#include <odb/core.hxx>
+
+namespace mi = boost::multi_index;
+
+#pragma db value
+struct comp
+{
+ comp () {}
+ comp (int n, const std::string& s) : num (n), str (s) {}
+
+ #pragma db column("number")
+ int num;
+ std::string str;
+};
+
+inline bool
+operator== (const comp& x, const comp& y)
+{
+ return x.num == y.num && x.str == y.str;
+}
+
+typedef
+mi::multi_index_container<
+ int,
+ mi::indexed_by<mi::sequenced<> >
+> int_lst;
+
+typedef
+mi::multi_index_container<
+ int,
+ mi::indexed_by<mi::random_access<> >
+> int_vec;
+
+typedef
+mi::multi_index_container<
+ int,
+ mi::indexed_by<mi::ordered_unique<mi::identity<int> > >
+> int_set;
+
+typedef
+mi::multi_index_container<
+ int,
+ mi::indexed_by<
+ mi::sequenced<>,
+ mi::ordered_unique<mi::identity<int> >
+ >
+> int_lst_set;
+
+typedef
+mi::multi_index_container<
+ comp,
+ mi::indexed_by<
+ mi::ordered_unique<mi::member<comp, std::string, &comp::str> >,
+ mi::random_access<>
+ >
+> comp_set_vec;
+
+typedef
+mi::multi_index_container<
+ comp,
+ mi::indexed_by<
+ mi::ordered_unique<mi::member<comp, int, &comp::num> >,
+ mi::ordered_unique<mi::member<comp, std::string, &comp::str> >
+ >
+> comp_set_set;
+
+#pragma db object
+struct object
+{
+ object () {}
+ object (const std::string& id): id (id) {}
+
+ #pragma db id
+ std::string id;
+
+ int_lst il;
+ int_lst iv;
+ int_set is;
+
+ int_lst_set ils;
+ comp_set_vec csv;
+ comp_set_set css;
+};
+
+inline bool
+operator== (const object& x, const object& y)
+{
+ return
+ x.id == y.id &&
+
+ x.il == y.il &&
+ x.iv == y.iv &&
+ x.is == y.is &&
+
+ x.ils == y.ils &&
+ x.csv == y.csv &&
+ x.css == y.css;
+}
+
+#endif // TEST_HXX
diff --git a/odb-tests/boost/common/multi-index/testscript b/odb-tests/boost/common/multi-index/testscript
new file mode 100644
index 0000000..c86fcaa
--- /dev/null
+++ b/odb-tests/boost/common/multi-index/testscript
@@ -0,0 +1,53 @@
+# file : boost/common/multi-index/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;
+ $*
+}