aboutsummaryrefslogtreecommitdiff
path: root/common/wrapper/driver.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2012-04-27 13:32:46 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2012-04-27 13:32:46 +0200
commitedfd1193d15696c7a2e54573776b9121d6167e83 (patch)
tree7faab184b8bc1fe6b26d739e0adeac832fa534dc /common/wrapper/driver.cxx
parentc8458a266eb258cf61b1e66066c72a2dc0f0ad8b (diff)
Support for NULL value semantics for composite values
Diffstat (limited to 'common/wrapper/driver.cxx')
-rw-r--r--common/wrapper/driver.cxx74
1 files changed, 74 insertions, 0 deletions
diff --git a/common/wrapper/driver.cxx b/common/wrapper/driver.cxx
index 4f78a1b..d8985fa 100644
--- a/common/wrapper/driver.cxx
+++ b/common/wrapper/driver.cxx
@@ -128,6 +128,80 @@ main (int argc, char* argv[])
assert (o->c == co.c);
}
}
+
+ // Test 5: composite NULL values.
+ //
+ {
+ using namespace test5;
+
+ using test5::object; //@@ tmp
+
+ object o1, o2;
+
+ o1.v.push_back (nullable<comp> ());
+
+ o2.p.reset (new comp (1, "a"));
+ o2.n = comp (2, "b");
+ o2.v.push_back (comp (3, "c"));
+
+ // Persist.
+ //
+ {
+ transaction t (db->begin ());
+ db->persist (o1);
+ db->persist (o2);
+ t.commit ();
+ }
+
+ // Load.
+ //
+ {
+ transaction t (db->begin ());
+ auto_ptr<object> p1 (db->load<object> (o1.id));
+ auto_ptr<object> p2 (db->load<object> (o2.id));
+ t.commit ();
+
+ assert (p1->p.get () == 0);
+ assert (!p1->n);
+ assert (!p1->v[0]);
+
+ assert (p2->p.get () != 0 && *p2->p == *o2.p);
+ assert (p2->n && *p2->n == *o2.n);
+ assert (p2->v[0] && *p2->v[0] == *o2.v[0]);
+ }
+
+ // Update.
+ //
+ {
+ o1.p.reset (new comp (1, "a"));
+ o1.n = comp (2, "b");
+ o1.v[0] = comp (3, "c");
+
+ o2.p.reset ();
+ o2.n.reset ();
+ o2.v[0].reset ();
+
+ transaction t (db->begin ());
+ db->update (o1);
+ db->update (o2);
+ t.commit ();
+ }
+
+ {
+ transaction t (db->begin ());
+ auto_ptr<object> p1 (db->load<object> (o1.id));
+ auto_ptr<object> p2 (db->load<object> (o2.id));
+ t.commit ();
+
+ assert (p1->p.get () != 0 && *p1->p == *o1.p);
+ assert (p1->n && *p1->n == *o1.n);
+ assert (p1->v[0] && *p1->v[0] == *o1.v[0]);
+
+ assert (p2->p.get () == 0);
+ assert (!p2->n);
+ assert (!p2->v[0]);
+ }
+ }
}
catch (const odb::exception& e)
{