# HG changeset patch # User Andre Heinecke # Date 1395055237 0 # Node ID 3f8c2d46ded60bdf2d346e1a8a93b7e76ededa67 # Parent 7e37c6033c815f740e723ae42bfdf5e0eb680eca Add test for no connection handling diff -r 7e37c6033c81 -r 3f8c2d46ded6 ui/tests/CMakeLists.txt --- a/ui/tests/CMakeLists.txt Mon Mar 17 11:03:17 2014 +0000 +++ b/ui/tests/CMakeLists.txt Mon Mar 17 11:20:37 2014 +0000 @@ -25,6 +25,11 @@ # so that it can be used in file names in the tests. add_definitions(-DSOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}") add_m13_test(certlistparsertest.cpp "${CERTIFICATELIST_SOURCES}") -add_m13_test(downloadertest.cpp "${DOWNLOADER_SOURCES}") + +# Downloader +set(DOWNLOADER_SOURCES_WITH_RESOURCES ${DOWNLOADER_SOURCES}) +qt5_add_resources(DOWNLOADER_SOURCES_WITH_RESOURCES ${M13UI_RESOURCES}) +add_m13_test(downloadertest.cpp "${DOWNLOADER_SOURCES_WITH_RESOURCES}") + #add_m13_test(${CMAKE_SOURCE_DIR}/ui/main.cpp "${M13UI_SOURCES}") diff -r 7e37c6033c81 -r 3f8c2d46ded6 ui/tests/downloadertest.cpp --- a/ui/tests/downloadertest.cpp Mon Mar 17 11:03:17 2014 +0000 +++ b/ui/tests/downloadertest.cpp Mon Mar 17 11:20:37 2014 +0000 @@ -3,6 +3,7 @@ #include #include +#include #include "unistd.h" void DownloaderTest::startServer(QString additionalOptions) @@ -63,6 +64,33 @@ return retval; } +void DownloaderTest::testNoConnection() +{ + Downloader* downloader = new Downloader(this, + QString::fromLatin1("https://foobar.intevation.de")); + QSignalSpy newListAvailable(downloader, + SIGNAL(newListAvailable(const QString&, const QDateTime&))); + QSignalSpy newSoftwareAvailable(downloader, + SIGNAL(newSoftwareAvailable(const QString&, const QDateTime&))); + QSignalSpy errors(downloader, SIGNAL(error(const QString &, + SSLConnection::ErrorCode))); + downloader->start(); + + int waited = 0; + while (newListAvailable.count() == 0 && + errors.count() == 0 && waited < 20) { + QTest::qWait(200); + waited++; + } + QVERIFY(waited != 20); + + QList arguments = errors.takeFirst(); + + int error = arguments.at(1).toInt(); + + QVERIFY(error == SSLConnection::NoConnection); +} + void DownloaderTest::testNewList() { QFile validCert(QString::fromLatin1(SOURCE_DIR) + @@ -92,7 +120,7 @@ int waited = 0; while (newListAvailable.count() == 0 && errors.count() == 0 && waited < 20) { - QTest::qWait(2000); + QTest::qWait(200); waited++; } QVERIFY(waited != 20); diff -r 7e37c6033c81 -r 3f8c2d46ded6 ui/tests/downloadertest.h --- a/ui/tests/downloadertest.h Mon Mar 17 11:03:17 2014 +0000 +++ b/ui/tests/downloadertest.h Mon Mar 17 11:20:37 2014 +0000 @@ -25,6 +25,7 @@ void initTestCase(); void cleanupTestCase(); void testNewList(); + void testNoConnection(); }; #endif