Refactor the test application so that it is board URL agnostic

This commit is contained in:
Luca Beltrame 2015-08-23 23:08:45 +02:00
parent 08402657a0
commit e8b64a4ad9
3 changed files with 52 additions and 23 deletions

View file

@ -5,9 +5,13 @@
#include <QTimer> #include <QTimer>
#include <QCommandLineParser> #include <QCommandLineParser>
void runKonachanTest(); void runTest(QUrl apiUrl);
void runPostTest();
void runNextPostPageTest();
void runPoolTest();
void runPoolRetrieval();
void runYandeReTest(); void runYandeReTest();
void runDanbooruTest();
Danbooru::KonachanServiceTest* testSvc = 0; Danbooru::KonachanServiceTest* testSvc = 0;
@ -22,37 +26,57 @@ int main(int argc, char *argv[]) {
QCommandLineOption testYandeRe("test-yandere", "Run yande.re tests"); QCommandLineOption testYandeRe("test-yandere", "Run yande.re tests");
cmdParser.addOptions({testKonachan, testYandeRe}); cmdParser.addOptions({testKonachan, testYandeRe});
// cmdParser.addOption(testKonachan);
// cmdParser.addOption(testYandeRe);
cmdParser.process(app); cmdParser.process(app);
if (cmdParser.isSet(testKonachan)) { if (cmdParser.isSet(testKonachan)) {
runKonachanTest(); qDebug() << "Starting Konachan.com test";
runTest(QUrl("http://konachan.com"));
} else if (cmdParser.isSet(testYandeRe)) { } else if (cmdParser.isSet(testYandeRe)) {
runYandeReTest(); qDebug() << "Starting yande.re test";
runTest(QUrl("http://yande.re"));
} }
app.exec(); app.exec();
} }
void runKonachanTest() void runTest(QUrl apiUrl)
{ {
qDebug() << "Starting Konachan API test"; testSvc = new Danbooru::KonachanServiceTest(apiUrl);
qDebug() << "------ POST TEST ----";
testSvc = new Danbooru::KonachanServiceTest(QUrl("http://konachan.com")); QObject::connect(testSvc->service(), &Danbooru::DanbooruServiceBase::postDownloadFinished,
testSvc, &runNextPostPageTest);
QObject::connect(testSvc->service(), &Danbooru::DanbooruServiceBase::poolDownloadFinished,
testSvc, &runPoolRetrieval);
qDebug() << "--- POST TEST ---";
testSvc->testPostService(); 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 ---"; qDebug() << "--- POOL TEST ---";
testSvc->testPoolService(); testSvc->testPoolService();
} }
void runYandeReTest() void runPoolRetrieval()
{ {
qDebug() << "Starting yande.re API test"; QObject::disconnect(testSvc->service(), &Danbooru::DanbooruServiceBase::poolDownloadFinished,
testSvc = new Danbooru::KonachanServiceTest(QUrl("http://yande.re")); testSvc, 0);
qDebug() << "------ POST TEST ----"; qDebug() << "--- POOL RETRIEVAL TEST ---";
testSvc->testPostService(); testSvc->testPoolRetrieval(300);
qDebug() << "--- POOL TEST ---";
testSvc->testPoolService();
} }

View file

@ -45,7 +45,11 @@ void KonachanServiceTest::testPostService() {
} }
void KonachanServiceTest::testPoolService() { 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) { void KonachanServiceTest::showPostData(DanbooruPost* post) {
@ -67,8 +71,8 @@ void KonachanServiceTest::showPoolData(DanbooruPool* pool) {
} }
QLabel* KonachanServiceTest::previewLabel() const { DanbooruServiceBase* KonachanServiceTest::service() const {
return m_label; return m_service;
} }
} // namespace Danbooru } // namespace Danbooru

View file

@ -64,8 +64,9 @@ public:
void testPostService(); void testPostService();
void testPoolService(); void testPoolService();
void testPoolRetrieval(int postid = 300);
void testTagService(); void testTagService();
QLabel* previewLabel() const; DanbooruServiceBase* service() const;
private Q_SLOTS: private Q_SLOTS:
void showPostData(DanbooruPost* post); void showPostData(DanbooruPost* post);