aboutsummaryrefslogtreecommitdiff
path: root/common/session/test.hxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2012-03-06 11:34:57 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2012-03-06 11:34:57 +0200
commit215a45dc83cd8fea56f413d164734345cfbfc994 (patch)
tree806255b3b1e38053efbd158a66cb22f9777b2617 /common/session/test.hxx
parent4059cc0ef58ffc40f50f15bdd1fecd78f49c2727 (diff)
Detect situations where session is required but not used
Throw session_required.
Diffstat (limited to 'common/session/test.hxx')
-rw-r--r--common/session/test.hxx66
1 files changed, 66 insertions, 0 deletions
diff --git a/common/session/test.hxx b/common/session/test.hxx
new file mode 100644
index 0000000..abc4628
--- /dev/null
+++ b/common/session/test.hxx
@@ -0,0 +1,66 @@
+// file : common/session/test.hxx
+// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef TEST_HXX
+#define TEST_HXX
+
+#include <common/config.hxx> // HAVE_CXX11, HAVE_TR1_MEMORY
+
+#include <memory>
+#include <vector>
+
+#include <odb/core.hxx>
+
+#if !defined(HAVE_CXX11) && defined(HAVE_TR1_MEMORY)
+# include <odb/tr1/memory.hxx>
+#endif
+
+// Test the session_required exception.
+//
+#if defined(HAVE_CXX11) || defined(HAVE_TR1_MEMORY)
+
+#pragma db namespace table("t1_")
+namespace test1
+{
+#ifdef HAVE_CXX11
+ using std::shared_ptr;
+ using std::weak_ptr;
+#else
+ using std::tr1::shared_ptr;
+ using std::tr1::weak_ptr;
+#endif
+
+ #pragma db namespace(test1) pointer(shared_ptr)
+
+ struct obj2;
+
+ #pragma db object
+ struct obj1
+ {
+ obj1 () {}
+ obj1 (unsigned long id): id_ (id) {}
+
+ #pragma db id
+ unsigned long id_;
+
+ shared_ptr<obj2> o2;
+ };
+
+ #pragma db object
+ struct obj2
+ {
+ obj2 () {}
+ obj2 (unsigned long id): id_ (id) {}
+
+ #pragma db id
+ unsigned long id_;
+
+ #pragma db inverse (o2)
+ std::vector< weak_ptr<obj1> > o1;
+ };
+}
+
+#endif // HAVE_CXX11 || HAVE_TR1_MEMORY
+
+#endif // TEST_HXX