summaryrefslogtreecommitdiff
path: root/odb-tests/qt/mysql/basic
diff options
context:
space:
mode:
Diffstat (limited to 'odb-tests/qt/mysql/basic')
-rw-r--r--odb-tests/qt/mysql/basic/buildfile43
-rw-r--r--odb-tests/qt/mysql/basic/driver.cxx62
-rw-r--r--odb-tests/qt/mysql/basic/test.hxx27
-rw-r--r--odb-tests/qt/mysql/basic/testscript11
4 files changed, 143 insertions, 0 deletions
diff --git a/odb-tests/qt/mysql/basic/buildfile b/odb-tests/qt/mysql/basic/buildfile
new file mode 100644
index 0000000..ea661aa
--- /dev/null
+++ b/odb-tests/qt/mysql/basic/buildfile
@@ -0,0 +1,43 @@
+# file : qt/mysql/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 ($mysql) "mysql 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-mysql%lib{odb-mysql}
+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_mysql_basic_ \
+ --profile qt/basic \
+ --generate-schema
+
+cxx.poptions =+ "-I$out_base" "-I$src_base"
+
+# Testscript's run-time prerequisites.
+#
+exe{driver}: ../../../alias{mysql-client}: include = adhoc
diff --git a/odb-tests/qt/mysql/basic/driver.cxx b/odb-tests/qt/mysql/basic/driver.cxx
new file mode 100644
index 0000000..f13378d
--- /dev/null
+++ b/odb-tests/qt/mysql/basic/driver.cxx
@@ -0,0 +1,62 @@
+// file : qt/mysql/basic/driver.cxx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+// Test Qt basic type persistence. MySQL version.
+//
+
+#include <memory> // std::unique_ptr
+#include <iostream>
+
+#include <QtCore/QCoreApplication>
+
+#include <odb/mysql/database.hxx>
+#include <odb/mysql/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/mysql/basic/test.hxx b/odb-tests/qt/mysql/basic/test.hxx
new file mode 100644
index 0000000..6dd246e
--- /dev/null
+++ b/odb-tests/qt/mysql/basic/test.hxx
@@ -0,0 +1,27 @@
+// file : qt/mysql/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/mysql/basic/testscript b/odb-tests/qt/mysql/basic/testscript
new file mode 100644
index 0000000..2a45932
--- /dev/null
+++ b/odb-tests/qt/mysql/basic/testscript
@@ -0,0 +1,11 @@
+# file : qt/mysql/basic/testscript
+# license : GNU GPL v2; see accompanying LICENSE file
+
+.include ../../../database-options.testscript
+.include ../../../mysql.testscript
+
++$create_schema
+
+: basics
+:
+$*