summaryrefslogtreecommitdiff
path: root/odb-tests/common/object/driver.cxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2024-01-25 20:32:06 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2024-01-25 20:32:06 +0300
commit0d49ea1fe08cf1eab41a00149393a291c65a59d7 (patch)
tree0391eb09309ca95282e200516937e64d89f3e1bb /odb-tests/common/object/driver.cxx
parentfc3fb39c90ab7fe5fccbe3f3bc0eb2645157bb96 (diff)
Turn odb-tests repository into package for muti-package repositoryodb-tests
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;
+ }
+}