annotate ui/tests/certlistparsertest.cpp @ 213:3ebebd055d3a

Refactored the list update dialog. Now it looks a bit more like the mainwindow.
author Raimund Renkert <rrenkert@intevation.de>
date Thu, 27 Mar 2014 09:08:44 +0100
parents 825b42da1855
children c05e126b0b9e
rev   line source
7
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
1 #include "certlistparsertest.h"
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
2 #include "certificatelist.h"
87
be13e5e0a98f Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents: 50
diff changeset
3 #include "certificate.h"
7
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
4
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
5 #include <QDebug>
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
6
31
37fc66967517 Implement signature verification wiht polarssl
Andre Heinecke <aheinecke@intevation.de>
parents: 26
diff changeset
7 void CertListTest::testValidList()
37fc66967517 Implement signature verification wiht polarssl
Andre Heinecke <aheinecke@intevation.de>
parents: 26
diff changeset
8 {
37fc66967517 Implement signature verification wiht polarssl
Andre Heinecke <aheinecke@intevation.de>
parents: 26
diff changeset
9 const char *fname = "list-valid-signed.txt";
88
abc76b750ea8 Fix extended list test. Add Benchmarking again
Andre Heinecke <aheinecke@intevation.de>
parents: 87
diff changeset
10
abc76b750ea8 Fix extended list test. Add Benchmarking again
Andre Heinecke <aheinecke@intevation.de>
parents: 87
diff changeset
11 QDir dataDir = QDir(SOURCE_DIR"/data/");
abc76b750ea8 Fix extended list test. Add Benchmarking again
Andre Heinecke <aheinecke@intevation.de>
parents: 87
diff changeset
12 QString fileName = dataDir.absoluteFilePath(fname);
abc76b750ea8 Fix extended list test. Add Benchmarking again
Andre Heinecke <aheinecke@intevation.de>
parents: 87
diff changeset
13 QFile validList(fileName);
87
be13e5e0a98f Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents: 50
diff changeset
14 validList.open(QIODevice::ReadOnly);
be13e5e0a98f Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents: 50
diff changeset
15 QString validData = QString::fromLatin1(validList.readAll());
be13e5e0a98f Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents: 50
diff changeset
16 QStringList instLines;
be13e5e0a98f Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents: 50
diff changeset
17 QStringList remoLines;
be13e5e0a98f Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents: 50
diff changeset
18
31
37fc66967517 Implement signature verification wiht polarssl
Andre Heinecke <aheinecke@intevation.de>
parents: 26
diff changeset
19 CertificateList *certList = testWithFile(fname);
87
be13e5e0a98f Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents: 50
diff changeset
20 QCOMPARE(certList->getStatus(), Valid);
be13e5e0a98f Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents: 50
diff changeset
21 QVERIFY(certList->isValid());
be13e5e0a98f Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents: 50
diff changeset
22
be13e5e0a98f Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents: 50
diff changeset
23 QVERIFY(certList->rawData() == validData.toLatin1());
be13e5e0a98f Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents: 50
diff changeset
24
be13e5e0a98f Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents: 50
diff changeset
25 const QList<Certificate> instList = certList->getInstallCertificates();
88
abc76b750ea8 Fix extended list test. Add Benchmarking again
Andre Heinecke <aheinecke@intevation.de>
parents: 87
diff changeset
26 const QList<Certificate> remoList = certList->getRemoveCertificates();
87
be13e5e0a98f Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents: 50
diff changeset
27
be13e5e0a98f Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents: 50
diff changeset
28 foreach (QString act, validData.split("\r\n")) {
be13e5e0a98f Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents: 50
diff changeset
29 if (act.startsWith("I:")) {
be13e5e0a98f Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents: 50
diff changeset
30 instLines << act;
be13e5e0a98f Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents: 50
diff changeset
31 continue;
be13e5e0a98f Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents: 50
diff changeset
32 }
be13e5e0a98f Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents: 50
diff changeset
33 if (act.startsWith("R:")) {
be13e5e0a98f Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents: 50
diff changeset
34 remoLines << act;
be13e5e0a98f Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents: 50
diff changeset
35 continue;
be13e5e0a98f Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents: 50
diff changeset
36 }
be13e5e0a98f Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents: 50
diff changeset
37 }
be13e5e0a98f Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents: 50
diff changeset
38
be13e5e0a98f Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents: 50
diff changeset
39 foreach (const Certificate& cert, instList) {
be13e5e0a98f Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents: 50
diff changeset
40 QVERIFY(cert.isValid());
be13e5e0a98f Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents: 50
diff changeset
41 QVERIFY(instLines.contains(cert.base64Line()));
be13e5e0a98f Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents: 50
diff changeset
42 }
be13e5e0a98f Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents: 50
diff changeset
43 foreach (const Certificate& cert, remoList) {
be13e5e0a98f Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents: 50
diff changeset
44 QVERIFY(cert.isValid());
be13e5e0a98f Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents: 50
diff changeset
45 QVERIFY(remoLines.contains(cert.base64Line()));
be13e5e0a98f Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents: 50
diff changeset
46 }
be13e5e0a98f Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents: 50
diff changeset
47
be13e5e0a98f Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents: 50
diff changeset
48 /* Be variable if test data changes later */
be13e5e0a98f Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents: 50
diff changeset
49 QVERIFY(instList.size() >= 1);
be13e5e0a98f Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents: 50
diff changeset
50 QVERIFY(remoList.size() >= 1);
be13e5e0a98f Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents: 50
diff changeset
51 QVERIFY(instLines.size() == instList.size());
be13e5e0a98f Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents: 50
diff changeset
52 QVERIFY(remoLines.size() == remoList.size());
be13e5e0a98f Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents: 50
diff changeset
53
204
825b42da1855 Avoid printing an error when an empty certificate ist constructed
Andre Heinecke <andre.heinecke@intevation.de>
parents: 203
diff changeset
54 /* Check that a default certificate is invalid */
95
b0b1375dfd40 Add check for default ctor of Certificate. Fix return value of empty file
Andre Heinecke <aheinecke@intevation.de>
parents: 88
diff changeset
55 Certificate cert;
b0b1375dfd40 Add check for default ctor of Certificate. Fix return value of empty file
Andre Heinecke <aheinecke@intevation.de>
parents: 88
diff changeset
56 QVERIFY(!cert.isValid());
b0b1375dfd40 Add check for default ctor of Certificate. Fix return value of empty file
Andre Heinecke <aheinecke@intevation.de>
parents: 88
diff changeset
57
203
60c5df8e7980 Reinitialize certificatelist when readFile is called
Andre Heinecke <andre.heinecke@intevation.de>
parents: 202
diff changeset
58 certList->readList(fileName.toLocal8Bit().data());
60c5df8e7980 Reinitialize certificatelist when readFile is called
Andre Heinecke <andre.heinecke@intevation.de>
parents: 202
diff changeset
59
60c5df8e7980 Reinitialize certificatelist when readFile is called
Andre Heinecke <andre.heinecke@intevation.de>
parents: 202
diff changeset
60 const QList<Certificate> instList2 = certList->getInstallCertificates();
60c5df8e7980 Reinitialize certificatelist when readFile is called
Andre Heinecke <andre.heinecke@intevation.de>
parents: 202
diff changeset
61 const QList<Certificate> remoList2 = certList->getRemoveCertificates();
202
0861069fd6d0 Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 95
diff changeset
62 QVERIFY(instLines.size() == instList2.size());
0861069fd6d0 Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 95
diff changeset
63 QVERIFY(remoLines.size() == remoList2.size());
87
be13e5e0a98f Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents: 50
diff changeset
64
31
37fc66967517 Implement signature verification wiht polarssl
Andre Heinecke <aheinecke@intevation.de>
parents: 26
diff changeset
65 delete certList;
37fc66967517 Implement signature verification wiht polarssl
Andre Heinecke <aheinecke@intevation.de>
parents: 26
diff changeset
66 }
7
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
67
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
68 void CertListTest::testInvalidSig()
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
69 {
42
6e7ef7e95031 Some more tests and some more test data
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
70 const char *fnames[] = {"list-invalid-signed.txt",
6e7ef7e95031 Some more tests and some more test data
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
71 "list-valid-other-signature.txt",
6e7ef7e95031 Some more tests and some more test data
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
72 "list-valid-sha1-signature.txt",
6e7ef7e95031 Some more tests and some more test data
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
73 NULL};
6e7ef7e95031 Some more tests and some more test data
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
74 for (int i=0; fnames[i] != NULL; i++) {
6e7ef7e95031 Some more tests and some more test data
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
75 CertificateList *certList = testWithFile(fnames[i]);
6e7ef7e95031 Some more tests and some more test data
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
76 QCOMPARE (certList->getStatus(), InvalidSignature);
6e7ef7e95031 Some more tests and some more test data
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
77 delete certList;
6e7ef7e95031 Some more tests and some more test data
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
78 }
7
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
79 }
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
80
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
81 void verifyInvalidFile(const char *fName) {
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
82 CertificateList *certList = new CertificateList(fName);
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
83 QVERIFY (certList->getStatus() != Valid);
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
84 delete certList;
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
85 }
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
86
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
87 void CertListTest::testInvalidFileNames()
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
88 {
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
89 verifyInvalidFile("/dev/random");
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
90 verifyInvalidFile("/tmp/");
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
91 verifyInvalidFile(NULL);
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
92 verifyInvalidFile("ä");
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
93 verifyInvalidFile("💩 ");
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
94 }
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
95
42
6e7ef7e95031 Some more tests and some more test data
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
96 void CertListTest::testEmptyFile()
6e7ef7e95031 Some more tests and some more test data
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
97 {
6e7ef7e95031 Some more tests and some more test data
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
98 const char *fname = "empty_file";
6e7ef7e95031 Some more tests and some more test data
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
99 CertificateList *certList = testWithFile(fname);
95
b0b1375dfd40 Add check for default ctor of Certificate. Fix return value of empty file
Andre Heinecke <aheinecke@intevation.de>
parents: 88
diff changeset
100 QCOMPARE (certList->getStatus(), SeekFailed);
42
6e7ef7e95031 Some more tests and some more test data
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
101 delete certList;
6e7ef7e95031 Some more tests and some more test data
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
102 }
6e7ef7e95031 Some more tests and some more test data
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
103
7
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
104 void CertListTest::testGarbage()
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
105 {
202
0861069fd6d0 Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 95
diff changeset
106 const char *fname = "list-with-null.txt";
0861069fd6d0 Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 95
diff changeset
107 QString fname2 = getRandomDataFile(200);
0861069fd6d0 Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 95
diff changeset
108 CertificateList *certList = testWithFile(fname);
0861069fd6d0 Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 95
diff changeset
109 QCOMPARE (certList->getStatus(), InvalidFormat);
0861069fd6d0 Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 95
diff changeset
110 delete certList;
0861069fd6d0 Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 95
diff changeset
111 certList = testWithFile(fname2.toLocal8Bit().constData());
0861069fd6d0 Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 95
diff changeset
112 QVERIFY(QFile::remove(fname2));
0861069fd6d0 Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 95
diff changeset
113 QCOMPARE (certList->getStatus(), InvalidFormat);
0861069fd6d0 Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 95
diff changeset
114 delete certList;
0861069fd6d0 Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 95
diff changeset
115 }
0861069fd6d0 Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 95
diff changeset
116
0861069fd6d0 Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 95
diff changeset
117 QString CertListTest::getRandomDataFile(size_t size)
0861069fd6d0 Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 95
diff changeset
118 {
0861069fd6d0 Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 95
diff changeset
119 QTemporaryFile tmpfile;
0861069fd6d0 Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 95
diff changeset
120 tmpfile.setAutoRemove(false);
0861069fd6d0 Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 95
diff changeset
121 tmpfile.open();
0861069fd6d0 Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 95
diff changeset
122 size_t bufsize = 1024 * 1024;
0861069fd6d0 Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 95
diff changeset
123 if (bufsize > size) {
0861069fd6d0 Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 95
diff changeset
124 bufsize = size;
42
6e7ef7e95031 Some more tests and some more test data
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
125 }
202
0861069fd6d0 Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 95
diff changeset
126 char buf[bufsize];
0861069fd6d0 Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 95
diff changeset
127
0861069fd6d0 Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 95
diff changeset
128 for (size_t i = 0; i < bufsize; i++) {
0861069fd6d0 Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 95
diff changeset
129 buf[i] = (char) qrand() % 255;
0861069fd6d0 Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 95
diff changeset
130 }
0861069fd6d0 Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 95
diff changeset
131
0861069fd6d0 Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 95
diff changeset
132 size_t bytesWritten=0;
0861069fd6d0 Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 95
diff changeset
133 int retval = 0;
0861069fd6d0 Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 95
diff changeset
134 do {
0861069fd6d0 Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 95
diff changeset
135 size_t toWrite = size - bytesWritten;
0861069fd6d0 Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 95
diff changeset
136 if (toWrite < bufsize) {
0861069fd6d0 Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 95
diff changeset
137 retval = tmpfile.write(buf, toWrite);
0861069fd6d0 Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 95
diff changeset
138 } else {
0861069fd6d0 Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 95
diff changeset
139 retval = tmpfile.write(buf, bufsize);
0861069fd6d0 Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 95
diff changeset
140 }
0861069fd6d0 Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 95
diff changeset
141 bytesWritten += retval;
0861069fd6d0 Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 95
diff changeset
142 } while (retval != -1 && bytesWritten < size);
0861069fd6d0 Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 95
diff changeset
143
0861069fd6d0 Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 95
diff changeset
144 tmpfile.close();
0861069fd6d0 Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 95
diff changeset
145 return tmpfile.fileName();
7
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
146 }
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
147
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
148 void CertListTest::testTooLarge()
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
149 {
202
0861069fd6d0 Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 95
diff changeset
150 QString fname = getRandomDataFile(MAX_LINE_LENGTH * MAX_LINES + 1);
0861069fd6d0 Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 95
diff changeset
151 CertificateList *certList = testWithFile(fname.toLocal8Bit().constData());
0861069fd6d0 Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 95
diff changeset
152 QVERIFY(QFile::remove(fname));
0861069fd6d0 Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 95
diff changeset
153 QCOMPARE(certList->getStatus(), TooLarge);
0861069fd6d0 Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 95
diff changeset
154 QVERIFY(!certList->isValid());
7
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
155 delete certList;
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
156 }
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
157
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
158 void CertListTest::benchmarkValid()
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
159 {
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
160 const char *fname = "list-valid-signed.txt";
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
161
88
abc76b750ea8 Fix extended list test. Add Benchmarking again
Andre Heinecke <aheinecke@intevation.de>
parents: 87
diff changeset
162 QBENCHMARK{
7
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
163 CertificateList *certList = testWithFile(fname);
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
164 delete certList;
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
165 }
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
166 }
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
167
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
168 CertificateList* CertListTest::testWithFile(const char *filename)
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
169 {
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
170 QDir dataDir = QDir(SOURCE_DIR"/data/");
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
171 QString fileName = dataDir.absoluteFilePath(filename);
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
172 return new CertificateList(fileName.toLocal8Bit().data());
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
173 }
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
174
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
175 int main( int argc, char **argv )
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
176 {
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
177 CertListTest tc;
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
178 return QTest::qExec( &tc, argc, argv );
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
179 }
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
180
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
181

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