From e8b64a4ad95c1e91dc6495abbddd564d0cbba30f Mon Sep 17 00:00:00 2001 From: Luca Beltrame Date: Sun, 23 Aug 2015 23:08:45 +0200 Subject: [PATCH] Refactor the test application so that it is board URL agnostic --- src/libdanbooru/tests/test_apis.cpp | 62 +++++++++++++++++-------- src/libdanbooru/tests/test_konachan.cpp | 10 ++-- src/libdanbooru/tests/test_konachan.h | 3 +- 3 files changed, 52 insertions(+), 23 deletions(-) diff --git a/src/libdanbooru/tests/test_apis.cpp b/src/libdanbooru/tests/test_apis.cpp index df3226c..3837dbd 100644 --- a/src/libdanbooru/tests/test_apis.cpp +++ b/src/libdanbooru/tests/test_apis.cpp @@ -5,9 +5,13 @@ #include #include -void runKonachanTest(); +void runTest(QUrl apiUrl); +void runPostTest(); +void runNextPostPageTest(); +void runPoolTest(); +void runPoolRetrieval(); + void runYandeReTest(); -void runDanbooruTest(); Danbooru::KonachanServiceTest* testSvc = 0; @@ -22,37 +26,57 @@ int main(int argc, char *argv[]) { QCommandLineOption testYandeRe("test-yandere", "Run yande.re tests"); cmdParser.addOptions({testKonachan, testYandeRe}); - -// cmdParser.addOption(testKonachan); -// cmdParser.addOption(testYandeRe); - cmdParser.process(app); if (cmdParser.isSet(testKonachan)) { - runKonachanTest(); + qDebug() << "Starting Konachan.com test"; + runTest(QUrl("http://konachan.com")); } else if (cmdParser.isSet(testYandeRe)) { - runYandeReTest(); + qDebug() << "Starting yande.re test"; + runTest(QUrl("http://yande.re")); } app.exec(); } -void runKonachanTest() +void runTest(QUrl apiUrl) { - qDebug() << "Starting Konachan API test"; - qDebug() << "------ POST TEST ----"; - testSvc = new Danbooru::KonachanServiceTest(QUrl("http://konachan.com")); + testSvc = new Danbooru::KonachanServiceTest(apiUrl); + + QObject::connect(testSvc->service(), &Danbooru::DanbooruServiceBase::postDownloadFinished, + testSvc, &runNextPostPageTest); + QObject::connect(testSvc->service(), &Danbooru::DanbooruServiceBase::poolDownloadFinished, + testSvc, &runPoolRetrieval); + qDebug() << "--- POST TEST ---"; testSvc->testPostService(); + +} + +void runNextPostPageTest() +{ + QObject::disconnect(testSvc->service(), &Danbooru::DanbooruServiceBase::postDownloadFinished, + testSvc, 0); + qDebug() << "--- NEXT POST PAGE TEST ---"; + QObject::connect(testSvc->service(), &Danbooru::DanbooruServiceBase::postDownloadFinished, + testSvc, &runPoolTest); + qDebug() << "--- NEXT POST PAGE TEST ---"; + testSvc->service()->nextPostPage(); +} + + +void runPoolTest() +{ + QObject::disconnect(testSvc->service(), &Danbooru::DanbooruServiceBase::postDownloadFinished, + testSvc, 0); + testSvc->service()->nextPostPage(); qDebug() << "--- POOL TEST ---"; testSvc->testPoolService(); } -void runYandeReTest() +void runPoolRetrieval() { - qDebug() << "Starting yande.re API test"; - testSvc = new Danbooru::KonachanServiceTest(QUrl("http://yande.re")); - qDebug() << "------ POST TEST ----"; - testSvc->testPostService(); - qDebug() << "--- POOL TEST ---"; - testSvc->testPoolService(); + QObject::disconnect(testSvc->service(), &Danbooru::DanbooruServiceBase::poolDownloadFinished, + testSvc, 0); + qDebug() << "--- POOL RETRIEVAL TEST ---"; + testSvc->testPoolRetrieval(300); } diff --git a/src/libdanbooru/tests/test_konachan.cpp b/src/libdanbooru/tests/test_konachan.cpp index 1eca5a8..1834324 100644 --- a/src/libdanbooru/tests/test_konachan.cpp +++ b/src/libdanbooru/tests/test_konachan.cpp @@ -45,7 +45,11 @@ void KonachanServiceTest::testPostService() { } void KonachanServiceTest::testPoolService() { - m_service->getPoolList(); + m_service->getPoolList(1 /*limit */); +} + +void KonachanServiceTest::testPoolRetrieval(int postid) { + m_service->getPool(postid); } void KonachanServiceTest::showPostData(DanbooruPost* post) { @@ -67,8 +71,8 @@ void KonachanServiceTest::showPoolData(DanbooruPool* pool) { } -QLabel* KonachanServiceTest::previewLabel() const { - return m_label; +DanbooruServiceBase* KonachanServiceTest::service() const { + return m_service; } } // namespace Danbooru \ No newline at end of file diff --git a/src/libdanbooru/tests/test_konachan.h b/src/libdanbooru/tests/test_konachan.h index b5b8113..53a3e4e 100644 --- a/src/libdanbooru/tests/test_konachan.h +++ b/src/libdanbooru/tests/test_konachan.h @@ -64,8 +64,9 @@ public: void testPostService(); void testPoolService(); + void testPoolRetrieval(int postid = 300); void testTagService(); - QLabel* previewLabel() const; + DanbooruServiceBase* service() const; private Q_SLOTS: void showPostData(DanbooruPost* post);