Mercurial > trustbridge
changeset 563:aee3eb10bbba
Add unit test for sw update execution and fix shell execute params
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Thu, 22 May 2014 15:18:06 +0000 |
parents | ccdc4c6b97ce |
children | f115da3645d5 |
files | ui/mainwindow.cpp ui/mainwindow.h ui/tests/CMakeLists.txt ui/tests/fakeinstaller.c ui/tests/mainwindowtest.cpp |
diffstat | 5 files changed, 50 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- 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 */ - QProcess installerProcess; - installerProcess.setProgram(fileName); + qDebug() << "Starting process " << filePath; - qDebug() << "Starting process " << fileName; - - if (!installerProcess.waitForStarted() || - installerProcess.state() == QProcess::NotRunning) { + if (!QProcess::startDetached(filePath)) { qDebug() << "Failed to start process."; return; }
--- 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. *
--- 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)
--- /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; +}
--- 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);