aheinecke@7: #include "certlistparsertest.h" aheinecke@7: #include "certificatelist.h" aheinecke@7: aheinecke@7: #include aheinecke@7: aheinecke@7: aheinecke@7: void CertListTest::testInvalidSig() aheinecke@7: { aheinecke@7: const char *fname = "list-invalid-signed.txt"; aheinecke@7: CertificateList *certList = testWithFile(fname); aheinecke@7: QCOMPARE (certList->getStatus(), InvalidSignature); aheinecke@7: delete certList; aheinecke@7: } aheinecke@7: aheinecke@7: void verifyInvalidFile(const char *fName) { aheinecke@7: CertificateList *certList = new CertificateList(fName); aheinecke@7: QVERIFY (certList->getStatus() != Valid); aheinecke@7: delete certList; aheinecke@7: } aheinecke@7: aheinecke@7: void CertListTest::testInvalidFileNames() aheinecke@7: { aheinecke@7: verifyInvalidFile("/dev/random"); aheinecke@7: verifyInvalidFile("/tmp/"); aheinecke@7: verifyInvalidFile(NULL); aheinecke@7: verifyInvalidFile("ä"); aheinecke@7: verifyInvalidFile("💩 "); aheinecke@7: } aheinecke@7: aheinecke@7: void CertListTest::testGarbage() aheinecke@7: { aheinecke@7: const char *fname = "random_500KB"; aheinecke@7: CertificateList *certList = testWithFile(fname); aheinecke@7: QCOMPARE (certList->getStatus(), InvalidFormat); aheinecke@7: delete certList; aheinecke@7: } aheinecke@7: aheinecke@7: void CertListTest::testTooLarge() aheinecke@7: { aheinecke@7: const char *fname = "random_2MB"; aheinecke@7: CertificateList *certList = testWithFile(fname); aheinecke@7: QCOMPARE (certList->getStatus(), TooLarge); aheinecke@7: QVERIFY (!certList->isValid()); aheinecke@7: delete certList; aheinecke@7: } aheinecke@7: aheinecke@7: void CertListTest::testValidList() aheinecke@7: { aheinecke@7: const char *fname = "list-valid-signed.txt"; aheinecke@7: CertificateList *certList = testWithFile(fname); aheinecke@7: QCOMPARE (certList->getStatus(), Valid); aheinecke@7: QVERIFY (certList->isValid()); aheinecke@7: delete certList; aheinecke@7: } aheinecke@7: aheinecke@7: void CertListTest::benchmarkValid() aheinecke@7: { aheinecke@7: const char *fname = "list-valid-signed.txt"; aheinecke@7: aheinecke@7: QBENCHMARK { aheinecke@7: CertificateList *certList = testWithFile(fname); aheinecke@7: delete certList; aheinecke@7: } aheinecke@7: } aheinecke@7: aheinecke@7: CertificateList* CertListTest::testWithFile(const char *filename) aheinecke@7: { aheinecke@7: QDir dataDir = QDir(SOURCE_DIR"/data/"); aheinecke@7: QString fileName = dataDir.absoluteFilePath(filename); aheinecke@7: return new CertificateList(fileName.toLocal8Bit().data()); aheinecke@7: } aheinecke@7: aheinecke@7: int main( int argc, char **argv ) aheinecke@7: { aheinecke@7: CertListTest tc; aheinecke@7: return QTest::qExec( &tc, argc, argv ); aheinecke@7: } aheinecke@7: aheinecke@7: