~focus-follows-mouse/ubuntu/oneiric/compiz/fix-883383

« back to all changes in this revision

Viewing changes to tests/timer/callbacks/test-timer-callbacks.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2011-07-19 08:00:29 UTC
  • mto: This revision was merged to the branch mainline in revision 235.
  • Revision ID: james.westby@ubuntu.com-20110719080029-lxt3wxch8uqkxro0
Tags: upstream-0.9.5.0
Import upstream version 0.9.5.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright © 2011 Canonical Ltd.
 
3
 *
 
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
 
13
 * implied warranty.
 
14
 *
 
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.
 
22
 *
 
23
 * Authored by: Sam Spilsbury <sam.spilsbury@canonical.com>
 
24
 */
 
25
 
 
26
#include "test-timer.h"
 
27
 
 
28
bool
 
29
CompTimerTestCallbacks::cb (int timernum)
 
30
{
 
31
    if (lastTimerTriggered == 0 && timernum == 1)
 
32
    {
 
33
        std::cout << "FAIL: timer with a higher timeout value triggered before the timer with the lower timeout" << std::endl;
 
34
        exit (1);
 
35
        return false;
 
36
    }
 
37
    else if (lastTimerTriggered == 2 && timernum != 1)
 
38
    {
 
39
        std::cout << "FAIL: the second timer should have triggered" << std::endl;
 
40
        exit (1);
 
41
        return false;
 
42
    }
 
43
 
 
44
    std::cout << "INFO: triggering timer " << timernum << std::endl;
 
45
 
 
46
    lastTimerTriggered = timernum;
 
47
 
 
48
    if (timernum == 1)
 
49
    {
 
50
        std::cout << "PASS: basic timers" << std::endl;
 
51
        ml->quit ();
 
52
    }
 
53
 
 
54
    return false;
 
55
}
 
56
 
 
57
void
 
58
CompTimerTestCallbacks::precallback ()
 
59
{
 
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));
 
65
 
 
66
    /* TimeoutHandler::timers should be empty */
 
67
    if (!TimeoutHandler::Default ()->timers ().empty ())
 
68
    {
 
69
        std::cout << "FAIL: timers list is not empty" << std::endl;
 
70
        exit (1);
 
71
    }
 
72
 
 
73
    timers.push_back (new CompTimer ());
 
74
    timers.back ()->setTimes (50, 90);
 
75
    timers.back ()->setCallback (boost::bind (&CompTimerTestCallbacks::cb, this, 2));
 
76
 
 
77
    /* Start both timers */
 
78
    timers.front ()->start ();
 
79
    timers.back ()->start ();
 
80
 
 
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 ())
 
85
    {
 
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;
 
88
 
 
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;
 
93
 
 
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;
 
98
        exit (1);
 
99
    }
 
100
 
 
101
    if (TimeoutHandler::Default ()->timers ().back () != timers.front ())
 
102
    {
 
103
        std::cout << "FAIL: timer with the most time is not at the back" << std::endl;
 
104
        exit (1);
 
105
    }
 
106
}