#26 fix test table names

This commit is contained in:
Hamed Masafi 2018-09-05 09:48:59 +04:30
parent 90be3ad9de
commit 5014016e4d
8 changed files with 35 additions and 35 deletions

View File

@ -42,8 +42,8 @@ void MainTest::initTestCase()
bool ok = db.open();
db.commentTable()->query()->remove();
db.postTable()->query()->remove();
db.comments()->query()->remove();
db.posts()->query()->remove();
QTEST_ASSERT(ok);
}
@ -63,7 +63,7 @@ void MainTest::createUser()
user = new User;
user->setUsername("admin");
user->setPassword("123456");
db.userTable()->append(user);
db.users()->append(user);
db.saveChanges();
}
@ -74,7 +74,7 @@ void MainTest::createPost()
newPost->setTitle("post title");
newPost->setSaveDate(QDateTime::currentDateTime());
db.postTable()->append(newPost);
db.posts()->append(newPost);
for(int i = 0 ; i < 3; i++){
Comment *comment = new Comment;
@ -104,7 +104,7 @@ void MainTest::createPost2()
newPost->setTitle("post title");
newPost->setSaveDate(QDateTime::currentDateTime());
db.postTable()->append(newPost);
db.posts()->append(newPost);
db.saveChanges();
for(int i = 0 ; i < 3; i++){
@ -113,7 +113,7 @@ void MainTest::createPost2()
comment->setSaveDate(QDateTime::currentDateTime());
comment->setAuthor(user);
comment->setPostId(newPost->id());
db.commentTable()->append(comment);
db.comments()->append(comment);
}
db.saveChanges();
@ -123,7 +123,7 @@ void MainTest::createPost2()
void MainTest::updatePostOnTheFly()
{
auto c = db.postTable()->query()
auto c = db.posts()->query()
->where(Post::idField() == postId)
->update(Post::titleField() = "New title");
@ -132,18 +132,18 @@ void MainTest::updatePostOnTheFly()
void MainTest::selectPublicts()
{
auto q = db.postTable()->query()
auto q = db.posts()->query()
->where(Post::isPublicField())
->toList();
auto q2 = db.postTable()->query()
auto q2 = db.posts()->query()
->where(!Post::isPublicField())
->toList();
}
void MainTest::selectPosts()
{
auto q = db.postTable()->query()
auto q = db.posts()->query()
->join<Comment>()//Comment::authorIdField() == Post::idField())
->orderBy(!Post::saveDateField() | Post::bodyField())
->setWhere(Post::idField() == postId);
@ -166,7 +166,7 @@ void MainTest::selectPosts()
void MainTest::selectScoreAverage()
{
auto a = db.scoreTable()->query()
auto a = db.scores()->query()
->join<Post>()
->setWhere(Post::idField() == 1)
->average(Score::scoreField());
@ -175,7 +175,7 @@ void MainTest::selectScoreAverage()
void MainTest::selectFirst()
{
auto posts = db.postTable()->query()
auto posts = db.posts()->query()
->first();
QTEST_ASSERT(posts != Q_NULLPTR);
@ -183,7 +183,7 @@ void MainTest::selectFirst()
void MainTest::selectPostsWithoutTitle()
{
auto q = db.postTable()->query();
auto q = db.posts()->query();
q->setWhere(Post::titleField().isNull());
auto count = q->count();
QTEST_ASSERT(count == 0);
@ -191,7 +191,7 @@ void MainTest::selectPostsWithoutTitle()
void MainTest::selectPostIds()
{
auto q = db.postTable()->query();
auto q = db.posts()->query();
auto ids = q->select(Post::idField());
qDebug() << q->sqlCommand();
QTEST_ASSERT(ids.count() == 2);
@ -207,11 +207,11 @@ void MainTest::testDate()
newPost->setTitle("post title");
newPost->setSaveDate(d);
db.postTable()->append(newPost);
db.posts()->append(newPost);
db.saveChanges(true);
auto q = db.postTable()->query()
auto q = db.posts()->query()
->setWhere(Post::idField() == newPost->id())
->first();
@ -221,7 +221,7 @@ void MainTest::testDate()
void MainTest::join()
{
TIC();
auto q = db.commentTable()->query()
auto q = db.comments()->query()
->join<User>()
->join<Post>();
@ -236,14 +236,14 @@ void MainTest::join()
void MainTest::selectWithInvalidRelation()
{
auto q = db.postTable()->query();
auto q = db.posts()->query();
q->join("Invalid_Class_Name");
q->toList();
}
void MainTest::modifyPost()
{
auto q = db.postTable()->query();
auto q = db.posts()->query();
q->setWhere(Post::idField() == postId);
Post *post = q->first();
@ -253,7 +253,7 @@ void MainTest::modifyPost()
post->setTitle("new name");
db.saveChanges();
q = db.postTable()->query()
q = db.posts()->query()
->setWhere(Post::idField() == postId);
post = q->first();
@ -263,8 +263,8 @@ void MainTest::modifyPost()
void MainTest::emptyDatabase()
{
auto commentsCount = db.commentTable()->query()->remove();
auto postsCount = db.postTable()->query()->remove();
auto commentsCount = db.comments()->query()->remove();
auto postsCount = db.posts()->query()->remove();
QTEST_ASSERT(postsCount == 3);
QTEST_ASSERT(commentsCount == 6);
}

View File

@ -16,7 +16,7 @@ class MainTest : public QObject
User *user;
public:
explicit MainTest(QObject *parent = 0);
explicit MainTest(QObject *parent = nullptr);
signals:

View File

@ -14,7 +14,7 @@ class MainTest : public QObject
Post *post;
Query<Post> *q;
public:
explicit MainTest(QObject *parent = 0);
explicit MainTest(QObject *parent = nullptr);
signals:

View File

@ -14,7 +14,7 @@ class MainTest : public QObject
Post *post;
Query<Post> *q;
public:
explicit MainTest(QObject *parent = 0);
explicit MainTest(QObject *parent = nullptr);
signals:

View File

@ -8,9 +8,9 @@
#include "weblogdatabase.h"
WeblogDatabase::WeblogDatabase() : Database(),
m_postTable(new TableSet<Post>(this)),
m_commentTable(new TableSet<Comment>(this)),
m_userTable(new TableSet<User>(this)),
m_scoreTable(new TableSet<Score>(this))
m_posts(new TableSet<Post>(this)),
m_comments(new TableSet<Comment>(this)),
m_users(new TableSet<User>(this)),
m_scores(new TableSet<Score>(this))
{
}

View File

@ -17,10 +17,10 @@ class WeblogDatabase : public Database
NUT_DB_VERSION(1)
NUT_DECLARE_TABLE(Post, post)
NUT_DECLARE_TABLE(Comment, comment)
NUT_DECLARE_TABLE(User, user)
NUT_DECLARE_TABLE(Score, score)
NUT_DECLARE_TABLE(Post, posts)
NUT_DECLARE_TABLE(Comment, comments)
NUT_DECLARE_TABLE(User, users)
NUT_DECLARE_TABLE(Score, scores)
public:
WeblogDatabase();

View File

@ -21,7 +21,7 @@ void MainTest::no1()
FieldPhrase<QString> name("main", "name");
FieldPhrase<QString> last_name("main", "last_name");
FieldPhrase<QDate> date("main", "date");
auto w = id == 4 && name == "salam";
auto w = (id == 4 && name == "hi");
}
QTEST_MAIN(MainTest)

View File

@ -11,7 +11,7 @@ class MainTest : public QObject
Q_OBJECT
public:
explicit MainTest(QObject *parent = 0);
explicit MainTest(QObject *parent = nullptr);
signals: