aboutsummaryrefslogtreecommitdiff
path: root/common/readonly/driver.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'common/readonly/driver.cxx')
-rw-r--r--common/readonly/driver.cxx67
1 files changed, 63 insertions, 4 deletions
diff --git a/common/readonly/driver.cxx b/common/readonly/driver.cxx
index 2ad40a1..0432c69 100644
--- a/common/readonly/driver.cxx
+++ b/common/readonly/driver.cxx
@@ -3,7 +3,9 @@
// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC
// license : GNU GPL v2; see accompanying LICENSE file
-// Test readonly members/objects.
+// Test readonly members/objects. Also test that const members are
+// treated as readonly. For other const member tests, see the const-
+// member test.
//
#include <memory> // std::auto_ptr
@@ -40,7 +42,7 @@ main (int argc, char* argv[])
}
o.ro++;
- // const_cast<unsigned long&> (o.co)++;
+ const_cast<unsigned long&> (o.co)++;
o.rw++;
{
@@ -55,7 +57,7 @@ main (int argc, char* argv[])
t.commit ();
}
- assert (o.ro == 1 && /*o.co == 1 &&*/ o.rw == 2);
+ assert (o.ro == 1 && o.co == 1 && o.rw == 2);
}
// Pointer.
@@ -74,6 +76,7 @@ main (int argc, char* argv[])
delete p.ro;
p.ro = p1.release ();
+ const_cast<pointer*&> (p.co) = p.ro;
p.rw = p.ro;
{
@@ -87,7 +90,7 @@ main (int argc, char* argv[])
auto_ptr<pointer> p (db->load<pointer> (1));
t.commit ();
- assert (p->ro->id == 2 && p->rw->id == 3);
+ assert (p->ro->id == 2 && p->co->id == 2 && p->rw->id == 3);
}
}
@@ -104,10 +107,18 @@ main (int argc, char* argv[])
o.ro.v++;
o.ro.ro++;
+ const_cast<unsigned long&> (o.ro.co)++;
o.ro.rw++;
+ value& co (const_cast<value&> (o.co));
+ co.v++;
+ co.ro++;
+ const_cast<unsigned long&> (co.co)++;
+ co.rw++;
+
o.rw.v++;
o.rw.ro++;
+ const_cast<unsigned long&> (o.rw.co)++;
o.rw.rw++;
o.v.v++;
@@ -126,10 +137,17 @@ main (int argc, char* argv[])
assert (o.ro.v == 1 &&
o.ro.ro == 1 &&
+ o.ro.co == 1 &&
o.ro.rw == 1 &&
+ o.co.v == 1 &&
+ o.co.ro == 1 &&
+ o.co.co == 1 &&
+ o.co.rw == 1 &&
+
o.rw.v == 1 &&
o.rw.ro == 1 &&
+ o.rw.co == 1 &&
o.rw.rw == 2 &&
o.v.v == 1);
@@ -138,11 +156,17 @@ main (int argc, char* argv[])
// Container.
//
{
+ typedef vector<unsigned long> ulongs;
+
container o (1);
o.ro.push_back (1);
o.ro.push_back (2);
+ ulongs& co (const_cast<ulongs&> (o.co));
+ co.push_back (1);
+ co.push_back (2);
+
o.rw.push_back (1);
o.rw.push_back (2);
@@ -155,6 +179,9 @@ main (int argc, char* argv[])
o.ro[0]++;
o.ro.pop_back ();
+ co[0]++;
+ co.pop_back ();
+
o.rw[0]++;
o.rw.pop_back ();
@@ -171,6 +198,7 @@ main (int argc, char* argv[])
}
assert (o.ro.size () == 2 && o.ro[0] == 1 && o.ro[1] == 2 &&
+ o.co.size () == 2 && o.co[0] == 1 && o.co[1] == 2 &&
o.rw.size () == 1 && o.rw[0] == 2);
}
@@ -221,6 +249,37 @@ main (int argc, char* argv[])
assert (rw_o.sv == 1 && rw_o.rw_sv == 2);
}
+
+ // Readonly object.
+ //
+ {
+ wrapper o (1, 1);
+
+ {
+ transaction t (db->begin ());
+ db->persist (o);
+ t.commit ();
+ }
+
+ *o.pl = 2;
+ *o.cpl = 2;
+ o.pcl.reset (new unsigned long (2));
+ const_cast<unsigned long&> (*o.cpcl) = 2;
+
+ {
+ transaction t (db->begin ());
+ db->update (o);
+ t.commit ();
+ }
+
+ {
+ transaction t (db->begin ());
+ db->load<wrapper> (1, o);
+ t.commit ();
+ }
+
+ assert (*o.pl == 2 && *o.cpl == 2 && *o.pcl == 2 && *o.cpcl == 1);
+ }
}
catch (const odb::exception& e)
{