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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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