commands test [skip ci]
This commit is contained in:
parent
762481ba2f
commit
6663158085
|
|
@ -6,7 +6,7 @@ SUBDIRS += \
|
|||
# tst_commands \
|
||||
tst_datatypes \
|
||||
#tst_join \
|
||||
# tst_phrases
|
||||
tst_phrases \
|
||||
tst_quuid \
|
||||
tst_generators \
|
||||
tst_upgrades
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
#include "consts.h"
|
||||
|
||||
#include "maintest.h"
|
||||
#include "tst_commands.h"
|
||||
#include "query.h"
|
||||
#include "tableset.h"
|
||||
#include "tablemodel.h"
|
||||
|
|
@ -15,16 +15,16 @@
|
|||
#include "user.h"
|
||||
#include "score.h"
|
||||
|
||||
MainTest::MainTest(QObject *parent) : QObject(parent)
|
||||
CommandsTest::CommandsTest(QObject *parent) : QObject(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void MainTest::initTestCase()
|
||||
void CommandsTest::initTestCase()
|
||||
{
|
||||
qDebug() << "User type id:" << qRegisterMetaType<Post*>();
|
||||
qDebug() << "Comment type id:" << qRegisterMetaType<Comment*>();
|
||||
qDebug() << "DB type id:" << qRegisterMetaType<WeblogDatabase*>();
|
||||
REGISTER(Post);
|
||||
REGISTER(Comment);
|
||||
REGISTER(WeblogDatabase);
|
||||
|
||||
db.setDriver(DRIVER);
|
||||
db.setHostName(HOST);
|
||||
|
|
@ -37,7 +37,7 @@ void MainTest::initTestCase()
|
|||
QTEST_ASSERT(ok);
|
||||
}
|
||||
|
||||
void MainTest::cmd1()
|
||||
void CommandsTest::cmd1()
|
||||
{
|
||||
Query<Post> *q = db.posts()->query()
|
||||
->setWhere(Post::titleField() == "test" && Post::idField() < 4 + 5);
|
||||
|
|
@ -47,7 +47,7 @@ void MainTest::cmd1()
|
|||
qDebug() << q->sqlCommand();
|
||||
}
|
||||
|
||||
void MainTest::cmd2()
|
||||
void CommandsTest::cmd2()
|
||||
{
|
||||
Query<Post> *q = db.posts()->query()
|
||||
->setWhere(!Post::idField().in({1, 2, 3, 4}));
|
||||
|
|
@ -58,7 +58,7 @@ void MainTest::cmd2()
|
|||
qDebug() << q->sqlCommand();
|
||||
}
|
||||
|
||||
void MainTest::join()
|
||||
void CommandsTest::join()
|
||||
{
|
||||
auto q = db.posts()->query()
|
||||
->join<User>()
|
||||
|
|
@ -66,4 +66,4 @@ void MainTest::join()
|
|||
|
||||
}
|
||||
|
||||
QTEST_MAIN(MainTest)
|
||||
QTEST_MAIN(CommandsTest)
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
#include "weblogdatabase.h"
|
||||
class Post;
|
||||
class MainTest : public QObject
|
||||
class CommandsTest : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
WeblogDatabase db;
|
||||
|
|
@ -14,7 +14,7 @@ class MainTest : public QObject
|
|||
Post *post;
|
||||
Query<Post> *q;
|
||||
public:
|
||||
explicit MainTest(QObject *parent = nullptr);
|
||||
explicit CommandsTest(QObject *parent = nullptr);
|
||||
|
||||
signals:
|
||||
|
||||
|
|
@ -9,15 +9,15 @@ include(../../nut.pri)
|
|||
TEMPLATE = app
|
||||
IMPORTPATH += $$OUT_PWD/../src/imports
|
||||
SOURCES += \
|
||||
maintest.cpp \
|
||||
../common/comment.cpp \
|
||||
../common/post.cpp \
|
||||
../common/weblogdatabase.cpp \
|
||||
../common/user.cpp
|
||||
../common/user.cpp \
|
||||
tst_commands.cpp
|
||||
|
||||
HEADERS += \
|
||||
maintest.h \
|
||||
../common/comment.h \
|
||||
../common/post.h \
|
||||
../common/weblogdatabase.h \
|
||||
../common/user.h
|
||||
../common/user.h \
|
||||
tst_commands.h
|
||||
|
|
|
|||
|
|
@ -1,27 +0,0 @@
|
|||
#include <QtTest>
|
||||
#include <QDate>
|
||||
|
||||
#include "maintest.h"
|
||||
#include "phrase.h"
|
||||
|
||||
using namespace Nut;
|
||||
|
||||
MainTest::MainTest(QObject *parent) : QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void MainTest::initTestCase()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void MainTest::no1()
|
||||
{
|
||||
FieldPhrase<int> id("main", "id");
|
||||
FieldPhrase<QString> name("main", "name");
|
||||
FieldPhrase<QString> last_name("main", "last_name");
|
||||
FieldPhrase<QDate> date("main", "date");
|
||||
auto w = (id == 4 && name == "hi");
|
||||
}
|
||||
|
||||
QTEST_MAIN(MainTest)
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
#include <QtTest>
|
||||
#include <QDate>
|
||||
|
||||
#include "tst_phrases.h"
|
||||
#include "phrase.h"
|
||||
|
||||
using namespace Nut;
|
||||
|
||||
MainTest::MainTest(QObject *parent) : QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void MainTest::initTestCase()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void MainTest::no1()
|
||||
{
|
||||
FieldPhrase<int> id("main", "id");
|
||||
FieldPhrase<QString> name("main", "name");
|
||||
FieldPhrase<QString> last_name("main", "last_name");
|
||||
FieldPhrase<QDate> date("main", "date");
|
||||
auto w = (id == 4 && name == "hi");
|
||||
}
|
||||
|
||||
void MainTest::numeric()
|
||||
{
|
||||
FieldPhrase<int> n("main", "int");
|
||||
|
||||
auto p1 = n == 1;
|
||||
auto p2 = n <= 1;
|
||||
auto p3 = n >= 1;
|
||||
auto p4 = n < 1;
|
||||
auto p5 = n > 1;
|
||||
auto p6 = n != 1;
|
||||
}
|
||||
|
||||
void MainTest::string()
|
||||
{
|
||||
FieldPhrase<QString> str("main", "string");
|
||||
|
||||
auto p1 = str == "salam";
|
||||
auto p2 = str.like("%hi%");
|
||||
auto p3 = str.isNull();
|
||||
auto p4 = str.in(QStringList() << "one" << "two" << "three");
|
||||
auto p5 = str != "hi" && str.like("%s");
|
||||
}
|
||||
|
||||
void MainTest::boolean()
|
||||
{
|
||||
FieldPhrase<bool> b("main", "bool");
|
||||
|
||||
auto p1 = b;
|
||||
auto p2 = !b;
|
||||
auto p3 = b == false;
|
||||
|
||||
QTEST_ASSERT(p1.data);
|
||||
QTEST_ASSERT(p2.data);
|
||||
QTEST_ASSERT(p3.data);
|
||||
}
|
||||
|
||||
void MainTest::datetime()
|
||||
{
|
||||
FieldPhrase<QTime> time("main", "time");
|
||||
FieldPhrase<QDate> date("main", "date");
|
||||
FieldPhrase<QDateTime> datetime("main", "datetime");
|
||||
|
||||
auto p1 = time <= QTime::currentTime();
|
||||
auto p2 = time.addHours(2) < QTime::currentTime();
|
||||
auto p3 = date == QDate::currentDate();
|
||||
auto p4 = date.addDays(1) == QDate::currentDate();
|
||||
auto p5 = datetime > QDateTime::currentDateTime();
|
||||
auto p6 = datetime.addMonths(1) >= QDateTime::currentDateTime();
|
||||
auto p7 = time.between(QTime::currentTime().addSecs(-100), QTime::currentTime());
|
||||
}
|
||||
|
||||
void MainTest::extra()
|
||||
{
|
||||
FieldPhrase<QUrl> url("main", "url");
|
||||
|
||||
auto p1 = url == QUrl();
|
||||
auto p2 = url == "http://google.com";
|
||||
}
|
||||
|
||||
QTEST_MAIN(MainTest)
|
||||
|
|
@ -18,6 +18,12 @@ signals:
|
|||
private slots:
|
||||
void initTestCase();
|
||||
void no1();
|
||||
|
||||
void numeric();
|
||||
void string();
|
||||
void boolean();
|
||||
void datetime();
|
||||
void extra();
|
||||
};
|
||||
|
||||
#endif // MAINTEST_H
|
||||
|
|
@ -9,7 +9,7 @@ INCLUDEPATH += $$PWD/../../src $$PWD/../common
|
|||
include(../../nut.pri)
|
||||
IMPORTPATH += $$OUT_PWD/../src/imports
|
||||
SOURCES += \
|
||||
maintest.cpp
|
||||
tst_phrases.cpp
|
||||
|
||||
HEADERS += \
|
||||
maintest.h
|
||||
tst_phrases.h
|
||||
|
|
|
|||
Loading…
Reference in New Issue