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
 | 
			
		||||
     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)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,11 +3,56 @@
 | 
			
		|||
 | 
			
		||||
#include <QApplication>
 | 
			
		||||
#include <QTimer>
 | 
			
		||||
#include <QCommandLineParser>
 | 
			
		||||
 | 
			
		||||
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();
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -19,30 +19,56 @@
 | 
			
		|||
 | 
			
		||||
#include "test_konachan.h"
 | 
			
		||||
 | 
			
		||||
#include <QLabel>
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
| 
						 | 
				
			
			@ -23,10 +23,32 @@
 | 
			
		|||
#include "../konachan.h"
 | 
			
		||||
#include "../servicebase.h"
 | 
			
		||||
#include "../danboorupost.h"
 | 
			
		||||
#include "../danboorupool.h"
 | 
			
		||||
 | 
			
		||||
#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>
 | 
			
		||||
 | 
			
		||||
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);
 | 
			
		||||
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue