Mercurial > trustbridge
comparison ui/tests/certlistparsertest.cpp @ 207:e35983a322d6
merged.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Wed, 26 Mar 2014 15:22:50 +0100 |
parents | 825b42da1855 |
children | c05e126b0b9e |
comparison
equal
deleted
inserted
replaced
206:d587d075eddc | 207:e35983a322d6 |
---|---|
49 QVERIFY(instList.size() >= 1); | 49 QVERIFY(instList.size() >= 1); |
50 QVERIFY(remoList.size() >= 1); | 50 QVERIFY(remoList.size() >= 1); |
51 QVERIFY(instLines.size() == instList.size()); | 51 QVERIFY(instLines.size() == instList.size()); |
52 QVERIFY(remoLines.size() == remoList.size()); | 52 QVERIFY(remoLines.size() == remoList.size()); |
53 | 53 |
54 /* Check that a default certificate is invalid */ | |
54 Certificate cert; | 55 Certificate cert; |
55 QVERIFY(!cert.isValid()); | 56 QVERIFY(!cert.isValid()); |
56 | 57 |
58 certList->readList(fileName.toLocal8Bit().data()); | |
59 | |
60 const QList<Certificate> instList2 = certList->getInstallCertificates(); | |
61 const QList<Certificate> remoList2 = certList->getRemoveCertificates(); | |
62 QVERIFY(instLines.size() == instList2.size()); | |
63 QVERIFY(remoLines.size() == remoList2.size()); | |
57 | 64 |
58 delete certList; | 65 delete certList; |
59 } | 66 } |
60 | 67 |
61 void CertListTest::testInvalidSig() | 68 void CertListTest::testInvalidSig() |
88 | 95 |
89 void CertListTest::testEmptyFile() | 96 void CertListTest::testEmptyFile() |
90 { | 97 { |
91 const char *fname = "empty_file"; | 98 const char *fname = "empty_file"; |
92 CertificateList *certList = testWithFile(fname); | 99 CertificateList *certList = testWithFile(fname); |
93 printf("Status :%i\n ",certList->getStatus()); | |
94 QCOMPARE (certList->getStatus(), SeekFailed); | 100 QCOMPARE (certList->getStatus(), SeekFailed); |
95 delete certList; | 101 delete certList; |
96 } | 102 } |
97 | 103 |
98 void CertListTest::testGarbage() | 104 void CertListTest::testGarbage() |
99 { | 105 { |
100 const char *fnames[] = {"garbage_500KB", | 106 const char *fname = "list-with-null.txt"; |
101 "list-with-null.txt", | 107 QString fname2 = getRandomDataFile(200); |
102 NULL}; | 108 CertificateList *certList = testWithFile(fname); |
103 for (int i=0; fnames[i] != NULL; i++) { | 109 QCOMPARE (certList->getStatus(), InvalidFormat); |
104 CertificateList *certList = testWithFile(fnames[i]); | 110 delete certList; |
105 QCOMPARE (certList->getStatus(), InvalidFormat); | 111 certList = testWithFile(fname2.toLocal8Bit().constData()); |
106 delete certList; | 112 QVERIFY(QFile::remove(fname2)); |
113 QCOMPARE (certList->getStatus(), InvalidFormat); | |
114 delete certList; | |
115 } | |
116 | |
117 QString CertListTest::getRandomDataFile(size_t size) | |
118 { | |
119 QTemporaryFile tmpfile; | |
120 tmpfile.setAutoRemove(false); | |
121 tmpfile.open(); | |
122 size_t bufsize = 1024 * 1024; | |
123 if (bufsize > size) { | |
124 bufsize = size; | |
107 } | 125 } |
126 char buf[bufsize]; | |
127 | |
128 for (size_t i = 0; i < bufsize; i++) { | |
129 buf[i] = (char) qrand() % 255; | |
130 } | |
131 | |
132 size_t bytesWritten=0; | |
133 int retval = 0; | |
134 do { | |
135 size_t toWrite = size - bytesWritten; | |
136 if (toWrite < bufsize) { | |
137 retval = tmpfile.write(buf, toWrite); | |
138 } else { | |
139 retval = tmpfile.write(buf, bufsize); | |
140 } | |
141 bytesWritten += retval; | |
142 } while (retval != -1 && bytesWritten < size); | |
143 | |
144 tmpfile.close(); | |
145 return tmpfile.fileName(); | |
108 } | 146 } |
109 | 147 |
110 void CertListTest::testTooLarge() | 148 void CertListTest::testTooLarge() |
111 { | 149 { |
112 const char *fname = "garbage_2MB"; | 150 QString fname = getRandomDataFile(MAX_LINE_LENGTH * MAX_LINES + 1); |
113 CertificateList *certList = testWithFile(fname); | 151 CertificateList *certList = testWithFile(fname.toLocal8Bit().constData()); |
114 QCOMPARE (certList->getStatus(), TooLarge); | 152 QVERIFY(QFile::remove(fname)); |
115 QVERIFY (!certList->isValid()); | 153 QCOMPARE(certList->getStatus(), TooLarge); |
154 QVERIFY(!certList->isValid()); | |
116 delete certList; | 155 delete certList; |
117 } | 156 } |
118 | 157 |
119 void CertListTest::benchmarkValid() | 158 void CertListTest::benchmarkValid() |
120 { | 159 { |