From 66631580856cd90daa8fa6cff596ac0ff9ba33f8 Mon Sep 17 00:00:00 2001 From: Hamed Masafi Date: Mon, 25 Feb 2019 19:46:18 +0330 Subject: [PATCH] commands test [skip ci] --- test/test.pro | 2 +- .../{maintest.cpp => tst_commands.cpp} | 20 ++--- .../{maintest.h => tst_commands.h} | 4 +- test/tst_commands/tst_commands.pro | 8 +- test/tst_phrases/maintest.cpp | 27 ------ test/tst_phrases/tst_phrases.cpp | 86 +++++++++++++++++++ .../tst_phrases/{maintest.h => tst_phrases.h} | 6 ++ test/tst_phrases/tst_phrases.pro | 4 +- 8 files changed, 111 insertions(+), 46 deletions(-) rename test/tst_commands/{maintest.cpp => tst_commands.cpp} (70%) rename test/tst_commands/{maintest.h => tst_commands.h} (80%) delete mode 100644 test/tst_phrases/maintest.cpp create mode 100644 test/tst_phrases/tst_phrases.cpp rename test/tst_phrases/{maintest.h => tst_phrases.h} (76%) diff --git a/test/test.pro b/test/test.pro index 4ca3c4f..ae95ff5 100644 --- a/test/test.pro +++ b/test/test.pro @@ -6,7 +6,7 @@ SUBDIRS += \ # tst_commands \ tst_datatypes \ #tst_join \ -# tst_phrases + tst_phrases \ tst_quuid \ tst_generators \ tst_upgrades diff --git a/test/tst_commands/maintest.cpp b/test/tst_commands/tst_commands.cpp similarity index 70% rename from test/tst_commands/maintest.cpp rename to test/tst_commands/tst_commands.cpp index 8f4462b..ee234d2 100644 --- a/test/tst_commands/maintest.cpp +++ b/test/tst_commands/tst_commands.cpp @@ -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(); - qDebug() << "Comment type id:" << qRegisterMetaType(); - qDebug() << "DB type id:" << qRegisterMetaType(); + 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 *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 *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() @@ -66,4 +66,4 @@ void MainTest::join() } -QTEST_MAIN(MainTest) +QTEST_MAIN(CommandsTest) diff --git a/test/tst_commands/maintest.h b/test/tst_commands/tst_commands.h similarity index 80% rename from test/tst_commands/maintest.h rename to test/tst_commands/tst_commands.h index 0f19910..fa2ad06 100644 --- a/test/tst_commands/maintest.h +++ b/test/tst_commands/tst_commands.h @@ -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 *q; public: - explicit MainTest(QObject *parent = nullptr); + explicit CommandsTest(QObject *parent = nullptr); signals: diff --git a/test/tst_commands/tst_commands.pro b/test/tst_commands/tst_commands.pro index a1d0878..cbdbdde 100644 --- a/test/tst_commands/tst_commands.pro +++ b/test/tst_commands/tst_commands.pro @@ -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 diff --git a/test/tst_phrases/maintest.cpp b/test/tst_phrases/maintest.cpp deleted file mode 100644 index 3e94a69..0000000 --- a/test/tst_phrases/maintest.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include -#include - -#include "maintest.h" -#include "phrase.h" - -using namespace Nut; - -MainTest::MainTest(QObject *parent) : QObject(parent) -{ -} - -void MainTest::initTestCase() -{ - -} - -void MainTest::no1() -{ - FieldPhrase id("main", "id"); - FieldPhrase name("main", "name"); - FieldPhrase last_name("main", "last_name"); - FieldPhrase date("main", "date"); - auto w = (id == 4 && name == "hi"); -} - -QTEST_MAIN(MainTest) diff --git a/test/tst_phrases/tst_phrases.cpp b/test/tst_phrases/tst_phrases.cpp new file mode 100644 index 0000000..5159b31 --- /dev/null +++ b/test/tst_phrases/tst_phrases.cpp @@ -0,0 +1,86 @@ +#include +#include + +#include "tst_phrases.h" +#include "phrase.h" + +using namespace Nut; + +MainTest::MainTest(QObject *parent) : QObject(parent) +{ +} + +void MainTest::initTestCase() +{ + +} + +void MainTest::no1() +{ + FieldPhrase id("main", "id"); + FieldPhrase name("main", "name"); + FieldPhrase last_name("main", "last_name"); + FieldPhrase date("main", "date"); + auto w = (id == 4 && name == "hi"); +} + +void MainTest::numeric() +{ + FieldPhrase 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 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 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 time("main", "time"); + FieldPhrase date("main", "date"); + FieldPhrase 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 url("main", "url"); + + auto p1 = url == QUrl(); + auto p2 = url == "http://google.com"; +} + +QTEST_MAIN(MainTest) diff --git a/test/tst_phrases/maintest.h b/test/tst_phrases/tst_phrases.h similarity index 76% rename from test/tst_phrases/maintest.h rename to test/tst_phrases/tst_phrases.h index 78d83bc..8c6dc28 100644 --- a/test/tst_phrases/maintest.h +++ b/test/tst_phrases/tst_phrases.h @@ -18,6 +18,12 @@ signals: private slots: void initTestCase(); void no1(); + + void numeric(); + void string(); + void boolean(); + void datetime(); + void extra(); }; #endif // MAINTEST_H diff --git a/test/tst_phrases/tst_phrases.pro b/test/tst_phrases/tst_phrases.pro index 5dd3829..2b30ca3 100644 --- a/test/tst_phrases/tst_phrases.pro +++ b/test/tst_phrases/tst_phrases.pro @@ -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