UI tests: use a dedicated desktop on Windows
Similar to commit 1f24d35033
(cppunittester:
use a dedicated desktop on Windows, 2023-07-09), this change allows to run
UI tests on Windows without them interferring with what you are doing.
The code testing LIBO_TEST_DEFAULT_DESKTOP environment variable to avoid
the separate desktop, and creating it, is extracted to a new function in
systools.
Change-Id: I6df3cb4ae581ae289e49b47d3135d01f632fbd95
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170615
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
This commit is contained in:
parent
aa938fe03c
commit
69586e8381
3 changed files with 43 additions and 6 deletions
|
@ -29,6 +29,10 @@
|
|||
// needed before sal/main.h to avoid redefinition of macros
|
||||
#include <prewin.h>
|
||||
|
||||
#if defined _WIN32
|
||||
#include <systools/win32/test_desktop.hxx>
|
||||
#endif
|
||||
|
||||
#include <rtl/bootstrap.hxx>
|
||||
#include <sal/main.h>
|
||||
#include <tools/extendapplicationenvironment.hxx>
|
||||
|
@ -51,6 +55,12 @@
|
|||
|
||||
extern "C" int DESKTOP_DLLPUBLIC soffice_main()
|
||||
{
|
||||
#if defined _WIN32
|
||||
// If this is a UI test, we may need to switch to a dedicated desktop
|
||||
if (getenv("LO_RUNNING_UI_TEST") != nullptr)
|
||||
sal::systools::maybeCreateTestDesktop();
|
||||
#endif
|
||||
|
||||
sal_detail_initialize(sal::detail::InitializeSoffice, nullptr);
|
||||
|
||||
#if HAVE_FEATURE_BREAKPAD
|
||||
|
|
31
include/systools/win32/test_desktop.hxx
Normal file
31
include/systools/win32/test_desktop.hxx
Normal file
|
@ -0,0 +1,31 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
|
||||
/*
|
||||
* This file is part of the LibreOffice project.
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <windows.h>
|
||||
|
||||
namespace sal::systools
|
||||
{
|
||||
// Create a desktop, to avoid popups interferring with active user session, because we don't use svp
|
||||
// vcl plugin on Windows for unit testing. Set LIBO_TEST_DEFAULT_DESKTOP environment variable to any
|
||||
// value when running the unit test process, to avoid use of a separate desktop.
|
||||
void maybeCreateTestDesktop()
|
||||
{
|
||||
if (getenv("LIBO_TEST_DEFAULT_DESKTOP") == nullptr)
|
||||
{
|
||||
if (HDESK hDesktop
|
||||
= CreateDesktopW(L"LIBO_TEST_DESKTOP", nullptr, nullptr, 0, GENERIC_ALL, nullptr))
|
||||
SetThreadDesktop(hDesktop);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
|
|
@ -22,6 +22,7 @@
|
|||
# define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
#include <windows.h>
|
||||
#include <systools/win32/test_desktop.hxx>
|
||||
#endif
|
||||
#if defined(_WIN32) && defined(_DEBUG)
|
||||
#include <dbghelp.h>
|
||||
|
@ -401,12 +402,7 @@ static bool main2()
|
|||
#endif
|
||||
// Create a desktop, to avoid popups interfering with active user session,
|
||||
// because on Windows, we don't use svp vcl plugin for unit testing
|
||||
if (getenv("CPPUNIT_DEFAULT_DESKTOP") == nullptr)
|
||||
{
|
||||
if (HDESK hDesktop
|
||||
= CreateDesktopW(L"LO_CPPUNIT_DESKTOP", nullptr, nullptr, 0, GENERIC_ALL, nullptr))
|
||||
SetThreadDesktop(hDesktop);
|
||||
}
|
||||
sal::systools::maybeCreateTestDesktop();
|
||||
#endif
|
||||
|
||||
std::vector<CppUnit::Protector *> protectors;
|
||||
|
|
Loading…
Reference in a new issue