annotate ui/tests/cinstprocesstest.cpp @ 1316:ff9cd05e861e

(issue166) Fix certificiate removal The index that should be removed came from the filter proxy model and did not map to the real index. This was broken.
author Andre Heinecke <andre.heinecke@intevation.de>
date Mon, 13 Oct 2014 17:23:35 +0200
parents c8f698ca6355
children
rev   line source
404
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 314
diff changeset
1 /* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 314
diff changeset
2 * Software engineering by Intevation GmbH
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 314
diff changeset
3 *
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 314
diff changeset
4 * This file is Free Software under the GNU GPL (v>=2)
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 314
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY!
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 314
diff changeset
6 * See LICENSE.txt for details.
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 314
diff changeset
7 */
100
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
8 #include "cinstprocesstest.h"
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
9 #include "certificatelist.h"
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
10 #include "errorcodes.h"
298
56507c3d5f1e Adapt remaining cinstprocesstest to new arg pattern
Andre Heinecke <aheinecke@intevation.de>
parents: 296
diff changeset
11 #include "common.h"
100
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
12
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
13 #include <QDebug>
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
14 #include <QDir>
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
15 #include <QFile>
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
16 #include <QProcess>
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
17
313
f17226aa2e09 Temporary build fix for windows. Also Use putenv in test
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
18 #include <stdlib.h>
f17226aa2e09 Temporary build fix for windows. Also Use putenv in test
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
19
1176
c8f698ca6355 (issue128) Rename cinst to trustbridge-certificate-installer
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1163
diff changeset
20 #define CINST_PATH_CANDIDATES "../../cinst/trustbridge-certificate-installer" << \
c8f698ca6355 (issue128) Rename cinst to trustbridge-certificate-installer
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1163
diff changeset
21 "trustbridge-certificate-installer" << \
c8f698ca6355 (issue128) Rename cinst to trustbridge-certificate-installer
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1163
diff changeset
22 "../../cinst/trustbridge-certificate-installer.exe" \
c8f698ca6355 (issue128) Rename cinst to trustbridge-certificate-installer
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1163
diff changeset
23 << "trustbridge-certificate-installer.exe";
100
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
24
294
d95fd88f6616 Prepare cinstprocesstest to be executed on Windows
Andre Heinecke <aheinecke@intevation.de>
parents: 249
diff changeset
25 QProcess *CinstProcessTest::startCinstProcess(const QStringList& args) {
d95fd88f6616 Prepare cinstprocesstest to be executed on Windows
Andre Heinecke <aheinecke@intevation.de>
parents: 249
diff changeset
26 QStringList cinstCandidates;
d95fd88f6616 Prepare cinstprocesstest to be executed on Windows
Andre Heinecke <aheinecke@intevation.de>
parents: 249
diff changeset
27 cinstCandidates << CINST_PATH_CANDIDATES;
d95fd88f6616 Prepare cinstprocesstest to be executed on Windows
Andre Heinecke <aheinecke@intevation.de>
parents: 249
diff changeset
28 QString processPath;
d95fd88f6616 Prepare cinstprocesstest to be executed on Windows
Andre Heinecke <aheinecke@intevation.de>
parents: 249
diff changeset
29 foreach (const QString& candidate, cinstCandidates) {
d95fd88f6616 Prepare cinstprocesstest to be executed on Windows
Andre Heinecke <aheinecke@intevation.de>
parents: 249
diff changeset
30 QFileInfo fi(candidate);
d95fd88f6616 Prepare cinstprocesstest to be executed on Windows
Andre Heinecke <aheinecke@intevation.de>
parents: 249
diff changeset
31 if (fi.isExecutable()) {
d95fd88f6616 Prepare cinstprocesstest to be executed on Windows
Andre Heinecke <aheinecke@intevation.de>
parents: 249
diff changeset
32 processPath = candidate;
d95fd88f6616 Prepare cinstprocesstest to be executed on Windows
Andre Heinecke <aheinecke@intevation.de>
parents: 249
diff changeset
33 break;
d95fd88f6616 Prepare cinstprocesstest to be executed on Windows
Andre Heinecke <aheinecke@intevation.de>
parents: 249
diff changeset
34 }
d95fd88f6616 Prepare cinstprocesstest to be executed on Windows
Andre Heinecke <aheinecke@intevation.de>
parents: 249
diff changeset
35 }
d95fd88f6616 Prepare cinstprocesstest to be executed on Windows
Andre Heinecke <aheinecke@intevation.de>
parents: 249
diff changeset
36
1060
317ee9dc4684 (issue46) Make debug output optional in cinst and mozilla and propagate its setting.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 904
diff changeset
37 QStringList newArgs = args;
317ee9dc4684 (issue46) Make debug output optional in cinst and mozilla and propagate its setting.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 904
diff changeset
38 newArgs << "--debug";
317ee9dc4684 (issue46) Make debug output optional in cinst and mozilla and propagate its setting.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 904
diff changeset
39
100
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
40 QProcess *installerProcess = new QProcess();
1060
317ee9dc4684 (issue46) Make debug output optional in cinst and mozilla and propagate its setting.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 904
diff changeset
41 installerProcess->setArguments(newArgs);
294
d95fd88f6616 Prepare cinstprocesstest to be executed on Windows
Andre Heinecke <aheinecke@intevation.de>
parents: 249
diff changeset
42 installerProcess->setProgram(processPath);
100
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
43 installerProcess->start();
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
44 installerProcess->waitForStarted();
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
45 return installerProcess;
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
46 }
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
47
151
0df62decff90 Test if uninstall is handled as instruction
Andre Heinecke <aheinecke@intevation.de>
parents: 150
diff changeset
48 #define VERIFY_PROC_DEBUG(x) \
0df62decff90 Test if uninstall is handled as instruction
Andre Heinecke <aheinecke@intevation.de>
parents: 150
diff changeset
49 if (! x ) { \
0df62decff90 Test if uninstall is handled as instruction
Andre Heinecke <aheinecke@intevation.de>
parents: 150
diff changeset
50 qDebug() << "Stdout:" << proc->readAllStandardOutput(); \
0df62decff90 Test if uninstall is handled as instruction
Andre Heinecke <aheinecke@intevation.de>
parents: 150
diff changeset
51 qDebug() << "Stderr:" << proc->readAllStandardError(); \
0df62decff90 Test if uninstall is handled as instruction
Andre Heinecke <aheinecke@intevation.de>
parents: 150
diff changeset
52 qDebug() << "Exit code: " << proc->exitCode(); \
305
4a3febc6d806 Some minor cleanups. Better debug output more Verify's
Andre Heinecke <andre.heinecke@intevation.de>
parents: 298
diff changeset
53 qDebug() << "Exit status: " << proc->exitStatus(); \
151
0df62decff90 Test if uninstall is handled as instruction
Andre Heinecke <aheinecke@intevation.de>
parents: 150
diff changeset
54 } \
0df62decff90 Test if uninstall is handled as instruction
Andre Heinecke <aheinecke@intevation.de>
parents: 150
diff changeset
55 QVERIFY(x)
0df62decff90 Test if uninstall is handled as instruction
Andre Heinecke <aheinecke@intevation.de>
parents: 150
diff changeset
56
100
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
57 void finishVerify(QProcess *proc, int exitCode) {
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
58 proc->closeWriteChannel();
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
59 proc->waitForFinished();
151
0df62decff90 Test if uninstall is handled as instruction
Andre Heinecke <aheinecke@intevation.de>
parents: 150
diff changeset
60 VERIFY_PROC_DEBUG(proc->exitStatus() == QProcess::NormalExit);
0df62decff90 Test if uninstall is handled as instruction
Andre Heinecke <aheinecke@intevation.de>
parents: 150
diff changeset
61 VERIFY_PROC_DEBUG(proc->exitCode() == exitCode);
100
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
62 delete proc;
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
63 }
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
64
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
65 void CinstProcessTest::testValidInput() {
295
02df89a275a6 Fix cinstprocesstest testValid with usage of arguments
Andre Heinecke <aheinecke@intevation.de>
parents: 294
diff changeset
66 QStringList args;
02df89a275a6 Fix cinstprocesstest testValid with usage of arguments
Andre Heinecke <aheinecke@intevation.de>
parents: 294
diff changeset
67 args << "list=" + validListFile.fileName();
100
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
68
295
02df89a275a6 Fix cinstprocesstest testValid with usage of arguments
Andre Heinecke <aheinecke@intevation.de>
parents: 294
diff changeset
69 QTemporaryFile instructions;
02df89a275a6 Fix cinstprocesstest testValid with usage of arguments
Andre Heinecke <aheinecke@intevation.de>
parents: 294
diff changeset
70 instructions.open();
02df89a275a6 Fix cinstprocesstest testValid with usage of arguments
Andre Heinecke <aheinecke@intevation.de>
parents: 294
diff changeset
71 foreach (const Certificate &cert, validList.getCertificates()) {
02df89a275a6 Fix cinstprocesstest testValid with usage of arguments
Andre Heinecke <aheinecke@intevation.de>
parents: 294
diff changeset
72 instructions.write(cert.base64Line().toLatin1());
02df89a275a6 Fix cinstprocesstest testValid with usage of arguments
Andre Heinecke <aheinecke@intevation.de>
parents: 294
diff changeset
73 instructions.write("\n");
02df89a275a6 Fix cinstprocesstest testValid with usage of arguments
Andre Heinecke <aheinecke@intevation.de>
parents: 294
diff changeset
74 }
02df89a275a6 Fix cinstprocesstest testValid with usage of arguments
Andre Heinecke <aheinecke@intevation.de>
parents: 294
diff changeset
75 instructions.close();
100
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
76
439
c88090a15ae4 Fix cinstprocesstest for new arguments. Handle errno on write errors
Andre Heinecke <aheinecke@intevation.de>
parents: 404
diff changeset
77 args << "choices=" + instructions.fileName();
100
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
78
295
02df89a275a6 Fix cinstprocesstest testValid with usage of arguments
Andre Heinecke <aheinecke@intevation.de>
parents: 294
diff changeset
79 QProcess* installerProcess = startCinstProcess(args);
159
37c9653b8755 Rename NO_ERROR as NO_ERROR is already defined in windows.h
Andre Heinecke <aheinecke@intevation.de>
parents: 151
diff changeset
80 finishVerify(installerProcess, ERR_NO_ERROR);
100
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
81 }
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
82
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
83 void CinstProcessTest::initTestCase() {
295
02df89a275a6 Fix cinstprocesstest testValid with usage of arguments
Andre Heinecke <aheinecke@intevation.de>
parents: 294
diff changeset
84 QFile valid(":/list-valid-signed.txt");
02df89a275a6 Fix cinstprocesstest testValid with usage of arguments
Andre Heinecke <aheinecke@intevation.de>
parents: 294
diff changeset
85 valid.open(QIODevice::ReadOnly);
02df89a275a6 Fix cinstprocesstest testValid with usage of arguments
Andre Heinecke <aheinecke@intevation.de>
parents: 294
diff changeset
86 validListFile.open();
02df89a275a6 Fix cinstprocesstest testValid with usage of arguments
Andre Heinecke <aheinecke@intevation.de>
parents: 294
diff changeset
87 validListFile.write(valid.readAll());
02df89a275a6 Fix cinstprocesstest testValid with usage of arguments
Andre Heinecke <aheinecke@intevation.de>
parents: 294
diff changeset
88 valid.close();
02df89a275a6 Fix cinstprocesstest testValid with usage of arguments
Andre Heinecke <aheinecke@intevation.de>
parents: 294
diff changeset
89 validListFile.close();
02df89a275a6 Fix cinstprocesstest testValid with usage of arguments
Andre Heinecke <aheinecke@intevation.de>
parents: 294
diff changeset
90 validList = CertificateList(validListFile.fileName().toLocal8Bit().data());
02df89a275a6 Fix cinstprocesstest testValid with usage of arguments
Andre Heinecke <aheinecke@intevation.de>
parents: 294
diff changeset
91
02df89a275a6 Fix cinstprocesstest testValid with usage of arguments
Andre Heinecke <aheinecke@intevation.de>
parents: 294
diff changeset
92 QVERIFY(validList.isValid());
02df89a275a6 Fix cinstprocesstest testValid with usage of arguments
Andre Heinecke <aheinecke@intevation.de>
parents: 294
diff changeset
93
02df89a275a6 Fix cinstprocesstest testValid with usage of arguments
Andre Heinecke <aheinecke@intevation.de>
parents: 294
diff changeset
94 QFile invalid(":/list-invalid-signed.txt");
02df89a275a6 Fix cinstprocesstest testValid with usage of arguments
Andre Heinecke <aheinecke@intevation.de>
parents: 294
diff changeset
95 invalid.open(QIODevice::ReadOnly);
02df89a275a6 Fix cinstprocesstest testValid with usage of arguments
Andre Heinecke <aheinecke@intevation.de>
parents: 294
diff changeset
96 invalidListFile.open();
02df89a275a6 Fix cinstprocesstest testValid with usage of arguments
Andre Heinecke <aheinecke@intevation.de>
parents: 294
diff changeset
97 invalidListFile.write(invalid.readAll());
02df89a275a6 Fix cinstprocesstest testValid with usage of arguments
Andre Heinecke <aheinecke@intevation.de>
parents: 294
diff changeset
98 invalid.close();
02df89a275a6 Fix cinstprocesstest testValid with usage of arguments
Andre Heinecke <aheinecke@intevation.de>
parents: 294
diff changeset
99 invalidListFile.close();
02df89a275a6 Fix cinstprocesstest testValid with usage of arguments
Andre Heinecke <aheinecke@intevation.de>
parents: 294
diff changeset
100 invalidList = CertificateList(invalidListFile.fileName().toLocal8Bit().data());
02df89a275a6 Fix cinstprocesstest testValid with usage of arguments
Andre Heinecke <aheinecke@intevation.de>
parents: 294
diff changeset
101
02df89a275a6 Fix cinstprocesstest testValid with usage of arguments
Andre Heinecke <aheinecke@intevation.de>
parents: 294
diff changeset
102 QVERIFY(!invalidList.isValid());
02df89a275a6 Fix cinstprocesstest testValid with usage of arguments
Andre Heinecke <aheinecke@intevation.de>
parents: 294
diff changeset
103
02df89a275a6 Fix cinstprocesstest testValid with usage of arguments
Andre Heinecke <aheinecke@intevation.de>
parents: 294
diff changeset
104 QFile other(":/list-valid-other-signature.txt");
02df89a275a6 Fix cinstprocesstest testValid with usage of arguments
Andre Heinecke <aheinecke@intevation.de>
parents: 294
diff changeset
105 other.open(QIODevice::ReadOnly);
02df89a275a6 Fix cinstprocesstest testValid with usage of arguments
Andre Heinecke <aheinecke@intevation.de>
parents: 294
diff changeset
106 otherListFile.open();
02df89a275a6 Fix cinstprocesstest testValid with usage of arguments
Andre Heinecke <aheinecke@intevation.de>
parents: 294
diff changeset
107 otherListFile.write(other.readAll());
02df89a275a6 Fix cinstprocesstest testValid with usage of arguments
Andre Heinecke <aheinecke@intevation.de>
parents: 294
diff changeset
108 other.close();
02df89a275a6 Fix cinstprocesstest testValid with usage of arguments
Andre Heinecke <aheinecke@intevation.de>
parents: 294
diff changeset
109 otherListFile.close();
02df89a275a6 Fix cinstprocesstest testValid with usage of arguments
Andre Heinecke <aheinecke@intevation.de>
parents: 294
diff changeset
110 otherList = CertificateList(otherListFile.fileName().toLocal8Bit().data());
02df89a275a6 Fix cinstprocesstest testValid with usage of arguments
Andre Heinecke <aheinecke@intevation.de>
parents: 294
diff changeset
111
02df89a275a6 Fix cinstprocesstest testValid with usage of arguments
Andre Heinecke <aheinecke@intevation.de>
parents: 294
diff changeset
112 QVERIFY(!otherList.isValid());
306
9c5e6b142611 Set the home directory to a temporary location to avoid writing into real nss stores
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
113
904
f89b41fa7048 Fix whitespace errors
Andre Heinecke <andre.heinecke@intevation.de>
parents: 439
diff changeset
114 /* Set HOME or APPDATA so that nss stores are not touched
306
9c5e6b142611 Set the home directory to a temporary location to avoid writing into real nss stores
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
115 * see nsstest for the real test of that code */
9c5e6b142611 Set the home directory to a temporary location to avoid writing into real nss stores
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
116 #ifdef WIN32
313
f17226aa2e09 Temporary build fix for windows. Also Use putenv in test
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
117 {
314
5e4ae994a320 Make buffer size for fakeHome environment variable dynamic.
Andre Heinecke <aheinecke@intevation.de>
parents: 313
diff changeset
118 char buf[fakeHome.path().toLocal8Bit().size() + 9];
5e4ae994a320 Make buffer size for fakeHome environment variable dynamic.
Andre Heinecke <aheinecke@intevation.de>
parents: 313
diff changeset
119 snprintf(buf, fakeHome.path().toLocal8Bit().size() + 9,
5e4ae994a320 Make buffer size for fakeHome environment variable dynamic.
Andre Heinecke <aheinecke@intevation.de>
parents: 313
diff changeset
120 "APPDATA=%s",fakeHome.path().toLocal8Bit().constData());
313
f17226aa2e09 Temporary build fix for windows. Also Use putenv in test
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
121 QVERIFY(_putenv (buf) != -1);
f17226aa2e09 Temporary build fix for windows. Also Use putenv in test
Andre Heinecke <aheinecke@intevation.de>
parents: 306
diff changeset
122 }
306
9c5e6b142611 Set the home directory to a temporary location to avoid writing into real nss stores
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
123 #else
9c5e6b142611 Set the home directory to a temporary location to avoid writing into real nss stores
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
124 QVERIFY(!setenv ("HOME", fakeHome.path().toLocal8Bit().constData(), 1));
9c5e6b142611 Set the home directory to a temporary location to avoid writing into real nss stores
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
125 #endif
100
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
126 }
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
127
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
128 void CinstProcessTest::testNoList() {
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
129 /* No list */
296
0b1453070561 Fix test no list
Andre Heinecke <aheinecke@intevation.de>
parents: 295
diff changeset
130 QTemporaryFile emptyFile;
0b1453070561 Fix test no list
Andre Heinecke <aheinecke@intevation.de>
parents: 295
diff changeset
131 emptyFile.open();
0b1453070561 Fix test no list
Andre Heinecke <aheinecke@intevation.de>
parents: 295
diff changeset
132 emptyFile.close();
100
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
133
296
0b1453070561 Fix test no list
Andre Heinecke <aheinecke@intevation.de>
parents: 295
diff changeset
134 QStringList args;
0b1453070561 Fix test no list
Andre Heinecke <aheinecke@intevation.de>
parents: 295
diff changeset
135 args << "list=" + emptyFile.fileName();
0b1453070561 Fix test no list
Andre Heinecke <aheinecke@intevation.de>
parents: 295
diff changeset
136
0b1453070561 Fix test no list
Andre Heinecke <aheinecke@intevation.de>
parents: 295
diff changeset
137 QTemporaryFile instructions;
0b1453070561 Fix test no list
Andre Heinecke <aheinecke@intevation.de>
parents: 295
diff changeset
138 instructions.open();
249
6a7eb102716d Remove code duplication by unifying the certificatelist.
Andre Heinecke <aheinecke@intevation.de>
parents: 159
diff changeset
139 foreach (const Certificate &cert, validList.getCertificates()) {
296
0b1453070561 Fix test no list
Andre Heinecke <aheinecke@intevation.de>
parents: 295
diff changeset
140 instructions.write(cert.base64Line().toLatin1());
0b1453070561 Fix test no list
Andre Heinecke <aheinecke@intevation.de>
parents: 295
diff changeset
141 instructions.write("\n");
100
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
142 }
296
0b1453070561 Fix test no list
Andre Heinecke <aheinecke@intevation.de>
parents: 295
diff changeset
143 instructions.close();
0b1453070561 Fix test no list
Andre Heinecke <aheinecke@intevation.de>
parents: 295
diff changeset
144
439
c88090a15ae4 Fix cinstprocesstest for new arguments. Handle errno on write errors
Andre Heinecke <aheinecke@intevation.de>
parents: 404
diff changeset
145 args << "choices=" + instructions.fileName();
296
0b1453070561 Fix test no list
Andre Heinecke <aheinecke@intevation.de>
parents: 295
diff changeset
146
0b1453070561 Fix test no list
Andre Heinecke <aheinecke@intevation.de>
parents: 295
diff changeset
147 QProcess* installerProcess = startCinstProcess(args);
100
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
148 finishVerify(installerProcess, ERR_INVALID_INPUT_NO_LIST);
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
149 }
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
150
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
151 void CinstProcessTest::testGarbageInput() {
298
56507c3d5f1e Adapt remaining cinstprocesstest to new arg pattern
Andre Heinecke <aheinecke@intevation.de>
parents: 296
diff changeset
152 QStringList args;
100
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
153
298
56507c3d5f1e Adapt remaining cinstprocesstest to new arg pattern
Andre Heinecke <aheinecke@intevation.de>
parents: 296
diff changeset
154 QString garbage = getRandomDataFile(21*1024*1024);
56507c3d5f1e Adapt remaining cinstprocesstest to new arg pattern
Andre Heinecke <aheinecke@intevation.de>
parents: 296
diff changeset
155 args << "list=" + garbage;
56507c3d5f1e Adapt remaining cinstprocesstest to new arg pattern
Andre Heinecke <aheinecke@intevation.de>
parents: 296
diff changeset
156
56507c3d5f1e Adapt remaining cinstprocesstest to new arg pattern
Andre Heinecke <aheinecke@intevation.de>
parents: 296
diff changeset
157 QTemporaryFile instructions;
56507c3d5f1e Adapt remaining cinstprocesstest to new arg pattern
Andre Heinecke <aheinecke@intevation.de>
parents: 296
diff changeset
158 instructions.open();
56507c3d5f1e Adapt remaining cinstprocesstest to new arg pattern
Andre Heinecke <aheinecke@intevation.de>
parents: 296
diff changeset
159 foreach (const Certificate &cert, validList.getCertificates()) {
56507c3d5f1e Adapt remaining cinstprocesstest to new arg pattern
Andre Heinecke <aheinecke@intevation.de>
parents: 296
diff changeset
160 instructions.write(cert.base64Line().toLatin1());
56507c3d5f1e Adapt remaining cinstprocesstest to new arg pattern
Andre Heinecke <aheinecke@intevation.de>
parents: 296
diff changeset
161 instructions.write("\n");
56507c3d5f1e Adapt remaining cinstprocesstest to new arg pattern
Andre Heinecke <aheinecke@intevation.de>
parents: 296
diff changeset
162 }
56507c3d5f1e Adapt remaining cinstprocesstest to new arg pattern
Andre Heinecke <aheinecke@intevation.de>
parents: 296
diff changeset
163 instructions.close();
56507c3d5f1e Adapt remaining cinstprocesstest to new arg pattern
Andre Heinecke <aheinecke@intevation.de>
parents: 296
diff changeset
164
439
c88090a15ae4 Fix cinstprocesstest for new arguments. Handle errno on write errors
Andre Heinecke <aheinecke@intevation.de>
parents: 404
diff changeset
165 args << "choices=" + instructions.fileName();
298
56507c3d5f1e Adapt remaining cinstprocesstest to new arg pattern
Andre Heinecke <aheinecke@intevation.de>
parents: 296
diff changeset
166
56507c3d5f1e Adapt remaining cinstprocesstest to new arg pattern
Andre Heinecke <aheinecke@intevation.de>
parents: 296
diff changeset
167 QProcess* installerProcess = startCinstProcess(args);
56507c3d5f1e Adapt remaining cinstprocesstest to new arg pattern
Andre Heinecke <aheinecke@intevation.de>
parents: 296
diff changeset
168 /* If the following failed there may be leftovers in /tmp */
56507c3d5f1e Adapt remaining cinstprocesstest to new arg pattern
Andre Heinecke <aheinecke@intevation.de>
parents: 296
diff changeset
169 finishVerify(installerProcess, ERR_INVALID_INPUT_NO_LIST);
56507c3d5f1e Adapt remaining cinstprocesstest to new arg pattern
Andre Heinecke <aheinecke@intevation.de>
parents: 296
diff changeset
170 QVERIFY(QFile::remove(garbage));
100
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
171 }
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
172
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
173 void CinstProcessTest::testNoInput() {
298
56507c3d5f1e Adapt remaining cinstprocesstest to new arg pattern
Andre Heinecke <aheinecke@intevation.de>
parents: 296
diff changeset
174 QStringList args;
56507c3d5f1e Adapt remaining cinstprocesstest to new arg pattern
Andre Heinecke <aheinecke@intevation.de>
parents: 296
diff changeset
175 args << "list=foobazbuf";
439
c88090a15ae4 Fix cinstprocesstest for new arguments. Handle errno on write errors
Andre Heinecke <aheinecke@intevation.de>
parents: 404
diff changeset
176 args << "choices=bazbuffoo";
298
56507c3d5f1e Adapt remaining cinstprocesstest to new arg pattern
Andre Heinecke <aheinecke@intevation.de>
parents: 296
diff changeset
177 QProcess* installerProcess;
56507c3d5f1e Adapt remaining cinstprocesstest to new arg pattern
Andre Heinecke <aheinecke@intevation.de>
parents: 296
diff changeset
178 installerProcess = startCinstProcess(args);
100
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
179 finishVerify(installerProcess, ERR_INVALID_INPUT_NO_LIST);
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
180 }
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
181
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
182
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
183 void CinstProcessTest::testNoInstructions() {
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
184 /* No instructions */
298
56507c3d5f1e Adapt remaining cinstprocesstest to new arg pattern
Andre Heinecke <aheinecke@intevation.de>
parents: 296
diff changeset
185 QTemporaryFile emptyFile;
56507c3d5f1e Adapt remaining cinstprocesstest to new arg pattern
Andre Heinecke <aheinecke@intevation.de>
parents: 296
diff changeset
186 emptyFile.open();
56507c3d5f1e Adapt remaining cinstprocesstest to new arg pattern
Andre Heinecke <aheinecke@intevation.de>
parents: 296
diff changeset
187 emptyFile.close();
100
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
188
298
56507c3d5f1e Adapt remaining cinstprocesstest to new arg pattern
Andre Heinecke <aheinecke@intevation.de>
parents: 296
diff changeset
189 QStringList args;
56507c3d5f1e Adapt remaining cinstprocesstest to new arg pattern
Andre Heinecke <aheinecke@intevation.de>
parents: 296
diff changeset
190 args << "list=" + validListFile.fileName();
439
c88090a15ae4 Fix cinstprocesstest for new arguments. Handle errno on write errors
Andre Heinecke <aheinecke@intevation.de>
parents: 404
diff changeset
191 args << "choices=" + emptyFile.fileName();
298
56507c3d5f1e Adapt remaining cinstprocesstest to new arg pattern
Andre Heinecke <aheinecke@intevation.de>
parents: 296
diff changeset
192
56507c3d5f1e Adapt remaining cinstprocesstest to new arg pattern
Andre Heinecke <aheinecke@intevation.de>
parents: 296
diff changeset
193 QProcess* installerProcess = startCinstProcess(args);
100
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
194 finishVerify(installerProcess, ERR_NO_INSTRUCTIONS);
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
195 }
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
196
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
197 void CinstProcessTest::testInvalidInstruction() {
298
56507c3d5f1e Adapt remaining cinstprocesstest to new arg pattern
Andre Heinecke <aheinecke@intevation.de>
parents: 296
diff changeset
198 QStringList args;
56507c3d5f1e Adapt remaining cinstprocesstest to new arg pattern
Andre Heinecke <aheinecke@intevation.de>
parents: 296
diff changeset
199 args << "list=" + validListFile.fileName();
100
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
200
298
56507c3d5f1e Adapt remaining cinstprocesstest to new arg pattern
Andre Heinecke <aheinecke@intevation.de>
parents: 296
diff changeset
201 QTemporaryFile instructions;
56507c3d5f1e Adapt remaining cinstprocesstest to new arg pattern
Andre Heinecke <aheinecke@intevation.de>
parents: 296
diff changeset
202 instructions.open();
56507c3d5f1e Adapt remaining cinstprocesstest to new arg pattern
Andre Heinecke <aheinecke@intevation.de>
parents: 296
diff changeset
203 foreach (const Certificate &cert, validList.getCertificates()) {
56507c3d5f1e Adapt remaining cinstprocesstest to new arg pattern
Andre Heinecke <aheinecke@intevation.de>
parents: 296
diff changeset
204 instructions.write(cert.base64Line().toLatin1());
56507c3d5f1e Adapt remaining cinstprocesstest to new arg pattern
Andre Heinecke <aheinecke@intevation.de>
parents: 296
diff changeset
205 instructions.write("\n");
56507c3d5f1e Adapt remaining cinstprocesstest to new arg pattern
Andre Heinecke <aheinecke@intevation.de>
parents: 296
diff changeset
206 }
56507c3d5f1e Adapt remaining cinstprocesstest to new arg pattern
Andre Heinecke <aheinecke@intevation.de>
parents: 296
diff changeset
207 instructions.write("I:ABCDEF\n");
56507c3d5f1e Adapt remaining cinstprocesstest to new arg pattern
Andre Heinecke <aheinecke@intevation.de>
parents: 296
diff changeset
208 instructions.close();
100
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
209
439
c88090a15ae4 Fix cinstprocesstest for new arguments. Handle errno on write errors
Andre Heinecke <aheinecke@intevation.de>
parents: 404
diff changeset
210 args << "choices=" + instructions.fileName();
298
56507c3d5f1e Adapt remaining cinstprocesstest to new arg pattern
Andre Heinecke <aheinecke@intevation.de>
parents: 296
diff changeset
211
56507c3d5f1e Adapt remaining cinstprocesstest to new arg pattern
Andre Heinecke <aheinecke@intevation.de>
parents: 296
diff changeset
212 QProcess* installerProcess = startCinstProcess(args);
100
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
213
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
214 finishVerify(installerProcess, ERR_INVALID_INSTRUCTIONS);
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
215 }
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
216
151
0df62decff90 Test if uninstall is handled as instruction
Andre Heinecke <aheinecke@intevation.de>
parents: 150
diff changeset
217 void CinstProcessTest::testUninstall() {
298
56507c3d5f1e Adapt remaining cinstprocesstest to new arg pattern
Andre Heinecke <aheinecke@intevation.de>
parents: 296
diff changeset
218 QStringList args;
56507c3d5f1e Adapt remaining cinstprocesstest to new arg pattern
Andre Heinecke <aheinecke@intevation.de>
parents: 296
diff changeset
219 args << "list=" + validListFile.fileName();
439
c88090a15ae4 Fix cinstprocesstest for new arguments. Handle errno on write errors
Andre Heinecke <aheinecke@intevation.de>
parents: 404
diff changeset
220 args << "choices=uninstall";
151
0df62decff90 Test if uninstall is handled as instruction
Andre Heinecke <aheinecke@intevation.de>
parents: 150
diff changeset
221
298
56507c3d5f1e Adapt remaining cinstprocesstest to new arg pattern
Andre Heinecke <aheinecke@intevation.de>
parents: 296
diff changeset
222 QProcess* installerProcess = startCinstProcess(args);
151
0df62decff90 Test if uninstall is handled as instruction
Andre Heinecke <aheinecke@intevation.de>
parents: 150
diff changeset
223
159
37c9653b8755 Rename NO_ERROR as NO_ERROR is already defined in windows.h
Andre Heinecke <aheinecke@intevation.de>
parents: 151
diff changeset
224 finishVerify(installerProcess, ERR_NO_ERROR);
151
0df62decff90 Test if uninstall is handled as instruction
Andre Heinecke <aheinecke@intevation.de>
parents: 150
diff changeset
225 }
0df62decff90 Test if uninstall is handled as instruction
Andre Heinecke <aheinecke@intevation.de>
parents: 150
diff changeset
226
1163
e3772d2810b3 Fix tests now that portpath includes logging
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1060
diff changeset
227 bool g_debug = true;
e3772d2810b3 Fix tests now that portpath includes logging
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1060
diff changeset
228
100
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
229 QTEST_GUILESS_MAIN (CinstProcessTest);

http://wald.intevation.org/projects/trustbridge/