diff --git a/src/libdanbooru/CMakeLists.txt b/src/libdanbooru/CMakeLists.txt index 9b8963d..6a44f79 100644 --- a/src/libdanbooru/CMakeLists.txt +++ b/src/libdanbooru/CMakeLists.txt @@ -29,4 +29,4 @@ target_link_libraries(danbooru PUBLIC install(TARGETS danbooru ${INSTALL_TARGETS_DEFAULT_ARGS}) - +add_subdirectory(tests) diff --git a/src/libdanbooru/tests/CMakeLists.txt b/src/libdanbooru/tests/CMakeLists.txt new file mode 100644 index 0000000..895b24f --- /dev/null +++ b/src/libdanbooru/tests/CMakeLists.txt @@ -0,0 +1,14 @@ +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 + ) diff --git a/src/libdanbooru/tests/test_apis.cpp b/src/libdanbooru/tests/test_apis.cpp new file mode 100644 index 0000000..bfdf69f --- /dev/null +++ b/src/libdanbooru/tests/test_apis.cpp @@ -0,0 +1,13 @@ + +#include "test_konachan.h" + +#include +#include + +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); + app.exec(); +} diff --git a/src/libdanbooru/tests/test_connect.h b/src/libdanbooru/tests/test_connect.h new file mode 100644 index 0000000..e69de29 diff --git a/src/libdanbooru/tests/test_konachan.cpp b/src/libdanbooru/tests/test_konachan.cpp new file mode 100644 index 0000000..bb66869 --- /dev/null +++ b/src/libdanbooru/tests/test_konachan.cpp @@ -0,0 +1,48 @@ +/* + * 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 "test_konachan.h" + +namespace Danbooru { + +KonachanServiceTest::KonachanServiceTest(): + m_service(0) +{ + m_service = new KonachanDanbooruService(boardUrl); + m_service->setMaxPosts(1); + connect(m_service, &DanbooruServiceBase::postDownloaded, this, &KonachanServiceTest::showPostData); +} + +KonachanServiceTest::~KonachanServiceTest() { + delete m_service; +} + +void KonachanServiceTest::testPostService() { + m_service->getPostList(); +} + +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"); +} + +} // namespace Danbooru \ No newline at end of file diff --git a/src/libdanbooru/tests/test_konachan.h b/src/libdanbooru/tests/test_konachan.h new file mode 100644 index 0000000..ad028e4 --- /dev/null +++ b/src/libdanbooru/tests/test_konachan.h @@ -0,0 +1,54 @@ +/* + * 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 . + */ + +#ifndef DANBOORU_TEST_CONNECT_H_ +#define DANBOORU_TEST_CONNECT_H_ + +#include "../konachan.h" +#include "../servicebase.h" +#include "../danboorupost.h" + +#include +#include + +namespace Danbooru { + +class KonachanServiceTest: public QObject +{ +Q_OBJECT + +private: + DanbooruServiceBase* m_service; + const QUrl boardUrl = QUrl("http://www.konachan.com"); +public: + KonachanServiceTest(); + ~KonachanServiceTest(); + + void testPostService(); + +private Q_SLOTS: + void showPostData(DanbooruPost* post); + +}; + +} + + + +#endif \ No newline at end of file