From 45cb70531f80c9c7b562e8507b46c70249806da3 Mon Sep 17 00:00:00 2001 From: Francesco Montorsi Date: Sun, 16 May 2010 15:44:17 +0000 Subject: [PATCH] remove TestTimer() (adds nothing to existing tests) and move wxStopWatch tests to a new CppUnit test. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64326 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- samples/console/console.cpp | 115 +----------------------------------- tests/Makefile.in | 4 ++ tests/events/stopwatch.cpp | 95 +++++++++++++++++++++++++++++ tests/events/timertest.cpp | 3 + tests/makefile.bcc | 4 ++ tests/makefile.gcc | 4 ++ tests/makefile.vc | 4 ++ tests/makefile.wat | 4 ++ tests/test.bkl | 1 + tests/test_test.dsp | 4 ++ tests/test_vc7_test.vcproj | 3 + tests/test_vc8_test.vcproj | 4 ++ tests/test_vc9_test.vcproj | 46 ++++++++++----- 13 files changed, 161 insertions(+), 130 deletions(-) create mode 100644 tests/events/stopwatch.cpp diff --git a/samples/console/console.cpp b/samples/console/console.cpp index f80181e48f..ccd1364776 100644 --- a/samples/console/console.cpp +++ b/samples/console/console.cpp @@ -131,10 +131,9 @@ #define TEST_STACKWALKER #define TEST_STDPATHS #define TEST_STREAMS - #define TEST_TIMER -// #define TEST_VOLUME --FIXME! (RN) #else // #if TEST_ALL #define TEST_DATETIME + #define TEST_VOLUME #endif // some tests are interactive, define this to run them @@ -2827,113 +2826,6 @@ static void TestMemoryStream() #endif // TEST_STREAMS -// ---------------------------------------------------------------------------- -// timers -// ---------------------------------------------------------------------------- - -#ifdef TEST_TIMER - -#include "wx/stopwatch.h" -#include "wx/utils.h" - -static void TestStopWatch() -{ - wxPuts(wxT("*** Testing wxStopWatch ***\n")); - - wxStopWatch sw; - sw.Pause(); - wxPrintf(wxT("Initially paused, after 2 seconds time is...")); - fflush(stdout); - wxSleep(2); - wxPrintf(wxT("\t%ldms\n"), sw.Time()); - - wxPrintf(wxT("Resuming stopwatch and sleeping 3 seconds...")); - fflush(stdout); - sw.Resume(); - wxSleep(3); - wxPrintf(wxT("\telapsed time: %ldms\n"), sw.Time()); - - sw.Pause(); - wxPrintf(wxT("Pausing agan and sleeping 2 more seconds...")); - fflush(stdout); - wxSleep(2); - wxPrintf(wxT("\telapsed time: %ldms\n"), sw.Time()); - - sw.Resume(); - wxPrintf(wxT("Finally resuming and sleeping 2 more seconds...")); - fflush(stdout); - wxSleep(2); - wxPrintf(wxT("\telapsed time: %ldms\n"), sw.Time()); - - wxStopWatch sw2; - wxPuts(wxT("\nChecking for 'backwards clock' bug...")); - for ( size_t n = 0; n < 70; n++ ) - { - sw2.Start(); - - for ( size_t m = 0; m < 100000; m++ ) - { - if ( sw.Time() < 0 || sw2.Time() < 0 ) - { - wxPuts(wxT("\ntime is negative - ERROR!")); - } - } - - wxPutchar('.'); - fflush(stdout); - } - - wxPuts(wxT(", ok.")); -} - -#include "wx/timer.h" -#include "wx/evtloop.h" - -void TestTimer() -{ - wxPuts(wxT("*** Testing wxTimer ***\n")); - - class MyTimer : public wxTimer - { - public: - MyTimer() : wxTimer() { m_num = 0; } - - virtual void Notify() - { - wxPrintf(wxT("%d"), m_num++); - fflush(stdout); - - if ( m_num == 10 ) - { - wxPrintf(wxT("... exiting the event loop")); - Stop(); - - wxEventLoop::GetActive()->Exit(0); - wxPuts(wxT(", ok.")); - } - - fflush(stdout); - } - - private: - int m_num; - }; - - wxEventLoop loop; - - wxTimer timer1; - timer1.Start(100, true /* one shot */); - timer1.Stop(); - timer1.Start(100, true /* one shot */); - - MyTimer timer; - timer.Start(500); - - loop.Run(); -} - -#endif // TEST_TIMER - // ---------------------------------------------------------------------------- // wxVolume tests // ---------------------------------------------------------------------------- @@ -3309,11 +3201,6 @@ int main(int argc, char **argv) TestMemoryStream(); #endif // TEST_STREAMS -#ifdef TEST_TIMER - TestStopWatch(); - TestTimer(); -#endif // TEST_TIMER - #ifdef TEST_DATETIME #if TEST_INTERACTIVE TestDateTimeInteractive(); diff --git a/tests/Makefile.in b/tests/Makefile.in index df5ab92c41..e5fd2ee4e6 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -65,6 +65,7 @@ TEST_OBJECTS = \ test_datetimetest.o \ test_evthandler.o \ test_evtsource.o \ + test_stopwatch.o \ test_timertest.o \ test_exec.o \ test_filetest.o \ @@ -389,6 +390,9 @@ test_evthandler.o: $(srcdir)/events/evthandler.cpp $(TEST_ODEP) test_evtsource.o: $(srcdir)/events/evtsource.cpp $(TEST_ODEP) $(CXXC) -c -o $@ $(TEST_CXXFLAGS) $(srcdir)/events/evtsource.cpp +test_stopwatch.o: $(srcdir)/events/stopwatch.cpp $(TEST_ODEP) + $(CXXC) -c -o $@ $(TEST_CXXFLAGS) $(srcdir)/events/stopwatch.cpp + test_timertest.o: $(srcdir)/events/timertest.cpp $(TEST_ODEP) $(CXXC) -c -o $@ $(TEST_CXXFLAGS) $(srcdir)/events/timertest.cpp diff --git a/tests/events/stopwatch.cpp b/tests/events/stopwatch.cpp new file mode 100644 index 0000000000..d26566f1ad --- /dev/null +++ b/tests/events/stopwatch.cpp @@ -0,0 +1,95 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: tests/events/stopwatch.cpp +// Purpose: Test wxStopWatch class +// Author: Francesco Montorsi (extracted from console sample) +// Created: 2010-05-16 +// RCS-ID: $Id$ +// Copyright: (c) 2010 wxWidgets team +/////////////////////////////////////////////////////////////////////////////// + + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + +#include "testprec.h" + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +#ifndef WX_PRECOMP +#endif // WX_PRECOMP + +#include + +#include "wx/stopwatch.h" +#include "wx/utils.h" + +// -------------------------------------------------------------------------- +// test class +// -------------------------------------------------------------------------- + +class StopWatchTestCase : public CppUnit::TestCase +{ +public: + StopWatchTestCase() {} + +private: + CPPUNIT_TEST_SUITE( StopWatchTestCase ); + CPPUNIT_TEST( Misc ); + CPPUNIT_TEST( BackwardsClockBug ); + CPPUNIT_TEST_SUITE_END(); + + void Misc(); + void BackwardsClockBug(); + + DECLARE_NO_COPY_CLASS(StopWatchTestCase) +}; + +// register in the unnamed registry so that these tests are run by default +CPPUNIT_TEST_SUITE_REGISTRATION( StopWatchTestCase ); + +// also include in it's own registry so that these tests can be run alone +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( StopWatchTestCase, "StopWatchTestCase" ); + +void StopWatchTestCase::Misc() +{ + wxStopWatch sw; + long tmp; + + sw.Pause(); // pause it immediately + + wxSleep(2); + tmp = sw.Time(); + CPPUNIT_ASSERT(tmp >= 0 && tmp < 100); + // should not have counted while paused! + + sw.Resume(); + wxSleep(3); + tmp = sw.Time(); + CPPUNIT_ASSERT(tmp >= 3000 && tmp < 4000); + + sw.Pause(); + sw.Resume(); + + wxSleep(2); + tmp = sw.Time(); + CPPUNIT_ASSERT(tmp >= 5000 && tmp < 6000); +} + +void StopWatchTestCase::BackwardsClockBug() +{ + wxStopWatch sw; + wxStopWatch sw2; + + for ( size_t n = 0; n < 10; n++ ) + { + sw2.Start(); + + for ( size_t m = 0; m < 10000; m++ ) + { + CPPUNIT_ASSERT ( sw.Time() >= 0 && sw2.Time() >= 0 ); + } + } +} diff --git a/tests/events/timertest.cpp b/tests/events/timertest.cpp index 48553a271a..56105d83fe 100644 --- a/tests/events/timertest.cpp +++ b/tests/events/timertest.cpp @@ -25,7 +25,10 @@ #include "wx/evtloop.h" #include "wx/timer.h" +// -------------------------------------------------------------------------- // helper class counting the number of timer events +// -------------------------------------------------------------------------- + class TimerCounterHandler : public wxEvtHandler { public: diff --git a/tests/makefile.bcc b/tests/makefile.bcc index bbad494156..a079fb9059 100644 --- a/tests/makefile.bcc +++ b/tests/makefile.bcc @@ -49,6 +49,7 @@ TEST_OBJECTS = \ $(OBJS)\test_datetimetest.obj \ $(OBJS)\test_evthandler.obj \ $(OBJS)\test_evtsource.obj \ + $(OBJS)\test_stopwatch.obj \ $(OBJS)\test_timertest.obj \ $(OBJS)\test_exec.obj \ $(OBJS)\test_filetest.obj \ @@ -431,6 +432,9 @@ $(OBJS)\test_evthandler.obj: .\events\evthandler.cpp $(OBJS)\test_evtsource.obj: .\events\evtsource.cpp $(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\events\evtsource.cpp +$(OBJS)\test_stopwatch.obj: .\events\stopwatch.cpp + $(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\events\stopwatch.cpp + $(OBJS)\test_timertest.obj: .\events\timertest.cpp $(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\events\timertest.cpp diff --git a/tests/makefile.gcc b/tests/makefile.gcc index b250c6377b..42d881e88e 100644 --- a/tests/makefile.gcc +++ b/tests/makefile.gcc @@ -41,6 +41,7 @@ TEST_OBJECTS = \ $(OBJS)\test_datetimetest.o \ $(OBJS)\test_evthandler.o \ $(OBJS)\test_evtsource.o \ + $(OBJS)\test_stopwatch.o \ $(OBJS)\test_timertest.o \ $(OBJS)\test_exec.o \ $(OBJS)\test_filetest.o \ @@ -412,6 +413,9 @@ $(OBJS)\test_evthandler.o: ./events/evthandler.cpp $(OBJS)\test_evtsource.o: ./events/evtsource.cpp $(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $< +$(OBJS)\test_stopwatch.o: ./events/stopwatch.cpp + $(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $< + $(OBJS)\test_timertest.o: ./events/timertest.cpp $(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $< diff --git a/tests/makefile.vc b/tests/makefile.vc index 237822026f..cc32e91070 100644 --- a/tests/makefile.vc +++ b/tests/makefile.vc @@ -43,6 +43,7 @@ TEST_OBJECTS = \ $(OBJS)\test_datetimetest.obj \ $(OBJS)\test_evthandler.obj \ $(OBJS)\test_evtsource.obj \ + $(OBJS)\test_stopwatch.obj \ $(OBJS)\test_timertest.obj \ $(OBJS)\test_exec.obj \ $(OBJS)\test_filetest.obj \ @@ -557,6 +558,9 @@ $(OBJS)\test_evthandler.obj: .\events\evthandler.cpp $(OBJS)\test_evtsource.obj: .\events\evtsource.cpp $(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\events\evtsource.cpp +$(OBJS)\test_stopwatch.obj: .\events\stopwatch.cpp + $(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\events\stopwatch.cpp + $(OBJS)\test_timertest.obj: .\events\timertest.cpp $(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\events\timertest.cpp diff --git a/tests/makefile.wat b/tests/makefile.wat index 7fca6b4ccb..67b82aead3 100644 --- a/tests/makefile.wat +++ b/tests/makefile.wat @@ -279,6 +279,7 @@ TEST_OBJECTS = & $(OBJS)\test_datetimetest.obj & $(OBJS)\test_evthandler.obj & $(OBJS)\test_evtsource.obj & + $(OBJS)\test_stopwatch.obj & $(OBJS)\test_timertest.obj & $(OBJS)\test_exec.obj & $(OBJS)\test_filetest.obj & @@ -469,6 +470,9 @@ $(OBJS)\test_evthandler.obj : .AUTODEPEND .\events\evthandler.cpp $(OBJS)\test_evtsource.obj : .AUTODEPEND .\events\evtsource.cpp $(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $< +$(OBJS)\test_stopwatch.obj : .AUTODEPEND .\events\stopwatch.cpp + $(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $< + $(OBJS)\test_timertest.obj : .AUTODEPEND .\events\timertest.cpp $(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $< diff --git a/tests/test.bkl b/tests/test.bkl index 629d6049e8..3ce77af3af 100644 --- a/tests/test.bkl +++ b/tests/test.bkl @@ -40,6 +40,7 @@ datetime/datetimetest.cpp events/evthandler.cpp events/evtsource.cpp + events/stopwatch.cpp events/timertest.cpp exec/exec.cpp file/filetest.cpp diff --git a/tests/test_test.dsp b/tests/test_test.dsp index 271690fa8b..981800bbbc 100644 --- a/tests/test_test.dsp +++ b/tests/test_test.dsp @@ -429,6 +429,10 @@ SOURCE=.\strings\stdstrings.cpp # End Source File # Begin Source File +SOURCE=.\events\stopwatch.cpp +# End Source File +# Begin Source File + SOURCE=.\strings\strings.cpp # End Source File # Begin Source File diff --git a/tests/test_vc7_test.vcproj b/tests/test_vc7_test.vcproj index 874d981a35..284639384d 100644 --- a/tests/test_vc7_test.vcproj +++ b/tests/test_vc7_test.vcproj @@ -757,6 +757,9 @@ + + diff --git a/tests/test_vc8_test.vcproj b/tests/test_vc8_test.vcproj index 7254ddcb87..8215eacc9f 100644 --- a/tests/test_vc8_test.vcproj +++ b/tests/test_vc8_test.vcproj @@ -1083,6 +1083,10 @@ RelativePath=".\strings\stdstrings.cpp" > + + diff --git a/tests/test_vc9_test.vcproj b/tests/test_vc9_test.vcproj index 071b74f23a..2b48c4b5d2 100644 --- a/tests/test_vc9_test.vcproj +++ b/tests/test_vc9_test.vcproj @@ -1,10 +1,16 @@ + + + + + @@ -1142,5 +1154,7 @@ + + -- 2.45.2