[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kio] autotests: Add unit test for KIO::AccessManager
From: Aleix Pol <aleixpol () kde ! org>
Date: 2015-04-20 15:23:26
Message-ID: E1YkDXi-0007ye-91 () scm ! kde ! org
[Download RAW message or body]
Git commit 1c1501b5d98e30a42b4052d011dbce5a645b7545 by Aleix Pol.
Committed on 20/04/2015 at 15:22.
Pushed by apol into branch 'master'.
Add unit test for KIO::AccessManager
I was having some weird behavior I wanted to test, having a test was a
minimum.
REVIEW: 123436
M +1 -0 autotests/CMakeLists.txt
A +80 -0 autotests/accessmanagertest.cpp [License: LGPL (v2/3+eV)]
http://commits.kde.org/kio/1c1501b5d98e30a42b4052d011dbce5a645b7545
diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt
index 0a9fcea..7bba3ea 100644
--- a/autotests/CMakeLists.txt
+++ b/autotests/CMakeLists.txt
@@ -60,6 +60,7 @@ ecm_add_tests(
kurlrequestertest.cpp
jobguitest.cpp
pastetest.cpp
+ accessmanagertest.cpp
NAME_PREFIX "kiowidgets-"
LINK_LIBRARIES KF5::KIOCore KF5::KIOWidgets Qt5::Test
)
diff --git a/autotests/accessmanagertest.cpp b/autotests/accessmanagertest.cpp
new file mode 100644
index 0000000..029267c
--- /dev/null
+++ b/autotests/accessmanagertest.cpp
@@ -0,0 +1,80 @@
+/* This file is part of the KDE libraries
+ Copyright (c) 2015 Aleix Pol Gonzalez <aleixpol@kde.org>
+
+ This library is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2 of the License or ( at
+ your option ) version 3 or, at the discretion of KDE e.V. ( which shall
+ act as a proxy as in section 14 of the GPLv3 ), any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <QtTest/QtTest>
+#include <accessmanager.h>
+#include <QNetworkReply>
+
+/**
+ * Unit test for AccessManager
+ */
+class AccessManagerTest : public QObject
+{
+Q_OBJECT
+public:
+ AccessManagerTest() : m_manager(0) {}
+
+private Q_SLOTS:
+ void initTestCase()
+ {
+ qputenv("KDE_FORK_SLAVES", "yes"); // To avoid a runtime dependency on \
klauncher + qputenv("KIOSLAVE_ENABLE_TESTMODE", "1"); // ensure the ioslaves \
call QStandardPaths::setTestModeEnabled too + \
QStandardPaths::setTestModeEnabled(true); + }
+
+ void testGet()
+ {
+ const QString aFile = QFINDTESTDATA("accessmanagertest.cpp");
+ QNetworkReply* reply = \
m_manager.get(QNetworkRequest(QUrl::fromLocalFile(aFile))); + QSignalSpy \
spy(reply, &QNetworkReply::finished); + QVERIFY(spy.wait());
+
+ QFile f(aFile);
+ QVERIFY(f.open(QIODevice::ReadOnly));
+ QCOMPARE(f.readAll(), reply->readAll());
+ }
+
+ void testPut()
+ {
+ const QString aDir = \
QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); + \
QVERIFY(QDir::temp().mkpath(aDir)); + const QString aFile = aDir + \
QStringLiteral("/accessmanagertest-data"); + const QByteArray content = "We \
love free software!"; +
+ QFile::remove(aFile);
+
+ QNetworkReply* reply = \
m_manager.put(QNetworkRequest(QUrl::fromLocalFile(aFile)), content); + \
QSignalSpy spy(reply, &QNetworkReply::finished); + QVERIFY(spy.wait());
+
+ QVERIFY(QFile::exists(aFile));
+ QFile f(aFile);
+ QVERIFY(f.open(QIODevice::ReadOnly));
+ QCOMPARE(f.readAll(), content);
+ }
+
+private:
+ KIO::AccessManager m_manager;
+// QNetworkAccessManager m_manager;
+};
+
+QTEST_MAIN(AccessManagerTest)
+
+#include "accessmanagertest.moc"
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic