Merge branch 'qt_module' of https://github.com/HamedMasafi/Nut into qt_module
# Conflicts: # tests/auto/tst_basic/tst_basic.cpp
This commit is contained in:
commit
bc88cd246c
|
|
@ -65,7 +65,7 @@ jobs:
|
||||||
${{steps.qt.outputs.make}}
|
${{steps.qt.outputs.make}}
|
||||||
${{steps.qt.outputs.make}} INSTALL_ROOT="${{steps.qt.outputs.installdir}}" install
|
${{steps.qt.outputs.make}} INSTALL_ROOT="${{steps.qt.outputs.installdir}}" install
|
||||||
- name: make tests
|
- name: make tests
|
||||||
if: steps.qt.outputs.tests == 'true' && !contains(matrix.platform, 'mingw')
|
if: steps.qt.outputs.tests == 'true'
|
||||||
run: |
|
run: |
|
||||||
${{steps.qt.outputs.make}} all
|
${{steps.qt.outputs.make}} all
|
||||||
${{steps.qt.outputs.make}} ${{steps.qt.outputs.testflags}} run-tests
|
${{steps.qt.outputs.make}} ${{steps.qt.outputs.testflags}} run-tests
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ AbstractQuery::AbstractQuery(QObject *parent) : QObject(parent)
|
||||||
}
|
}
|
||||||
|
|
||||||
Nut::AbstractQueryPrivate::AbstractQueryPrivate(Nut::AbstractQuery *parent) :
|
Nut::AbstractQueryPrivate::AbstractQueryPrivate(Nut::AbstractQuery *parent) :
|
||||||
q_ptr(parent)
|
q_ptr(parent), skip(0), take(0)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -282,7 +282,7 @@ DatabaseModel DatabasePrivate::getLastSchema()
|
||||||
{
|
{
|
||||||
Row<ChangeLogTable> u = changeLogs->query()
|
Row<ChangeLogTable> u = changeLogs->query()
|
||||||
->orderBy(!ChangeLogTable::idField())
|
->orderBy(!ChangeLogTable::idField())
|
||||||
->first();
|
.first();
|
||||||
|
|
||||||
// DatabaseModel ret(q->metaObject()->className());
|
// DatabaseModel ret(q->metaObject()->className());
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
#define TIC() QElapsedTimer timer; timer.start()
|
#define TIC() QElapsedTimer timer; timer.start()
|
||||||
#define TOC() qDebug() << QStringLiteral("Elapsed time: %1ms for %2") \
|
#define TOC() qDebug() << QStringLiteral("Elapsed time: %1ms for %2") \
|
||||||
.arg(timer.elapsed() / 1000.) \
|
.arg(timer.elapsed() / 1000.) \
|
||||||
.arg(__func__)
|
.arg(QString::fromUtf8(__func__))
|
||||||
|
|
||||||
|
|
||||||
#define DRIVER QStringLiteral("QSQLITE")
|
#define DRIVER QStringLiteral("QSQLITE")
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ void BasicTest::initTestCase()
|
||||||
db.setPassword(PASSWORD);
|
db.setPassword(PASSWORD);
|
||||||
|
|
||||||
bool ok = db.open();
|
bool ok = db.open();
|
||||||
QTEST_ASSERT(ok);
|
QVERIFY(ok);
|
||||||
|
|
||||||
db.comments()->query()->remove();
|
db.comments()->query()->remove();
|
||||||
db.posts()->query()->remove();
|
db.posts()->query()->remove();
|
||||||
|
|
@ -57,8 +57,8 @@ void BasicTest::dataSchema()
|
||||||
void BasicTest::createUser()
|
void BasicTest::createUser()
|
||||||
{
|
{
|
||||||
user = Nut::create<User>();
|
user = Nut::create<User>();
|
||||||
user->setUsername("admin");
|
user->setUsername(QStringLiteral("admin"));
|
||||||
user->setPassword("123456");
|
user->setPassword(QStringLiteral("123456"));
|
||||||
db.users()->append(user);
|
db.users()->append(user);
|
||||||
db.saveChanges();
|
db.saveChanges();
|
||||||
}
|
}
|
||||||
|
|
@ -75,7 +75,7 @@ void BasicTest::createPost()
|
||||||
|
|
||||||
for(int i = 0 ; i < 3; i++){
|
for(int i = 0 ; i < 3; i++){
|
||||||
auto comment = Nut::create<Comment>();
|
auto comment = Nut::create<Comment>();
|
||||||
comment->setMessage("comment #" + QString::number(i));
|
comment->setMessage(QStringLiteral("comment #") + QString::number(i));
|
||||||
comment->setSaveDate(QDateTime::currentDateTime());
|
comment->setSaveDate(QDateTime::currentDateTime());
|
||||||
comment->setAuthorId(user->id());
|
comment->setAuthorId(user->id());
|
||||||
newPost->comments()->append(comment);
|
newPost->comments()->append(comment);
|
||||||
|
|
@ -92,24 +92,23 @@ void BasicTest::createPost()
|
||||||
|
|
||||||
QTEST_ASSERT(newPost->id() != 0);
|
QTEST_ASSERT(newPost->id() != 0);
|
||||||
TOC();
|
TOC();
|
||||||
qDebug() << "New post inserted with id:" << newPost->id();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BasicTest::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(
|
||||||
(Post::titleField() = "This is a sample")
|
(Post::titleField() = QStringLiteral("This is a sample"))
|
||||||
& (Post::isPublicField() = true));
|
& (Post::isPublicField() = true));
|
||||||
|
|
||||||
QTEST_ASSERT(postIdVar.type() == QVariant::LongLong
|
QVERIFY(postIdVar.type() == QVariant::LongLong
|
||||||
|| postIdVar.type() == QVariant::ULongLong
|
|| postIdVar.type() == QVariant::ULongLong
|
||||||
|| postIdVar.type() == QVariant::Double);
|
|| postIdVar.type() == QVariant::Double);
|
||||||
int postId = postIdVar.toInt();
|
int postId = postIdVar.toInt();
|
||||||
|
|
||||||
for(int i = 0 ; i < 3; i++){
|
for(int i = 0 ; i < 3; i++){
|
||||||
auto comment = Nut::create<Comment>();
|
auto comment = Nut::create<Comment>();
|
||||||
comment->setMessage("comment #" + QString::number(i + 2));
|
comment->setMessage(QStringLiteral("comment #") + QString::number(i + 2));
|
||||||
comment->setSaveDate(QDateTime::currentDateTime());
|
comment->setSaveDate(QDateTime::currentDateTime());
|
||||||
comment->setAuthor(user);
|
comment->setAuthor(user);
|
||||||
//join child to master by id
|
//join child to master by id
|
||||||
|
|
@ -125,9 +124,17 @@ void BasicTest::updatePostOnTheFly()
|
||||||
{
|
{
|
||||||
auto c = db.posts()->query()
|
auto c = db.posts()->query()
|
||||||
->where(Post::idField() == postId)
|
->where(Post::idField() == postId)
|
||||||
->update(Post::titleField() = "New title");
|
->update(Post::titleField() = QStringLiteral("New title"));
|
||||||
|
|
||||||
QCOMPARE(c, 1);
|
QCOMPARE(c, 1);
|
||||||
|
|
||||||
|
auto titles = db.posts()
|
||||||
|
->query()
|
||||||
|
->where(Post::idField() == postId)
|
||||||
|
->select(Post::titleField());
|
||||||
|
|
||||||
|
QCOMPARE(titles.count(), 1);
|
||||||
|
QCOMPARE(titles.at(0), QStringLiteral("New title"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void BasicTest::selectPublicts()
|
void BasicTest::selectPublicts()
|
||||||
|
|
@ -153,17 +160,17 @@ void BasicTest::selectPosts()
|
||||||
|
|
||||||
auto posts = q->toList();
|
auto posts = q->toList();
|
||||||
post = posts.at(0);
|
post = posts.at(0);
|
||||||
post->setBody("");
|
post->setBody(QStringLiteral(""));
|
||||||
|
|
||||||
PRINT(posts.length());
|
PRINT(posts.length());
|
||||||
PRINT(posts.at(0)->comments()->length());
|
PRINT(posts.at(0)->comments()->length());
|
||||||
QCOMPARE(posts.length(), 1);
|
QCOMPARE(posts.length(), 1);
|
||||||
QCOMPARE(posts.at(0)->comments()->length(), 3);
|
QCOMPARE(posts.at(0)->comments()->length(), 3);
|
||||||
QCOMPARE(posts.at(0)->title(), "post title");
|
QCOMPARE(posts.at(0)->title(), QStringLiteral("post title"));
|
||||||
|
|
||||||
QCOMPARE(posts.at(0)->comments()->at(0)->message(), "comment #0");
|
QCOMPARE(posts.at(0)->comments()->at(0)->message(), QStringLiteral("comment #0"));
|
||||||
QCOMPARE(posts.at(0)->comments()->at(1)->message(), "comment #1");
|
QCOMPARE(posts.at(0)->comments()->at(1)->message(), QStringLiteral("comment #1"));
|
||||||
QCOMPARE(posts.at(0)->comments()->at(2)->message(), "comment #2");
|
QCOMPARE(posts.at(0)->comments()->at(2)->message(), QStringLiteral("comment #2"));
|
||||||
db.cleanUp();
|
db.cleanUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -177,7 +184,7 @@ void BasicTest::selectScoreAverage()
|
||||||
->average(Score::scoreField())
|
->average(Score::scoreField())
|
||||||
.toInt(&ok);
|
.toInt(&ok);
|
||||||
|
|
||||||
QTEST_ASSERT(ok);
|
QVERIFY(ok);
|
||||||
QCOMPARE(avg, 2);
|
QCOMPARE(avg, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -199,7 +206,7 @@ void BasicTest::selectFirst()
|
||||||
->orderBy(Post::idField())
|
->orderBy(Post::idField())
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
QCOMPARE(posts, Q_NULLPTR);
|
QVERIFY(posts != Q_NULLPTR);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BasicTest::selectPostsWithoutTitle()
|
void BasicTest::selectPostsWithoutTitle()
|
||||||
|
|
@ -225,7 +232,7 @@ void BasicTest::testDate()
|
||||||
d.setTime(t);
|
d.setTime(t);
|
||||||
|
|
||||||
auto newPost = Nut::create<Post>();
|
auto newPost = Nut::create<Post>();
|
||||||
newPost->setTitle("post title");
|
newPost->setTitle(QStringLiteral("post title"));
|
||||||
newPost->setSaveDate(d);
|
newPost->setSaveDate(d);
|
||||||
|
|
||||||
db.posts()->append(newPost);
|
db.posts()->append(newPost);
|
||||||
|
|
@ -237,14 +244,15 @@ void BasicTest::testDate()
|
||||||
->orderBy(Post::idField())
|
->orderBy(Post::idField())
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
qDebug() << q->saveDate() << d;
|
QCOMPARE(q->saveDate(), d);
|
||||||
QTEST_ASSERT(q->saveDate() == d);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BasicTest::testLimitedQuery()
|
void BasicTest::testLimitedQuery()
|
||||||
{
|
{
|
||||||
auto comments = db.comments()->query()->toList(2);
|
auto q = db.comments()->query();
|
||||||
QTEST_ASSERT(comments.length() == 2);
|
auto comments = q->toList(2);
|
||||||
|
qDebug() << q->sqlCommand();
|
||||||
|
QCOMPARE(comments.length(), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BasicTest::join()
|
void BasicTest::join()
|
||||||
|
|
@ -266,7 +274,7 @@ void BasicTest::join()
|
||||||
void BasicTest::selectWithInvalidRelation()
|
void BasicTest::selectWithInvalidRelation()
|
||||||
{
|
{
|
||||||
auto q = db.posts()->query();
|
auto q = db.posts()->query();
|
||||||
q->join("Invalid_Class_Name");
|
q->join(QStringLiteral("Invalid_Class_Name"));
|
||||||
q->toList();
|
q->toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -280,7 +288,7 @@ void BasicTest::modifyPost()
|
||||||
|
|
||||||
QTEST_ASSERT(post != nullptr);
|
QTEST_ASSERT(post != nullptr);
|
||||||
|
|
||||||
post->setTitle("new name");
|
post->setTitle(QStringLiteral("new name"));
|
||||||
db.saveChanges();
|
db.saveChanges();
|
||||||
|
|
||||||
q = db.posts()->query()
|
q = db.posts()->query()
|
||||||
|
|
@ -289,7 +297,7 @@ void BasicTest::modifyPost()
|
||||||
|
|
||||||
post = q->first();
|
post = q->first();
|
||||||
PRINT(post->title());
|
PRINT(post->title());
|
||||||
QTEST_ASSERT(post->title() == "new name");
|
QCOMPARE(post->title(), "new name");
|
||||||
}
|
}
|
||||||
|
|
||||||
void BasicTest::emptyDatabase()
|
void BasicTest::emptyDatabase()
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ void BenchmarkTest::insert1kPost()
|
||||||
|
|
||||||
for (int i = 0; i < 100; ++i) {
|
for (int i = 0; i < 100; ++i) {
|
||||||
auto newPost = Nut::create<Post>();
|
auto newPost = Nut::create<Post>();
|
||||||
newPost->setTitle("post title");
|
newPost->setTitle(QStringLiteral("post title"));
|
||||||
newPost->setSaveDate(QDateTime::currentDateTime());
|
newPost->setSaveDate(QDateTime::currentDateTime());
|
||||||
|
|
||||||
db.posts()->append(newPost);
|
db.posts()->append(newPost);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue