aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2014-11-24 10:43:35 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2014-11-24 10:43:35 +0200
commit16632e04c20599fd02737f0ad6d8f94d46f038bf (patch)
treef58dc21a1b07045e6f146ff401de55bc4056984b
parentb9f83d0d666037b7f7728b674362d365470a244a (diff)
Test class templates
-rw-r--r--common/bulk/driver.cxx91
-rw-r--r--common/bulk/test.hxx34
2 files changed, 124 insertions, 1 deletions
diff --git a/common/bulk/driver.cxx b/common/bulk/driver.cxx
index 4b3b9f8..2903ae4 100644
--- a/common/bulk/driver.cxx
+++ b/common/bulk/driver.cxx
@@ -287,7 +287,7 @@ main (int argc, char* argv[])
#if defined(DATABASE_ORACLE) || defined(DATABASE_MSSQL)
// Test database class API with various forms of containers
- // and elements.
+ // and elements (test #6 is a copy).
//
{
using namespace test1;
@@ -926,6 +926,95 @@ main (int argc, char* argv[])
}
}
+ // Test API with persistent class template instantiations (copy of
+ // test #1).
+ {
+ using namespace test6;
+
+ // Make sure we can still call the non-bulk API.
+ //
+ {
+ object o (0, "z");
+ transaction t (db->begin ());
+ db->persist (o);
+ db->update<object> (o);
+ db->reload<object> (o);
+ db->erase<object> (o);
+ t.commit ();
+ }
+
+
+ // The rest is a copy of test #1.
+ //
+ {
+ object a[2];
+ a[0] = object (1, "a");
+ a[1] = object (2, "b");
+ test (db, a, a + sizeof (a) / sizeof (a[0]));
+ }
+
+ {
+ vector<object> v;
+ v.push_back (object (1, "a"));
+ v.push_back (object (2, "b"));
+ test (db, v.begin (), v.end ());
+ }
+
+ {
+ object o1 (1, "a");
+ object o2 (2, "b");
+ object* a[2] = {&o1, &o2};
+ test (db, a, a + sizeof (a) / sizeof (a[0]));
+ }
+
+ {
+ object o1 (1, "a");
+ object o2 (2, "b");
+ vector<object*> v;
+ v.push_back (&o1);
+ v.push_back (&o2);
+ test (db, v.begin (), v.end ());
+ }
+
+ {
+ auto_ptr<auto_object> a[2];
+ a[0].reset (new auto_object (1, "a"));
+ a[1].reset (new auto_object (2, "b"));
+ test (db, a, a + sizeof (a) / sizeof (a[0]));
+ }
+
+#ifdef HAVE_CXX11
+ {
+ vector<unique_ptr<unique_object>> v;
+ v.push_back (unique_ptr<unique_object> (new unique_object (1, "a")));
+ v.push_back (unique_ptr<unique_object> (new unique_object (2, "b")));
+ test (db, v.begin (), v.end ());
+ }
+#endif
+
+ {
+ vector<object> v;
+ v.push_back (object (1, "a"));
+ v.push_back (object (2, "b"));
+ persist (db, v.begin (), v.end ());
+
+ unsigned long id[2] = {v[0].id, v[1].id};
+ erase_id<object> (db, id, id + sizeof (id) / sizeof (id[0]));
+ }
+
+ {
+ vector<object> v;
+ v.push_back (object (1, "a"));
+ v.push_back (object (2, "b"));
+ persist (db, v.begin (), v.end ());
+
+ vector<unsigned long> id;
+ id.push_back (v[0].id);
+ id.push_back (v[1].id);
+ erase_id<object> (db, id.begin (), id.end ());
+ }
+ }
+
#endif
}
catch (const odb::exception& e)
diff --git a/common/bulk/test.hxx b/common/bulk/test.hxx
index 8497174..526762f 100644
--- a/common/bulk/test.hxx
+++ b/common/bulk/test.hxx
@@ -155,4 +155,38 @@ namespace test5
};
}
+// Test API with persistent class template instantiations.
+//
+#pragma db namespace table("t6_")
+namespace test6
+{
+ template <int>
+ struct object_template
+ {
+ object_template (unsigned int n_ = 0, std::string s_ = "")
+ : id (0), n (n_), s (s_) {}
+
+ unsigned long id;
+ unsigned int n;
+ std::string s;
+ };
+
+ typedef object_template<1> object;
+
+ #pragma db object(object) bulk(3)
+ #pragma db member(object::id) id auto
+
+ typedef object_template<2> auto_object;
+
+ #pragma db object(auto_object) bulk(3) pointer(std::auto_ptr)
+ #pragma db member(auto_object::id) id auto
+
+#ifdef HAVE_CXX11
+ typedef object_template<3> unique_object;
+
+ #pragma db object(unique_object) bulk(3) pointer(std::unique_ptr)
+ #pragma db member(unique_object::id) id auto
+#endif
+}
+
#endif // TEST_HXX