Mercurial > trustbridge
comparison 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 |
comparison
equal
deleted
inserted
replaced
297:f733f4aa2a90 | 298:56507c3d5f1e |
---|---|
1 #include "cinstprocesstest.h" | 1 #include "cinstprocesstest.h" |
2 #include "certificatelist.h" | 2 #include "certificatelist.h" |
3 #include "errorcodes.h" | 3 #include "errorcodes.h" |
4 #include "common.h" | |
4 | 5 |
5 #include <QDebug> | 6 #include <QDebug> |
6 #include <QDir> | 7 #include <QDir> |
7 #include <QFile> | 8 #include <QFile> |
8 #include <QProcess> | 9 #include <QProcess> |
118 QProcess* installerProcess = startCinstProcess(args); | 119 QProcess* installerProcess = startCinstProcess(args); |
119 finishVerify(installerProcess, ERR_INVALID_INPUT_NO_LIST); | 120 finishVerify(installerProcess, ERR_INVALID_INPUT_NO_LIST); |
120 } | 121 } |
121 | 122 |
122 void CinstProcessTest::testGarbageInput() { | 123 void CinstProcessTest::testGarbageInput() { |
123 QProcess* installerProcess = startCinstProcess(); | 124 QStringList args; |
124 QVERIFY(installerProcess->state() == QProcess::Running); | |
125 /* Garbage */ | |
126 installerProcess = startCinstProcess(); | |
127 installerProcess->write("-----BEGIN CERTIFICATE LIST-----\r\n"); | |
128 int retval=0; | |
129 int bytesWritten=0; | |
130 do { | |
131 char garbage[1030]; | |
132 for (int i = 0; i < 1030; i++) { | |
133 garbage[i] = (char) qrand() % 255; | |
134 } | |
135 retval = installerProcess->write(garbage, 1030); | |
136 bytesWritten += retval; | |
137 } while (retval != -1 && bytesWritten < 15 *1024 *1024 ); | |
138 | 125 |
139 finishVerify(installerProcess, ERR_INVALID_INPUT); | 126 QString garbage = getRandomDataFile(21*1024*1024); |
127 args << "list=" + garbage; | |
128 | |
129 QTemporaryFile instructions; | |
130 instructions.open(); | |
131 foreach (const Certificate &cert, validList.getCertificates()) { | |
132 instructions.write(cert.base64Line().toLatin1()); | |
133 instructions.write("\n"); | |
134 } | |
135 instructions.close(); | |
136 | |
137 args << "instructions=" + instructions.fileName(); | |
138 | |
139 QProcess* installerProcess = startCinstProcess(args); | |
140 /* If the following failed there may be leftovers in /tmp */ | |
141 finishVerify(installerProcess, ERR_INVALID_INPUT_NO_LIST); | |
142 QVERIFY(QFile::remove(garbage)); | |
140 } | 143 } |
141 | 144 |
142 void CinstProcessTest::testNoInput() { | 145 void CinstProcessTest::testNoInput() { |
143 QProcess* installerProcess = startCinstProcess(); | 146 QStringList args; |
144 QVERIFY(installerProcess->state() == QProcess::Running); | 147 args << "list=foobazbuf"; |
145 | 148 args << "instructions=bazbuffoo"; |
146 /* Nothing */ | 149 QProcess* installerProcess; |
147 installerProcess = startCinstProcess(); | 150 installerProcess = startCinstProcess(args); |
148 finishVerify(installerProcess, ERR_INVALID_INPUT_NO_LIST); | 151 finishVerify(installerProcess, ERR_INVALID_INPUT_NO_LIST); |
149 } | 152 } |
150 | 153 |
151 | 154 |
152 void CinstProcessTest::testNoInstructions() { | 155 void CinstProcessTest::testNoInstructions() { |
153 /* No instructions */ | 156 /* No instructions */ |
154 QProcess* installerProcess = startCinstProcess(); | 157 QTemporaryFile emptyFile; |
155 QVERIFY(installerProcess->state() == QProcess::Running); | 158 emptyFile.open(); |
156 installerProcess->write("-----BEGIN CERTIFICATE LIST-----\r\n"); | 159 emptyFile.close(); |
157 installerProcess->write(validList.rawData().toLatin1()); | |
158 installerProcess->write("-----END CERTIFICATE LIST-----\r\n"); | |
159 | 160 |
161 QStringList args; | |
162 args << "list=" + validListFile.fileName(); | |
163 args << "instructions=" + emptyFile.fileName(); | |
164 | |
165 QProcess* installerProcess = startCinstProcess(args); | |
160 finishVerify(installerProcess, ERR_NO_INSTRUCTIONS); | 166 finishVerify(installerProcess, ERR_NO_INSTRUCTIONS); |
161 } | 167 } |
162 | 168 |
163 void CinstProcessTest::testInvalidInstruction() { | 169 void CinstProcessTest::testInvalidInstruction() { |
164 QProcess* installerProcess = startCinstProcess(); | 170 QStringList args; |
165 QVERIFY(installerProcess->state() == QProcess::Running); | 171 args << "list=" + validListFile.fileName(); |
166 | 172 |
167 installerProcess->write("-----BEGIN CERTIFICATE LIST-----\r\n"); | 173 QTemporaryFile instructions; |
168 installerProcess->write(validList.rawData().toLatin1()); | 174 instructions.open(); |
169 installerProcess->write("-----END CERTIFICATE LIST-----\r\n"); | 175 foreach (const Certificate &cert, validList.getCertificates()) { |
176 instructions.write(cert.base64Line().toLatin1()); | |
177 instructions.write("\n"); | |
178 } | |
179 instructions.write("I:ABCDEF\n"); | |
180 instructions.close(); | |
170 | 181 |
171 installerProcess->write("I:ABCDEF\r\n"); | 182 args << "instructions=" + instructions.fileName(); |
183 | |
184 QProcess* installerProcess = startCinstProcess(args); | |
172 | 185 |
173 finishVerify(installerProcess, ERR_INVALID_INSTRUCTIONS); | 186 finishVerify(installerProcess, ERR_INVALID_INSTRUCTIONS); |
174 } | 187 } |
175 | 188 |
176 void CinstProcessTest::testUninstall() { | 189 void CinstProcessTest::testUninstall() { |
177 QProcess* installerProcess = startCinstProcess(); | 190 QStringList args; |
178 QVERIFY(installerProcess->state() == QProcess::Running); | 191 args << "list=" + validListFile.fileName(); |
192 args << "instructions=uninstall"; | |
179 | 193 |
180 installerProcess->write("-----BEGIN CERTIFICATE LIST-----\r\n"); | 194 QProcess* installerProcess = startCinstProcess(args); |
181 installerProcess->write(validList.rawData().toLatin1()); | |
182 installerProcess->write("-----END CERTIFICATE LIST-----\r\n"); | |
183 | |
184 installerProcess->write("UNINSTALL\r\n"); | |
185 | 195 |
186 finishVerify(installerProcess, ERR_NO_ERROR); | 196 finishVerify(installerProcess, ERR_NO_ERROR); |
187 } | 197 } |
188 | 198 |
189 QTEST_GUILESS_MAIN (CinstProcessTest); | 199 QTEST_GUILESS_MAIN (CinstProcessTest); |