Json test added

This commit is contained in:
Hamed Masafi 2019-06-03 00:59:44 +04:30
parent 0e61d62ab6
commit 465200821a
8 changed files with 154 additions and 1 deletions

View File

@ -9,5 +9,6 @@ SUBDIRS += \
tst_phrases \
tst_quuid \
tst_generators \
tst_upgrades
tst_upgrades \
tst_json

9
test/tst_json/db.cpp Normal file
View File

@ -0,0 +1,9 @@
#include "db.h"
#include "sampletable.h"
DB::DB() : Nut::Database (),
m_sampleTable(new Nut::TableSet<Table>(this))
{
}

22
test/tst_json/db.h Normal file
View File

@ -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

View File

@ -0,0 +1,7 @@
#include "sampletable.h"
Table::Table(QObject *parent) : Nut::Table (parent)
{
}

View File

@ -0,0 +1,23 @@
#ifndef TABLE1_H
#define TABLE1_H
#include "table.h"
#include <QJsonDocument>
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

View File

@ -0,0 +1,45 @@
#include <QtTest>
#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)

27
test/tst_json/tst_json.h Normal file
View File

@ -0,0 +1,27 @@
#ifndef TST_TESTJSON_H
#define TST_TESTJSON_H
#include <QObject>
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

View File

@ -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)