From: Markus Goetz Date: Tue, 14 Apr 2015 12:41:48 +0000 (+0200) Subject: LsColXMLParser: More testing X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~1803^2~193 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=2074bdbb195b36d14db600734ffa7f86b478dc29;p=nextcloud-desktop.git LsColXMLParser: More testing --- diff --git a/test/testxmlparse.h b/test/testxmlparse.h index 4e871902c..065d5cf6d 100644 --- a/test/testxmlparse.h +++ b/test/testxmlparse.h @@ -22,30 +22,35 @@ private: QStringList _subdirs; QStringList _items; +public slots: + 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; + } + private slots: - void initTestCase() { + void init() { + qDebug() << Q_FUNC_INFO; _success = false; + _subdirs.clear(); + _items.clear(); } - void cleanupTestCase() { - } - - void slotDirectoryListingSubFolders(const QStringList& list) - { - qDebug() << "subfolders: " << list; - _subdirs.append(list); + void cleanup() { } - void slotDirectoryListingIterated(const QString& item, const QMap& ) - { - qDebug() << " item: " << item; - _items.append(item); - } - - void slotFinishedSuccessfully() - { - _success = true; - } void testParser1() { const QByteArray testXml = "" @@ -120,6 +125,99 @@ private slots: QVERIFY(_subdirs.contains("/oc/remote.php/webdav/sharefolder/")); QVERIFY(_subdirs.size() == 1); } + + void testParserBrokenXml() { + const QByteArray testXml = "X" + "" + "" + "/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; + QVERIFY(false == parser.parse( testXml, &sizes )); // verify false + + QVERIFY(!_success); + QVERIFY(sizes.size() == 0 ); // No quota info in the XML + + QVERIFY(_items.size() == 0 ); // FIXME: We should change the parser to not emit during parsing but at the end + + QVERIFY(_subdirs.size() == 0); + } + + void testParserEmptyXml() { + const QByteArray testXml = ""; + + 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; + QVERIFY(false == parser.parse( testXml, &sizes )); // verify false + + QVERIFY(!_success); + QVERIFY(sizes.size() == 0 ); // No quota info in the XML + + QVERIFY(_items.size() == 0 ); // FIXME: We should change the parser to not emit during parsing but at the end + QVERIFY(_subdirs.size() == 0); + } }; #endif