diff --git a/test/test.pro b/test/test.pro index ae95ff5..504a9c5 100644 --- a/test/test.pro +++ b/test/test.pro @@ -9,5 +9,6 @@ SUBDIRS += \ tst_phrases \ tst_quuid \ tst_generators \ - tst_upgrades + tst_upgrades \ + tst_json diff --git a/test/tst_json/db.cpp b/test/tst_json/db.cpp new file mode 100644 index 0000000..598f17c --- /dev/null +++ b/test/tst_json/db.cpp @@ -0,0 +1,9 @@ +#include "db.h" + +#include "sampletable.h" + +DB::DB() : Nut::Database (), + m_sampleTable(new Nut::TableSet(this)) +{ + +} diff --git a/test/tst_json/db.h b/test/tst_json/db.h new file mode 100644 index 0000000..d31adb7 --- /dev/null +++ b/test/tst_json/db.h @@ -0,0 +1,22 @@ +#ifndef DB1_H +#define DB1_H + +#include "database.h" + +class Table; + +class DB : public Nut::Database +{ + Q_OBJECT + + NUT_DB_VERSION(1) + + NUT_DECLARE_TABLE(Table, sampleTable) + +public: + DB(); +}; + +Q_DECLARE_METATYPE(DB*) + +#endif // DB1_H diff --git a/test/tst_json/sampletable.cpp b/test/tst_json/sampletable.cpp new file mode 100644 index 0000000..3ba992b --- /dev/null +++ b/test/tst_json/sampletable.cpp @@ -0,0 +1,7 @@ +#include "sampletable.h" + + +Table::Table(QObject *parent) : Nut::Table (parent) +{ + +} diff --git a/test/tst_json/sampletable.h b/test/tst_json/sampletable.h new file mode 100644 index 0000000..57ac136 --- /dev/null +++ b/test/tst_json/sampletable.h @@ -0,0 +1,23 @@ +#ifndef TABLE1_H +#define TABLE1_H + +#include "table.h" +#include + +class Table : public Nut::Table +{ + Q_OBJECT + + NUT_PRIMARY_AUTO_INCREMENT(id) + NUT_DECLARE_FIELD(int, id, id, setId) + + NUT_DECLARE_FIELD(QJsonDocument, doc, doc, setDoc) + +public: + Q_INVOKABLE Table(QObject *parent = Q_NULLPTR); + +}; + +Q_DECLARE_METATYPE(Table*) + +#endif // TABLE1_H diff --git a/test/tst_json/tst_json.cpp b/test/tst_json/tst_json.cpp new file mode 100644 index 0000000..3129b16 --- /dev/null +++ b/test/tst_json/tst_json.cpp @@ -0,0 +1,45 @@ +#include + +#include "db.h" +#include "sampletable.h" +#include "query.h" + +#include "tst_json.h" +#include "consts.h" + +void TestJson::initDb(Nut::Database &db) +{ + db.setDriver(DRIVER); + db.setHostName(HOST); + db.setDatabaseName(DATABASE); + db.setUserName(USERNAME); + db.setPassword(PASSWORD); +} + +TestJson::TestJson() +{ + +} + +TestJson::~TestJson() +{ + +} + +void TestJson::initTestCase() +{ + QFile::remove(DATABASE); + REGISTER(DB); + REGISTER(Table); +} + +void TestJson::store() +{ + DB db; + initDb(db); + + QTEST_ASSERT(db.open()); +} + +QTEST_APPLESS_MAIN(TestJson) + diff --git a/test/tst_json/tst_json.h b/test/tst_json/tst_json.h new file mode 100644 index 0000000..5271c65 --- /dev/null +++ b/test/tst_json/tst_json.h @@ -0,0 +1,27 @@ +#ifndef TST_TESTJSON_H +#define TST_TESTJSON_H + +#include + +namespace Nut { +class Database; +} +class TestJson : public QObject +{ + Q_OBJECT + + void initDb(Nut::Database &db); + + int id; +public: + TestJson(); + ~TestJson(); + +private slots: + void initTestCase(); + + void store(); + +}; + +#endif // TST_TESTJSON_H diff --git a/test/tst_json/tst_json.pro b/test/tst_json/tst_json.pro new file mode 100644 index 0000000..04f053c --- /dev/null +++ b/test/tst_json/tst_json.pro @@ -0,0 +1,19 @@ +QT += testlib sql + +TARGET = tst_upgrades +TEMPLATE = app +CONFIG += warn_on c++11 + +include(../common/nut-lib.pri) + +SOURCES += \ + tst_json.cpp \ + db.cpp \ + sampletable.cpp + +HEADERS += \ + tst_json.h \ + db.h \ + sampletable.h + +include($$PWD/../../ci-test-init.pri)