Mercurial > trustbridge
annotate ui/tests/cinstprocesstest.cpp @ 117:080660b2ce7d
Merged
author | Sascha Wilde <wilde@intevation.de> |
---|---|
date | Fri, 21 Mar 2014 17:46:09 +0100 |
parents | 5ed770c41a73 |
children | f5fa39347366 |
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; |
115
5ed770c41a73
Change garbage input to invalid input. Fix InvalidInstructions test.
Andre Heinecke <aheinecke@intevation.de>
parents:
100
diff
changeset
|
80 } while (retval != -1 && bytesWritten < 15 *1024 *1024 ); |
100
8fa273791242
Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
81 |
115
5ed770c41a73
Change garbage input to invalid input. Fix InvalidInstructions test.
Andre Heinecke <aheinecke@intevation.de>
parents:
100
diff
changeset
|
82 finishVerify(installerProcess, ERR_INVALID_INPUT); |
100
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 |
8fa273791242
Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
85 void CinstProcessTest::testNoInput() { |
8fa273791242
Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
86 QProcess* installerProcess = startCinstProcess(); |
8fa273791242
Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
87 QVERIFY(installerProcess->state() == QProcess::Running); |
8fa273791242
Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
88 |
8fa273791242
Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
89 /* Nothing */ |
8fa273791242
Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
90 installerProcess = startCinstProcess(); |
8fa273791242
Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
91 finishVerify(installerProcess, ERR_INVALID_INPUT_NO_LIST); |
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 |
8fa273791242
Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
95 void CinstProcessTest::testNoInstructions() { |
8fa273791242
Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
96 /* No instructions */ |
8fa273791242
Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
97 QProcess* installerProcess = startCinstProcess(); |
8fa273791242
Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
98 QVERIFY(installerProcess->state() == QProcess::Running); |
8fa273791242
Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
99 installerProcess->write("-----BEGIN CERTIFICATE LIST-----\r\n"); |
8fa273791242
Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
100 installerProcess->write(validList.rawData().toLatin1()); |
8fa273791242
Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
101 installerProcess->write("-----END CERTIFICATE LIST-----\r\n"); |
8fa273791242
Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
102 |
8fa273791242
Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
103 finishVerify(installerProcess, ERR_NO_INSTRUCTIONS); |
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 |
8fa273791242
Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
106 void CinstProcessTest::testInvalidInstruction() { |
8fa273791242
Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
107 QProcess* installerProcess = startCinstProcess(); |
8fa273791242
Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
108 QVERIFY(installerProcess->state() == QProcess::Running); |
8fa273791242
Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
109 |
115
5ed770c41a73
Change garbage input to invalid input. Fix InvalidInstructions test.
Andre Heinecke <aheinecke@intevation.de>
parents:
100
diff
changeset
|
110 /* I: as instruction */ |
100
8fa273791242
Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
111 installerProcess->write("-----BEGIN CERTIFICATE LIST-----\r\n"); |
8fa273791242
Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
112 installerProcess->write(validList.rawData().toLatin1()); |
8fa273791242
Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
113 installerProcess->write("-----END CERTIFICATE LIST-----\r\n"); |
8fa273791242
Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
114 |
115
5ed770c41a73
Change garbage input to invalid input. Fix InvalidInstructions test.
Andre Heinecke <aheinecke@intevation.de>
parents:
100
diff
changeset
|
115 installerProcess->write("I:ABCDEF"); |
100
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 finishVerify(installerProcess, ERR_INVALID_INSTRUCTIONS); |
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 |
8fa273791242
Add test for cinstprocess
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
120 QTEST_GUILESS_MAIN (CinstProcessTest); |