[SCM] kdeconnect packaging branch, master, updated. debian/0.9g-1-1183-g9d69498
Maximiliano Curia
maxy at moszumanska.debian.org
Fri Oct 14 14:27:29 UTC 2016
Gitweb-URL: http://git.debian.org/?p=pkg-kde/kde-extras/kdeconnect.git;a=commitdiff;h=71d339a
The following commit has been merged in the master branch:
commit 71d339adeaf30fe8f68c3aed89dc8fb991d8663b
Author: Àlex Fiestas <afiestas at kde.org>
Date: Fri Mar 7 00:36:49 2014 +0100
Added autotest for SocketLineReader
I want to re-write this class, so before I can do that I must
make sure that I don't break existing behavior.
The test basically sends 5 lines and then checks that those 5 lines
have been correctly identified.
---
kded/CMakeLists.txt | 1 +
kded/autotests/CMakeLists.txt | 5 ++
kded/autotests/testsocketlinereader.cpp | 116 ++++++++++++++++++++++++++++++++
3 files changed, 122 insertions(+)
diff --git a/kded/CMakeLists.txt b/kded/CMakeLists.txt
index e2dcb21..ec1c968 100644
--- a/kded/CMakeLists.txt
+++ b/kded/CMakeLists.txt
@@ -1,4 +1,5 @@
add_subdirectory(plugins)
+add_subdirectory(autotests)
find_package (QJSON 0.8.1 REQUIRED)
find_package (QCA2 REQUIRED)
diff --git a/kded/autotests/CMakeLists.txt b/kded/autotests/CMakeLists.txt
new file mode 100644
index 0000000..1495c6a
--- /dev/null
+++ b/kded/autotests/CMakeLists.txt
@@ -0,0 +1,5 @@
+set(_testname testsocketlinereader)
+qt4_generate_moc(${_testname}.cpp ${CMAKE_CURRENT_BINARY_DIR}/${_testname}.moc)
+include_directories(${QT_INCLUDES} ${KDE4_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR})
+kde4_add_unit_test(${_testname} ${_testname}.cpp ${_testname}.moc ../backends/lan/socketlinereader.cpp ../kdebugnamespace.cpp)
+target_link_libraries(${_testname} ${KDE4_KDECORE_LIBS} ${QT_QTTEST_LIBRARY} ${QT_QTCORE_LIBRARY} ${QT_QTNETWORK_LIBRARY})
\ No newline at end of file
diff --git a/kded/autotests/testsocketlinereader.cpp b/kded/autotests/testsocketlinereader.cpp
new file mode 100644
index 0000000..92a084d
--- /dev/null
+++ b/kded/autotests/testsocketlinereader.cpp
@@ -0,0 +1,116 @@
+/*************************************************************************************
+ * Copyright (C) 2014 by Alejandro Fiestas Olivares <afiestas at 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.1 of the License, or (at your option) 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 *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this library; if not, write to the Free Software *
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
+ *************************************************************************************/
+
+#include "../backends/lan/socketlinereader.h"
+
+#include <QTest>
+#include <QTcpServer>
+#include <QTcpSocket>
+#include <QProcess>
+#include <QEventLoop>
+#include <QTimer>
+#include <unistd.h>
+
+class TestSocketLineReader : public QObject
+{
+ Q_OBJECT
+public Q_SLOTS:
+ void initTestCase();
+ void newPackage();
+
+private Q_SLOTS:
+ void socketLineReader();
+
+private:
+ QTimer mTimer;
+ QEventLoop mLoop;
+ QList<QByteArray> mPackages;
+ QTcpServer *mServer;
+ QTcpSocket *mConn;
+ SocketLineReader *mReader;
+};
+
+void TestSocketLineReader::initTestCase()
+{
+ mServer = new QTcpServer(this);
+ QVERIFY2(mServer->listen(QHostAddress::LocalHost, 8694), "Failed to create local tcp server");
+
+ mTimer.setInterval(4000);//For second is more enough to send some data via local socket
+ mTimer.setSingleShot(true);
+ connect(&mTimer, SIGNAL(timeout()), &mLoop, SLOT(quit()));
+
+ mConn = new QTcpSocket(this);
+ mConn->connectToHost(QHostAddress::LocalHost, 8694);
+ connect(mConn, SIGNAL(connected()), &mLoop, SLOT(quit()));
+ mTimer.start();
+ mLoop.exec();
+
+ QVERIFY2(mConn->isOpen(), "Could not connect to local tcp server");
+}
+
+void TestSocketLineReader::socketLineReader()
+{
+ QList<QByteArray> dataToSend;
+ dataToSend << "foobar
" << "barfoo
" << "foobar?
" << "barfoo!
" << "panda
";
+ Q_FOREACH(const QByteArray &line, dataToSend) {
+ mConn->write(line);
+ }
+ mConn->flush();
+
+ int maxAttemps = 5;
+ while(!mServer->hasPendingConnections() && maxAttemps > 0) {
+ --maxAttemps;
+ QTest::qSleep(1000);
+ }
+
+ QTcpSocket *sock = mServer->nextPendingConnection();
+ mReader = new SocketLineReader(sock, this);
+ connect(mReader, SIGNAL(readyRead()), SLOT(newPackage()));
+ mTimer.start();
+ mLoop.exec();
+
+ QCOMPARE(mPackages.count(), 5);//We expect 5 Packages
+ for(int x = 0;x < 5; ++x) {
+ QCOMPARE(mPackages[x], dataToSend[x]);
+ }
+}
+
+void TestSocketLineReader::newPackage()
+{
+ if (!mReader->bytesAvailable()) {
+ return;
+ }
+
+ int maxLoops = 5;
+ while(mReader->bytesAvailable() > 0 && maxLoops > 0) {
+ --maxLoops;
+ const QByteArray package = mReader->readLine();
+ if (!package.isEmpty()) {
+ mPackages.append(package);
+ }
+
+ if (mPackages.count() == 5) {
+ mLoop.exit();
+ }
+ }
+}
+
+
+QTEST_MAIN(TestSocketLineReader)
+
+#include "testsocketlinereader.moc"
\ No newline at end of file
--
kdeconnect packaging
More information about the pkg-kde-commits
mailing list