aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/composite/driver.cxx37
-rw-r--r--common/composite/makefile2
-rw-r--r--common/composite/test.hxx62
3 files changed, 99 insertions, 2 deletions
diff --git a/common/composite/driver.cxx b/common/composite/driver.cxx
index 606f367..a3825e1 100644
--- a/common/composite/driver.cxx
+++ b/common/composite/driver.cxx
@@ -122,6 +122,43 @@ main (int argc, char* argv[])
t.commit ();
}
}
+
+ // Test composite class template instantiation.
+ //
+ {
+ object o (1);
+
+ o.comp_.num = 123;
+ o.comp_.str = "abc";
+ o.comp_.vec.push_back (int_str_pair (123, "abc"));
+ o.comp_.vec.push_back (int_str_pair (234, "bcd"));
+ o.comp_.vec.push_back (int_str_pair (345, "cde"));
+
+ o.pair_.first = 123;
+ o.pair_.second = "abc";
+
+ o.vec_.push_back (int_str_pair (123, "abc"));
+ o.vec_.push_back (int_str_pair (234, "bcd"));
+ o.vec_.push_back (int_str_pair (345, "cde"));
+
+ // persist
+ //
+ {
+ transaction t (db->begin ());
+ db->persist (o);
+ t.commit ();
+ }
+
+ // load & check
+ //
+ {
+ transaction t (db->begin ());
+ auto_ptr<object> o1 (db->load<object> (1));
+ t.commit ();
+
+ assert (o == *o1);
+ }
+ }
}
catch (const odb::exception& e)
{
diff --git a/common/composite/makefile b/common/composite/makefile
index 1a4ceb7..58fa6eb 100644
--- a/common/composite/makefile
+++ b/common/composite/makefile
@@ -36,7 +36,7 @@ gen := $(addprefix $(out_base)/,$(genf))
$(gen): $(odb)
$(gen): odb := $(odb)
$(gen) $(dist): export odb_options += --database $(db_id) --generate-schema \
---generate-query --table-prefix t_composite_
+--generate-query --table-prefix t_comp_
$(gen): cpp_options := -I$(src_base)
$(gen): $(common.l.cpp-options)
diff --git a/common/composite/test.hxx b/common/composite/test.hxx
index 120476a..d846c9c 100644
--- a/common/composite/test.hxx
+++ b/common/composite/test.hxx
@@ -7,6 +7,8 @@
#define TEST_HXX
#include <string>
+#include <vector>
+#include <utility> // std::pair
#include <odb/core.hxx>
@@ -68,7 +70,7 @@ struct person
};
inline bool
-operator== (person const& x, person const& y)
+operator== (const person& x, const person& y)
{
return x.id_ == y.id_ &&
x.name_.first == y.name_.first&&
@@ -82,4 +84,62 @@ operator== (person const& x, person const& y)
x.age_ == y.age_;
}
+// Test composite class template instantiation.
+//
+template <typename I, typename S>
+struct comp
+{
+ I num;
+ S str;
+ std::vector<std::pair<I, S> > vec;
+};
+
+template <typename I, typename S>
+inline bool
+operator== (const comp<I, S>& x, const comp<I, S>& y)
+{
+ return x.num == y.num && x.str == y.str && x.vec == y.vec;
+}
+
+typedef std::pair<int, std::string> int_str_pair;
+#pragma db value(int_str_pair)
+
+// Make sure we use the name that was specified in the pragma.
+//
+#ifdef ODB_COMPILER
+typedef comp<int, std::string> int_str_comp1;
+#endif
+
+typedef comp<int, std::string> int_str_comp;
+#pragma db value(int_str_comp)
+
+#pragma db object
+struct object
+{
+ object (unsigned long id)
+ : id_ (id)
+ {
+ }
+
+ object ()
+ {
+ }
+
+ #pragma db id
+ unsigned long id_;
+
+ comp<int, std::string> comp_;
+ std::pair<int, std::string> pair_;
+ std::vector<int_str_pair> vec_;
+};
+
+inline bool
+operator== (const object& x, const object& y)
+{
+ return x.id_ == y.id_ &&
+ x.comp_ == y.comp_ &&
+ x.pair_ == y.pair_ &&
+ x.vec_ == y.vec_;
+}
+
#endif // TEST_HXX