File indexing completed on 2024-03-24 16:13:26

0001 /** ===========================================================
0002  * @file
0003  *
0004  * This file is a part of KDE project
0005  * <a href="https://commits.kde.org/libmediawiki">libmediawiki</a>
0006  *
0007  * @date   2011-03-22
0008  * @brief  a MediaWiki C++ interface for KDE
0009  *
0010  * @author Copyright (C) 2010 by Alexandre Mendes
0011  *         <a href="mailto:alex dot mendes1988 at gmail dot com">alex dot mendes1988 at gmail dot com</a>
0012  * @author Copyright (C) 2010 by Ludovic Delfau
0013  *         <a href="mailto:ludovicdelfau at gmail dot com">ludovicdelfau at gmail dot com</a>
0014  *
0015  * This program is free software; you can redistribute it
0016  * and/or modify it under the terms of the GNU General
0017  * Public License as published by the Free Software Foundation;
0018  * either version 2, or (at your option)
0019  * any later version.
0020  *
0021  * This program is distributed in the hope that it will be useful,
0022  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0023  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0024  * GNU General Public License for more details.
0025  *
0026  * ============================================================ */
0027 
0028 #include <QObject>
0029 #include <QString>
0030 #include <QUrl>
0031 #include <QtTest>
0032 
0033 #include "mediawiki.h"
0034 
0035 using mediawiki::MediaWiki;
0036 
0037 class MediaWikiTest : public QObject
0038 {
0039 
0040     Q_OBJECT
0041 
0042 private Q_SLOTS:
0043 
0044     void testConstructor() {
0045         QFETCH(QUrl, url);
0046         QFETCH(QString, customUserAgent);
0047         QFETCH(QString, userAgent);
0048 
0049         MediaWiki mediawiki(url, customUserAgent);
0050 
0051         QCOMPARE(mediawiki.url(), url);
0052         QCOMPARE(mediawiki.userAgent(), userAgent);
0053     }
0054 
0055     void testConstructor_data() {
0056         QTest::addColumn<QUrl>("url");
0057         QTest::addColumn<QString>("customUserAgent");
0058         QTest::addColumn<QString>("userAgent");
0059 
0060         QTest::newRow("") << QUrl(QStringLiteral("http://127.0.0.1:12566")) << QString() << QStringLiteral("mediawiki-silk");
0061         QTest::newRow("") << QUrl(QStringLiteral("commons.wikimedia.org/w/api.php")) << QString() << QStringLiteral("mediawiki-silk");
0062         QTest::newRow("") << QUrl(QStringLiteral("http://commons.wikimedia.org/w/api.php")) << QStringLiteral("test1") << QStringLiteral("test1-mediawiki-silk");
0063         QTest::newRow("") << QUrl(QStringLiteral("http://commons.wikimedia.org/w/api.php/")) << QStringLiteral("test2") << QStringLiteral("test2-mediawiki-silk");
0064     }
0065 
0066 };
0067 
0068 QTEST_MAIN(MediaWikiTest)
0069 
0070 #include "mediawikitest.moc"