1 //------------------------------------------------------------------------------
2 // MessengerAssignmentTester.cpp
4 //------------------------------------------------------------------------------
6 // Standard Includes -----------------------------------------------------------
9 // System Includes -------------------------------------------------------------
14 #include <Messenger.h>
16 // Project Includes ------------------------------------------------------------
17 #include <TestUtils.h>
18 #include <ThreadedTestCaller.h>
19 #include <cppunit/TestSuite.h>
21 // Local Includes --------------------------------------------------------------
23 #include "MessengerAssignmentTester.h"
25 // Local Defines ---------------------------------------------------------------
27 // Globals ---------------------------------------------------------------------
29 //------------------------------------------------------------------------------
32 MessengerAssignmentTester::MessengerAssignmentTester()
33 : BThreadedTestCase(),
40 MessengerAssignmentTester::MessengerAssignmentTester(std::string name
)
41 : BThreadedTestCase(name
),
48 MessengerAssignmentTester::~MessengerAssignmentTester()
53 fLooper
->RemoveHandler(fHandler
);
61 BMessenger &operator=(const BMessenger &from)
62 @case 1 from is uninitialized
63 @results IsValid() and IsTargetLocal() should return false
64 Target() should return NULL and NULL for looper.
65 Team() should return -1.
67 void MessengerAssignmentTester::AssignmentTest1()
71 CHK(&(messenger
= from
) == &messenger
);
72 CHK(messenger
.IsValid() == false);
73 CHK(messenger
.IsTargetLocal() == false);
75 CHK(messenger
.Target(&looper
) == NULL
);
77 CHK(messenger
.Team() == -1);
81 BMessenger &operator=(const BMessenger &from)
82 @case 2 from is properly initialized to a local target
84 @results IsValid() and IsTargetLocal() should return true
85 Target() should return the same values as for from.
86 Team() should return this team.
88 void MessengerAssignmentTester::AssignmentTest2()
91 status_t result
= B_OK
;
92 BLooper
*looper
= new BLooper
;
94 LooperQuitter
quitter(looper
);
95 // create the from messenger
96 BMessenger
from(NULL
, looper
, &result
);
97 CHK(from
.IsValid() == true);
98 CHK(from
.IsTargetLocal() == true);
99 BLooper
*resultLooper
;
100 CHK(from
.Target(&resultLooper
) == NULL
);
101 CHK(resultLooper
== looper
);
102 CHK(from
.Team() == get_this_team());
104 // create the messenger and do the checks
105 BMessenger messenger
;
106 CHK(&(messenger
= from
) == &messenger
);
107 CHK(messenger
.IsValid() == true);
108 CHK(messenger
.IsTargetLocal() == true);
110 CHK(messenger
.Target(&resultLooper
) == NULL
);
111 CHK(resultLooper
== looper
);
112 CHK(messenger
.Team() == get_this_team());
116 BMessenger &operator=(const BMessenger &from)
117 @case 3 from is properly initialized to a local target
119 @results IsValid() and IsTargetLocal() should return true
120 Target() should return the same values as for from.
121 Team() should return this team.
123 void MessengerAssignmentTester::AssignmentTest3()
125 // create looper and handler
126 status_t result
= B_OK
;
127 BLooper
*looper
= new BLooper
;
129 LooperQuitter
quitter(looper
);
130 BHandler
*handler
= new BHandler
;
131 HandlerDeleter
deleter(handler
);
133 looper
->AddHandler(handler
);
135 // create the from messenger
136 BMessenger
from(handler
, looper
, &result
);
137 CHK(from
.IsValid() == true);
138 CHK(from
.IsTargetLocal() == true);
139 BLooper
*resultLooper
;
140 CHK(from
.Target(&resultLooper
) == handler
);
141 CHK(resultLooper
== looper
);
142 CHK(from
.Team() == get_this_team());
144 // create the messenger and do the checks
145 BMessenger messenger
;
146 CHK(&(messenger
= from
) == &messenger
);
147 CHK(messenger
.IsValid() == true);
148 CHK(messenger
.IsTargetLocal() == true);
150 CHK(messenger
.Target(&resultLooper
) == handler
);
151 CHK(resultLooper
== looper
);
152 CHK(messenger
.Team() == get_this_team());
156 Test
* MessengerAssignmentTester::Suite()
158 typedef BThreadedTestCaller
<MessengerAssignmentTester
> TC
;
160 TestSuite
* testSuite
= new TestSuite
;
162 ADD_TEST4(BMessenger
, testSuite
, MessengerAssignmentTester
, AssignmentTest1
);
163 ADD_TEST4(BMessenger
, testSuite
, MessengerAssignmentTester
, AssignmentTest2
);
164 ADD_TEST4(BMessenger
, testSuite
, MessengerAssignmentTester
, AssignmentTest3
);