[PATCH] (issue169) Fix handling of exclusive locks

Wald Commits scm-commit at wald.intevation.org
Wed Oct 15 13:06:22 CEST 2014


# HG changeset patch
# User Andre Heinecke <andre.heinecke at intevation.de>
# Date 1413371179 -7200
# Node ID 562d66614b5c88002f9643a925187b337810ee3b
# Parent  dd3eefda850327485c4ece866b426406118718f0
(issue169) Fix handling of exclusive locks.

diff -r dd3eefda8503 -r 562d66614b5c ui/tests/windowsstoretest.cpp
--- a/ui/tests/windowsstoretest.cpp	Wed Oct 15 10:03:48 2014 +0200
+++ b/ui/tests/windowsstoretest.cpp	Wed Oct 15 13:06:19 2014 +0200
@@ -8,6 +8,7 @@
 #include "windowsstoretest.h"
 #include "certificatelist.h"
 #include "strhelp.h"
+#include "logging.h"
 #include "certificate.h"
 #include "../cinst/windowsstore.h"
 
@@ -38,13 +39,16 @@
       0,                         // No flags
       NULL);                     // Not needed
     QVERIFY (testStore);
-    QFile res(":/list-valid-signed.txt");
-    res.open(QIODevice::ReadOnly);
-    tmpFile.open();
-    tmpFile.write(res.readAll());
+    tmpFile.open(); // get the file name
+    /* This is not really a secure way to open a temporay file but it's ok
+     * for a unit test. The Problem is that qtemporaryfile prohibits obtaining
+     * an exclusive lock on the created file. */
+    QVERIFY(QFile::copy(":/list-valid-signed.txt", tmpFile.fileName() + "_exclusive"));
     tmpFile.close();
 
-    validList = CertificateList(tmpFile.fileName().toLocal8Bit().data());
+    validList = CertificateList((tmpFile.fileName() + "_exclusive").toLocal8Bit().data());
+    QVERIFY(validList.isValid());
+    QVERIFY(validList.getCertificates().size() > 0);
 }
 
 void WindowsStoreTest::testInstRemove() {
@@ -68,6 +72,7 @@
 
     /* Just a quick check for str_append_str functionality */
     QVERIFY((size_t) instList.size() == strv_length(to_install));
+    QVERIFY(strv_length(to_install) > 0);
     for (i = 0; i < strv_length(to_install); i++) {
         QVERIFY (instList[i].base64Line().right(
                     instList[i].base64Line().size() - 2) ==
@@ -94,6 +99,7 @@
     QVERIFY ((size_t)instList.size() == i);
 
     /* Remove all except one */
+    QVERIFY(strv_length(to_install));
     for (i = 0; i < strv_length(to_install) - 1; i++) {
         strv_append(&to_remove, to_install[i], qstrlen(to_install[i]));
     }
@@ -156,6 +162,7 @@
 }
 
 void WindowsStoreTest::cleanupTestCase() {
+    QFile::remove(tmpFile.fileName() + "_exclusive");
     CertCloseStore(testStore, 0);
 }
 


More information about the Trustbridge-commits mailing list