Adapt to the rename

This commit is contained in:
Luca Beltrame 2018-08-24 18:27:24 +02:00
parent 023d977ae4
commit c8dda3d020
Signed by: einar
GPG key ID: 8DF631FD021DB0C5

View file

@ -1,19 +1,40 @@
/*
* Copyright 2018 Luca Beltrame <lbeltrame@kde.org>
*
* This file is part of Danbooru Client.
*
* Danbooru Client is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Danbooru Client is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Danbooru Client. If not, see <http://www.gnu.org/licenses/>.
*/
#include "test_konachan.h" #include "test_service.h"
#include "../danbooru.h"
#include "../servicebase.h"
#include <QApplication> #include <QApplication>
#include <QTimer> #include <QTimer>
#include <QThread>
#include <QCommandLineParser> #include <QCommandLineParser>
void runTest(QUrl apiUrl); void runTest(QUrl apiUrl, Danbooru::ApiType apiType);
void runPostTest(); void runPostTest();
void runNextPostPageTest(); void runNextPostPageTest();
void runPoolTest(); void runPoolTest();
void runPoolRetrieval(); void runPoolRetrieval();
void runYandeReTest(); template<Danbooru::ApiType> class ServiceTest;
Danbooru::KonachanServiceTest* testSvc = 0; Danbooru::DanbooruServiceTest* testSvc = nullptr;
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
QApplication app(argc, argv); QApplication app(argc, argv);
@ -24,31 +45,36 @@ int main(int argc, char *argv[]) {
QCommandLineOption testKonachan("test-konachan", "Run Konachan.com tests"); QCommandLineOption testKonachan("test-konachan", "Run Konachan.com tests");
QCommandLineOption testYandeRe("test-yandere", "Run yande.re tests"); QCommandLineOption testYandeRe("test-yandere", "Run yande.re tests");
QCommandLineOption testDonmai("test-danbooru", "Run danbooru.donmai.us tests");
cmdParser.addOptions({testKonachan, testYandeRe}); cmdParser.addOptions({testKonachan, testYandeRe, testDonmai});
cmdParser.process(app); cmdParser.process(app);
if (cmdParser.isSet(testKonachan)) { if (cmdParser.isSet(testKonachan)) {
qDebug() << "Starting Konachan.com test"; qDebug() << "Starting Konachan.com test";
runTest(QUrl("http://konachan.com")); runTest(QUrl("http://konachan.net"), Danbooru::MoeBooru);
} else if (cmdParser.isSet(testYandeRe)) { } else if (cmdParser.isSet(testYandeRe)) {
qDebug() << "Starting yande.re test"; qDebug() << "Starting yande.re test";
runTest(QUrl("http://yande.re")); runTest(QUrl("http://yande.re"), Danbooru::MoeBooru);
} else if (cmdParser.isSet(testDonmai)) {
runTest(QUrl("http://danbooru.donmai.us"), Danbooru::Danbooru);
} else {
cmdParser.showHelp();
} }
app.exec(); app.exec();
} }
void runTest(QUrl apiUrl) void runTest(QUrl apiUrl, Danbooru::ApiType apiType)
{ {
testSvc = new Danbooru::KonachanServiceTest(apiUrl); testSvc = new Danbooru::DanbooruServiceTest(apiUrl, apiType);
QObject::connect(testSvc->service(), &Danbooru::DanbooruServiceBase::postDownloadFinished, QObject::connect(testSvc->service(), &Danbooru::DanbooruServiceBase::postDownloadFinished,
testSvc, &runNextPostPageTest); testSvc, &runNextPostPageTest);
QObject::connect(testSvc->service(), &Danbooru::DanbooruServiceBase::poolDownloadFinished,
testSvc, &runPoolRetrieval);
qDebug() << "--- POST TEST ---";
testSvc->testPostService(); testSvc->testPostService();
qDebug() << "--- POST TEST ---";
} }
@ -67,6 +93,8 @@ void runPoolTest()
{ {
QObject::disconnect(testSvc->service(), &Danbooru::DanbooruServiceBase::postDownloadFinished, QObject::disconnect(testSvc->service(), &Danbooru::DanbooruServiceBase::postDownloadFinished,
testSvc, 0); testSvc, 0);
QObject::connect(testSvc->service(), &Danbooru::DanbooruServiceBase::poolDownloadFinished,
testSvc, &runPoolRetrieval);
testSvc->service()->nextPostPage(); testSvc->service()->nextPostPage();
qDebug() << "--- POOL TEST ---"; qDebug() << "--- POOL TEST ---";
testSvc->testPoolService(); testSvc->testPoolService();
@ -76,6 +104,10 @@ void runPoolRetrieval()
{ {
QObject::disconnect(testSvc->service(), &Danbooru::DanbooruServiceBase::poolDownloadFinished, QObject::disconnect(testSvc->service(), &Danbooru::DanbooruServiceBase::poolDownloadFinished,
testSvc, 0); testSvc, 0);
QObject::connect(testSvc->service(), &Danbooru::DanbooruServiceBase::postDownloadFinished,
testSvc, [=]() {
QThread::sleep(5);
QApplication::quit();});
qDebug() << "--- POOL RETRIEVAL TEST ---"; qDebug() << "--- POOL RETRIEVAL TEST ---";
testSvc->testPoolRetrieval(300); testSvc->testPoolRetrieval(300);
} }