From c9e79561ae1a2baf302515a6c755410deffde851 Mon Sep 17 00:00:00 2001 From: Luca Beltrame Date: Tue, 25 Aug 2015 16:49:15 +0200 Subject: [PATCH] Add proper tests to support Konachan posts Danbooru posts are up next. --- src/libdanbooru/autotests/CMakeLists.txt | 10 ++++ src/libdanbooru/autotests/konachan.json | 1 + .../autotests/test_danbooru_post.cpp | 50 +++++++++++++++++++ .../autotests/test_danbooru_post.h | 44 ++++++++++++++++ 4 files changed, 105 insertions(+) create mode 100644 src/libdanbooru/autotests/CMakeLists.txt create mode 100644 src/libdanbooru/autotests/konachan.json diff --git a/src/libdanbooru/autotests/CMakeLists.txt b/src/libdanbooru/autotests/CMakeLists.txt new file mode 100644 index 0000000..9514d50 --- /dev/null +++ b/src/libdanbooru/autotests/CMakeLists.txt @@ -0,0 +1,10 @@ +include(ECMAddTests) + +ecm_add_test(test_danbooru_post.cpp LINK_LIBRARIES + Qt5::Widgets + Qt5::Test + Qt5::Core + danbooru + TEST_NAME test_danbooru_post) + +configure_file(konachan.json konachan.json COPYONLY) \ No newline at end of file diff --git a/src/libdanbooru/autotests/konachan.json b/src/libdanbooru/autotests/konachan.json new file mode 100644 index 0000000..c97dc6f --- /dev/null +++ b/src/libdanbooru/autotests/konachan.json @@ -0,0 +1 @@ +[{"id":205621,"tags":"azuki_(sayori) coconut_(sayori) game_cg nekopara sayori","created_at":1440435510,"creator_id":121572,"author":"ffbros","change":906550,"source":"","score":0,"md5":"eb36c568af4f4e4ea2f59eda7d8c802d","file_size":885610,"file_url":"http://konachan.net/image/eb36c568af4f4e4ea2f59eda7d8c802d/Konachan.com%20-%20205621%20azuki_%28sayori%29%20coconut_%28sayori%29%20game_cg%20nekopara%20sayori.png","is_shown_in_index":true,"preview_url":"http://konachan.net/data/preview/eb/36/eb36c568af4f4e4ea2f59eda7d8c802d.jpg","preview_width":150,"preview_height":84,"actual_preview_width":300,"actual_preview_height":169,"sample_url":"http://konachan.net/jpeg/eb36c568af4f4e4ea2f59eda7d8c802d/Konachan.com%20-%20205621%20azuki_%28sayori%29%20coconut_%28sayori%29%20game_cg%20nekopara%20sayori.jpg","sample_width":1280,"sample_height":720,"sample_file_size":0,"jpeg_url":"http://konachan.net/jpeg/eb36c568af4f4e4ea2f59eda7d8c802d/Konachan.com%20-%20205621%20azuki_%28sayori%29%20coconut_%28sayori%29%20game_cg%20nekopara%20sayori.jpg","jpeg_width":1280,"jpeg_height":720,"jpeg_file_size":311321,"rating":"s","has_children":false,"parent_id":205617,"status":"pending","width":1280,"height":720,"is_held":false,"frames_pending_string":"","frames_pending":[],"frames_string":"","frames":[],"flag_detail":null}] \ No newline at end of file diff --git a/src/libdanbooru/autotests/test_danbooru_post.cpp b/src/libdanbooru/autotests/test_danbooru_post.cpp index 8b13789..c96bb16 100644 --- a/src/libdanbooru/autotests/test_danbooru_post.cpp +++ b/src/libdanbooru/autotests/test_danbooru_post.cpp @@ -1 +1,51 @@ +/* + * 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_danbooru_post.h" +#include "../danboorupost.h" +#include "../utils.h" + +#include +#include +#include + +void TestDanbooruPost::initTestCase() +{ + QFile file; + file.setFileName(m_fileName); + file.open(QIODevice::ReadOnly | QIODevice::Text); + bool ok; + m_data = Danbooru::parseDanbooruResult(file.readAll(), &ok).toList().at(0).toMap(); +} + +void TestDanbooruPost::testPostLoading() +{ + m_post = new Danbooru::DanbooruPost(m_data); + QCOMPARE(m_post->fileUrl(), + QUrl("http://konachan.net/image/eb36c568af4f4e4ea2f59eda7d8c802d/Konachan.com%20-%20205621%20azuki_%28sayori%29%20coconut_%28sayori%29%20game_cg%20nekopara%20sayori.png")); + QCOMPARE(m_post->thumbnailUrl(), + QUrl("http://konachan.net/data/preview/eb/36/eb36c568af4f4e4ea2f59eda7d8c802d.jpg")); + QCOMPARE(m_post->id(), 205621); + QCOMPARE(m_post->width(), 1280); + QCOMPARE(m_post->height(), 720); +} + +QTEST_MAIN(TestDanbooruPost) diff --git a/src/libdanbooru/autotests/test_danbooru_post.h b/src/libdanbooru/autotests/test_danbooru_post.h index 8b13789..83e7dfa 100644 --- a/src/libdanbooru/autotests/test_danbooru_post.h +++ b/src/libdanbooru/autotests/test_danbooru_post.h @@ -1 +1,45 @@ +/* + * 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_POST_H +#define DANBOORU_TEST_POST_H + +#include + +namespace Danbooru { + class DanbooruPost; +} + +class TestDanbooruPost: public QObject +{ +Q_OBJECT + +private: + QLatin1String m_fileName = QLatin1String("konachan.json"); + Danbooru::DanbooruPost* m_post = nullptr; + QVariantMap m_data; + +private Q_SLOTS: + void initTestCase(); + void testPostLoading(); + +}; + + +#endif