desktop/source/app/sofficemain.cxx      |   10 ++++++++++
 include/systools/win32/test_desktop.hxx |   31 +++++++++++++++++++++++++++++++
 sal/cppunittester/cppunittester.cxx     |    8 ++------
 3 files changed, 43 insertions(+), 6 deletions(-)

New commits:
commit 69586e8381037417d106d8474d9f73638c5b9c55
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Wed Jul 17 14:45:22 2024 +0500
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Wed Jul 17 18:13:19 2024 +0200

    UI tests: use a dedicated desktop on Windows
    
    Similar to commit 1f24d35033c2f02335ce254bbcf6ba89e1b7565e (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.kagan...@collabora.com>

diff --git a/desktop/source/app/sofficemain.cxx 
b/desktop/source/app/sofficemain.cxx
index 33881784d45c..7e38ac2b2807 100644
--- a/desktop/source/app/sofficemain.cxx
+++ b/desktop/source/app/sofficemain.cxx
@@ -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
diff --git a/include/systools/win32/test_desktop.hxx 
b/include/systools/win32/test_desktop.hxx
new file mode 100644
index 000000000000..fdd8640deb28
--- /dev/null
+++ b/include/systools/win32/test_desktop.hxx
@@ -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: */
diff --git a/sal/cppunittester/cppunittester.cxx 
b/sal/cppunittester/cppunittester.cxx
index 854c0999c911..610f8a8155ef 100644
--- a/sal/cppunittester/cppunittester.cxx
+++ b/sal/cppunittester/cppunittester.cxx
@@ -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;

Reply via email to