summaryrefslogtreecommitdiff
path: root/odb-tests/common/definition
diff options
context:
space:
mode:
Diffstat (limited to 'odb-tests/common/definition')
-rw-r--r--odb-tests/common/definition/.gitignore6
-rw-r--r--odb-tests/common/definition/buildfile52
-rw-r--r--odb-tests/common/definition/driver.cxx56
-rw-r--r--odb-tests/common/definition/test.hxx26
-rw-r--r--odb-tests/common/definition/testscript53
-rw-r--r--odb-tests/common/definition/time-mapping.hxx17
6 files changed, 210 insertions, 0 deletions
diff --git a/odb-tests/common/definition/.gitignore b/odb-tests/common/definition/.gitignore
new file mode 100644
index 0000000..5838670
--- /dev/null
+++ b/odb-tests/common/definition/.gitignore
@@ -0,0 +1,6 @@
+# ODB-generated files.
+#
+time-mapping-odb.?xx
+time-mapping-odb-*.?xx
+time-mapping.sql
+time-mapping-*.sql
diff --git a/odb-tests/common/definition/buildfile b/odb-tests/common/definition/buildfile
new file mode 100644
index 0000000..83a09ff
--- /dev/null
+++ b/odb-tests/common/definition/buildfile
@@ -0,0 +1,52 @@
+# file : common/definition/buildfile
+# license : GNU GPL v2; see accompanying LICENSE file
+
+import libodb = libodb%lib{odb}
+
+libs =
+
+for db: $databases
+ import libs += libodb-$db%lib{odb-$db}
+
+import libs += lib{common}
+
+hdrs = test time-mapping
+
+exe{driver}: {hxx cxx}{* -*-odb -*-odb-*} testscript
+
+# Introduce the metadata library target to make sure the libodb library is
+# resolved for the odb_compile ad hoc rule (see build/root.build for details).
+#
+libue{test-meta}: $libodb
+
+for h: $hdrs
+{
+ exe{driver}: {hxx ixx cxx}{$h-odb}
+
+ <{hxx ixx cxx}{$h-odb}>: hxx{$h} libue{test-meta}
+
+ for db: $databases
+ {
+ exe{driver}: {hxx ixx cxx}{$h-odb-$db}: include = $multi
+ <{hxx ixx cxx}{$h-odb-$db}>: hxx{$h} libue{test-meta}
+ }
+}
+
+exe{driver}: libue{test-meta} $libs
+
+# Specify the ODB custom options to be used by the odb_compile ad hoc rule
+# (see build/root.build for details).
+#
+odb_options = --table-prefix definition_ \
+ --generate-schema
+
+<{hxx ixx cxx}{time-mapping-odb}>: odb_options =
+
+for db: $databases
+ {hxx ixx cxx}{time-mapping-odb-$db}: odb_options =
+
+cxx.poptions =+ "-I$out_base" "-I$src_base"
+
+# Testscript's run-time prerequisites.
+#
+exe{driver}: ../../alias{database-client}: include = adhoc
diff --git a/odb-tests/common/definition/driver.cxx b/odb-tests/common/definition/driver.cxx
new file mode 100644
index 0000000..223eeaf
--- /dev/null
+++ b/odb-tests/common/definition/driver.cxx
@@ -0,0 +1,56 @@
+// file : common/definition/driver.cxx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+// Test overriding composite value definition point. This is primarily
+// useful to make composite values out of third-party types.
+//
+
+#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));
+
+ object o;
+ o.time.tv_sec = 1;
+ o.time.tv_usec = 1000;
+
+ {
+ transaction t (db->begin ());
+ db->persist (o);
+ t.commit ();
+ }
+
+ {
+ transaction t (db->begin ());
+ unique_ptr<object> p (db->load<object> (o.id));
+ t.commit ();
+
+ assert (p->time.tv_sec == o.time.tv_sec &&
+ p->time.tv_usec == o.time.tv_usec);
+ }
+ }
+ catch (const odb::exception& e)
+ {
+ cerr << e.what () << endl;
+ return 1;
+ }
+}
diff --git a/odb-tests/common/definition/test.hxx b/odb-tests/common/definition/test.hxx
new file mode 100644
index 0000000..38fc02a
--- /dev/null
+++ b/odb-tests/common/definition/test.hxx
@@ -0,0 +1,26 @@
+// file : common/definition/test.hxx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef TEST_HXX
+#define TEST_HXX
+
+#ifdef _WIN32
+# include <winsock2.h> // timeval
+#else
+# include <sys/time.h> // timeval
+#endif
+
+#include <odb/core.hxx>
+
+#include "time-mapping.hxx"
+
+#pragma db object
+struct object
+{
+ #pragma db id auto
+ unsigned long id;
+
+ timeval time;
+};
+
+#endif // TEST_HXX
diff --git a/odb-tests/common/definition/testscript b/odb-tests/common/definition/testscript
new file mode 100644
index 0000000..5d59884
--- /dev/null
+++ b/odb-tests/common/definition/testscript
@@ -0,0 +1,53 @@
+# file : common/definition/testscript
+# license : GNU GPL v2; see accompanying LICENSE file
+
+.include ../../database-options.testscript
+
+: mysql
+:
+if $mysql
+{
+ .include ../../mysql.testscript
+
+ $create_schema;
+ $*
+}
+
+: sqlite
+:
+if $sqlite
+{
+ .include ../../sqlite.testscript
+
+ $*
+}
+
+: pgsql
+:
+if $pgsql
+{
+ .include ../../pgsql.testscript
+
+ $create_schema;
+ $*
+}
+
+: oracle
+:
+if $oracle
+{
+ .include ../../oracle.testscript
+
+ $create_schema;
+ $*
+}
+
+: mssql
+:
+if $mssql
+{
+ .include ../../mssql.testscript
+
+ $create_schema;
+ $*
+}
diff --git a/odb-tests/common/definition/time-mapping.hxx b/odb-tests/common/definition/time-mapping.hxx
new file mode 100644
index 0000000..469cfb7
--- /dev/null
+++ b/odb-tests/common/definition/time-mapping.hxx
@@ -0,0 +1,17 @@
+// file : common/definition/time-mapping.hxx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef TIME_MAPPING_HXX
+#define TIME_MAPPING_HXX
+
+#ifdef _WIN32
+# include <winsock2.h> // timeval
+#else
+# include <sys/time.h> // timeval
+#endif
+
+#pragma db value(timeval) definition
+#pragma db member(timeval::tv_sec) column("sec")
+#pragma db member(timeval::tv_usec) column("usec")
+
+#endif // TIME_MAPPING_HXX