~samuel-thibault/compiz/clone

« back to all changes in this revision

Viewing changes to src/timer/tests/set-values/src/test-timer-set-values.cpp

  • Committer: Daniel van Vugt
  • Date: 2012-01-12 06:48:58 UTC
  • mfrom: (2908 compiz-core)
  • mto: (2908.6.2 trunk)
  • mto: This revision was merged to the branch mainline in revision 2916.
  • Revision ID: vanvugt@gmail.com-20120112064858-xcu22jq1dlerirmp
Merge with upstream changes (lp:compiz-core).

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 */
25
25
 
26
26
#include "test-timer.h"
27
 
 
28
 
bool
29
 
CompTimerTestSetValues::cb (int timernum)
30
 
{
31
 
    if (timernum == 3)
32
 
    {
33
 
        ml->quit ();
34
 
        std::cout << "PASS: testing values" << std::endl;
35
 
    }
36
 
    return false;
37
 
}
38
 
 
39
 
void
40
 
CompTimerTestSetValues::precallback ()
41
 
{
42
 
    CompTimer      *t1, *t2, *t3;
43
 
 
44
 
    std::cout << "-= TEST: testing values" << std::endl;
45
 
 
46
 
    t1 = new CompTimer ();
 
27
#include <unistd.h>
 
28
 
 
29
TEST_F(CompTimerTest, TimerSetValues)
 
30
{
 
31
    CompTimer* t1 = new CompTimer ();
47
32
 
48
33
    t1->setTimes (100, 90);
49
 
    t1->setCallback (boost::bind (&CompTimerTestSetValues::cb, this, 1));
50
34
    t1->start ();
51
35
 
52
 
    if (t1->minTime () != 100)
53
 
    {
54
 
        std::cout << "FAIL: min time was not the min value passed" << std::endl;
55
 
        exit (1);
56
 
    }
57
 
 
58
 
    if (t1->maxTime () != 100)
59
 
    {
60
 
        std::cout << "FAIL: max time was not the min value passed" << std::endl;
61
 
        exit (1);
62
 
    }
63
 
 
64
 
    if (t1->minLeft () != 100)
65
 
    {
66
 
        std::cout << "FAIL: min left was not the min value passed " << std::endl;
67
 
        exit (1);
68
 
    }
69
 
 
70
 
    if (t1->maxLeft () != 100)
71
 
    {
72
 
        std::cout << "FAIL: max left was not the min value passed" << std::endl;
73
 
        exit (1);
74
 
    }
75
 
 
76
 
    t2 = new CompTimer ();
77
 
 
78
 
    t2->setTimes (100, 110);
79
 
    t2->setCallback (boost::bind (&CompTimerTestSetValues::cb, this, 2));
80
 
    t2->start ();
81
 
 
82
 
    if (t2->minTime () != 100)
83
 
    {
84
 
        std::cout << "FAIL: min time was not the min value passed" << std::endl;
85
 
        exit (1);
86
 
    }
87
 
 
88
 
    if (t2->maxTime () != 110)
89
 
    {
90
 
        std::cout << "FAIL: max time was not the max value passed" << std::endl;
91
 
        exit (1);
92
 
    }
93
 
 
94
 
    if (t2->minLeft () != 100)
95
 
    {
96
 
        std::cout << "FAIL: min left was not the min value passed " << std::endl;
97
 
        exit (1);
98
 
    }
99
 
 
100
 
    if (t2->maxLeft () != 110)
101
 
    {
102
 
        std::cout << "FAIL: max left was not the max value passed" << std::endl;
103
 
        exit (1);
104
 
    }
105
 
 
106
 
    t3 = new CompTimer ();
107
 
 
108
 
    t3->setTimes (100);
109
 
    t3->setCallback (boost::bind (&CompTimerTestSetValues::cb, this, 3));
110
 
    t3->start ();
111
 
 
112
 
    if (t3->minTime () != 100)
113
 
    {
114
 
        std::cout << "FAIL: min time was not the value passed" << std::endl;
115
 
        exit (1);
116
 
    }
117
 
 
118
 
    if (t3->maxTime () != 100)
119
 
    {
120
 
        std::cout << "FAIL: max time was not the value passed" << std::endl;
121
 
        exit (1);
122
 
    }
123
 
 
124
 
    if (t3->minLeft () != 100)
125
 
    {
126
 
        std::cout << "FAIL: min left was not the value passed" << t3->minLeft () << std::endl;
127
 
        exit (1);
128
 
    }
129
 
 
130
 
    if (t3->maxLeft () != 100)
131
 
    {
132
 
        std::cout << "FAIL: max left was not the value passed" << std::endl;
133
 
        exit (1);
134
 
    }
135
 
 
136
 
    timers.push_back (t1);
137
 
    timers.push_back (t2);
138
 
    timers.push_back (t3);
 
36
    usleep (100000);
 
37
 
 
38
    /* minLeft and maxLeft are now
 
39
     * real-time, so wait the guarunteed
 
40
     * expiry time in order to check them
 
41
     * for an accurate value of zero */
 
42
 
 
43
    ASSERT_EQ (t1->minTime(), 100);
 
44
    ASSERT_EQ (t1->maxTime(), 100);
 
45
    ASSERT_EQ (t1->minLeft(), 0);
 
46
    ASSERT_EQ (t1->maxLeft(), 0);
 
47
 
 
48
    delete t1;
139
49
}