comparison tests/certlistparsertest.cpp @ 7:992c0ec57660

Add unit tests make CertificateList work.
author Andre Heinecke <aheinecke@intevation.de>
date Wed, 12 Feb 2014 16:52:27 +0000
parents
children 2ad9a96518e3
comparison
equal deleted inserted replaced
6:1f6455d46b30 7:992c0ec57660
1 #include "certlistparsertest.h"
2 #include "certificatelist.h"
3
4 #include <QDebug>
5
6
7 void CertListTest::testInvalidSig()
8 {
9 const char *fname = "list-invalid-signed.txt";
10 CertificateList *certList = testWithFile(fname);
11 QCOMPARE (certList->getStatus(), InvalidSignature);
12 delete certList;
13 }
14
15 void verifyInvalidFile(const char *fName) {
16 CertificateList *certList = new CertificateList(fName);
17 QVERIFY (certList->getStatus() != Valid);
18 delete certList;
19 }
20
21 void CertListTest::testInvalidFileNames()
22 {
23 verifyInvalidFile("/dev/random");
24 verifyInvalidFile("/tmp/");
25 verifyInvalidFile(NULL);
26 verifyInvalidFile("ä");
27 verifyInvalidFile("💩 ");
28 }
29
30 void CertListTest::testGarbage()
31 {
32 const char *fname = "random_500KB";
33 CertificateList *certList = testWithFile(fname);
34 QCOMPARE (certList->getStatus(), InvalidFormat);
35 delete certList;
36 }
37
38 void CertListTest::testTooLarge()
39 {
40 const char *fname = "random_2MB";
41 CertificateList *certList = testWithFile(fname);
42 QCOMPARE (certList->getStatus(), TooLarge);
43 QVERIFY (!certList->isValid());
44 delete certList;
45 }
46
47 void CertListTest::testValidList()
48 {
49 const char *fname = "list-valid-signed.txt";
50 CertificateList *certList = testWithFile(fname);
51 QCOMPARE (certList->getStatus(), Valid);
52 QVERIFY (certList->isValid());
53 delete certList;
54 }
55
56 void CertListTest::benchmarkValid()
57 {
58 const char *fname = "list-valid-signed.txt";
59
60 QBENCHMARK {
61 CertificateList *certList = testWithFile(fname);
62 delete certList;
63 }
64 }
65
66 CertificateList* CertListTest::testWithFile(const char *filename)
67 {
68 QDir dataDir = QDir(SOURCE_DIR"/data/");
69 QString fileName = dataDir.absoluteFilePath(filename);
70 return new CertificateList(fileName.toLocal8Bit().data());
71 }
72
73 int main( int argc, char **argv )
74 {
75 CertListTest tc;
76 return QTest::qExec( &tc, argc, argv );
77 }
78
79

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