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 #include #include +#include #include #include #include @@ -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 protectors;