From c5b8fccc6ffd6e7a7b4a9ad20635ea1089c66dac Mon Sep 17 00:00:00 2001 From: Luca Beltrame Date: Sun, 23 Aug 2015 17:26:41 +0200 Subject: [PATCH] Build test application for Konachan API --- src/libdanbooru/tests/CMakeLists.txt | 19 +++++---- src/libdanbooru/tests/test_apis.cpp | 51 +++++++++++++++++++++++-- src/libdanbooru/tests/test_konachan.cpp | 32 ++++++++++++++-- src/libdanbooru/tests/test_konachan.h | 30 ++++++++++++++- 4 files changed, 114 insertions(+), 18 deletions(-) diff --git a/src/libdanbooru/tests/CMakeLists.txt b/src/libdanbooru/tests/CMakeLists.txt index 895b24f..a463062 100644 --- a/src/libdanbooru/tests/CMakeLists.txt +++ b/src/libdanbooru/tests/CMakeLists.txt @@ -1,14 +1,13 @@ +include(ECMAddTests) + set (test_SRCS test_konachan.cpp test_apis.cpp) -add_executable(test_service - ${test_SRCS} - ) -target_link_libraries(test_service PRIVATE - Qt5::Widgets - Qt5::Core - KF5::KIOCore - KF5::GuiAddons - danbooru - ) +ecm_add_test(${test_SRCS} LINK_LIBRARIES + Qt5::Widgets + Qt5::Core + KF5::KIOCore + KF5::GuiAddons + danbooru + TEST_NAME test_konachan_api) diff --git a/src/libdanbooru/tests/test_apis.cpp b/src/libdanbooru/tests/test_apis.cpp index bfdf69f..df3226c 100644 --- a/src/libdanbooru/tests/test_apis.cpp +++ b/src/libdanbooru/tests/test_apis.cpp @@ -3,11 +3,56 @@ #include #include +#include + +void runKonachanTest(); +void runYandeReTest(); +void runDanbooruTest(); + +Danbooru::KonachanServiceTest* testSvc = 0; int main(int argc, char *argv[]) { QApplication app(argc, argv); - qDebug() << "Starting Konachan API test"; - Danbooru::KonachanServiceTest* testSvc = new Danbooru::KonachanServiceTest(); - QTimer::singleShot(2000, testSvc, &Danbooru::KonachanServiceTest::testPostService); + + QCommandLineParser cmdParser; + cmdParser.addHelpOption(); + cmdParser.addVersionOption(); + + QCommandLineOption testKonachan("test-konachan", "Run Konachan.com tests"); + 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(); + } else if (cmdParser.isSet(testYandeRe)) { + runYandeReTest(); + } + app.exec(); } + +void runKonachanTest() +{ + qDebug() << "Starting Konachan API test"; + qDebug() << "------ POST TEST ----"; + testSvc = new Danbooru::KonachanServiceTest(QUrl("http://konachan.com")); + testSvc->testPostService(); + qDebug() << "--- POOL TEST ---"; + testSvc->testPoolService(); +} + +void runYandeReTest() +{ + qDebug() << "Starting yande.re API test"; + testSvc = new Danbooru::KonachanServiceTest(QUrl("http://yande.re")); + qDebug() << "------ POST TEST ----"; + testSvc->testPostService(); + qDebug() << "--- POOL TEST ---"; + testSvc->testPoolService(); +} diff --git a/src/libdanbooru/tests/test_konachan.cpp b/src/libdanbooru/tests/test_konachan.cpp index bb66869..1eca5a8 100644 --- a/src/libdanbooru/tests/test_konachan.cpp +++ b/src/libdanbooru/tests/test_konachan.cpp @@ -19,30 +19,56 @@ #include "test_konachan.h" +#include + namespace Danbooru { -KonachanServiceTest::KonachanServiceTest(): - m_service(0) +KonachanServiceTest::KonachanServiceTest(QUrl boardUrl): + m_service(0), + m_label(new QLabel()) { m_service = new KonachanDanbooruService(boardUrl); + m_service->setParent(this); + m_service->setMaximumAllowedRating(DanbooruPost::Explicit); m_service->setMaxPosts(1); connect(m_service, &DanbooruServiceBase::postDownloaded, this, &KonachanServiceTest::showPostData); + connect(m_service, &DanbooruServiceBase::poolDownloaded, this, &KonachanServiceTest::showPoolData); } KonachanServiceTest::~KonachanServiceTest() { delete m_service; + delete m_label; } void KonachanServiceTest::testPostService() { m_service->getPostList(); } +void KonachanServiceTest::testPoolService() { + m_service->getPoolList(); +} + void KonachanServiceTest::showPostData(DanbooruPost* post) { qDebug() << "Post File URL" << post->fileUrl().toString(); qDebug() << "Post ID" << post->id(); qDebug() << "Post tags" << post->tags(); qDebug() << "Post rating" << post->rating(); - post->pixmap().save("tmp.png"); + m_label->setPixmap(post->pixmap()); + m_label->show(); +} + +void KonachanServiceTest::showPoolData(DanbooruPool* pool) { + qDebug() << "----"; + qDebug() << "Pool ID" << pool->id(); + qDebug() << "Pool name" << pool->name(); + qDebug() << "Pool description" << pool->description(); + qDebug() << "Pool post count" << pool->postCount(); +// qDebug() << "Post IDs" << pool->posts(); + +} + +QLabel* KonachanServiceTest::previewLabel() const { + return m_label; } } // 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 ad028e4..b5b8113 100644 --- a/src/libdanbooru/tests/test_konachan.h +++ b/src/libdanbooru/tests/test_konachan.h @@ -23,10 +23,32 @@ #include "../konachan.h" #include "../servicebase.h" #include "../danboorupost.h" +#include "../danboorupool.h" #include +/* + * Copyright 2015 Luca Beltrame + * + * 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 . + */ + #include +class QLabel; + namespace Danbooru { class KonachanServiceTest: public QObject @@ -35,15 +57,19 @@ Q_OBJECT private: DanbooruServiceBase* m_service; - const QUrl boardUrl = QUrl("http://www.konachan.com"); + QLabel* m_label; public: - KonachanServiceTest(); + KonachanServiceTest(QUrl boardUrl); ~KonachanServiceTest(); void testPostService(); + void testPoolService(); + void testTagService(); + QLabel* previewLabel() const; private Q_SLOTS: void showPostData(DanbooruPost* post); + void showPoolData(DanbooruPool* pool); };