source: tests/SystemQueue-tests.cc@ 12749

Last change on this file since 12749 was 12749, checked in by hock@…, 11 years ago

first test that actually runs the SystemQueue

(but a FIXME is still open..)

File size: 2.2 KB
Line 
1#include "gtest/gtest.h"
2#include "ariba/utility/system/SystemQueue.h"
3
4#include <ostream>
5
6using namespace ::testing;
7using namespace ariba::utility;
8using namespace std;
9
10/**
11 * Tests if the SystemQueue is initialized empty and not running.
12 */
13TEST(SystemQueue, Instantiation)
14{
15 SystemQueue& sysq = SystemQueue::instance();
16
17// cout << &sysq << endl;
18
19 EXPECT_FALSE( sysq.isRunning() );
20 EXPECT_TRUE( sysq.isEmpty() );
21}
22
23
24/**
25 * Tests whether calling the SystemQueue::instance() always returns the same object.
26 *
27 * NOTE: This is an easy case, since this is the same compile unit..
28 * But can't hurt to test it anyway.
29 */
30TEST(SystemQueue, Singleton)
31{
32 SystemQueue& sysq = SystemQueue::instance();
33 SystemQueue& sysq2 = SystemQueue::instance();
34
35// cout << &sysq << endl;
36
37 EXPECT_TRUE( &sysq == &sysq2 );
38}
39
40
41/**
42 * Start and stop the SystemQueue
43 */
44TEST(SystemQueue, StartStop)
45{
46 SystemQueue& sysq = SystemQueue::instance();
47
48 EXPECT_FALSE( sysq.isRunning() );
49
50 // start
51 sysq.run();
52
53 EXPECT_TRUE( sysq.isRunning() );
54
55 // stop
56 sysq.cancel();
57
58 EXPECT_FALSE( sysq.isRunning() );
59}
60
61
62/**
63 * Test fixture
64 *
65 * class that can be called by the SystemQueue
66 */
67// To use a test fixture, derive a class from testing::Test.
68class SystemQueueTest :
69 public testing::Test
70{
71public:
72
73 SystemQueueTest() :
74 checkmark(false)
75 {
76 }
77
78 void Check()
79 {
80 checkmark = true;
81// cout << "Hallo Mario ^^" << endl;
82 }
83
84 bool checkmark;
85};
86
87TEST_F(SystemQueueTest, ScheduleCall)
88{
89 SystemQueue& sysq = SystemQueue::instance();
90 checkmark = false; // just to be sure..
91
92 // start
93 sysq.run();
94
95 // scheduleCall
96 sysq.scheduleCall(
97 boost::bind(&SystemQueueTest::Check, this)
98 );
99
100 // FIXME: yes, we have to wait a while here...
101 // maybe write a function (in the fixture): wait_for_remaining_events(int max_millisecs)
102
103 // stop
104 sysq.cancel();
105
106 EXPECT_TRUE( checkmark );
107
108 /* NOTE: If this fails, maybe we'll have to wait a bit..?
109 * There should be a possibility to cancel the SystemQueue as soon as it's empty..
110 */
111}
112
Note: See TracBrowser for help on using the repository browser.