Page MenuHomePhorge

TimerTests.cpp
No OneTemporary

Size
2 KB
Referenced Files
None
Subscribers
None

TimerTests.cpp

/*
* File: TimerTests.cpp
* Author: sean
*
* Created on 11-Apr-2015, 19:22:59
*/
#include <stdlib.h>
#include <iostream>
/*
* Simple C++ Test Suite
*/
#include <echo/Application.h>
#include <echo/Chrono/CountDownTimer.h>
#include <echo/Platform.h>
#include <echo/PlatformStub.h>
#include <boost/bind.hpp>
using namespace Echo;
class CountDownTimerTests : public Application
{
public:
CountDownTimerTests() : mRepeatCount(0), mSingleFinishCount(0)
{
GetConfiguration().Set<u32>("resolution.x",100);
GetConfiguration().Set<u32>("resolution.y",100);
Initialise("CountDownTimerTests");
SetPauseHint(false);
std::cout << "%SUITE_STARTING% CountDownTimerTests" << std::endl;
std::cout << "%SUITE_STARTED%" << std::endl;
std::cout << "%TEST_STARTED% mSingleTest (CountDownTimerTests)" << std::endl;
mSingleTest = new CountDownTimer(Seconds(0.5f));
mSingleTest->AddTimeoutFunction(boost::bind(&CountDownTimerTests::SingleTestFinished,this),"CountDownExpire");
AddTask(*mSingleTest);
std::cout << "%TEST_STARTED% mRepeatTest (CountDownTimerTests)" << std::endl;
mRepeatTest = new CountDownTimer(Seconds(0.5f));
mRepeatTest->SetRepeat(true);
mRepeatTest->AddTimeoutFunction(boost::bind(&CountDownTimerTests::RepeatTestFinished,this),"CountDownRepeat");
AddTask(*mRepeatTest);
}
~CountDownTimerTests()
{
if(mRepeatCount!=5)
{
std::cout << "%TEST_FAILED% time=0 testname=mRepeatTest (CountDownTimerTests) message=The repeat task did not repeat for the anticipated number of times." << std::endl;
}
RemoveTask(*mSingleTest);
RemoveTask(*mRepeatTest);
std::cout << "%TEST_FINISHED% time=0 mSingleTest (CountDownTimerTests)" << std::endl;
std::cout << "%TEST_FINISHED% time=0 mRepeatTest (CountDownTimerTests)" << std::endl;
std::cout << "%SUITE_FINISHED% time=0" << std::endl;
}
void SingleTestFinished()
{
std::cout << "SingleTestFinished()" << std::endl;
mSingleFinishCount++;
if(mSingleFinishCount>1)
{
std::cout << "%TEST_FAILED% time=0 testname=mSingleTest (CountDownTimerTests) message=The no repeat task repeated." << std::endl;
}
RemoveTask(mSingleTest);
}
void RepeatTestFinished()
{
std::cout << "RepeatTestFinished()" << std::endl;
mRepeatCount++;
if(mRepeatCount==5)
{
RemoveAllTasks();
}
}
private:
CountDownTimer* mSingleTest;
CountDownTimer* mRepeatTest;
size_t mRepeatCount;
size_t mSingleFinishCount;
};
shared_ptr<Kernel> EchoInitialise()
{
shared_ptr<Kernel> kernel = shared_ptr<Kernel>(new CountDownTimerTests());
return kernel;
}

File Metadata

Mime Type
text/x-c++
Expires
Wed, Jan 15, 7:34 PM (1 h, 18 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
72036
Default Alt Text
TimerTests.cpp (2 KB)

Event Timeline