summaryrefslogtreecommitdiff
path: root/odb-tests/common/object/driver.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'odb-tests/common/object/driver.cxx')
-rw-r--r--odb-tests/common/object/driver.cxx84
1 files changed, 84 insertions, 0 deletions
diff --git a/odb-tests/common/object/driver.cxx b/odb-tests/common/object/driver.cxx
new file mode 100644
index 0000000..1c29417
--- /dev/null
+++ b/odb-tests/common/object/driver.cxx
@@ -0,0 +1,84 @@
+// file : common/object/driver.cxx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+// Test persistent classes.
+//
+
+#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));
+
+ // Test persistent class template instantiation.
+ //
+ {
+ using namespace test1;
+
+ pair_object po;
+ po.second = "abc";
+
+ derived d;
+ d.x = "abc";
+ d.n = 123;
+
+ // persist
+ //
+ {
+ transaction t (db->begin ());
+ db->persist<pair_object> (po);
+ db->persist (d);
+ t.commit ();
+ }
+
+ // load & check
+ //
+ {
+ transaction t (db->begin ());
+ unique_ptr<pair_object> po1 (db->load<pair_object> (po.first));
+ unique_ptr<derived> d1 (db->load<derived> (d.id));
+ t.commit ();
+
+ assert (po == *po1);
+
+ assert (d.x == d1->x);
+ assert (d.n == d1->n);
+ }
+
+ // Test the API confusion.
+ //
+ {
+ transaction t (db->begin ());
+ db->update<pair_object> (po);
+ db->reload<pair_object> (po);
+ db->erase<pair_object> (po);
+
+ db->query<pair_object> ();
+ t.commit ();
+ }
+ }
+ }
+ catch (const odb::exception& e)
+ {
+ cerr << e.what () << endl;
+ return 1;
+ }
+}