Mercurial > trustbridge
diff ui/tests/certlistparsertest.cpp @ 26:cbd57d767dfa
Move layout around. Restructure CMakeLists
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Tue, 11 Mar 2014 19:00:35 +0100 |
parents | tests/certlistparsertest.cpp@2ad9a96518e3 |
children | 37fc66967517 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/tests/certlistparsertest.cpp Tue Mar 11 19:00:35 2014 +0100 @@ -0,0 +1,79 @@ +#include "certlistparsertest.h" +#include "certificatelist.h" + +#include <QDebug> + + +void CertListTest::testInvalidSig() +{ + const char *fname = "list-invalid-signed.txt"; + CertificateList *certList = testWithFile(fname); + QCOMPARE (certList->getStatus(), InvalidSignature); + delete certList; +} + +void verifyInvalidFile(const char *fName) { + CertificateList *certList = new CertificateList(fName); + QVERIFY (certList->getStatus() != Valid); + delete certList; +} + +void CertListTest::testInvalidFileNames() +{ + verifyInvalidFile("/dev/random"); + verifyInvalidFile("/tmp/"); + verifyInvalidFile(NULL); + verifyInvalidFile("ä"); + verifyInvalidFile("💩 "); +} + +void CertListTest::testGarbage() +{ + const char *fname = "random_500KB"; + CertificateList *certList = testWithFile(fname); + QCOMPARE (certList->getStatus(), InvalidFormat); + delete certList; +} + +void CertListTest::testTooLarge() +{ + const char *fname = "random_2MB"; + CertificateList *certList = testWithFile(fname); + QCOMPARE (certList->getStatus(), TooLarge); + QVERIFY (!certList->isValid()); + delete certList; +} + +void CertListTest::testValidList() +{ + const char *fname = "list-valid-signed.txt"; + CertificateList *certList = testWithFile(fname); + QCOMPARE (certList->getStatus(), Valid); + QVERIFY (certList->isValid()); + delete certList; +} + +void CertListTest::benchmarkValid() +{ + const char *fname = "list-valid-signed.txt"; + + QBENCHMARK_ONCE { + CertificateList *certList = testWithFile(fname); + delete certList; + } +} + +CertificateList* CertListTest::testWithFile(const char *filename) +{ + QDir dataDir = QDir(SOURCE_DIR"/data/"); + QString fileName = dataDir.absoluteFilePath(filename); + return new CertificateList(fileName.toLocal8Bit().data()); +} + +int main( int argc, char **argv ) +{ + CertListTest tc; + return QTest::qExec( &tc, argc, argv ); +} + +