diff ui/tests/certlistparsertest.cpp @ 87:be13e5e0a98f

Expand test to cover more functionality from certificate and certificatelist
author Andre Heinecke <aheinecke@intevation.de>
date Thu, 20 Mar 2014 16:23:31 +0000
parents a7b8cb29f1f6
children abc76b750ea8
line wrap: on
line diff
--- a/ui/tests/certlistparsertest.cpp	Thu Mar 20 16:23:02 2014 +0000
+++ b/ui/tests/certlistparsertest.cpp	Thu Mar 20 16:23:31 2014 +0000
@@ -1,14 +1,54 @@
 #include "certlistparsertest.h"
 #include "certificatelist.h"
+#include "certificate.h"
 
 #include <QDebug>
 
 void CertListTest::testValidList()
 {
     const char *fname = "list-valid-signed.txt";
+    QFile validList(fname);
+    validList.open(QIODevice::ReadOnly);
+    QString validData = QString::fromLatin1(validList.readAll());
+    QStringList instLines;
+    QStringList remoLines;
+
     CertificateList *certList = testWithFile(fname);
-    QCOMPARE (certList->getStatus(), Valid);
-    QVERIFY (certList->isValid());
+    QCOMPARE(certList->getStatus(), Valid);
+    QVERIFY(certList->isValid());
+
+    QVERIFY(certList->rawData() == validData.toLatin1());
+
+    const QList<Certificate> instList = certList->getInstallCertificates();
+    const QList<Certificate> remoList = certList->getInstallCertificates();
+
+    foreach (QString act, validData.split("\r\n")) {
+        if (act.startsWith("I:")) {
+            instLines << act;
+            continue;
+        }
+        if (act.startsWith("R:")) {
+            remoLines << act;
+            continue;
+        }
+    }
+
+    foreach (const Certificate& cert, instList) {
+        QVERIFY(cert.isValid());
+        QVERIFY(instLines.contains(cert.base64Line()));
+    }
+    foreach (const Certificate& cert, remoList) {
+        QVERIFY(cert.isValid());
+        QVERIFY(remoLines.contains(cert.base64Line()));
+    }
+
+    /* Be variable if test data changes later */
+    QVERIFY(instList.size() >= 1);
+    QVERIFY(remoList.size() >= 1);
+    QVERIFY(instLines.size() == instList.size());
+    QVERIFY(remoLines.size() == remoList.size());
+
+
     delete certList;
 }
 

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