tests renamed [skip ci]
This commit is contained in:
parent
c96ead047b
commit
4ea071836b
|
|
@ -3,7 +3,7 @@ TEMPLATE = subdirs
|
||||||
SUBDIRS += \
|
SUBDIRS += \
|
||||||
tst_basic \
|
tst_basic \
|
||||||
tst_benckmark \
|
tst_benckmark \
|
||||||
# tst_commands \
|
tst_commands \
|
||||||
tst_datatypes
|
tst_datatypes
|
||||||
#tst_join \
|
#tst_join \
|
||||||
# tst_phrases
|
# tst_phrases
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
#include "consts.h"
|
#include "consts.h"
|
||||||
|
|
||||||
#include "maintest.h"
|
#include "tst_basic.h"
|
||||||
#include "query.h"
|
#include "query.h"
|
||||||
#include "tableset.h"
|
#include "tableset.h"
|
||||||
#include "tablemodel.h"
|
#include "tablemodel.h"
|
||||||
|
|
@ -16,11 +16,11 @@
|
||||||
#include "comment.h"
|
#include "comment.h"
|
||||||
#include "score.h"
|
#include "score.h"
|
||||||
|
|
||||||
MainTest::MainTest(QObject *parent) : QObject(parent)
|
BasicTest::BasicTest(QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainTest::initTestCase()
|
void BasicTest::initTestCase()
|
||||||
{
|
{
|
||||||
//register all entities with Qt-MetaType mechanism
|
//register all entities with Qt-MetaType mechanism
|
||||||
REGISTER(User);
|
REGISTER(User);
|
||||||
|
|
@ -44,7 +44,7 @@ void MainTest::initTestCase()
|
||||||
db.scores()->query()->remove();
|
db.scores()->query()->remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainTest::dataScheema()
|
void BasicTest::dataScheema()
|
||||||
{
|
{
|
||||||
// auto json = db.model().toJson();
|
// auto json = db.model().toJson();
|
||||||
// auto model = DatabaseModel::fromJson(json);
|
// auto model = DatabaseModel::fromJson(json);
|
||||||
|
|
@ -54,7 +54,7 @@ void MainTest::dataScheema()
|
||||||
// QTEST_ASSERT(model == db.model());
|
// QTEST_ASSERT(model == db.model());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainTest::createUser()
|
void BasicTest::createUser()
|
||||||
{
|
{
|
||||||
user = new User;
|
user = new User;
|
||||||
user->setUsername("admin");
|
user->setUsername("admin");
|
||||||
|
|
@ -63,7 +63,7 @@ void MainTest::createUser()
|
||||||
db.saveChanges();
|
db.saveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainTest::createPost()
|
void BasicTest::createPost()
|
||||||
{
|
{
|
||||||
TIC();
|
TIC();
|
||||||
Post *newPost = new Post;
|
Post *newPost = new Post;
|
||||||
|
|
@ -95,7 +95,7 @@ void MainTest::createPost()
|
||||||
qDebug() << "New post inserted with id:" << newPost->id();
|
qDebug() << "New post inserted with id:" << newPost->id();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainTest::createPost2()
|
void BasicTest::createPost2()
|
||||||
{
|
{
|
||||||
//create post on the fly
|
//create post on the fly
|
||||||
QVariant postIdVar = db.posts()->query()->insert(
|
QVariant postIdVar = db.posts()->query()->insert(
|
||||||
|
|
@ -119,7 +119,7 @@ void MainTest::createPost2()
|
||||||
QTEST_ASSERT(postId != 0);
|
QTEST_ASSERT(postId != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainTest::updatePostOnTheFly()
|
void BasicTest::updatePostOnTheFly()
|
||||||
{
|
{
|
||||||
auto c = db.posts()->query()
|
auto c = db.posts()->query()
|
||||||
->where(Post::idField() == postId)
|
->where(Post::idField() == postId)
|
||||||
|
|
@ -128,7 +128,7 @@ void MainTest::updatePostOnTheFly()
|
||||||
QTEST_ASSERT(c == 1);
|
QTEST_ASSERT(c == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainTest::selectPublicts()
|
void BasicTest::selectPublicts()
|
||||||
{
|
{
|
||||||
auto q = db.posts()->query()
|
auto q = db.posts()->query()
|
||||||
->where(Post::isPublicField())
|
->where(Post::isPublicField())
|
||||||
|
|
@ -142,7 +142,7 @@ void MainTest::selectPublicts()
|
||||||
QTEST_ASSERT(q2 == 1);
|
QTEST_ASSERT(q2 == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainTest::selectPosts()
|
void BasicTest::selectPosts()
|
||||||
{
|
{
|
||||||
auto q = db.posts()->query()
|
auto q = db.posts()->query()
|
||||||
->join<Comment>()
|
->join<Comment>()
|
||||||
|
|
@ -166,7 +166,7 @@ void MainTest::selectPosts()
|
||||||
db.cleanUp();
|
db.cleanUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainTest::selectScoreAverage()
|
void BasicTest::selectScoreAverage()
|
||||||
{
|
{
|
||||||
auto a = db.scores()->query()
|
auto a = db.scores()->query()
|
||||||
->join<Post>()
|
->join<Post>()
|
||||||
|
|
@ -175,7 +175,7 @@ void MainTest::selectScoreAverage()
|
||||||
qDebug() << a;
|
qDebug() << a;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainTest::selectFirst()
|
void BasicTest::selectFirst()
|
||||||
{
|
{
|
||||||
auto posts = db.posts()->query()
|
auto posts = db.posts()->query()
|
||||||
->first();
|
->first();
|
||||||
|
|
@ -183,7 +183,7 @@ void MainTest::selectFirst()
|
||||||
QTEST_ASSERT(posts != Q_NULLPTR);
|
QTEST_ASSERT(posts != Q_NULLPTR);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainTest::selectPostsWithoutTitle()
|
void BasicTest::selectPostsWithoutTitle()
|
||||||
{
|
{
|
||||||
auto q = db.posts()->query();
|
auto q = db.posts()->query();
|
||||||
q->setWhere(Post::titleField().isNull());
|
q->setWhere(Post::titleField().isNull());
|
||||||
|
|
@ -191,7 +191,7 @@ void MainTest::selectPostsWithoutTitle()
|
||||||
QTEST_ASSERT(count == 0);
|
QTEST_ASSERT(count == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainTest::selectPostIds()
|
void BasicTest::selectPostIds()
|
||||||
{
|
{
|
||||||
auto q = db.posts()->query();
|
auto q = db.posts()->query();
|
||||||
auto ids = q->select(Post::idField());
|
auto ids = q->select(Post::idField());
|
||||||
|
|
@ -199,7 +199,7 @@ qDebug() << ids.count();
|
||||||
QTEST_ASSERT(ids.count() == 2);
|
QTEST_ASSERT(ids.count() == 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainTest::testDate()
|
void BasicTest::testDate()
|
||||||
{
|
{
|
||||||
QDateTime d = QDateTime::currentDateTime();
|
QDateTime d = QDateTime::currentDateTime();
|
||||||
QTime t = QTime(d.time().hour(), d.time().minute(), d.time().second());
|
QTime t = QTime(d.time().hour(), d.time().minute(), d.time().second());
|
||||||
|
|
@ -220,30 +220,30 @@ void MainTest::testDate()
|
||||||
QTEST_ASSERT(q->saveDate() == d);
|
QTEST_ASSERT(q->saveDate() == d);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainTest::join()
|
void BasicTest::join()
|
||||||
{
|
{
|
||||||
TIC();
|
// TIC();
|
||||||
auto q = db.comments()->query()
|
// auto q = db.comments()->query()
|
||||||
->join<User>()
|
// ->join<User>()
|
||||||
->join<Post>();
|
// ->join<Post>();
|
||||||
|
|
||||||
auto comments = q->toList();
|
// auto comments = q->toList();
|
||||||
|
|
||||||
TOC();
|
// TOC();
|
||||||
QTEST_ASSERT(comments.length());
|
// QTEST_ASSERT(comments.length());
|
||||||
QTEST_ASSERT(comments[0]->author());
|
// QTEST_ASSERT(comments[0]->author());
|
||||||
QTEST_ASSERT(comments[0]->author()->username() == "admin");
|
// QTEST_ASSERT(comments[0]->author()->username() == "admin");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MainTest::selectWithInvalidRelation()
|
void BasicTest::selectWithInvalidRelation()
|
||||||
{
|
{
|
||||||
auto q = db.posts()->query();
|
auto q = db.posts()->query();
|
||||||
q->join("Invalid_Class_Name");
|
q->join("Invalid_Class_Name");
|
||||||
q->toList();
|
q->toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainTest::modifyPost()
|
void BasicTest::modifyPost()
|
||||||
{
|
{
|
||||||
auto q = db.posts()->query();
|
auto q = db.posts()->query();
|
||||||
q->setWhere(Post::idField() == postId);
|
q->setWhere(Post::idField() == postId);
|
||||||
|
|
@ -263,7 +263,7 @@ void MainTest::modifyPost()
|
||||||
QTEST_ASSERT(post->title() == "new name");
|
QTEST_ASSERT(post->title() == "new name");
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainTest::emptyDatabase()
|
void BasicTest::emptyDatabase()
|
||||||
{
|
{
|
||||||
// auto commentsCount = db.comments()->query()->remove();
|
// auto commentsCount = db.comments()->query()->remove();
|
||||||
// auto postsCount = db.posts()->query()->remove();
|
// auto postsCount = db.posts()->query()->remove();
|
||||||
|
|
@ -271,7 +271,7 @@ void MainTest::emptyDatabase()
|
||||||
// QTEST_ASSERT(commentsCount == 6);
|
// QTEST_ASSERT(commentsCount == 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainTest::cleanupTestCase()
|
void BasicTest::cleanupTestCase()
|
||||||
{
|
{
|
||||||
post->deleteLater();
|
post->deleteLater();
|
||||||
user->deleteLater();
|
user->deleteLater();
|
||||||
|
|
@ -285,4 +285,4 @@ void MainTest::cleanupTestCase()
|
||||||
PRINT_FORM(db);
|
PRINT_FORM(db);
|
||||||
}
|
}
|
||||||
|
|
||||||
QTEST_MAIN(MainTest)
|
QTEST_MAIN(BasicTest)
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
#include "weblogdatabase.h"
|
#include "weblogdatabase.h"
|
||||||
class Post;
|
class Post;
|
||||||
class User;
|
class User;
|
||||||
class MainTest : public QObject
|
class BasicTest : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
WeblogDatabase db;
|
WeblogDatabase db;
|
||||||
|
|
@ -16,7 +16,7 @@ class MainTest : public QObject
|
||||||
User *user;
|
User *user;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit MainTest(QObject *parent = nullptr);
|
explicit BasicTest(QObject *parent = nullptr);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
|
|
@ -9,18 +9,18 @@ INCLUDEPATH += $$PWD/../../src $$PWD/../common
|
||||||
include(../../nut.pri)
|
include(../../nut.pri)
|
||||||
IMPORTPATH += $$OUT_PWD/../src/imports
|
IMPORTPATH += $$OUT_PWD/../src/imports
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
maintest.cpp \
|
|
||||||
../common/comment.cpp \
|
../common/comment.cpp \
|
||||||
../common/post.cpp \
|
../common/post.cpp \
|
||||||
../common/user.cpp \
|
../common/user.cpp \
|
||||||
../common/weblogdatabase.cpp \
|
../common/weblogdatabase.cpp \
|
||||||
../common/score.cpp
|
../common/score.cpp \
|
||||||
|
tst_basic.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
maintest.h \
|
|
||||||
../common/consts.h \
|
../common/consts.h \
|
||||||
../common/comment.h \
|
../common/comment.h \
|
||||||
../common/post.h \
|
../common/post.h \
|
||||||
../common/user.h \
|
../common/user.h \
|
||||||
../common/weblogdatabase.h \
|
../common/weblogdatabase.h \
|
||||||
../common/score.h
|
../common/score.h \
|
||||||
|
tst_basic.h
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
#include "weblogdatabase.h"
|
#include "weblogdatabase.h"
|
||||||
class Post;
|
class Post;
|
||||||
class MainTest : public QObject
|
class BenchmarkTest : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
WeblogDatabase db;
|
WeblogDatabase db;
|
||||||
|
|
@ -14,7 +14,7 @@ class MainTest : public QObject
|
||||||
Post *post;
|
Post *post;
|
||||||
Query<Post> *q;
|
Query<Post> *q;
|
||||||
public:
|
public:
|
||||||
explicit MainTest(QObject *parent = nullptr);
|
explicit BenchmarkTest(QObject *parent = nullptr);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,12 +15,12 @@
|
||||||
#include "comment.h"
|
#include "comment.h"
|
||||||
#include "score.h"
|
#include "score.h"
|
||||||
|
|
||||||
MainTest::MainTest(QObject *parent) : QObject(parent)
|
BenchmarkTest::BenchmarkTest(QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainTest::initTestCase()
|
void BenchmarkTest::initTestCase()
|
||||||
{
|
{
|
||||||
REGISTER(User);
|
REGISTER(User);
|
||||||
REGISTER(Post);
|
REGISTER(Post);
|
||||||
|
|
@ -39,7 +39,7 @@ void MainTest::initTestCase()
|
||||||
QTEST_ASSERT(ok);
|
QTEST_ASSERT(ok);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainTest::insert1kPost()
|
void BenchmarkTest::insert1kPost()
|
||||||
{
|
{
|
||||||
QTime t;
|
QTime t;
|
||||||
t.start();
|
t.start();
|
||||||
|
|
@ -56,4 +56,4 @@ void MainTest::insert1kPost()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QTEST_MAIN(MainTest)
|
QTEST_MAIN(BenchmarkTest)
|
||||||
|
|
@ -9,12 +9,12 @@ INCLUDEPATH += $$PWD/../../src $$PWD/../common
|
||||||
include(../../nut.pri)
|
include(../../nut.pri)
|
||||||
IMPORTPATH += $$OUT_PWD/../src/imports
|
IMPORTPATH += $$OUT_PWD/../src/imports
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
maintest.cpp \
|
|
||||||
../common/comment.cpp \
|
../common/comment.cpp \
|
||||||
../common/post.cpp \
|
../common/post.cpp \
|
||||||
../common/user.cpp \
|
../common/user.cpp \
|
||||||
../common/weblogdatabase.cpp \
|
../common/weblogdatabase.cpp \
|
||||||
../common/score.cpp
|
../common/score.cpp \
|
||||||
|
tst_benchmark.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
maintest.h \
|
maintest.h \
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
#include "post.h"
|
#include "post.h"
|
||||||
#include "comment.h"
|
#include "comment.h"
|
||||||
|
#include "user.h"
|
||||||
|
|
||||||
MainTest::MainTest(QObject *parent) : QObject(parent)
|
MainTest::MainTest(QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
#include <QUuid>
|
#include <QUuid>
|
||||||
|
|
||||||
#include "db.h"
|
#include "db.h"
|
||||||
class MainTest : public QObject
|
class DataTypesTest : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
DB db;
|
DB db;
|
||||||
|
|
@ -52,7 +52,7 @@ class MainTest : public QObject
|
||||||
QColor color;
|
QColor color;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit MainTest(QObject *parent = nullptr);
|
explicit DataTypesTest(QObject *parent = nullptr);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,11 +16,11 @@
|
||||||
#include "generators/sqlitegenerator.h"
|
#include "generators/sqlitegenerator.h"
|
||||||
#include "generators/sqlservergenerator.h"
|
#include "generators/sqlservergenerator.h"
|
||||||
|
|
||||||
MainTest::MainTest(QObject *parent) : QObject(parent)
|
DataTypesTest::DataTypesTest(QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainTest::initTestCase()
|
void DataTypesTest::initTestCase()
|
||||||
{
|
{
|
||||||
//register all entities with Qt-MetaType mechanism
|
//register all entities with Qt-MetaType mechanism
|
||||||
REGISTER(SampleTable);
|
REGISTER(SampleTable);
|
||||||
|
|
@ -76,7 +76,7 @@ void MainTest::initTestCase()
|
||||||
QTEST_ASSERT(ok);
|
QTEST_ASSERT(ok);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainTest::types()
|
void DataTypesTest::types()
|
||||||
{
|
{
|
||||||
QList<QMetaType::Type> types;
|
QList<QMetaType::Type> types;
|
||||||
types
|
types
|
||||||
|
|
@ -141,7 +141,7 @@ void MainTest::types()
|
||||||
// qDebug() << en.value(i);
|
// qDebug() << en.value(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainTest::insert()
|
void DataTypesTest::insert()
|
||||||
{
|
{
|
||||||
SampleTable t;
|
SampleTable t;
|
||||||
t.setInt8(n8);
|
t.setInt8(n8);
|
||||||
|
|
@ -184,7 +184,7 @@ void MainTest::insert()
|
||||||
db.saveChanges();
|
db.saveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainTest::retrive()
|
void DataTypesTest::retrive()
|
||||||
{
|
{
|
||||||
QList<SampleTable*> list = db.sampleTables()->query()->toList();
|
QList<SampleTable*> list = db.sampleTables()->query()->toList();
|
||||||
QTEST_ASSERT(list.count() == 1);
|
QTEST_ASSERT(list.count() == 1);
|
||||||
|
|
@ -228,7 +228,7 @@ void MainTest::retrive()
|
||||||
QTEST_ASSERT(t->f_color() == color);
|
QTEST_ASSERT(t->f_color() == color);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainTest::cleanupTestCase()
|
void DataTypesTest::cleanupTestCase()
|
||||||
{
|
{
|
||||||
db.sampleTables()->query()->remove();
|
db.sampleTables()->query()->remove();
|
||||||
db.close();
|
db.close();
|
||||||
|
|
@ -236,4 +236,4 @@ void MainTest::cleanupTestCase()
|
||||||
PRINT_FORM(db);
|
PRINT_FORM(db);
|
||||||
}
|
}
|
||||||
|
|
||||||
QTEST_MAIN(MainTest)
|
QTEST_MAIN(DataTypesTest)
|
||||||
|
|
@ -9,9 +9,9 @@ INCLUDEPATH += $$PWD/../../src $$PWD/../common
|
||||||
include(../../nut.pri)
|
include(../../nut.pri)
|
||||||
IMPORTPATH += $$OUT_PWD/../src/imports
|
IMPORTPATH += $$OUT_PWD/../src/imports
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
maintest.cpp \
|
|
||||||
db.cpp \
|
db.cpp \
|
||||||
sampletable.cpp
|
sampletable.cpp \
|
||||||
|
tst_datatypes.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
maintest.h \
|
maintest.h \
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue