ultimatepp/bazaar/TimerTest/main.cpp
kohait cd8510db6e Timer: smaller glitches with 'sleep time remainder', TimerTest: proper close / wait for Timer enabled applications example
git-svn-id: svn://ultimatepp.org/upp/trunk@2549 f0d560ea-af0d-0410-9eb7-867de7ffcac7
2010-07-19 11:23:24 +00:00

67 lines
1.1 KiB
C++

#include "TimerTest.h"
#define REPEAT_TEST
TimerTest::TimerTest()
: demo(0)
{
CtrlLayout(*this, "Window title");
int a = AtomicInc(demo);
ASSERT(a==1); //preload, 1 means running demo mode, 2 means a cb is executing
#ifdef REPEAT_TEST
t.SetTimeCallback(-100, THISBACK(Test), (int)this);
#else
t.SetTimeCallback(0, THISBACK(Test), (int)this);
#endif
}
void TimerTest::Info(const String & s)
{
info.Insert(info.GetLength(), s);
info.SetCursor(info.GetLength());
}
void TimerTest::Test()
{
int a = AtomicInc(demo);
ASSERT(a==2);
Info("O");
RLOG("O");
a = AtomicDec(demo);
if(a<=0)
return;
ASSERT(a>=0);
#ifdef REPEAT_TEST
#else
t.SetTimeCallback(100, THISBACK(Test), (int)this);
#endif
}
void TimerTest::Close()
{
t.KillTimeCallback((int)this);
int a = AtomicDec(demo);
Thread::Start(THISBACK(Close0));
}
void TimerTest::Close0()
{
while(AtomicRead(demo) > 0) Sleep(1);
ASSERT(AtomicRead(demo)==0);
TopWindow::Close();
}
TimerTest::~TimerTest()
{
}
GUI_APP_MAIN
{
TimerTest().Run();
}