Files
Gabor Kelemen f8dad0daf9 tdf#146619 Use more forward declarations in include/vcl/svapp.hxx
this was skipped in previous runs, since it contains some code behind #if

After inspecting these, it seems like the removals should not cause trouble.

Change-Id: If1e3e3c7c0fc14ed6e8b51174a0e7f1220fdbc8b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/197496
Tested-by: Jenkins
Reviewed-by: Gabor Kelemen <gabor.kelemen@collabora.com>
2026-01-25 13:31:57 +01:00

112 lines
3.0 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* 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/.
*/
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/plugin/TestPlugIn.h>
#include <rtl/ref.hxx>
#include <vcl/svapp.hxx>
#include <vcl/idletask.hxx>
#include <salhelper/thread.hxx>
// This tests that IdleThread::waitUntilIdleDispatched actually waits until the main thread is idle
// and all event processing is actually completed instead of just waiting until all the events have
// just been popped off the queue.
namespace
{
void eventCallback(void*, void* pData)
{
bool* pDone = static_cast<bool*>(pData);
// Release the solar mutex for a little while. This shouldn’t
// cause waitUntilIdleDispatched to return
{
SolarMutexReleaser aRelease;
std::this_thread::sleep_for(std::chrono::seconds(10));
}
*pDone = true;
}
struct OtherThread : public salhelper::Thread
{
bool m_bDone;
OtherThread()
: salhelper::Thread("IdleTask test")
, m_bDone(false)
{
}
protected:
void execute() override;
private:
DECL_LINK(setDone, void*, void);
};
void OtherThread::execute()
{
bool bEventCallbackDone = false;
Application::PostUserEvent(LINK_NONMEMBER(nullptr, eventCallback), &bEventCallbackDone);
// Sleep for a little bit to make sure the main thread picks up
// the pending event before this thread does
std::this_thread::sleep_for(std::chrono::seconds(5));
// Wait for idle. This should wait for eventCallback to actually
// complete, not just that the main loop has started executing it.
::IdleTask::waitUntilIdleDispatched();
// If this is false then eventCallback hasn’t actually completed
CPPUNIT_ASSERT(bEventCallbackDone);
// Post another event to wake up the main thread
Application::PostUserEvent(LINK(this, OtherThread, setDone), nullptr);
}
IMPL_LINK_NOARG(OtherThread, setDone, void*, void) { m_bDone = true; }
CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, IdleTaskOtherThread)
{
CPPUNIT_ASSERT(Application::IsMainThread());
rtl::Reference<OtherThread> pOtherThread(new OtherThread);
pOtherThread->launch();
SolarMutexGuard aGuard;
while (!pOtherThread->m_bDone)
Application::Yield();
pOtherThread->join();
}
CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, IdleTaskMainThread)
{
CPPUNIT_ASSERT(Application::IsMainThread());
bool bEventCallbackDone = false;
Application::PostUserEvent(LINK_NONMEMBER(nullptr, eventCallback), &bEventCallbackDone);
::IdleTask::waitUntilIdleDispatched();
CPPUNIT_ASSERT(bEventCallbackDone);
}
} // namespace
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */