sal/cppunittester/cppunittester.cxx |   19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

New commits:
commit 1f24d35033c2f02335ce254bbcf6ba89e1b7565e
Author:     Mike Kaganski <[email protected]>
AuthorDate: Fri Jul 7 16:02:08 2023 +0300
Commit:     Mike Kaganski <[email protected]>
CommitDate: Sun Jul 9 10:40:33 2023 +0200

    cppunittester: use a dedicated desktop on Windows
    
    Since introduction of accessibility tests infrastructure in commit
    0185ddd6d5f0324ba57b3fa36229103a6b27138e (Add infrastructure and
    basic tests including slight UI interaction, 2022-08-01) and the
    respective tests, running 'make check' on Windows produces pop-up
    dialogs, while these tests run. These dialogs distract, steal focus,
    swallow text that I type elsewhere, and may fail the tests if
    accidental user input interferes with what the tests check.
    
    This commit creates a dedicated system desktop for cppunittests,
    which would be isolated from the active desktop, yet allow creation
    of windows, thus not preventing accessibility testing. This way,
    it workarounds unavailability of svp vcl plugin on Windows.
    
    Change-Id: I83db54c82bfe98d14171355cc19cdd5767549fdb
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154194
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <[email protected]>

diff --git a/sal/cppunittester/cppunittester.cxx 
b/sal/cppunittester/cppunittester.cxx
index 6729903edd5d..50910fecfdd7 100644
--- a/sal/cppunittester/cppunittester.cxx
+++ b/sal/cppunittester/cppunittester.cxx
@@ -40,6 +40,7 @@
 #include <string>
 #include <sal/log.hxx>
 #include <sal/types.h>
+#include <comphelper/scopeguard.hxx>
 #include <cppunittester/protectorfactory.hxx>
 #include <osl/module.h>
 #include <osl/module.hxx>
@@ -404,6 +405,24 @@ static bool main2()
     _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG|_CRTDBG_MODE_FILE);
     _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
 #endif
+    // Create a desktop, to avoid popups interferring with active user session,
+    // because on Windows, we don't use svp vcl plugin for unit testing
+    HDESK hDesktop = nullptr;
+    comphelper::ScopeGuard desktopRestore(
+        [&hDesktop, hPrevDesktop = GetThreadDesktop(GetCurrentThreadId())]()
+        {
+            if (hDesktop)
+            {
+                SetThreadDesktop(hPrevDesktop);
+                CloseDesktop(hDesktop);
+            }
+        });
+    if (getenv("CPPUNIT_DEFAULT_DESKTOP") == nullptr)
+    {
+        hDesktop = CreateDesktopW(L"LO_CPPUNIT_DESKTOP", nullptr, nullptr, 0, 
GENERIC_ALL, nullptr);
+        if (hDesktop)
+            SetThreadDesktop(hDesktop);
+    }
 #endif
 
     std::vector<CppUnit::Protector *> protectors;

Reply via email to