2
* Copyright © 2011 Canonical Ltd.
4
* Permission to use, copy, modify, distribute, and sell this software
5
* and its documentation for any purpose is hereby granted without
6
* fee, provided that the above copyright notice appear in all copies
7
* and that both that copyright notice and this permission notice
8
* appear in supporting documentation, and that the name of
9
* Canonical Ltd. not be used in advertising or publicity pertaining to
10
* distribution of the software without specific, written prior permission.
11
* Canonical Ltd. makes no representations about the suitability of this
12
* software for any purpose. It is provided "as is" without express or
15
* CANONICAL, LTD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
17
* NO EVENT SHALL CANONICAL, LTD. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
19
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
20
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
21
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23
* Authored by: Sam Spilsbury <sam.spilsbury@canonical.com>
26
#include "test-timer.h"
29
CompTimerTestCallbacks::cb (int timernum)
31
if (lastTimerTriggered == 0 && timernum == 1)
33
std::cout << "FAIL: timer with a higher timeout value triggered before the timer with the lower timeout" << std::endl;
37
else if (lastTimerTriggered == 2 && timernum != 1)
39
std::cout << "FAIL: the second timer should have triggered" << std::endl;
44
std::cout << "INFO: triggering timer " << timernum << std::endl;
46
lastTimerTriggered = timernum;
50
std::cout << "PASS: basic timers" << std::endl;
58
CompTimerTestCallbacks::precallback ()
60
/* Test 2: Adding timers */
61
std::cout << "-= TEST: adding timers and callbacks" << std::endl;
62
timers.push_back (new CompTimer ());
63
timers.front ()->setTimes (100, 110);
64
timers.front ()->setCallback (boost::bind (&CompTimerTestCallbacks::cb, this, 1));
66
/* TimeoutHandler::timers should be empty */
67
if (!TimeoutHandler::Default ()->timers ().empty ())
69
std::cout << "FAIL: timers list is not empty" << std::endl;
73
timers.push_back (new CompTimer ());
74
timers.back ()->setTimes (50, 90);
75
timers.back ()->setCallback (boost::bind (&CompTimerTestCallbacks::cb, this, 2));
77
/* Start both timers */
78
timers.front ()->start ();
79
timers.back ()->start ();
81
/* TimeoutHandler::timers should have the timer that
82
* is going to trigger first at the front of the
83
* list and the last timer at the back */
84
if (TimeoutHandler::Default ()->timers ().front () != timers.back ())
86
std::cout << "FAIL: timer with the least time is not at the front" << std::endl;
87
std::cout << "INFO: TimeoutHandler::Default ().size " << TimeoutHandler::Default ()->timers ().size () << std::endl;
89
std::cout << "INFO: TimeoutHandler::Default ().front->minLeft " << TimeoutHandler::Default ()->timers ().front ()->minLeft () << std::endl << \
90
"INFO: TimeoutHandler::Default ().front->maxLeft " << TimeoutHandler::Default ()->timers ().front ()->maxLeft () << std::endl << \
91
"INFO: TimeoutHandler::Default ().front->minTime " << TimeoutHandler::Default ()->timers ().front ()->minTime () << std::endl << \
92
"INFO: TimeoutHandler::Default ().front->maxTime " << TimeoutHandler::Default ()->timers ().front ()->maxTime () << std::endl;
94
std::cout << "INFO: TimeoutHandler::Default ().back->minLeft " << TimeoutHandler::Default ()->timers ().back ()->minLeft () << std::endl << \
95
"INFO: TimeoutHandler::Default ().back->maxLeft " << TimeoutHandler::Default ()->timers ().back ()->maxLeft () << std::endl << \
96
"INFO: TimeoutHandler::Default ().back->minTime " << TimeoutHandler::Default ()->timers ().back ()->minTime () << std::endl << \
97
"INFO: TimeoutHandler::Default ().back->maxTime " << TimeoutHandler::Default ()->timers ().back ()->maxTime () << std::endl;
101
if (TimeoutHandler::Default ()->timers ().back () != timers.front ())
103
std::cout << "FAIL: timer with the most time is not at the back" << std::endl;