Mercurial > trustbridge
changeset 298:56507c3d5f1e
Adapt remaining cinstprocesstest to new arg pattern
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Wed, 02 Apr 2014 16:13:37 +0000 (2014-04-02) |
parents | f733f4aa2a90 |
children | ccb00bf48b75 |
files | ui/tests/CMakeLists.txt ui/tests/cinstprocesstest.cpp |
diffstat | 2 files changed, 52 insertions(+), 42 deletions(-) [+] |
line wrap: on
line diff
--- a/ui/tests/CMakeLists.txt Wed Apr 02 16:12:18 2014 +0000 +++ b/ui/tests/CMakeLists.txt Wed Apr 02 16:13:37 2014 +0000 @@ -15,7 +15,7 @@ macro(add_m13_test _source _additional_sources) set(_test ${_source}) get_filename_component(_name ${_source} NAME_WE) - set(_test_sources_with_resources ${_test} ${_additional_sources}) + set(_test_sources_with_resources ${_test} "${_additional_sources};${CMAKE_CURRENT_SOURCE_DIR}/common.cpp") qt5_add_resources(_test_sources_with_resources ${CMAKE_CURRENT_SOURCE_DIR}/data/testdata.qrc) add_executable(${_name} ${_test_sources_with_resources}) @@ -29,13 +29,13 @@ # Add the current source dir to the definition # 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};${CMAKE_CURRENT_SOURCE_DIR}/common.cpp") +add_m13_test(certlistparsertest.cpp "${CERTIFICATELIST_SOURCES}") # Downloader if (HIAWATHA_EXECUTABLE) 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};${CMAKE_CURRENT_SOURCE_DIR}/common.cpp") + add_m13_test(downloadertest.cpp "${DOWNLOADER_SOURCES_WITH_RESOURCES}") endif() # Cinstprocess
--- a/ui/tests/cinstprocesstest.cpp Wed Apr 02 16:12:18 2014 +0000 +++ b/ui/tests/cinstprocesstest.cpp Wed Apr 02 16:13:37 2014 +0000 @@ -1,6 +1,7 @@ #include "cinstprocesstest.h" #include "certificatelist.h" #include "errorcodes.h" +#include "common.h" #include <QDebug> #include <QDir> @@ -120,68 +121,77 @@ } void CinstProcessTest::testGarbageInput() { - QProcess* installerProcess = startCinstProcess(); - QVERIFY(installerProcess->state() == QProcess::Running); - /* Garbage */ - installerProcess = startCinstProcess(); - installerProcess->write("-----BEGIN CERTIFICATE LIST-----\r\n"); - int retval=0; - int bytesWritten=0; - do { - char garbage[1030]; - for (int i = 0; i < 1030; i++) { - garbage[i] = (char) qrand() % 255; - } - retval = installerProcess->write(garbage, 1030); - bytesWritten += retval; - } while (retval != -1 && bytesWritten < 15 *1024 *1024 ); + QStringList args; - finishVerify(installerProcess, ERR_INVALID_INPUT); + QString garbage = getRandomDataFile(21*1024*1024); + args << "list=" + garbage; + + QTemporaryFile instructions; + instructions.open(); + foreach (const Certificate &cert, validList.getCertificates()) { + instructions.write(cert.base64Line().toLatin1()); + instructions.write("\n"); + } + instructions.close(); + + args << "instructions=" + instructions.fileName(); + + QProcess* installerProcess = startCinstProcess(args); + /* If the following failed there may be leftovers in /tmp */ + finishVerify(installerProcess, ERR_INVALID_INPUT_NO_LIST); + QVERIFY(QFile::remove(garbage)); } void CinstProcessTest::testNoInput() { - QProcess* installerProcess = startCinstProcess(); - QVERIFY(installerProcess->state() == QProcess::Running); - - /* Nothing */ - installerProcess = startCinstProcess(); + QStringList args; + args << "list=foobazbuf"; + args << "instructions=bazbuffoo"; + QProcess* installerProcess; + installerProcess = startCinstProcess(args); finishVerify(installerProcess, ERR_INVALID_INPUT_NO_LIST); } void CinstProcessTest::testNoInstructions() { /* No instructions */ - QProcess* installerProcess = startCinstProcess(); - QVERIFY(installerProcess->state() == QProcess::Running); - installerProcess->write("-----BEGIN CERTIFICATE LIST-----\r\n"); - installerProcess->write(validList.rawData().toLatin1()); - installerProcess->write("-----END CERTIFICATE LIST-----\r\n"); + QTemporaryFile emptyFile; + emptyFile.open(); + emptyFile.close(); + QStringList args; + args << "list=" + validListFile.fileName(); + args << "instructions=" + emptyFile.fileName(); + + QProcess* installerProcess = startCinstProcess(args); finishVerify(installerProcess, ERR_NO_INSTRUCTIONS); } void CinstProcessTest::testInvalidInstruction() { - QProcess* installerProcess = startCinstProcess(); - QVERIFY(installerProcess->state() == QProcess::Running); + QStringList args; + args << "list=" + validListFile.fileName(); - installerProcess->write("-----BEGIN CERTIFICATE LIST-----\r\n"); - installerProcess->write(validList.rawData().toLatin1()); - installerProcess->write("-----END CERTIFICATE LIST-----\r\n"); + QTemporaryFile instructions; + instructions.open(); + foreach (const Certificate &cert, validList.getCertificates()) { + instructions.write(cert.base64Line().toLatin1()); + instructions.write("\n"); + } + instructions.write("I:ABCDEF\n"); + instructions.close(); - installerProcess->write("I:ABCDEF\r\n"); + args << "instructions=" + instructions.fileName(); + + QProcess* installerProcess = startCinstProcess(args); finishVerify(installerProcess, ERR_INVALID_INSTRUCTIONS); } void CinstProcessTest::testUninstall() { - QProcess* installerProcess = startCinstProcess(); - QVERIFY(installerProcess->state() == QProcess::Running); + QStringList args; + args << "list=" + validListFile.fileName(); + args << "instructions=uninstall"; - installerProcess->write("-----BEGIN CERTIFICATE LIST-----\r\n"); - installerProcess->write(validList.rawData().toLatin1()); - installerProcess->write("-----END CERTIFICATE LIST-----\r\n"); - - installerProcess->write("UNINSTALL\r\n"); + QProcess* installerProcess = startCinstProcess(args); finishVerify(installerProcess, ERR_NO_ERROR); }