include/vcl/timer.hxx | 5 - vcl/CppunitTest_vcl_timer.mk | 51 ++++++++++ vcl/Module_vcl.mk | 6 + vcl/qa/cppunit/timer.cxx | 200 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 261 insertions(+), 1 deletion(-)
New commits: commit 48e1675ca204b6ad68f5844e21de1f7485cfd306 Author: Michael Meeks <michael.me...@collabora.com> Date: Thu Sep 25 16:20:36 2014 +0100 vcl: comment timer classes at least minimally. Change-Id: Iabc76b3e78afa491a38fa04d648f48f15ac3870e diff --git a/include/vcl/timer.hxx b/include/vcl/timer.hxx index 6659780..d3ebe1a 100644 --- a/include/vcl/timer.hxx +++ b/include/vcl/timer.hxx @@ -27,6 +27,7 @@ struct ImplTimerData; struct ImplSVData; +/// Base-class for timers - usually a simple, one-shot timeout class VCL_DLLPUBLIC Timer { protected: @@ -51,6 +52,7 @@ public: sal_uLong GetTimeout() const { return mnTimeout; } bool IsActive() const { return mbActive; } + /// Make it possible to associate a callback with this timeout void SetTimeoutHdl( const Link& rLink ) { maTimeoutHdl = rLink; } const Link& GetTimeoutHdl() const { return maTimeoutHdl; } @@ -60,7 +62,8 @@ public: static void ImplTimerCallbackProc(); }; - +/// An auto-timer is a multi-shot timer re-emitting itself at +/// interval until destroyed. class VCL_DLLPUBLIC AutoTimer : public Timer { public: commit d998a6ae3afab1ea51c72843d8400cf5c1eca35c Author: Michael Meeks <michael.me...@collabora.com> Date: Thu Sep 25 11:22:39 2014 +0100 fdo#84000 - unit test timers / main-loop bits. At least test Unix platforms. Change-Id: I960343cb9622474fe48687a5e458e1c6dbe55358 diff --git a/vcl/CppunitTest_vcl_timer.mk b/vcl/CppunitTest_vcl_timer.mk new file mode 100644 index 0000000..c1abf2f --- /dev/null +++ b/vcl/CppunitTest_vcl_timer.mk @@ -0,0 +1,51 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +# +# 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/. +# + +$(eval $(call gb_CppunitTest_CppunitTest,vcl_timer)) + +$(eval $(call gb_CppunitTest_set_include,vcl_timer,\ + $$(INCLUDE) \ + -I$(SRCDIR)/vcl/inc \ +)) + +$(eval $(call gb_CppunitTest_add_exception_objects,vcl_timer, \ + vcl/qa/cppunit/timer \ +)) + +$(eval $(call gb_CppunitTest_use_externals,vcl_timer,boost_headers)) + +$(eval $(call gb_CppunitTest_use_libraries,vcl_timer, \ + comphelper \ + cppu \ + cppuhelper \ + sal \ + salhelper \ + test \ + unotest \ + vcl \ + $(gb_UWINAPI) \ +)) + +$(eval $(call gb_CppunitTest_use_api,vcl_timer,\ + udkapi \ + offapi \ +)) + +$(eval $(call gb_CppunitTest_use_ure,vcl_timer)) +$(eval $(call gb_CppunitTest_use_vcl,vcl_timer)) + +$(eval $(call gb_CppunitTest_use_components,vcl_timer,\ + configmgr/source/configmgr \ + i18npool/util/i18npool \ + ucb/source/core/ucb1 \ +)) + +$(eval $(call gb_CppunitTest_use_configuration,vcl_timer)) + +# vim: set noet sw=4 ts=4: diff --git a/vcl/Module_vcl.mk b/vcl/Module_vcl.mk index acf8ccb..f2eef6f 100644 --- a/vcl/Module_vcl.mk +++ b/vcl/Module_vcl.mk @@ -100,4 +100,10 @@ $(eval $(call gb_Module_add_check_targets,vcl,\ CppunitTest_vcl_wmf_test \ )) +ifeq ($(GUIBASE),unx) +$(eval $(call gb_Module_add_check_targets,vcl,\ + CppunitTest_vcl_timer \ +)) +endif + # vim: set noet sw=4 ts=4: diff --git a/vcl/qa/cppunit/timer.cxx b/vcl/qa/cppunit/timer.cxx new file mode 100644 index 0000000..99d71a9 --- /dev/null +++ b/vcl/qa/cppunit/timer.cxx @@ -0,0 +1,200 @@ +/* -*- 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/. + */ +/* + * Timers are evil beasties across platforms ... + */ + +#include <test/bootstrapfixture.hxx> + +#include <osl/thread.hxx> +#include <salhelper/thread.hxx> + +#include <vcl/timer.hxx> +#include <vcl/svapp.hxx> + +/// Avoid our timer tests just wedging the build if they fail. +class WatchDog : public osl::Thread +{ + sal_Int32 mnSeconds; +public: + WatchDog(sal_Int32 nSeconds) : + Thread(), + mnSeconds( nSeconds ) + { + create(); + } + virtual void SAL_CALL run() SAL_OVERRIDE + { + TimeValue aWait; + aWait.Seconds = mnSeconds; + aWait.Nanosec = 1000000; // +1ms + osl::Thread::wait( aWait ); + CPPUNIT_ASSERT_MESSAGE("watchdog triggered", false); + } +}; + +static WatchDog aWatchDog( 10 /* 10 secs should be enough */); + +class TimerTest : public test::BootstrapFixture +{ +public: + TimerTest() : BootstrapFixture(true, false) {} + + void testWatchdog(); + void testDurations(); + void testAutoTimer(); + void testRecursiveTimer(); + void testSlowTimerCallback(); + + CPPUNIT_TEST_SUITE(TimerTest); + CPPUNIT_TEST(testDurations); + CPPUNIT_TEST(testAutoTimer); + CPPUNIT_TEST(testRecursiveTimer); + CPPUNIT_TEST(testSlowTimerCallback); + + CPPUNIT_TEST_SUITE_END(); +}; + +void TimerTest::testWatchdog() +{ + // out-wait the watchdog. + TimeValue aWait; + aWait.Seconds = 12; + aWait.Nanosec = 0; + osl::Thread::wait( aWait ); +} + +// -------------------------------------------------------------------- + +class TimerBool : public Timer +{ + bool &mrBool; +public: + TimerBool( sal_uLong nMS, bool &rBool ) : + Timer(), mrBool( rBool ) + { + SetTimeout( nMS ); + Start(); + mrBool = false; + } + virtual void Timeout() + { + mrBool = true; + Application::EndYield(); + } +}; + +void TimerTest::testDurations() +{ + static const sal_uLong aDurations[] = { 0, 1, 500, 1000 }; + for (size_t i = 0; i < SAL_N_ELEMENTS( aDurations ); i++) + { + bool bDone = false; + TimerBool aTimer( aDurations[i], bDone ); + while( !bDone ) + { + Application::Yield(); + } + } +} + +// -------------------------------------------------------------------- + +class AutoTimerCount : public AutoTimer +{ + sal_Int32 &mrCount; +public: + AutoTimerCount( sal_uLong nMS, sal_Int32 &rCount ) : + AutoTimer(), mrCount( rCount ) + { + SetTimeout( nMS ); + Start(); + mrCount = 0; + } + virtual void Timeout() + { + mrCount++; + } +}; + +void TimerTest::testAutoTimer() +{ + sal_Int32 nCount = 0; + AutoTimerCount aCount(1, nCount); + while (nCount < 100) { + Application::Yield(); + } +} + +// -------------------------------------------------------------------- + +class YieldTimer : public Timer +{ +public: + YieldTimer( sal_uLong nMS ) : Timer() + { + SetTimeout( nMS ); + Start(); + } + virtual void Timeout() + { + for (int i = 0; i < 100; i++) + Application::Yield(); + } +}; + +void TimerTest::testRecursiveTimer() +{ + sal_Int32 nCount = 0; + YieldTimer aCount(5); + AutoTimerCount aCountUp( 3, nCount ); + while (nCount < 20) + Application::Yield(); +} + +// -------------------------------------------------------------------- + +class SlowCallbackTimer : public Timer +{ + bool &mbSlow; +public: + SlowCallbackTimer( sal_uLong nMS, bool &bBeenSlow ) : + Timer(), mbSlow( bBeenSlow ) + { + SetTimeout( nMS ); + Start(); + mbSlow = false; + } + virtual void Timeout() + { + TimeValue aWait; + aWait.Seconds = 1; + aWait.Nanosec = 0; + osl::Thread::wait( aWait ); + mbSlow = true; + } +}; + +void TimerTest::testSlowTimerCallback() +{ + bool bBeenSlow = false; + sal_Int32 nCount = 0; + AutoTimerCount aHighFreq(1, nCount); + SlowCallbackTimer aSlow(250, bBeenSlow); + while (!bBeenSlow) + Application::Yield(); + while (nCount < 200) + Application::Yield(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(TimerTest); + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits