comparison ui/tests/windowsstoretest.cpp @ 1327:562d66614b5c

(issue169) Fix handling of exclusive locks.
author Andre Heinecke <andre.heinecke@intevation.de>
date Wed, 15 Oct 2014 13:06:19 +0200
parents 317ee9dc4684
children
comparison
equal deleted inserted replaced
1326:dd3eefda8503 1327:562d66614b5c
6 * See LICENSE.txt for details. 6 * See LICENSE.txt for details.
7 */ 7 */
8 #include "windowsstoretest.h" 8 #include "windowsstoretest.h"
9 #include "certificatelist.h" 9 #include "certificatelist.h"
10 #include "strhelp.h" 10 #include "strhelp.h"
11 #include "logging.h"
11 #include "certificate.h" 12 #include "certificate.h"
12 #include "../cinst/windowsstore.h" 13 #include "../cinst/windowsstore.h"
13 14
14 #include <QTest> 15 #include <QTest>
15 16
36 // Not used with a memory store 37 // Not used with a memory store
37 0, // Use the default provider 38 0, // Use the default provider
38 0, // No flags 39 0, // No flags
39 NULL); // Not needed 40 NULL); // Not needed
40 QVERIFY (testStore); 41 QVERIFY (testStore);
41 QFile res(":/list-valid-signed.txt"); 42 tmpFile.open(); // get the file name
42 res.open(QIODevice::ReadOnly); 43 /* This is not really a secure way to open a temporay file but it's ok
43 tmpFile.open(); 44 * for a unit test. The Problem is that qtemporaryfile prohibits obtaining
44 tmpFile.write(res.readAll()); 45 * an exclusive lock on the created file. */
46 QVERIFY(QFile::copy(":/list-valid-signed.txt", tmpFile.fileName() + "_exclusive"));
45 tmpFile.close(); 47 tmpFile.close();
46 48
47 validList = CertificateList(tmpFile.fileName().toLocal8Bit().data()); 49 validList = CertificateList((tmpFile.fileName() + "_exclusive").toLocal8Bit().data());
50 QVERIFY(validList.isValid());
51 QVERIFY(validList.getCertificates().size() > 0);
48 } 52 }
49 53
50 void WindowsStoreTest::testInstRemove() { 54 void WindowsStoreTest::testInstRemove() {
51 char ** to_install = NULL, 55 char ** to_install = NULL,
52 ** to_remove = NULL; 56 ** to_remove = NULL;
66 cert.base64Line().size() - 2); 70 cert.base64Line().size() - 2);
67 } 71 }
68 72
69 /* Just a quick check for str_append_str functionality */ 73 /* Just a quick check for str_append_str functionality */
70 QVERIFY((size_t) instList.size() == strv_length(to_install)); 74 QVERIFY((size_t) instList.size() == strv_length(to_install));
75 QVERIFY(strv_length(to_install) > 0);
71 for (i = 0; i < strv_length(to_install); i++) { 76 for (i = 0; i < strv_length(to_install); i++) {
72 QVERIFY (instList[i].base64Line().right( 77 QVERIFY (instList[i].base64Line().right(
73 instList[i].base64Line().size() - 2) == 78 instList[i].base64Line().size() - 2) ==
74 QString::fromLatin1(to_install[i])); 79 QString::fromLatin1(to_install[i]));
75 } 80 }
92 i++; 97 i++;
93 } 98 }
94 QVERIFY ((size_t)instList.size() == i); 99 QVERIFY ((size_t)instList.size() == i);
95 100
96 /* Remove all except one */ 101 /* Remove all except one */
102 QVERIFY(strv_length(to_install));
97 for (i = 0; i < strv_length(to_install) - 1; i++) { 103 for (i = 0; i < strv_length(to_install) - 1; i++) {
98 strv_append(&to_remove, to_install[i], qstrlen(to_install[i])); 104 strv_append(&to_remove, to_install[i], qstrlen(to_install[i]));
99 } 105 }
100 106
101 do_remove(testStore, to_remove); 107 do_remove(testStore, to_remove);
154 strv_free(to_install); 160 strv_free(to_install);
155 strv_free(to_remove); 161 strv_free(to_remove);
156 } 162 }
157 163
158 void WindowsStoreTest::cleanupTestCase() { 164 void WindowsStoreTest::cleanupTestCase() {
165 QFile::remove(tmpFile.fileName() + "_exclusive");
159 CertCloseStore(testStore, 0); 166 CertCloseStore(testStore, 0);
160 } 167 }
161 168
162 bool g_debug = true; 169 bool g_debug = true;
163 170

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