Mercurial > trustbridge
diff ui/tests/cinstprocesstest.cpp @ 298:56507c3d5f1e
Adapt remaining cinstprocesstest to new arg pattern
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Wed, 02 Apr 2014 16:13:37 +0000 |
parents | 0b1453070561 |
children | 4a3febc6d806 |
line wrap: on
line diff
--- 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); }