From d2bae21b14f1c8f1ed5c83904038d4d4cb6507e6 Mon Sep 17 00:00:00 2001 From: Klaas Freitag Date: Tue, 14 Apr 2015 08:37:06 +0200 Subject: [PATCH] Added unit test for XML Parser class. --- test/CMakeLists.txt | 2 +- test/testxmlparse.h | 125 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 test/testxmlparse.h diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 62acf37c8..f1d44061b 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -32,5 +32,5 @@ owncloud_add_test(SyncJournalDB "") owncloud_add_test(SyncFileItem "") owncloud_add_test(ConcatUrl "") - +owncloud_add_test(XmlParse "") diff --git a/test/testxmlparse.h b/test/testxmlparse.h new file mode 100644 index 000000000..78f2db0a3 --- /dev/null +++ b/test/testxmlparse.h @@ -0,0 +1,125 @@ +/* + * This software is in the public domain, furnished "as is", without technical + * support, and with no warranty, express or implied, as to its usefulness for + * any purpose. + * */ + +#ifndef MIRALL_TESTXMLPARSE_H +#define MIRALL_TESTXMLPARSE_H + +#include + +#include "networkjobs.h" + +using namespace OCC; + +class TestXmlParse : public QObject +{ + Q_OBJECT + +private: + bool _success; + QStringList _subdirs; + QStringList _items; + +private slots: + void initTestCase() { + _success = false; + } + + void cleanupTestCase() { + } + + void slotDirectoryListingSubFolders(const QStringList& list) + { + qDebug() << "subfolders: " << list; + _subdirs.append(list); + } + + void slotDirectoryListingIterated(const QString& item, const QMap& ) + { + qDebug() << " item: " << item; + _items.append(item); + } + + void slotFinishedSuccessfully() + { + _success = true; + } + + void testParser1() { + const QByteArray testXml = "" + "" + "" + "/oc/remote.php/webdav/sharefolder/" + "" + "" + "00004213ocobzus5kn6s" + "RDNVCK" + "121780" + "\"5527beb0400b0\"" + "" + "" + "" + "Fri, 06 Feb 2015 13:49:55 GMT" + "" + "HTTP/1.1 200 OK" + "" + "" + "" + "" + "" + "" + "" + "HTTP/1.1 404 Not Found" + "" + "" + "" + "/oc/remote.php/webdav/sharefolder/quitte.pdf" + "" + "" + "00004215ocobzus5kn6s" + "RDNVW" + "\"2fa2f0d9ed49ea0c3e409d49e652dea0\"" + "" + "Fri, 06 Feb 2015 13:49:55 GMT" + "121780" + "" + "HTTP/1.1 200 OK" + "" + "" + "" + "" + "" + "" + "HTTP/1.1 404 Not Found" + "" + "" + ""; + + + LsColXMLParser parser; + + connect( &parser, SIGNAL(directoryListingSubfolders(const QStringList&)), + this, SLOT(slotDirectoryListingSubFolders(const QStringList&)) ); + connect( &parser, SIGNAL(directoryListingIterated(const QString&, const QMap&)), + this, SLOT(slotDirectoryListingIterated(const QString&, const QMap&)) ); + connect( &parser, SIGNAL(finishedWithoutError()), + this, SLOT(slotFinishedSuccessfully()) ); + + QHash sizes; + parser.parse( testXml, &sizes ); + + QVERIFY(_success); + QVERIFY(sizes.size() == 0 ); // No quota info in the XML + + QVERIFY(_items.contains("/oc/remote.php/webdav/sharefolder/quitte.pdf")); + QVERIFY(_items.contains("/oc/remote.php/webdav/sharefolder")); + QVERIFY(_items.size() == 2 ); + + QVERIFY(_subdirs.contains("/oc/remote.php/webdav/sharefolder/")); + QVERIFY(_subdirs.size() == 1); + } +}; + +#endif -- 2.30.2