Build test application for Konachan API
This commit is contained in:
parent
7caa2d6956
commit
c5b8fccc6f
4 changed files with 114 additions and 18 deletions
|
@ -1,14 +1,13 @@
|
||||||
|
include(ECMAddTests)
|
||||||
|
|
||||||
set (test_SRCS
|
set (test_SRCS
|
||||||
test_konachan.cpp
|
test_konachan.cpp
|
||||||
test_apis.cpp)
|
test_apis.cpp)
|
||||||
|
|
||||||
add_executable(test_service
|
ecm_add_test(${test_SRCS} LINK_LIBRARIES
|
||||||
${test_SRCS}
|
Qt5::Widgets
|
||||||
)
|
Qt5::Core
|
||||||
target_link_libraries(test_service PRIVATE
|
KF5::KIOCore
|
||||||
Qt5::Widgets
|
KF5::GuiAddons
|
||||||
Qt5::Core
|
danbooru
|
||||||
KF5::KIOCore
|
TEST_NAME test_konachan_api)
|
||||||
KF5::GuiAddons
|
|
||||||
danbooru
|
|
||||||
)
|
|
||||||
|
|
|
@ -3,11 +3,56 @@
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
#include <QCommandLineParser>
|
||||||
|
|
||||||
|
void runKonachanTest();
|
||||||
|
void runYandeReTest();
|
||||||
|
void runDanbooruTest();
|
||||||
|
|
||||||
|
Danbooru::KonachanServiceTest* testSvc = 0;
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
qDebug() << "Starting Konachan API test";
|
|
||||||
Danbooru::KonachanServiceTest* testSvc = new Danbooru::KonachanServiceTest();
|
QCommandLineParser cmdParser;
|
||||||
QTimer::singleShot(2000, testSvc, &Danbooru::KonachanServiceTest::testPostService);
|
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();
|
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();
|
||||||
|
}
|
||||||
|
|
|
@ -19,30 +19,56 @@
|
||||||
|
|
||||||
#include "test_konachan.h"
|
#include "test_konachan.h"
|
||||||
|
|
||||||
|
#include <QLabel>
|
||||||
|
|
||||||
namespace Danbooru {
|
namespace Danbooru {
|
||||||
|
|
||||||
KonachanServiceTest::KonachanServiceTest():
|
KonachanServiceTest::KonachanServiceTest(QUrl boardUrl):
|
||||||
m_service(0)
|
m_service(0),
|
||||||
|
m_label(new QLabel())
|
||||||
{
|
{
|
||||||
m_service = new KonachanDanbooruService(boardUrl);
|
m_service = new KonachanDanbooruService(boardUrl);
|
||||||
|
m_service->setParent(this);
|
||||||
|
m_service->setMaximumAllowedRating(DanbooruPost::Explicit);
|
||||||
m_service->setMaxPosts(1);
|
m_service->setMaxPosts(1);
|
||||||
connect(m_service, &DanbooruServiceBase::postDownloaded, this, &KonachanServiceTest::showPostData);
|
connect(m_service, &DanbooruServiceBase::postDownloaded, this, &KonachanServiceTest::showPostData);
|
||||||
|
connect(m_service, &DanbooruServiceBase::poolDownloaded, this, &KonachanServiceTest::showPoolData);
|
||||||
}
|
}
|
||||||
|
|
||||||
KonachanServiceTest::~KonachanServiceTest() {
|
KonachanServiceTest::~KonachanServiceTest() {
|
||||||
delete m_service;
|
delete m_service;
|
||||||
|
delete m_label;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KonachanServiceTest::testPostService() {
|
void KonachanServiceTest::testPostService() {
|
||||||
m_service->getPostList();
|
m_service->getPostList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void KonachanServiceTest::testPoolService() {
|
||||||
|
m_service->getPoolList();
|
||||||
|
}
|
||||||
|
|
||||||
void KonachanServiceTest::showPostData(DanbooruPost* post) {
|
void KonachanServiceTest::showPostData(DanbooruPost* post) {
|
||||||
qDebug() << "Post File URL" << post->fileUrl().toString();
|
qDebug() << "Post File URL" << post->fileUrl().toString();
|
||||||
qDebug() << "Post ID" << post->id();
|
qDebug() << "Post ID" << post->id();
|
||||||
qDebug() << "Post tags" << post->tags();
|
qDebug() << "Post tags" << post->tags();
|
||||||
qDebug() << "Post rating" << post->rating();
|
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
|
} // namespace Danbooru
|
|
@ -23,10 +23,32 @@
|
||||||
#include "../konachan.h"
|
#include "../konachan.h"
|
||||||
#include "../servicebase.h"
|
#include "../servicebase.h"
|
||||||
#include "../danboorupost.h"
|
#include "../danboorupost.h"
|
||||||
|
#include "../danboorupool.h"
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
/*
|
||||||
|
* Copyright 2015 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 <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
|
class QLabel;
|
||||||
|
|
||||||
namespace Danbooru {
|
namespace Danbooru {
|
||||||
|
|
||||||
class KonachanServiceTest: public QObject
|
class KonachanServiceTest: public QObject
|
||||||
|
@ -35,15 +57,19 @@ Q_OBJECT
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DanbooruServiceBase* m_service;
|
DanbooruServiceBase* m_service;
|
||||||
const QUrl boardUrl = QUrl("http://www.konachan.com");
|
QLabel* m_label;
|
||||||
public:
|
public:
|
||||||
KonachanServiceTest();
|
KonachanServiceTest(QUrl boardUrl);
|
||||||
~KonachanServiceTest();
|
~KonachanServiceTest();
|
||||||
|
|
||||||
void testPostService();
|
void testPostService();
|
||||||
|
void testPoolService();
|
||||||
|
void testTagService();
|
||||||
|
QLabel* previewLabel() const;
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void showPostData(DanbooruPost* post);
|
void showPostData(DanbooruPost* post);
|
||||||
|
void showPoolData(DanbooruPool* pool);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue