diff options
Diffstat (limited to 'odb-tests/qt/pgsql/basic')
-rw-r--r-- | odb-tests/qt/pgsql/basic/buildfile | 43 | ||||
-rw-r--r-- | odb-tests/qt/pgsql/basic/driver.cxx | 62 | ||||
-rw-r--r-- | odb-tests/qt/pgsql/basic/test.hxx | 27 | ||||
-rw-r--r-- | odb-tests/qt/pgsql/basic/testscript | 11 |
4 files changed, 143 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 +: +$* |