annotate ui/tests/cinstprocesstest.cpp @ 108:39c42b5a5693

Syntax fix
author Andre Heinecke <aheinecke@intevation.de>
date Fri, 21 Mar 2014 16:05:33 +0000
parents 8fa273791242
children 5ed770c41a73
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 #include <QTest>
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
10
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
11 #define RELATIVE_CINST_PATH "../../cinst/cinst"
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 QProcess *CinstProcessTest::startCinstProcess() {
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
14 QProcess *installerProcess = new QProcess();
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
15 installerProcess->setProgram(RELATIVE_CINST_PATH);
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
16 installerProcess->start();
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
17 installerProcess->waitForStarted();
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
18 return installerProcess;
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
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
21 void finishVerify(QProcess *proc, int exitCode) {
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
22 proc->closeWriteChannel();
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
23 proc->waitForFinished();
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
24 QVERIFY(proc->exitStatus() == QProcess::NormalExit);
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
25 QVERIFY(proc->exitCode() == exitCode);
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
26 delete proc;
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
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
29 void CinstProcessTest::testValidInput() {
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
30 QProcess* installerProcess = startCinstProcess();
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
31 QVERIFY(installerProcess->state() == QProcess::Running);
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
32
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
33 installerProcess->write("-----BEGIN CERTIFICATE LIST-----\r\n");
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
34 installerProcess->write(validList.rawData().toLatin1());
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
35 installerProcess->write("-----END CERTIFICATE LIST-----\r\n");
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
36
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
37 foreach (const Certificate &cert, validList.getInstallCertificates()) {
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
38 installerProcess->write(cert.base64Line().toLatin1());
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
39 installerProcess->write("\r\n");
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
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
42 finishVerify(installerProcess, 0);
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
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
45 void CinstProcessTest::initTestCase() {
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
46 QDir dataDir = QDir(SOURCE_DIR"/data/");
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
47 QString fileName = dataDir.absoluteFilePath("list-valid-signed.txt");
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
48 validList = CertificateList(fileName.toLocal8Bit().data());
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
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
51 void CinstProcessTest::testNoList() {
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
52 /* No list */
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
53 QProcess* installerProcess = startCinstProcess();
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
54 QVERIFY(installerProcess->state() == QProcess::Running);
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
55 installerProcess->write("-----BEGIN CERTIFICATE LIST-----\r\n");
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
56 installerProcess->write("-----END CERTIFICATE LIST-----\r\n");
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 foreach (const Certificate &cert, validList.getInstallCertificates()) {
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
59 installerProcess->write(cert.base64Line().toLatin1());
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
60 installerProcess->write("\r\n");
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
61 }
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
62 finishVerify(installerProcess, ERR_INVALID_INPUT_NO_LIST);
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::testGarbageInput() {
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
66 QProcess* installerProcess = startCinstProcess();
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
67 QVERIFY(installerProcess->state() == QProcess::Running);
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
68 /* Garbage */
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
69 installerProcess = startCinstProcess();
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
70 installerProcess->write("-----BEGIN CERTIFICATE LIST-----\r\n");
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
71 int retval=0;
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
72 int bytesWritten=0;
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
73 do {
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
74 char garbage[1030];
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
75 for (int i = 0; i < 1030; i++) {
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
76 garbage[i] = (char) qrand() % 255;
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
77 }
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
78 retval = installerProcess->write(garbage, 1030);
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
79 bytesWritten += retval;
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
80 } while (retval != -1 && bytesWritten < 100 *1024 *1024 );
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 QVERIFY (bytesWritten < 100 *1024 *1024);
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 finishVerify(installerProcess, ERR_TOO_MUCH_INPUT);
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
85 }
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
86
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
87 void CinstProcessTest::testNoInput() {
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
88 QProcess* installerProcess = startCinstProcess();
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
89 QVERIFY(installerProcess->state() == QProcess::Running);
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 /* Nothing */
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
92 installerProcess = startCinstProcess();
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
93 finishVerify(installerProcess, ERR_INVALID_INPUT_NO_LIST);
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
94 }
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
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
97 void CinstProcessTest::testNoInstructions() {
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
98 /* No instructions */
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
99 QProcess* installerProcess = startCinstProcess();
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
100 QVERIFY(installerProcess->state() == QProcess::Running);
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
101 installerProcess->write("-----BEGIN CERTIFICATE LIST-----\r\n");
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
102 installerProcess->write(validList.rawData().toLatin1());
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
103 installerProcess->write("-----END CERTIFICATE LIST-----\r\n");
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 finishVerify(installerProcess, ERR_NO_INSTRUCTIONS);
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
106 }
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
107
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
108 void CinstProcessTest::testInvalidInstruction() {
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
109 QProcess* installerProcess = startCinstProcess();
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
110 QVERIFY(installerProcess->state() == QProcess::Running);
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 /* foobar as instruction */
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
113 installerProcess->write("-----BEGIN CERTIFICATE LIST-----\r\n");
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
114 installerProcess->write(validList.rawData().toLatin1());
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
115 installerProcess->write("-----END CERTIFICATE LIST-----\r\n");
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("foobar");
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 finishVerify(installerProcess, ERR_INVALID_INSTRUCTIONS);
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
120 }
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
121
8fa273791242 Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
122 QTEST_GUILESS_MAIN (CinstProcessTest);

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