26
26
#include "test-timer.h"
29
CompTimerTestSetCalling::cb (int timernum, CompTimer *t1, CompTimer *t2, CompTimer *t3)
31
std::cout << "INFO: triggering timer " << timernum << std::endl;
33
if (lastTimerTriggered == 0 && timernum == 1)
35
/* Change the timeout time of the second timer to be after the third */
36
t2->setTimes (4000, 4100);
38
/* Check if it is now at the back of the timeout list */
39
if (TimeoutHandler::Default ()->timers ().back () != t2)
41
std::cout << "FAIL: timer with higher timeout time is not at the back of the list" << std::endl;
43
for (std::list <CompTimer *>::iterator it = TimeoutHandler::Default ()->timers ().begin ();
44
it != TimeoutHandler::Default ()->timers ().end (); it++)
47
std::cout << "INFO: t->minLeft " << t->minLeft () << std::endl << \
48
"INFO: t->maxLeft " << t->maxLeft () << std::endl << \
49
"INFO: t->minTime " << t->minTime () << std::endl << \
50
"INFO: t->maxTime " << t->maxTime () << std::endl;
56
else if (lastTimerTriggered == 1 && timernum == 2)
58
std::cout << "FAIL: timer with a higher timeout time got triggered before a timer with a lower timeout time" << std::endl;
60
for (std::list <CompTimer *>::iterator it = TimeoutHandler::Default ()->timers ().begin ();
61
it != TimeoutHandler::Default ()->timers ().end (); it++)
64
std::cout << "INFO: t->minLeft " << t->minLeft () << std::endl << \
65
"INFO: t->maxLeft " << t->maxLeft () << std::endl << \
66
"INFO: t->minTime " << t->minTime () << std::endl << \
67
"INFO: t->maxTime " << t->maxTime () << std::endl;
72
else if (lastTimerTriggered == 2 && timernum != 1)
74
std::cout << "FAIL: timer with higher timeout time didn't get triggered after a lower timeout time" << std::endl;
76
for (std::list <CompTimer *>::iterator it = TimeoutHandler::Default ()->timers ().begin ();
77
it != TimeoutHandler::Default ()->timers ().end (); it++)
80
std::cout << "INFO: t->minLeft " << t->minLeft () << std::endl << \
81
"INFO: t->maxLeft " << t->maxLeft () << std::endl << \
82
"INFO: t->minTime " << t->minTime () << std::endl << \
83
"INFO: t->maxTime " << t->maxTime () << std::endl;
89
lastTimerTriggered = timernum;
93
std::cout << "PASS: retiming" << std::endl;
101
CompTimerTestSetCalling::precallback ()
103
CompTimer *t1, *t2, *t3;
105
std::cout << "-= TEST: changing timeout time" << std::endl;
107
t1 = new CompTimer ();
108
t2 = new CompTimer ();
109
t3 = new CompTimer ();
111
timers.push_back (t1);
112
timers.push_back (t2);
113
timers.push_back (t3);
115
t1->setCallback (boost::bind (&CompTimerTestSetCalling::cb, this, 1, t1, t2, t3));
116
t1->setTimes (1000, 1100);
118
t2->setCallback (boost::bind (&CompTimerTestSetCalling::cb, this, 2, t1, t2, t3));
119
t2->setTimes (2000, 2100);
121
t3->setCallback (boost::bind (&CompTimerTestSetCalling::cb, this, 3, t1, t2, t3));
122
t3->setTimes (3000, 3100);
30
class CompTimerTestSetTimes: public CompTimerTest
34
int mlastTimerTriggered;
36
static void* run (void* cb)
42
static_cast<CompTimerTestSetTimes*>(cb)->ml->run();
46
pthread_t mmainLoopThread;
47
std::list<int> mtriggeredTimers;
51
for (std::list<CompTimer *>::iterator it =
52
TimeoutHandler::Default()->timers().begin();
53
it != TimeoutHandler::Default()->timers().end(); it++)
56
RecordProperty("t->minLeft", t->minLeft());
57
RecordProperty("t->maxLeft", t->maxLeft());
58
RecordProperty("t->minTime", t->minTime());
59
RecordProperty("t->maxTime", t->maxTime());
63
bool cb (int timernum, CompTimer* t1, CompTimer* t2, CompTimer* t3) {
64
cb_(timernum,t1,t2,t3);
67
void cb_ (int timernum, CompTimer* t1, CompTimer* t2, CompTimer* t3)
70
if (mlastTimerTriggered == 0 && timernum == 1)
72
/* Change the timeout time of the second timer to be after the third */
73
t2->setTimes(4000, 4100);
77
/* Check if it is now at the back of the timeout list */
78
ASSERT_EQ( TimeoutHandler::Default()->timers().back(), t2 );
80
else if (mlastTimerTriggered == 1 && timernum == 2)
83
FAIL() << "timer with a higher timeout time got triggered "
84
"before a timer with a lower timeout time";
86
else if (mlastTimerTriggered == 2 && timernum != 1)
90
FAIL() << "timer with higher timeout time didn't get "
91
"triggered after a lower timeout time";
94
mlastTimerTriggered = timernum;
99
CompTimerTest::SetUp();
100
mlastTimerTriggered = 0;
101
CompTimer *t1, *t2, *t3;
103
t1 = new CompTimer();
104
t2 = new CompTimer();
105
t3 = new CompTimer();
107
timers.push_back(t1);
108
timers.push_back(t2);
109
timers.push_back(t3);
112
boost::bind(&CompTimerTestSetTimes::cb, this, 1, t1, t2, t3));
113
t1->setTimes(1000, 1100);
116
boost::bind(&CompTimerTestSetTimes::cb, this, 2, t1, t2, t3));
117
t2->setTimes(2000, 2100);
120
boost::bind(&CompTimerTestSetTimes::cb, this, 3, t1, t2, t3));
121
t3->setTimes(3000, 3100);
126
pthread_create(&mmainLoopThread, NULL, CompTimerTestSetTimes::run, this));
132
pthread_join(mmainLoopThread, NULL);
134
CompTimerTest::TearDown();
138
TEST_F(CompTimerTestSetTimes, SetTimesWhileCalling)
141
// Just a dummy forcing instantiation of fixture.