Add proper tests to support Konachan posts

Danbooru posts are up next.
This commit is contained in:
Luca Beltrame 2015-08-25 16:49:15 +02:00
parent 229e648d93
commit c9e79561ae
4 changed files with 105 additions and 0 deletions

View file

@ -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)

View file

@ -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}]

View file

@ -1 +1,51 @@
/*
* 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 "test_danbooru_post.h"
#include "../danboorupost.h"
#include "../utils.h"
#include <QFile>
#include <QJsonDocument>
#include <QJsonObject>
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)

View file

@ -1 +1,45 @@
/*
* 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/>.
*/
#ifndef DANBOORU_TEST_POST_H
#define DANBOORU_TEST_POST_H
#include <QTest>
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