[PATCH] Add unit test for sw update execution and fix shell execute params
Wald Commits
scm-commit at wald.intevation.org
Thu May 22 17:18:31 CEST 2014
# HG changeset patch
# User Andre Heinecke <aheinecke at intevation.de>
# Date 1400771886 0
# Node ID aee3eb10bbba50fc8c7de2c28ad8f9a4d0b160dd
# Parent ccdc4c6b97ce868cbb3bbb7a3030cf522035ccbf
Add unit test for sw update execution and fix shell execute params
diff -r ccdc4c6b97ce -r aee3eb10bbba ui/mainwindow.cpp
--- a/ui/mainwindow.cpp Thu May 22 15:29:59 2014 +0200
+++ b/ui/mainwindow.cpp Thu May 22 15:18:06 2014 +0000
@@ -14,6 +14,7 @@
#include <QSystemTrayIcon>
#include <QAction>
#include <QDialog>
+#include <QDir>
#include <QMenu>
#include <QApplication>
#include <QFile>
@@ -149,7 +150,6 @@
mSettings.remove("List/installedDate");
}
} else {
- // Make sure the available notation is also removed
mSettings.remove("List/installed");
mSettings.remove("List/installedDate");
}
@@ -201,10 +201,15 @@
setState(TransferError);
return;
}
+ QString filePath = QDir::toNativeSeparators(instProcInfo.absoluteFilePath());
#ifdef WIN32
SHELLEXECUTEINFOW shExecInfo;
- shExecInfo.lpFile = reinterpret_cast<LPCWSTR> (
- QDir::toNativeSeparators(instProcInfo.absoluteFilePath()).utf16());
+ memset (&shExecInfo, 0, sizeof(SHELLEXECUTEINFOW));
+ shExecInfo.cbSize = sizeof(SHELLEXECUTEINFOW);
+
+ shExecInfo.lpFile = reinterpret_cast<LPCWSTR> (filePath.utf16());
+
+ shExecInfo.fMask = SEE_MASK_NOASYNC;
if (!is_admin()) {
shExecInfo.lpVerb = L"open";
@@ -212,8 +217,7 @@
shExecInfo.lpVerb = L"runas";
}
- qDebug() << "Admin? " << is_admin();
- qDebug() << "Starting processs: " << QDir::toNativeSeparators(instProcInfo.absoluteFilePath());
+ qDebug() << "Starting process: " << filePath;
if (!ShellExecuteExW(&shExecInfo)) {
/* Execution failed, maybe the user aborted the UAC check? */
@@ -224,15 +228,10 @@
setState(NewSoftwareAvailable);
return;
}
+#else /* WIN32 */
+ qDebug() << "Starting process " << filePath;
-#else /* WIN32 */
- QProcess installerProcess;
- installerProcess.setProgram(fileName);
-
- qDebug() << "Starting process " << fileName;
-
- if (!installerProcess.waitForStarted() ||
- installerProcess.state() == QProcess::NotRunning) {
+ if (!QProcess::startDetached(filePath)) {
qDebug() << "Failed to start process.";
return;
}
diff -r ccdc4c6b97ce -r aee3eb10bbba ui/mainwindow.h
--- a/ui/mainwindow.h Thu May 22 15:29:59 2014 +0200
+++ b/ui/mainwindow.h Thu May 22 15:18:06 2014 +0000
@@ -125,7 +125,7 @@
*
* Perform a clean exit (saving state etc.) and close
* the application */
- void closeApp();
+ virtual void closeApp();
/* @brief Execute the file fileName to install the softwareupdate.
*
diff -r ccdc4c6b97ce -r aee3eb10bbba ui/tests/CMakeLists.txt
--- a/ui/tests/CMakeLists.txt Thu May 22 15:29:59 2014 +0200
+++ b/ui/tests/CMakeLists.txt Thu May 22 15:18:06 2014 +0000
@@ -60,6 +60,9 @@
add_custom_test(createcertlisttest.cpp "")
add_custom_test(mainwindowtest.cpp "")
+# Using fakeinstaller here would cause windows UAC heuristics to trigger
+add_executable(fakeinst fakeinstaller.c)
+
if (WIN32)
add_custom_test(windowsstoretest.cpp "${CMAKE_SOURCE_DIR}/cinst/windowsstore.c")
endif (WIN32)
diff -r ccdc4c6b97ce -r aee3eb10bbba ui/tests/fakeinstaller.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ui/tests/fakeinstaller.c Thu May 22 15:18:06 2014 +0000
@@ -0,0 +1,26 @@
+/* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik
+* Software engineering by Intevation GmbH
+
+* This file is Free Software under the GNU GPL (v>=2)
+* and comes with ABSOLUTELY NO WARRANTY!
+* See LICENSE.txt for details. */
+
+/**@file dummy program to test installer execution */
+
+#include <stdio.h>
+#ifdef WIN32
+#include <windows.h>
+#endif
+
+int main() {
+
+ int i = 0;
+#ifdef WIN32
+ OutputDebugStringA("Fakeinstaller started.");
+#else
+ printf("Fakeinstaller started\n");
+#endif
+ for (; i < 0x0fffffff; i++);
+
+ return 0;
+}
diff -r ccdc4c6b97ce -r aee3eb10bbba ui/tests/mainwindowtest.cpp
--- a/ui/tests/mainwindowtest.cpp Thu May 22 15:29:59 2014 +0200
+++ b/ui/tests/mainwindowtest.cpp Thu May 22 15:18:06 2014 +0000
@@ -8,6 +8,8 @@
#include "mainwindowtest.h"
+#include <QSignalSpy>
+
#ifdef Q_OS_WIN
Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin)
#else
@@ -26,7 +28,13 @@
}
void MainWindowTest::testValidUpdate() {
- // TODO
+ QSignalSpy closed(this, SIGNAL(closeCalled()));
+#ifdef Q_OS_WIN
+ installNewSW(QString::fromLatin1("c:/fakeinst.exe"), QDateTime::currentDateTime());
+#else
+ installNewSW(QString::fromLatin1("fakeinst"), QDateTime::currentDateTime());
+#endif
+ QVERIFY(closed.count() == 1);
}
QTEST_MAIN(MainWindowTest);
More information about the Trustbridge-commits
mailing list