annotate ui/tests/cinstprocesstest.cpp @ 180:344b8a79ad2e

Implemented detection profile paths for Windows Vista/7.
author Sascha Wilde <wilde@intevation.de>
date Tue, 25 Mar 2014 17:51:24 +0100
parents 37c9653b8755
children 6a7eb102716d
rev   line source
100
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
1 #include "cinstprocesstest.h"
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
2 #include "certificatelist.h"
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
3 #include "errorcodes.h"
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
4
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
5 #include <QDebug>
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
6 #include <QDir>
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
7 #include <QFile>
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
8 #include <QProcess>
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
9
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
10 #define RELATIVE_CINST_PATH "../../cinst/cinst"
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
11
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
12 QProcess *CinstProcessTest::startCinstProcess() {
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
13 QProcess *installerProcess = new QProcess();
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
14 installerProcess->setProgram(RELATIVE_CINST_PATH);
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
15 installerProcess->start();
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
16 installerProcess->waitForStarted();
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
17 return installerProcess;
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
18 }
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
19
151
0df62decff90 Test if uninstall is handled as instruction
Andre Heinecke <aheinecke@intevation.de>
parents: 150
diff changeset
20 #define VERIFY_PROC_DEBUG(x) \
0df62decff90 Test if uninstall is handled as instruction
Andre Heinecke <aheinecke@intevation.de>
parents: 150
diff changeset
21 if (! x ) { \
0df62decff90 Test if uninstall is handled as instruction
Andre Heinecke <aheinecke@intevation.de>
parents: 150
diff changeset
22 qDebug() << "Stdout:" << proc->readAllStandardOutput(); \
0df62decff90 Test if uninstall is handled as instruction
Andre Heinecke <aheinecke@intevation.de>
parents: 150
diff changeset
23 qDebug() << "Stderr:" << proc->readAllStandardError(); \
0df62decff90 Test if uninstall is handled as instruction
Andre Heinecke <aheinecke@intevation.de>
parents: 150
diff changeset
24 qDebug() << "Exit code: " << proc->exitCode(); \
0df62decff90 Test if uninstall is handled as instruction
Andre Heinecke <aheinecke@intevation.de>
parents: 150
diff changeset
25 } \
0df62decff90 Test if uninstall is handled as instruction
Andre Heinecke <aheinecke@intevation.de>
parents: 150
diff changeset
26 QVERIFY(x)
0df62decff90 Test if uninstall is handled as instruction
Andre Heinecke <aheinecke@intevation.de>
parents: 150
diff changeset
27
100
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
28 void finishVerify(QProcess *proc, int exitCode) {
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
29 proc->closeWriteChannel();
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
30 proc->waitForFinished();
151
0df62decff90 Test if uninstall is handled as instruction
Andre Heinecke <aheinecke@intevation.de>
parents: 150
diff changeset
31 VERIFY_PROC_DEBUG(proc->exitStatus() == QProcess::NormalExit);
0df62decff90 Test if uninstall is handled as instruction
Andre Heinecke <aheinecke@intevation.de>
parents: 150
diff changeset
32 VERIFY_PROC_DEBUG(proc->exitCode() == exitCode);
100
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
33 delete proc;
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
34 }
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
35
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
36 void CinstProcessTest::testValidInput() {
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
37 QProcess* installerProcess = startCinstProcess();
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
38 QVERIFY(installerProcess->state() == QProcess::Running);
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
39
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
40 installerProcess->write("-----BEGIN CERTIFICATE LIST-----\r\n");
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
41 installerProcess->write(validList.rawData().toLatin1());
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
42 installerProcess->write("-----END CERTIFICATE LIST-----\r\n");
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
43
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
44 foreach (const Certificate &cert, validList.getInstallCertificates()) {
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
45 installerProcess->write(cert.base64Line().toLatin1());
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
46 installerProcess->write("\r\n");
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
47 }
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
48
159
37c9653b8755 Rename NO_ERROR as NO_ERROR is already defined in windows.h
Andre Heinecke <aheinecke@intevation.de>
parents: 151
diff changeset
49 finishVerify(installerProcess, ERR_NO_ERROR);
100
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
50 }
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
51
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
52 void CinstProcessTest::initTestCase() {
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
53 QDir dataDir = QDir(SOURCE_DIR"/data/");
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
54 QString fileName = dataDir.absoluteFilePath("list-valid-signed.txt");
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
55 validList = CertificateList(fileName.toLocal8Bit().data());
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
56 }
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
57
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
58 void CinstProcessTest::testNoList() {
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
59 /* No list */
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
60 QProcess* installerProcess = startCinstProcess();
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
61 QVERIFY(installerProcess->state() == QProcess::Running);
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
62 installerProcess->write("-----BEGIN CERTIFICATE LIST-----\r\n");
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
63 installerProcess->write("-----END CERTIFICATE LIST-----\r\n");
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 foreach (const Certificate &cert, validList.getInstallCertificates()) {
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
66 installerProcess->write(cert.base64Line().toLatin1());
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
67 installerProcess->write("\r\n");
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
68 }
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
69 finishVerify(installerProcess, ERR_INVALID_INPUT_NO_LIST);
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
70 }
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
71
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
72 void CinstProcessTest::testGarbageInput() {
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
73 QProcess* installerProcess = startCinstProcess();
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
74 QVERIFY(installerProcess->state() == QProcess::Running);
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
75 /* Garbage */
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
76 installerProcess = startCinstProcess();
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
77 installerProcess->write("-----BEGIN CERTIFICATE LIST-----\r\n");
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
78 int retval=0;
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
79 int bytesWritten=0;
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
80 do {
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
81 char garbage[1030];
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
82 for (int i = 0; i < 1030; i++) {
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
83 garbage[i] = (char) qrand() % 255;
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
84 }
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
85 retval = installerProcess->write(garbage, 1030);
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
86 bytesWritten += retval;
115
5ed770c41a73 Change garbage input to invalid input. Fix InvalidInstructions test.
Andre Heinecke <aheinecke@intevation.de>
parents: 100
diff changeset
87 } while (retval != -1 && bytesWritten < 15 *1024 *1024 );
100
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
88
115
5ed770c41a73 Change garbage input to invalid input. Fix InvalidInstructions test.
Andre Heinecke <aheinecke@intevation.de>
parents: 100
diff changeset
89 finishVerify(installerProcess, ERR_INVALID_INPUT);
100
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
90 }
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
91
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
92 void CinstProcessTest::testNoInput() {
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
93 QProcess* installerProcess = startCinstProcess();
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
94 QVERIFY(installerProcess->state() == QProcess::Running);
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
95
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
96 /* Nothing */
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
97 installerProcess = startCinstProcess();
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
98 finishVerify(installerProcess, ERR_INVALID_INPUT_NO_LIST);
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
99 }
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
100
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
101
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
102 void CinstProcessTest::testNoInstructions() {
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
103 /* No instructions */
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
104 QProcess* installerProcess = startCinstProcess();
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
105 QVERIFY(installerProcess->state() == QProcess::Running);
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
106 installerProcess->write("-----BEGIN CERTIFICATE LIST-----\r\n");
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
107 installerProcess->write(validList.rawData().toLatin1());
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
108 installerProcess->write("-----END CERTIFICATE LIST-----\r\n");
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
109
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
110 finishVerify(installerProcess, ERR_NO_INSTRUCTIONS);
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
111 }
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
112
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
113 void CinstProcessTest::testInvalidInstruction() {
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
114 QProcess* installerProcess = startCinstProcess();
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
115 QVERIFY(installerProcess->state() == QProcess::Running);
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
116
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
117 installerProcess->write("-----BEGIN CERTIFICATE LIST-----\r\n");
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
118 installerProcess->write(validList.rawData().toLatin1());
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
119 installerProcess->write("-----END CERTIFICATE LIST-----\r\n");
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
120
150
a99339d0dce8 Fix test for invalid instructions
Andre Heinecke <aheinecke@intevation.de>
parents: 141
diff changeset
121 installerProcess->write("I:ABCDEF\r\n");
100
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
122
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
123 finishVerify(installerProcess, ERR_INVALID_INSTRUCTIONS);
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
124 }
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
125
151
0df62decff90 Test if uninstall is handled as instruction
Andre Heinecke <aheinecke@intevation.de>
parents: 150
diff changeset
126 void CinstProcessTest::testUninstall() {
0df62decff90 Test if uninstall is handled as instruction
Andre Heinecke <aheinecke@intevation.de>
parents: 150
diff changeset
127 QProcess* installerProcess = startCinstProcess();
0df62decff90 Test if uninstall is handled as instruction
Andre Heinecke <aheinecke@intevation.de>
parents: 150
diff changeset
128 QVERIFY(installerProcess->state() == QProcess::Running);
0df62decff90 Test if uninstall is handled as instruction
Andre Heinecke <aheinecke@intevation.de>
parents: 150
diff changeset
129
0df62decff90 Test if uninstall is handled as instruction
Andre Heinecke <aheinecke@intevation.de>
parents: 150
diff changeset
130 installerProcess->write("-----BEGIN CERTIFICATE LIST-----\r\n");
0df62decff90 Test if uninstall is handled as instruction
Andre Heinecke <aheinecke@intevation.de>
parents: 150
diff changeset
131 installerProcess->write(validList.rawData().toLatin1());
0df62decff90 Test if uninstall is handled as instruction
Andre Heinecke <aheinecke@intevation.de>
parents: 150
diff changeset
132 installerProcess->write("-----END CERTIFICATE LIST-----\r\n");
0df62decff90 Test if uninstall is handled as instruction
Andre Heinecke <aheinecke@intevation.de>
parents: 150
diff changeset
133
0df62decff90 Test if uninstall is handled as instruction
Andre Heinecke <aheinecke@intevation.de>
parents: 150
diff changeset
134 installerProcess->write("UNINSTALL\r\n");
0df62decff90 Test if uninstall is handled as instruction
Andre Heinecke <aheinecke@intevation.de>
parents: 150
diff changeset
135
159
37c9653b8755 Rename NO_ERROR as NO_ERROR is already defined in windows.h
Andre Heinecke <aheinecke@intevation.de>
parents: 151
diff changeset
136 finishVerify(installerProcess, ERR_NO_ERROR);
151
0df62decff90 Test if uninstall is handled as instruction
Andre Heinecke <aheinecke@intevation.de>
parents: 150
diff changeset
137 }
0df62decff90 Test if uninstall is handled as instruction
Andre Heinecke <aheinecke@intevation.de>
parents: 150
diff changeset
138
100
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
139 QTEST_GUILESS_MAIN (CinstProcessTest);

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