/* * 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. * */ #include #include "networkjobs.h" #include "logger.h" using namespace OCC; class TestXmlParse : public QObject { Q_OBJECT private: bool _success = false; 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() { OCC::Logger::instance()->setLogFlush(true); OCC::Logger::instance()->setLogDebug(true); QStandardPaths::setTestModeEnabled(true); } void init() { qDebug() << Q_FUNC_INFO; _success = false; _subdirs.clear(); _items.clear(); } void cleanup() { } void testParser1() { const QByteArray testXml = "" "" "" "/oc/remote.php/dav/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/dav/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, &LsColXMLParser::directoryListingSubfolders, this, &TestXmlParse::slotDirectoryListingSubFolders ); connect( &parser, &LsColXMLParser::directoryListingIterated, this, &TestXmlParse::slotDirectoryListingIterated ); connect( &parser, &LsColXMLParser::finishedWithoutError, this, &TestXmlParse::slotFinishedSuccessfully ); QHash sizes; QVERIFY(parser.parse( testXml, &sizes, "/oc/remote.php/dav/sharefolder" )); QVERIFY(_success); QCOMPARE(sizes.size(), 1 ); // Quota info in the XML QVERIFY(_items.contains("/oc/remote.php/dav/sharefolder/quitte.pdf")); QVERIFY(_items.contains("/oc/remote.php/dav/sharefolder")); QVERIFY(_items.size() == 2 ); QVERIFY(_subdirs.contains("/oc/remote.php/dav/sharefolder/")); QVERIFY(_subdirs.size() == 1); } void testParserBrokenXml() { const QByteArray testXml = "X" "" "" "/oc/remote.php/dav/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/dav/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, &LsColXMLParser::directoryListingSubfolders, this, &TestXmlParse::slotDirectoryListingSubFolders ); connect( &parser, &LsColXMLParser::directoryListingIterated, this, &TestXmlParse::slotDirectoryListingIterated ); connect( &parser, &LsColXMLParser::finishedWithoutError, this, &TestXmlParse::slotFinishedSuccessfully ); QHash sizes; QVERIFY(false == parser.parse( testXml, &sizes, "/oc/remote.php/dav/sharefolder" )); // 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 testParserEmptyXmlNoDav() { const QByteArray testXml = "I am under construction"; LsColXMLParser parser; connect( &parser, &LsColXMLParser::directoryListingSubfolders, this, &TestXmlParse::slotDirectoryListingSubFolders ); connect( &parser, &LsColXMLParser::directoryListingIterated, this, &TestXmlParse::slotDirectoryListingIterated ); connect( &parser, &LsColXMLParser::finishedWithoutError, this, &TestXmlParse::slotFinishedSuccessfully ); QHash sizes; QVERIFY(false == parser.parse( testXml, &sizes, "/oc/remote.php/dav/sharefolder" )); // 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, &LsColXMLParser::directoryListingSubfolders, this, &TestXmlParse::slotDirectoryListingSubFolders ); connect( &parser, &LsColXMLParser::directoryListingIterated, this, &TestXmlParse::slotDirectoryListingIterated ); connect( &parser, &LsColXMLParser::finishedWithoutError, this, &TestXmlParse::slotFinishedSuccessfully ); QHash sizes; QVERIFY(false == parser.parse( testXml, &sizes, "/oc/remote.php/dav/sharefolder" )); // 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 testParserTruncatedXml() { const QByteArray testXml = "" "" "" "/oc/remote.php/dav/sharefolder/" "" "" "00004213ocobzus5kn6s" "RDNVCK" "121780" "\"5527beb0400b0\"" "" "" "" "Fri, 06 Feb 2015 13:49:55 GMT" "" "HTTP/1.1 200 OK" ""; // no proper end here LsColXMLParser parser; connect( &parser, &LsColXMLParser::directoryListingSubfolders, this, &TestXmlParse::slotDirectoryListingSubFolders ); connect( &parser, &LsColXMLParser::directoryListingIterated, this, &TestXmlParse::slotDirectoryListingIterated ); connect( &parser, &LsColXMLParser::finishedWithoutError, this, &TestXmlParse::slotFinishedSuccessfully ); QHash sizes; QVERIFY(!parser.parse( testXml, &sizes, "/oc/remote.php/dav/sharefolder" )); QVERIFY(!_success); } void testParserBogfusHref1() { const QByteArray testXml = "" "" "" "http://127.0.0.1:81/oc/remote.php/dav/sharefolder/" "" "" "00004213ocobzus5kn6s" "RDNVCK" "121780" "\"5527beb0400b0\"" "" "" "" "Fri, 06 Feb 2015 13:49:55 GMT" "" "HTTP/1.1 200 OK" "" "" "" "" "" "" "" "HTTP/1.1 404 Not Found" "" "" "" "http://127.0.0.1:81/oc/remote.php/dav/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, &LsColXMLParser::directoryListingSubfolders, this, &TestXmlParse::slotDirectoryListingSubFolders ); connect( &parser, &LsColXMLParser::directoryListingIterated, this, &TestXmlParse::slotDirectoryListingIterated ); connect( &parser, &LsColXMLParser::finishedWithoutError, this, &TestXmlParse::slotFinishedSuccessfully ); QHash sizes; QVERIFY(false == parser.parse( testXml, &sizes, "/oc/remote.php/dav/sharefolder" )); QVERIFY(!_success); } void testParserBogfusHref2() { const QByteArray testXml = "" "" "" "/sharefolder" "" "" "00004213ocobzus5kn6s" "RDNVCK" "121780" "\"5527beb0400b0\"" "" "" "" "Fri, 06 Feb 2015 13:49:55 GMT" "" "HTTP/1.1 200 OK" "" "" "" "" "" "" "" "HTTP/1.1 404 Not Found" "" "" "" "/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, &LsColXMLParser::directoryListingSubfolders, this, &TestXmlParse::slotDirectoryListingSubFolders ); connect( &parser, &LsColXMLParser::directoryListingIterated, this, &TestXmlParse::slotDirectoryListingIterated ); connect( &parser, &LsColXMLParser::finishedWithoutError, this, &TestXmlParse::slotFinishedSuccessfully ); QHash sizes; QVERIFY(false == parser.parse( testXml, &sizes, "/oc/remote.php/dav/sharefolder" )); QVERIFY(!_success); } void testParserDenormalizedPath() { const QByteArray testXml = "" "" "" "/oc/remote.php/dav/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/dav/sharefolder/../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, &LsColXMLParser::directoryListingSubfolders, this, &TestXmlParse::slotDirectoryListingSubFolders ); connect( &parser, &LsColXMLParser::directoryListingIterated, this, &TestXmlParse::slotDirectoryListingIterated ); connect( &parser, &LsColXMLParser::finishedWithoutError, this, &TestXmlParse::slotFinishedSuccessfully ); QHash sizes; QVERIFY(parser.parse( testXml, &sizes, "/oc/remote.php/dav/sharefolder" )); QVERIFY(_success); QCOMPARE(sizes.size(), 1 ); // Quota info in the XML QVERIFY(_items.contains("/oc/remote.php/dav/sharefolder/quitte.pdf")); QVERIFY(_items.contains("/oc/remote.php/dav/sharefolder")); QVERIFY(_items.size() == 2 ); QVERIFY(_subdirs.contains("/oc/remote.php/dav/sharefolder/")); QVERIFY(_subdirs.size() == 1); } void testParserDenormalizedPathOutsideNamespace() { const QByteArray testXml = "" "" "" "/oc/remote.php/dav/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/dav/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, &LsColXMLParser::directoryListingSubfolders, this, &TestXmlParse::slotDirectoryListingSubFolders ); connect( &parser, &LsColXMLParser::directoryListingIterated, this, &TestXmlParse::slotDirectoryListingIterated ); connect( &parser, &LsColXMLParser::finishedWithoutError, this, &TestXmlParse::slotFinishedSuccessfully ); QHash sizes; QVERIFY(!parser.parse( testXml, &sizes, "/oc/remote.php/dav/sharefolder" )); QVERIFY(!_success); } void testHrefUrlEncoding() { const QByteArray testXml = "" "" "" "/%C3%A4" // a-umlaut utf8 "" "" "00004213ocobzus5kn6s" "RDNVCK" "121780" "\"5527beb0400b0\"" "" "" "" "Fri, 06 Feb 2015 13:49:55 GMT" "" "HTTP/1.1 200 OK" "" "" "" "" "" "" "" "HTTP/1.1 404 Not Found" "" "" "" "/%C3%A4/%C3%A4.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, &LsColXMLParser::directoryListingSubfolders, this, &TestXmlParse::slotDirectoryListingSubFolders ); connect( &parser, &LsColXMLParser::directoryListingIterated, this, &TestXmlParse::slotDirectoryListingIterated ); connect( &parser, &LsColXMLParser::finishedWithoutError, this, &TestXmlParse::slotFinishedSuccessfully ); QHash sizes; QVERIFY(parser.parse( testXml, &sizes, QString::fromUtf8("/ä") )); QVERIFY(_success); QVERIFY(_items.contains(QString::fromUtf8("/ä/ä.pdf"))); QVERIFY(_items.contains(QString::fromUtf8("/ä"))); QVERIFY(_items.size() == 2 ); QVERIFY(_subdirs.contains(QString::fromUtf8("/ä"))); QVERIFY(_subdirs.size() == 1); } }; QTEST_GUILESS_MAIN(TestXmlParse) #include "testxmlparse.moc"