LsColXMLParser: More testing 2
authorMarkus Goetz <markus@woboq.com>
Tue, 14 Apr 2015 12:56:25 +0000 (14:56 +0200)
committerMarkus Goetz <markus@woboq.com>
Tue, 14 Apr 2015 12:56:25 +0000 (14:56 +0200)
src/libsync/networkjobs.cpp
test/testxmlparse.h

index 18837ea8b1e734303afebd42465e6c2cd2a76b8d..7e92d96c14ae969b4a9429922dc81a73698d0779 100644 (file)
@@ -363,6 +363,7 @@ bool LsColXMLParser::parse( const QByteArray& xml, QHash<QString, qint64> *sizes
     bool currentPropsHaveHttp200 = false;
     bool insidePropstat = false;
     bool insideProp = false;
+    bool insideMultiStatus = false;
 
     while (!reader.atEnd()) {
         QXmlStreamReader::TokenType type = reader.readNext();
@@ -384,6 +385,9 @@ bool LsColXMLParser::parse( const QByteArray& xml, QHash<QString, qint64> *sizes
             } else if (name == QLatin1String("prop")) {
                 insideProp = true;
                 continue;
+            } else if (name == QLatin1String("multistatus")) {
+                insideMultiStatus = true;
+                continue;
             }
         }
 
@@ -428,7 +432,10 @@ bool LsColXMLParser::parse( const QByteArray& xml, QHash<QString, qint64> *sizes
 
     if (reader.hasError()) {
         // XML Parser error? Whatever had been emitted before will come as directoryListingIterated
-        qDebug() << "ERROR" << reader.errorString();
+        qDebug() << "ERROR" << reader.errorString() << xml;
+        return false;
+    } else if (!insideMultiStatus) {
+        qDebug() << "ERROR no WebDAV response?" << xml;
         return false;
     } else {
         emit directoryListingSubfolders(folders);
index 065d5cf6de65b069164bc906da227a7e1a092b66..add06cdd8c883180b60f1136d73247dc659c17fe 100644 (file)
@@ -197,6 +197,28 @@ private slots:
         QVERIFY(_subdirs.size() == 0);
     }
 
+    void testParserEmptyXmlNoDav() {
+        const QByteArray testXml = "<html><body>I am under construction</body></html>";
+
+        LsColXMLParser parser;
+
+        connect( &parser, SIGNAL(directoryListingSubfolders(const QStringList&)),
+                 this, SLOT(slotDirectoryListingSubFolders(const QStringList&)) );
+        connect( &parser, SIGNAL(directoryListingIterated(const QString&, const QMap<QString,QString>&)),
+                 this, SLOT(slotDirectoryListingIterated(const QString&, const QMap<QString,QString>&)) );
+        connect( &parser, SIGNAL(finishedWithoutError()),
+                 this, SLOT(slotFinishedSuccessfully()) );
+
+        QHash <QString, qint64> 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 = "";