annotate ui/tests/cinstprocesstest.cpp @ 150:a99339d0dce8

Fix test for invalid instructions The missing line break made it invalid_input and not an instruction.
author Andre Heinecke <aheinecke@intevation.de>
date Mon, 24 Mar 2014 17:23:42 +0000
parents f5fa39347366
children 0df62decff90
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
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
20 void finishVerify(QProcess *proc, int exitCode) {
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
21 proc->closeWriteChannel();
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
22 proc->waitForFinished();
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
23 QVERIFY(proc->exitStatus() == QProcess::NormalExit);
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
24 QVERIFY(proc->exitCode() == exitCode);
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
25 delete proc;
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
26 }
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
27
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
28 void CinstProcessTest::testValidInput() {
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
29 QProcess* installerProcess = startCinstProcess();
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
30 QVERIFY(installerProcess->state() == QProcess::Running);
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
31
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
32 installerProcess->write("-----BEGIN CERTIFICATE LIST-----\r\n");
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
33 installerProcess->write(validList.rawData().toLatin1());
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
34 installerProcess->write("-----END CERTIFICATE LIST-----\r\n");
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 foreach (const Certificate &cert, validList.getInstallCertificates()) {
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
37 installerProcess->write(cert.base64Line().toLatin1());
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
38 installerProcess->write("\r\n");
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
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
41 finishVerify(installerProcess, 0);
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
42 }
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 void CinstProcessTest::initTestCase() {
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
45 QDir dataDir = QDir(SOURCE_DIR"/data/");
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
46 QString fileName = dataDir.absoluteFilePath("list-valid-signed.txt");
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
47 validList = CertificateList(fileName.toLocal8Bit().data());
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
48 }
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
49
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
50 void CinstProcessTest::testNoList() {
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
51 /* No list */
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
52 QProcess* installerProcess = startCinstProcess();
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
53 QVERIFY(installerProcess->state() == QProcess::Running);
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
54 installerProcess->write("-----BEGIN CERTIFICATE LIST-----\r\n");
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
55 installerProcess->write("-----END CERTIFICATE LIST-----\r\n");
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 foreach (const Certificate &cert, validList.getInstallCertificates()) {
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
58 installerProcess->write(cert.base64Line().toLatin1());
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
59 installerProcess->write("\r\n");
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
60 }
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
61 finishVerify(installerProcess, ERR_INVALID_INPUT_NO_LIST);
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
62 }
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 void CinstProcessTest::testGarbageInput() {
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
65 QProcess* installerProcess = startCinstProcess();
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
66 QVERIFY(installerProcess->state() == QProcess::Running);
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
67 /* Garbage */
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
68 installerProcess = startCinstProcess();
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
69 installerProcess->write("-----BEGIN CERTIFICATE LIST-----\r\n");
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
70 int retval=0;
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
71 int bytesWritten=0;
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
72 do {
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
73 char garbage[1030];
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
74 for (int i = 0; i < 1030; i++) {
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
75 garbage[i] = (char) qrand() % 255;
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
76 }
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
77 retval = installerProcess->write(garbage, 1030);
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
78 bytesWritten += retval;
115
5ed770c41a73 Change garbage input to invalid input. Fix InvalidInstructions test.
Andre Heinecke <aheinecke@intevation.de>
parents: 100
diff changeset
79 } while (retval != -1 && bytesWritten < 15 *1024 *1024 );
100
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
80
115
5ed770c41a73 Change garbage input to invalid input. Fix InvalidInstructions test.
Andre Heinecke <aheinecke@intevation.de>
parents: 100
diff changeset
81 finishVerify(installerProcess, ERR_INVALID_INPUT);
100
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
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
84 void CinstProcessTest::testNoInput() {
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
85 QProcess* installerProcess = startCinstProcess();
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
86 QVERIFY(installerProcess->state() == QProcess::Running);
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
87
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
88 /* Nothing */
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
89 installerProcess = startCinstProcess();
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
90 finishVerify(installerProcess, ERR_INVALID_INPUT_NO_LIST);
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
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
93
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
94 void CinstProcessTest::testNoInstructions() {
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
95 /* No instructions */
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
96 QProcess* installerProcess = startCinstProcess();
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
97 QVERIFY(installerProcess->state() == QProcess::Running);
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
98 installerProcess->write("-----BEGIN CERTIFICATE LIST-----\r\n");
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
99 installerProcess->write(validList.rawData().toLatin1());
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
100 installerProcess->write("-----END CERTIFICATE LIST-----\r\n");
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 finishVerify(installerProcess, ERR_NO_INSTRUCTIONS);
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
103 }
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
104
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
105 void CinstProcessTest::testInvalidInstruction() {
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
106 QProcess* installerProcess = startCinstProcess();
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
107 QVERIFY(installerProcess->state() == QProcess::Running);
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
108
115
5ed770c41a73 Change garbage input to invalid input. Fix InvalidInstructions test.
Andre Heinecke <aheinecke@intevation.de>
parents: 100
diff changeset
109 /* I: as instruction */
100
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
110 installerProcess->write("-----BEGIN CERTIFICATE LIST-----\r\n");
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
111 installerProcess->write(validList.rawData().toLatin1());
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
112 installerProcess->write("-----END CERTIFICATE LIST-----\r\n");
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
113
150
a99339d0dce8 Fix test for invalid instructions
Andre Heinecke <aheinecke@intevation.de>
parents: 141
diff changeset
114 installerProcess->write("I:ABCDEF\r\n");
100
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
115
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
116 finishVerify(installerProcess, ERR_INVALID_INSTRUCTIONS);
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
117 }
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
118
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
119 QTEST_GUILESS_MAIN (CinstProcessTest);

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