summaryrefslogtreecommitdiff
path: root/odb-tests/qt/pgsql
diff options
context:
space:
mode:
Diffstat (limited to 'odb-tests/qt/pgsql')
-rw-r--r--odb-tests/qt/pgsql/basic/buildfile43
-rw-r--r--odb-tests/qt/pgsql/basic/driver.cxx62
-rw-r--r--odb-tests/qt/pgsql/basic/test.hxx27
-rw-r--r--odb-tests/qt/pgsql/basic/testscript11
-rw-r--r--odb-tests/qt/pgsql/date-time/buildfile43
-rw-r--r--odb-tests/qt/pgsql/date-time/driver.cxx110
-rw-r--r--odb-tests/qt/pgsql/date-time/test.hxx43
-rw-r--r--odb-tests/qt/pgsql/date-time/testscript11
8 files changed, 350 insertions, 0 deletions
diff --git a/odb-tests/qt/pgsql/basic/buildfile b/odb-tests/qt/pgsql/basic/buildfile
new file mode 100644
index 0000000..1f1acfc
--- /dev/null
+++ b/odb-tests/qt/pgsql/basic/buildfile
@@ -0,0 +1,43 @@
+# file : qt/pgsql/basic/buildfile
+# license : GNU GPL v2; see accompanying LICENSE file
+
+if ($build.meta_operation != 'dist')
+{
+ assert ($qt) \
+ "Qt version should be configured for this test via config.odb_tests.qt variable"
+
+ assert ($pgsql) "pgsql should be configured for this test"
+ assert (!$multi) "multi-database mode is not supported by this test"
+}
+
+import meta_libs = libodb%lib{odb}
+import meta_libs += libodb-qt%lib{odb-qt}
+import meta_libs += "libQt$(qt_ver)Core"%lib{"Qt$(qt_ver)Core"}
+
+import libs = libodb-pgsql%lib{odb-pgsql}
+import libs += lib{common}
+
+exe{driver}: {hxx cxx}{* -test-odb} {hxx ixx cxx}{test-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}: $meta_libs
+
+<{hxx ixx cxx}{test-odb}>: hxx{test} 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 = --std ($qt_ver == 5 ? c++11 : c++17) \
+ --table-prefix qt_pgsql_basic_ \
+ --profile qt/basic \
+ --generate-schema
+
+cxx.poptions =+ "-I$out_base" "-I$src_base"
+
+# Testscript's run-time prerequisites.
+#
+exe{driver}: ../../../alias{pgsql-client}: include = adhoc
diff --git a/odb-tests/qt/pgsql/basic/driver.cxx b/odb-tests/qt/pgsql/basic/driver.cxx
new file mode 100644
index 0000000..db4eacb
--- /dev/null
+++ b/odb-tests/qt/pgsql/basic/driver.cxx
@@ -0,0 +1,62 @@
+// file : qt/pgsql/basic/driver.cxx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+// Test Qt basic type persistence. PostgreSQL version.
+//
+
+#include <memory> // std::unique_ptr
+#include <iostream>
+
+#include <QtCore/QCoreApplication>
+
+#include <odb/pgsql/database.hxx>
+#include <odb/pgsql/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[])
+{
+ QCoreApplication app (argc, argv);
+
+ try
+ {
+ unique_ptr<database> db (create_database (argc, argv));
+
+ object o;
+ o.str = "Constantin Michael";
+ o.blob = QByteArray ("\0x13\0xDE\0x00\0x00\0x00\0x54\0xF2\0x6A", 8);
+
+ // Persist.
+ //
+ {
+ transaction t (db->begin ());
+ db->persist (o);
+ t.commit ();
+ }
+
+ // Load.
+ //
+ {
+ transaction t (db->begin ());
+ unique_ptr<object> p (db->load<object> (o.str));
+ t.commit ();
+
+ assert (*p == o);
+ }
+ }
+ catch (const odb::exception& e)
+ {
+ cerr << e.what () << endl;
+ return 1;
+ }
+}
diff --git a/odb-tests/qt/pgsql/basic/test.hxx b/odb-tests/qt/pgsql/basic/test.hxx
new file mode 100644
index 0000000..d4a1ba6
--- /dev/null
+++ b/odb-tests/qt/pgsql/basic/test.hxx
@@ -0,0 +1,27 @@
+// file : qt/pgsql/basic/test.hxx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef TEST_HXX
+#define TEST_HXX
+
+#include <QtCore/QString>
+#include <QtCore/QByteArray>
+
+#pragma db object
+struct object
+{
+ bool
+ operator== (const object& x) const
+ {
+ return
+ str == x.str &&
+ blob == x.blob;
+ }
+
+ #pragma db id
+ QString str;
+
+ QByteArray blob;
+};
+
+#endif // TEST_HXX
diff --git a/odb-tests/qt/pgsql/basic/testscript b/odb-tests/qt/pgsql/basic/testscript
new file mode 100644
index 0000000..d6f7b51
--- /dev/null
+++ b/odb-tests/qt/pgsql/basic/testscript
@@ -0,0 +1,11 @@
+# file : qt/pgsql/basic/testscript
+# license : GNU GPL v2; see accompanying LICENSE file
+
+.include ../../../database-options.testscript
+.include ../../../pgsql.testscript
+
++$create_schema
+
+: basics
+:
+$*
diff --git a/odb-tests/qt/pgsql/date-time/buildfile b/odb-tests/qt/pgsql/date-time/buildfile
new file mode 100644
index 0000000..00512ba
--- /dev/null
+++ b/odb-tests/qt/pgsql/date-time/buildfile
@@ -0,0 +1,43 @@
+# file : qt/pgsql/date-time/buildfile
+# license : GNU GPL v2; see accompanying LICENSE file
+
+if ($build.meta_operation != 'dist')
+{
+ assert ($qt) \
+ "Qt version should be configured for this test via config.odb_tests.qt variable"
+
+ assert ($pgsql) "pgsql should be configured for this test"
+ assert (!$multi) "multi-database mode is not supported by this test"
+}
+
+import meta_libs = libodb%lib{odb}
+import meta_libs += libodb-qt%lib{odb-qt}
+import meta_libs += "libQt$(qt_ver)Core"%lib{"Qt$(qt_ver)Core"}
+
+import libs = libodb-pgsql%lib{odb-pgsql}
+import libs += lib{common}
+
+exe{driver}: {hxx cxx}{* -test-odb} {hxx ixx cxx}{test-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}: $meta_libs
+
+<{hxx ixx cxx}{test-odb}>: hxx{test} 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 = --std ($qt_ver == 5 ? c++11 : c++17) \
+ --table-prefix qt_pgsql_dt_ \
+ --profile qt/date-time \
+ --generate-schema
+
+cxx.poptions =+ "-I$out_base" "-I$src_base"
+
+# Testscript's run-time prerequisites.
+#
+exe{driver}: ../../../alias{pgsql-client}: include = adhoc
diff --git a/odb-tests/qt/pgsql/date-time/driver.cxx b/odb-tests/qt/pgsql/date-time/driver.cxx
new file mode 100644
index 0000000..f03d48c
--- /dev/null
+++ b/odb-tests/qt/pgsql/date-time/driver.cxx
@@ -0,0 +1,110 @@
+// file : qt/pgsql/date-time/driver.cxx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+// Test Qt date/time type persistence. PostgreSQL version.
+//
+
+#include <memory> // std::unique_ptr
+#include <iostream>
+
+#include <QtCore/QDateTime>
+#include <QtCore/QCoreApplication>
+
+#include <odb/pgsql/database.hxx>
+#include <odb/pgsql/transaction.hxx>
+
+#include <libcommon/common.hxx>
+
+#include "test.hxx"
+#include "test-odb.hxx"
+
+#undef NDEBUG
+#include <cassert>
+
+using namespace std;
+using namespace odb::core;
+
+bool
+test_out_of_range_value (object&, database&);
+
+int
+main (int argc, char* argv[])
+{
+ QCoreApplication app (argc, argv);
+
+ try
+ {
+ unique_ptr<database> db (create_database (argc, argv));
+
+ // Check persistence of null values.
+ //
+ {
+ object o;
+
+ {
+ transaction t (db->begin ());
+ db->persist (o);
+ t.commit ();
+ }
+
+ {
+ transaction t (db->begin ());
+ unique_ptr<object> ol (db->load<object> (o.id));
+ t.commit ();
+
+ assert (ol->is_null ());
+ }
+ }
+
+ // Check persistence of valid dates and times.
+ //
+ {
+ QDateTime ct (QDateTime::currentDateTime ());
+
+ object o;
+ o.date = ct.date ();
+ o.time = ct.time ();
+ o.date_time = ct;
+
+ {
+ transaction t (db->begin ());
+ db->persist (o);
+ t.commit ();
+ }
+
+ {
+ transaction t (db->begin ());
+ unique_ptr<object> ol (db->load<object> (o.id));
+ t.commit ();
+
+ assert (*ol == o);
+ }
+ }
+
+ // Test a QDateTime value before PG epoch.
+ //
+ {
+ object o;
+ o.date_time = QDateTime (QDate (1969, 12, 31), QTime (23, 59, 59, 123));
+
+ {
+ transaction t (db->begin ());
+ db->persist (o);
+ t.commit ();
+ }
+
+ {
+ transaction t (db->begin ());
+ unique_ptr<object> ol (db->load<object> (o.id));
+ t.commit ();
+
+ assert (*ol == o);
+ }
+ }
+ }
+ catch (const odb::exception& e)
+ {
+ cerr << e.what () << endl;
+ return 1;
+ }
+}
diff --git a/odb-tests/qt/pgsql/date-time/test.hxx b/odb-tests/qt/pgsql/date-time/test.hxx
new file mode 100644
index 0000000..2da5587
--- /dev/null
+++ b/odb-tests/qt/pgsql/date-time/test.hxx
@@ -0,0 +1,43 @@
+// file : qt/pgsql/date-time/test.hxx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef TEST_HXX
+#define TEST_HXX
+
+#include <vector>
+
+#include <QtCore/QDateTime>
+
+#include <odb/core.hxx>
+
+#pragma db object
+struct object
+{
+ bool
+ operator== (const object& x) const
+ {
+ return
+ id == x.id &&
+ date == x.date &&
+ time == x.time &&
+ date_time == x.date_time;
+ }
+
+ bool
+ is_null () const
+ {
+ return
+ date.isNull () &&
+ time.isNull () &&
+ date_time.isNull ();
+ }
+
+ #pragma db id auto
+ unsigned long id;
+
+ QDate date;
+ QTime time;
+ QDateTime date_time;
+};
+
+#endif // TEST_HXX
diff --git a/odb-tests/qt/pgsql/date-time/testscript b/odb-tests/qt/pgsql/date-time/testscript
new file mode 100644
index 0000000..d6f7b51
--- /dev/null
+++ b/odb-tests/qt/pgsql/date-time/testscript
@@ -0,0 +1,11 @@
+# file : qt/pgsql/basic/testscript
+# license : GNU GPL v2; see accompanying LICENSE file
+
+.include ../../../database-options.testscript
+.include ../../../pgsql.testscript
+
++$create_schema
+
+: basics
+:
+$*