1 //------------------------------------------------------------------------------
2 // TargetTester.cpp
3 //
4 //------------------------------------------------------------------------------
5
6 // Standard Includes -----------------------------------------------------------
7 #include <stdio.h>
8
9 // System Includes -------------------------------------------------------------
10 #include <Message.h>
11 #include <OS.h>
12 #include <Handler.h>
13 #include <Looper.h>
14 #include <Messenger.h>
15
16 #define CHK CPPUNIT_ASSERT
17
18 // Project Includes ------------------------------------------------------------
19
20 // Local Includes --------------------------------------------------------------
21 #include "Helpers.h"
22 #include "SMTarget.h"
23 #include "TargetTester.h"
24
25 // Local Defines ---------------------------------------------------------------
26
27 // Globals ---------------------------------------------------------------------
28
29 //------------------------------------------------------------------------------
30
31 /*
32 bool IsTargetLocal() const
33 @case 1 this is uninitialized
34 @results should return false.
35 */
IsTargetLocalTest1()36 void TargetTester::IsTargetLocalTest1()
37 {
38 BMessenger messenger;
39 CHK(messenger.IsTargetLocal() == false);
40 }
41
42 /*
43 bool IsTargetLocal() const
44 @case 2 this is initialized to local target with preferred handler
45 @results should return true.
46 */
IsTargetLocalTest2()47 void TargetTester::IsTargetLocalTest2()
48 {
49 status_t result = B_OK;
50 BLooper *looper = new BLooper;
51 looper->Run();
52 LooperQuitter quitter(looper);
53 BMessenger messenger(NULL, looper, &result);
54 CHK(messenger.IsTargetLocal() == true);
55 }
56
57 /*
58 bool IsTargetLocal() const
59 @case 3 this is initialized to local target with specific handler
60 @results should return true.
61 */
IsTargetLocalTest3()62 void TargetTester::IsTargetLocalTest3()
63 {
64 // create looper and handler
65 status_t result = B_OK;
66 BLooper *looper = new BLooper;
67 looper->Run();
68 LooperQuitter quitter(looper);
69 BHandler *handler = new BHandler;
70 HandlerDeleter deleter(handler);
71 CHK(looper->Lock());
72 looper->AddHandler(handler);
73 looper->Unlock();
74 // create the messenger and do the checks
75 BMessenger messenger(handler, NULL, &result);
76 CHK(messenger.IsTargetLocal() == true);
77 }
78
79 /*
80 bool IsTargetLocal() const
81 @case 4 this is initialized to remote target with preferred handler
82 @results should return false.
83 */
IsTargetLocalTest4()84 void TargetTester::IsTargetLocalTest4()
85 {
86 RemoteSMTarget target(true);
87 BMessenger messenger(target.Messenger());
88 CHK(messenger.IsTargetLocal() == false);
89 }
90
91 /*
92 bool IsTargetLocal() const
93 @case 5 this is initialized to remote target with specific handler
94 @results should return false.
95 */
IsTargetLocalTest5()96 void TargetTester::IsTargetLocalTest5()
97 {
98 RemoteSMTarget target(false);
99 BMessenger messenger(target.Messenger());
100 CHK(messenger.IsTargetLocal() == false);
101 }
102
103 /*
104 BHandler *Target(BLooper **looper) const
105 @case 1 this is uninitialized, looper is NULL
106 @results should return NULL.
107 */
TargetTest1()108 void TargetTester::TargetTest1()
109 {
110 BMessenger messenger;
111 CHK(messenger.Target(NULL) == NULL);
112 }
113
114 /*
115 BHandler *Target(BLooper **looper) const
116 @case 2 this is initialized to local target with preferred handler,
117 looper is NULL
118 @results should return NULL.
119 */
TargetTest2()120 void TargetTester::TargetTest2()
121 {
122 status_t result = B_OK;
123 BLooper *looper = new BLooper;
124 looper->Run();
125 LooperQuitter quitter(looper);
126 BMessenger messenger(NULL, looper, &result);
127 CHK(messenger.Target(NULL) == NULL);
128 }
129
130 /*
131 BHandler *Target(BLooper **looper) const
132 @case 3 this is initialized to local target with specific handler,
133 looper is NULL
134 @results should return correct handler.
135 */
TargetTest3()136 void TargetTester::TargetTest3()
137 {
138 // create looper and handler
139 status_t result = B_OK;
140 BLooper *looper = new BLooper;
141 looper->Run();
142 LooperQuitter quitter(looper);
143 BHandler *handler = new BHandler;
144 HandlerDeleter deleter(handler);
145 CHK(looper->Lock());
146 looper->AddHandler(handler);
147 looper->Unlock();
148 // create the messenger and do the checks
149 BMessenger messenger(handler, NULL, &result);
150 CHK(messenger.Target(NULL) == handler);
151 }
152
153 /*
154 BHandler *Target(BLooper **looper) const
155 @case 4 this is initialized to remote target with preferred
156 handler, looper is NULL
157 @results should return NULL.
158 */
TargetTest4()159 void TargetTester::TargetTest4()
160 {
161 RemoteSMTarget target(true);
162 BMessenger messenger(target.Messenger());
163 CHK(messenger.Target(NULL) == NULL);
164 }
165
166 /*
167 BHandler *Target(BLooper **looper) const
168 @case 5 this is initialized to remote target with specific handler,
169 looper is NULL
170 @results should return NULL.
171 */
TargetTest5()172 void TargetTester::TargetTest5()
173 {
174 RemoteSMTarget target(false);
175 BMessenger messenger(target.Messenger());
176 CHK(messenger.Target(NULL) == NULL);
177 }
178
179
Suite()180 Test* TargetTester::Suite()
181 {
182 TestSuite* SuiteOfTests = new TestSuite;
183
184 ADD_TEST4(BMessenger, SuiteOfTests, TargetTester, IsTargetLocalTest1);
185 ADD_TEST4(BMessenger, SuiteOfTests, TargetTester, IsTargetLocalTest2);
186 ADD_TEST4(BMessenger, SuiteOfTests, TargetTester, IsTargetLocalTest3);
187 ADD_TEST4(BMessenger, SuiteOfTests, TargetTester, IsTargetLocalTest4);
188 ADD_TEST4(BMessenger, SuiteOfTests, TargetTester, IsTargetLocalTest5);
189
190 ADD_TEST4(BMessenger, SuiteOfTests, TargetTester, TargetTest1);
191 ADD_TEST4(BMessenger, SuiteOfTests, TargetTester, TargetTest2);
192 ADD_TEST4(BMessenger, SuiteOfTests, TargetTester, TargetTest3);
193 ADD_TEST4(BMessenger, SuiteOfTests, TargetTester, TargetTest4);
194 ADD_TEST4(BMessenger, SuiteOfTests, TargetTester, TargetTest5);
195
196 return SuiteOfTests;
197 }
198
199
200