Mercurial > trustbridge
comparison ui/tests/certlistparsertest.cpp @ 243:4b67cc2d4dad
Merged
author | Sascha Wilde <wilde@intevation.de> |
---|---|
date | Fri, 28 Mar 2014 18:38:34 +0100 |
parents | c05e126b0b9e |
children | 6a7eb102716d |
comparison
equal
deleted
inserted
replaced
242:809eaca3898c | 243:4b67cc2d4dad |
---|---|
1 #include "certlistparsertest.h" | 1 #include "certlistparsertest.h" |
2 #include "certificatelist.h" | 2 #include "certificatelist.h" |
3 #include "certificate.h" | 3 #include "certificate.h" |
4 #include "common.h" | |
4 | 5 |
5 #include <QDebug> | 6 #include <QDebug> |
6 | 7 |
7 void CertListTest::testValidList() | 8 void CertListTest::testValidList() |
8 { | 9 { |
112 QVERIFY(QFile::remove(fname2)); | 113 QVERIFY(QFile::remove(fname2)); |
113 QCOMPARE (certList->getStatus(), InvalidFormat); | 114 QCOMPARE (certList->getStatus(), InvalidFormat); |
114 delete certList; | 115 delete certList; |
115 } | 116 } |
116 | 117 |
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; | |
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(); | |
146 } | |
147 | |
148 void CertListTest::testTooLarge() | 118 void CertListTest::testTooLarge() |
149 { | 119 { |
150 QString fname = getRandomDataFile(MAX_LINE_LENGTH * MAX_LINES + 1); | 120 QString fname = getRandomDataFile(MAX_LINE_LENGTH * MAX_LINES + 1); |
151 CertificateList *certList = testWithFile(fname.toLocal8Bit().constData()); | 121 CertificateList *certList = testWithFile(fname.toLocal8Bit().constData()); |
152 QVERIFY(QFile::remove(fname)); | 122 QVERIFY(QFile::remove(fname)); |