1dace24c6SIngo Weinhold//------------------------------------------------------------------------------
2dace24c6SIngo Weinhold//	BMessageRunnerTester.cpp
3dace24c6SIngo Weinhold//
4dace24c6SIngo Weinhold//------------------------------------------------------------------------------
5dace24c6SIngo Weinhold
6dace24c6SIngo Weinhold// Standard Includes -----------------------------------------------------------
7bef39d09SClemens Zeidler#include <algorithm>
8dace24c6SIngo Weinhold#include <stdio.h>
9dace24c6SIngo Weinhold
10dace24c6SIngo Weinhold// System Includes -------------------------------------------------------------
11dace24c6SIngo Weinhold#include <Application.h>
12dace24c6SIngo Weinhold#include <Handler.h>
13dace24c6SIngo Weinhold#include <Looper.h>
14dace24c6SIngo Weinhold#include <Message.h>
15dace24c6SIngo Weinhold#include <MessageRunner.h>
16dace24c6SIngo Weinhold#include <Messenger.h>
17dace24c6SIngo Weinhold#include <OS.h>
18dace24c6SIngo Weinhold
19dace24c6SIngo Weinhold// Project Includes ------------------------------------------------------------
20dace24c6SIngo Weinhold#include <TestShell.h>
21dace24c6SIngo Weinhold#include <TestUtils.h>
22dace24c6SIngo Weinhold#include <cppunit/TestAssert.h>
23dace24c6SIngo Weinhold
24dace24c6SIngo Weinhold// Local Includes --------------------------------------------------------------
25dace24c6SIngo Weinhold#include "BMessageRunnerTester.h"
26dace24c6SIngo Weinhold#include "MessageRunnerTestHelpers.h"
27dace24c6SIngo Weinhold
28dace24c6SIngo Weinhold// Local Defines ---------------------------------------------------------------
29dace24c6SIngo Weinhold
30dace24c6SIngo Weinhold// Globals ---------------------------------------------------------------------
31dace24c6SIngo Weinhold
32dace24c6SIngo Weinhold//------------------------------------------------------------------------------
33dace24c6SIngo Weinhold
34bef39d09SClemens Zeidler
35bef39d09SClemens Zeidlerusing namespace std;
36bef39d09SClemens Zeidler
37bef39d09SClemens Zeidler
38dace24c6SIngo Weinholdstatic const char *kTesterSignature
39dace24c6SIngo Weinhold	= "application/x-vnd.obos-messagerunner-constructor-test";
40dace24c6SIngo Weinhold
41dace24c6SIngo Weinholdstatic const bigtime_t kMinTimeInterval = 50000;
42dace24c6SIngo Weinhold
43dace24c6SIngo Weinhold// check_message_runner_info
44dace24c6SIngo Weinholdstatic
45dace24c6SIngo Weinholdvoid
46dace24c6SIngo Weinholdcheck_message_runner_info(const BMessageRunner &runner, status_t error,
47dace24c6SIngo Weinhold						  bigtime_t interval = 0, int32 count = 0)
48dace24c6SIngo Weinhold{
49dace24c6SIngo Weinhold	bigtime_t runnerInterval = 0;
50dace24c6SIngo Weinhold	int32 runnerCount = 0;
51dace24c6SIngo Weinhold	CHK(runner.GetInfo(&runnerInterval, &runnerCount) == error);
52dace24c6SIngo Weinhold	if (error == B_OK) {
53dace24c6SIngo Weinhold		CHK(runnerInterval == interval);
54dace24c6SIngo Weinhold		CHK(runnerCount == count);
55dace24c6SIngo Weinhold	}
56dace24c6SIngo Weinhold}
57dace24c6SIngo Weinhold
58dace24c6SIngo Weinhold/*
59dace24c6SIngo Weinhold	BMessageRunner(BMessenger target, const BMessage *message,
60dace24c6SIngo Weinhold				   bigtime_t interval, int32 count)
61dace24c6SIngo Weinhold	@case 1			target is invalid, message is valid, interval > 0,
62dace24c6SIngo Weinhold					count > 0
63dace24c6SIngo Weinhold	@results		InitCheck() should return B_OK. The message runner turns
64dace24c6SIngo Weinhold					to unusable as soon as the first message had to be sent.
65dace24c6SIngo Weinhold					GetInfo() should return B_OK.
66dace24c6SIngo Weinhold */
67dace24c6SIngo Weinholdvoid TBMessageRunnerTester::BMessageRunnerA1()
68dace24c6SIngo Weinhold{
69dace24c6SIngo Weinhold	MessageRunnerTestApp app(kTesterSignature);
70dace24c6SIngo Weinhold	BMessenger target;
71dace24c6SIngo Weinhold	BMessage message(MSG_RUNNER_MESSAGE);
72dace24c6SIngo Weinhold	bigtime_t interval = 100000;
73dace24c6SIngo Weinhold	int32 count = 5;
74dace24c6SIngo Weinhold	BMessageRunner runner(target, &message, interval, count);
75dace24c6SIngo Weinhold	CHK(runner.InitCheck() == B_OK);
76dace24c6SIngo Weinhold	check_message_runner_info(runner, B_OK, interval, count);
77dace24c6SIngo Weinhold	snooze(interval + 10000);
78dace24c6SIngo Weinhold	check_message_runner_info(runner, B_BAD_VALUE);
79dace24c6SIngo Weinhold	CHK(app.CountReplies() == 0);
80dace24c6SIngo Weinhold}
81dace24c6SIngo Weinhold
82dace24c6SIngo Weinhold/*
83dace24c6SIngo Weinhold	BMessageRunner(BMessenger target, const BMessage *message,
84dace24c6SIngo Weinhold				   bigtime_t interval, int32 count)
85dace24c6SIngo Weinhold	@case 2			target is valid, message is NULL, interval > 0, count > 0
86dace24c6SIngo Weinhold	@results		InitCheck() should return B_BAD_VALUE.
87dace24c6SIngo Weinhold					GetInfo() should return B_BAD_VALUE.
88dace24c6SIngo Weinhold */
89dace24c6SIngo Weinholdvoid TBMessageRunnerTester::BMessageRunnerA2()
90dace24c6SIngo Weinhold{
91dace24c6SIngo Weinhold// R5: chrashes when passing a NULL message
92dace24c6SIngo Weinhold#ifndef TEST_R5
93dace24c6SIngo Weinhold	MessageRunnerTestApp app(kTesterSignature);
94dace24c6SIngo Weinhold	MessageRunnerTestLooper *looper = app.TestLooper();
95dace24c6SIngo Weinhold	BMessenger target(looper);
96dace24c6SIngo Weinhold	bigtime_t interval = 100000;
97dace24c6SIngo Weinhold	int32 count = 5;
98dace24c6SIngo Weinhold	BMessageRunner runner(target, NULL, interval, count);
99dace24c6SIngo Weinhold	CHK(runner.InitCheck() == B_BAD_VALUE);
100dace24c6SIngo Weinhold	check_message_runner_info(runner, B_BAD_VALUE);
101dace24c6SIngo Weinhold#endif
102dace24c6SIngo Weinhold}
103dace24c6SIngo Weinhold
104dace24c6SIngo Weinhold/*
105dace24c6SIngo Weinhold	BMessageRunner(BMessenger target, const BMessage *message,
106dace24c6SIngo Weinhold				   bigtime_t interval, int32 count)
107dace24c6SIngo Weinhold	@case 3			target is valid, message is valid, interval == 0, count > 0
108dace24c6SIngo Weinhold	@results		R5: InitCheck() should return B_ERROR.
109dace24c6SIngo Weinhold						GetInfo() should return B_BAD_VALUE.
110dace24c6SIngo Weinhold					OBOS: InitCheck() should return B_OK.
111dace24c6SIngo Weinhold						  GetInfo() should return B_OK.
112dace24c6SIngo Weinhold						  A minimal time interval is used (50000).
113dace24c6SIngo Weinhold */
114dace24c6SIngo Weinholdvoid TBMessageRunnerTester::BMessageRunnerA3()
115dace24c6SIngo Weinhold{
116dace24c6SIngo Weinhold	MessageRunnerTestApp app(kTesterSignature);
117dace24c6SIngo Weinhold	MessageRunnerTestLooper *looper = app.TestLooper();
118dace24c6SIngo Weinhold	BMessenger target(looper);
119dace24c6SIngo Weinhold	BMessage message(MSG_RUNNER_MESSAGE);
120dace24c6SIngo Weinhold	bigtime_t interval = 0;
121dace24c6SIngo Weinhold	int32 count = 5;
122dace24c6SIngo Weinhold	BMessageRunner runner(target, &message, interval, count);
123dace24c6SIngo Weinhold#ifdef TEST_R5
124dace24c6SIngo Weinhold	CHK(runner.InitCheck() == B_ERROR);
125dace24c6SIngo Weinhold	check_message_runner_info(runner, B_BAD_VALUE);
126dace24c6SIngo Weinhold#else
127dace24c6SIngo Weinhold	bigtime_t startTime = system_time();
128dace24c6SIngo Weinhold	CHK(runner.InitCheck() == B_OK);
129dace24c6SIngo Weinhold	interval = max(interval, kMinTimeInterval);
130dace24c6SIngo Weinhold	check_message_runner_info(runner, B_OK, interval, count);
131dace24c6SIngo Weinhold	snooze((count + 1) * interval + 10000);
132dace24c6SIngo Weinhold	CHK(looper->CheckMessages(startTime, interval, count));
133c890b606SIngo Weinhold	CHK(app.CountReplies() == count);
134dace24c6SIngo Weinhold#endif
135dace24c6SIngo Weinhold}
136dace24c6SIngo Weinhold
137dace24c6SIngo Weinhold/*
138dace24c6SIngo Weinhold	BMessageRunner(BMessenger target, const BMessage *message,
139dace24c6SIngo Weinhold				   bigtime_t interval, int32 count)
140dace24c6SIngo Weinhold	@case 4			target is valid, message is valid, interval < 0, count > 0
141dace24c6SIngo Weinhold	@results		InitCheck() should return B_OK.
142dace24c6SIngo Weinhold					GetInfo() should return B_OK.
143dace24c6SIngo Weinhold					A minimal time interval is used (50000).
144dace24c6SIngo Weinhold */
145dace24c6SIngo Weinholdvoid TBMessageRunnerTester::BMessageRunnerA4()
146dace24c6SIngo Weinhold{
147dace24c6SIngo Weinhold	MessageRunnerTestApp app(kTesterSignature);
148dace24c6SIngo Weinhold	MessageRunnerTestLooper *looper = app.TestLooper();
149dace24c6SIngo Weinhold	BMessenger target(looper);
150dace24c6SIngo Weinhold	BMessage message(MSG_RUNNER_MESSAGE);
151dace24c6SIngo Weinhold	bigtime_t interval = -1;
152dace24c6SIngo Weinhold	int32 count = 5;
153dace24c6SIngo Weinhold	BMessageRunner runner(target, &message, interval, count);
154dace24c6SIngo Weinhold	bigtime_t startTime = system_time();
155dace24c6SIngo Weinhold	CHK(runner.InitCheck() == B_OK);
156dace24c6SIngo Weinhold	interval = max(interval, kMinTimeInterval);
157dace24c6SIngo Weinhold	check_message_runner_info(runner, B_OK, interval, count);
158dace24c6SIngo Weinhold	snooze((count + 1) * interval + 10000);
159dace24c6SIngo Weinhold	CHK(looper->CheckMessages(startTime, interval, count));
160dace24c6SIngo Weinhold	CHK(app.CountReplies() == count);
161dace24c6SIngo Weinhold}
162dace24c6SIngo Weinhold
163dace24c6SIngo Weinhold/*
164dace24c6SIngo Weinhold	BMessageRunner(BMessenger target, const BMessage *message,
165dace24c6SIngo Weinhold				   bigtime_t interval, int32 count)
166dace24c6SIngo Weinhold	@case 5			target is valid, message is valid,
167dace24c6SIngo Weinhold					interval == LONGLONG_MAX, count > 0
168dace24c6SIngo Weinhold	@results		InitCheck() should return B_OK.
169dace24c6SIngo Weinhold					GetInfo() should return B_OK.
170dace24c6SIngo Weinhold					No message should be delivered.
171dace24c6SIngo Weinhold */
172dace24c6SIngo Weinholdvoid TBMessageRunnerTester::BMessageRunnerA5()
173dace24c6SIngo Weinhold{
174dace24c6SIngo Weinhold// R5: doesn't behave very well. In worst case registrar time loop gets
175dace24c6SIngo Weinhold// locked up and system wide message runners don't get messages anymore.
176dace24c6SIngo Weinhold#ifndef TEST_R5
177dace24c6SIngo Weinhold	MessageRunnerTestApp app(kTesterSignature);
178dace24c6SIngo Weinhold	MessageRunnerTestLooper *looper = app.TestLooper();
179dace24c6SIngo Weinhold	BMessenger target(looper);
180dace24c6SIngo Weinhold	BMessage message(MSG_RUNNER_MESSAGE);
181dace24c6SIngo Weinhold	bigtime_t interval = LONGLONG_MAX;
182dace24c6SIngo Weinhold	int32 count = 5;
183dace24c6SIngo Weinhold	BMessageRunner runner(target, &message, interval, count);
184dace24c6SIngo Weinhold	bigtime_t startTime = system_time();
185dace24c6SIngo Weinhold	CHK(runner.InitCheck() == B_OK);
186dace24c6SIngo Weinhold	interval = max(interval, kMinTimeInterval);
187dace24c6SIngo Weinhold	check_message_runner_info(runner, B_OK, interval, count);
188dace24c6SIngo Weinhold	snooze(10000);
189dace24c6SIngo Weinhold	CHK(looper->CheckMessages(startTime, interval, 0));
190dace24c6SIngo Weinhold	CHK(app.CountReplies() == 0);
191dace24c6SIngo Weinhold#endif
192dace24c6SIngo Weinhold}
193dace24c6SIngo Weinhold
194dace24c6SIngo Weinhold/*
195dace24c6SIngo Weinhold	BMessageRunner(BMessenger target, const BMessage *message,
196dace24c6SIngo Weinhold				   bigtime_t interval, int32 count)
197dace24c6SIngo Weinhold	@case 6			target is valid, message is valid, interval > 0, count == 0
198dace24c6SIngo Weinhold	@results		InitCheck() should return B_ERROR.
199dace24c6SIngo Weinhold					GetInfo() should return B_BAD_VALUE.
200dace24c6SIngo Weinhold */
201dace24c6SIngo Weinholdvoid TBMessageRunnerTester::BMessageRunnerA6()
202dace24c6SIngo Weinhold{
203dace24c6SIngo Weinhold	MessageRunnerTestApp app(kTesterSignature);
204dace24c6SIngo Weinhold	MessageRunnerTestLooper *looper = app.TestLooper();
205dace24c6SIngo Weinhold	BMessenger target(looper);
206dace24c6SIngo Weinhold	BMessage message(MSG_RUNNER_MESSAGE);
207dace24c6SIngo Weinhold	bigtime_t interval = 100000;
208dace24c6SIngo Weinhold	int32 count = 0;
209dace24c6SIngo Weinhold	BMessageRunner runner(target, &message, interval, count);
210dace24c6SIngo Weinhold	CHK(runner.InitCheck() == B_ERROR);
211dace24c6SIngo Weinhold	check_message_runner_info(runner, B_BAD_VALUE);
212dace24c6SIngo Weinhold}
213dace24c6SIngo Weinhold
214dace24c6SIngo Weinhold/*
215dace24c6SIngo Weinhold	BMessageRunner(BMessenger target, const BMessage *message,
216dace24c6SIngo Weinhold				   bigtime_t interval, int32 count)
217dace24c6SIngo Weinhold	@case 7			target is valid, message is valid, interval > 0, count < 0
218dace24c6SIngo Weinhold	@results		InitCheck() should return B_OK.
219dace24c6SIngo Weinhold					GetInfo() should return B_OK.
220dace24c6SIngo Weinhold					Unlimited number of messages.
221dace24c6SIngo Weinhold */
222dace24c6SIngo Weinholdvoid TBMessageRunnerTester::BMessageRunnerA7()
223dace24c6SIngo Weinhold{
224dace24c6SIngo Weinhold	MessageRunnerTestApp app(kTesterSignature);
225dace24c6SIngo Weinhold	MessageRunnerTestLooper *looper = app.TestLooper();
226dace24c6SIngo Weinhold	BMessenger target(looper);
227dace24c6SIngo Weinhold	BMessage message(MSG_RUNNER_MESSAGE);
228dace24c6SIngo Weinhold	bigtime_t interval = 100000;
229dace24c6SIngo Weinhold	int32 count = 5;
230dace24c6SIngo Weinhold	BMessageRunner runner(target, &message, interval, count);
231dace24c6SIngo Weinhold	bigtime_t startTime = system_time();
232dace24c6SIngo Weinhold	CHK(runner.InitCheck() == B_OK);
233dace24c6SIngo Weinhold	interval = max(interval, kMinTimeInterval);
234dace24c6SIngo Weinhold	check_message_runner_info(runner, B_OK, interval, count);
235dace24c6SIngo Weinhold	int32 checkCount = 5;
236dace24c6SIngo Weinhold	snooze(checkCount * interval + 10000);
237dace24c6SIngo Weinhold	CHK(looper->CheckMessages(startTime, interval, checkCount));
238dace24c6SIngo Weinhold	CHK(app.CountReplies() == checkCount);
239dace24c6SIngo Weinhold}
240dace24c6SIngo Weinhold
241dace24c6SIngo Weinhold/*
242dace24c6SIngo Weinhold	BMessageRunner(BMessenger target, const BMessage *message,
243dace24c6SIngo Weinhold				   bigtime_t interval, int32 count)
244dace24c6SIngo Weinhold	@case 8			target is valid, message is valid, interval > 0, count > 0
245dace24c6SIngo Weinhold	@results		InitCheck() should return B_OK.
246dace24c6SIngo Weinhold					GetInfo() should return B_OK.
247dace24c6SIngo Weinhold					count messages are sent.
248dace24c6SIngo Weinhold */
249dace24c6SIngo Weinholdvoid TBMessageRunnerTester::BMessageRunnerA8()
250dace24c6SIngo Weinhold{
251dace24c6SIngo Weinhold	MessageRunnerTestApp app(kTesterSignature);
252dace24c6SIngo Weinhold	MessageRunnerTestLooper *looper = app.TestLooper();
253dace24c6SIngo Weinhold	BMessenger target(looper);
254dace24c6SIngo Weinhold	BMessage message(MSG_RUNNER_MESSAGE);
255dace24c6SIngo Weinhold	bigtime_t interval = 100000;
256dace24c6SIngo Weinhold	int32 count = 5;
257dace24c6SIngo Weinhold	BMessageRunner runner(target, &message, interval, count);
258dace24c6SIngo Weinhold	bigtime_t startTime = system_time();
259dace24c6SIngo Weinhold	CHK(runner.InitCheck() == B_OK);
260dace24c6SIngo Weinhold	interval = max(interval, kMinTimeInterval);
261dace24c6SIngo Weinhold	check_message_runner_info(runner, B_OK, interval, count);
262dace24c6SIngo Weinhold	snooze((count + 1) * interval + 10000);
263dace24c6SIngo Weinhold	CHK(looper->CheckMessages(startTime, interval, count));
264dace24c6SIngo Weinhold	CHK(app.CountReplies() == count);
265dace24c6SIngo Weinhold}
266dace24c6SIngo Weinhold
267dace24c6SIngo Weinhold/*
268dace24c6SIngo Weinhold	BMessageRunner(BMessenger target, const BMessage *message,
269dace24c6SIngo Weinhold				   bigtime_t interval, int32 count, BMessenger replyTo)
270dace24c6SIngo Weinhold	@case 1			target is invalid, message is valid, interval > 0,
271dace24c6SIngo Weinhold					count > 0
272dace24c6SIngo Weinhold	@results		InitCheck() should return B_OK. The message runner turns
273dace24c6SIngo Weinhold					to unusable as soon as the first message had to be sent.
274dace24c6SIngo Weinhold					GetInfo() should return B_OK.
275dace24c6SIngo Weinhold */
276dace24c6SIngo Weinholdvoid TBMessageRunnerTester::BMessageRunnerB1()
277dace24c6SIngo Weinhold{
278dace24c6SIngo Weinhold	MessageRunnerTestApp app(kTesterSignature);
279dace24c6SIngo Weinhold	BMessenger target;
280dace24c6SIngo Weinhold	BMessage message(MSG_RUNNER_MESSAGE);
281dace24c6SIngo Weinhold	bigtime_t interval = 100000;
282dace24c6SIngo Weinhold	int32 count = 5;
283dace24c6SIngo Weinhold	MessageRunnerTestHandler *handler = app.TestHandler();
284dace24c6SIngo Weinhold	BMessenger replyTo(handler);
285dace24c6SIngo Weinhold	BMessageRunner runner(target, &message, interval, count, replyTo);
286dace24c6SIngo Weinhold	CHK(runner.InitCheck() == B_OK);
287dace24c6SIngo Weinhold	check_message_runner_info(runner, B_OK, interval, count);
288dace24c6SIngo Weinhold	snooze(interval + 10000);
289dace24c6SIngo Weinhold	check_message_runner_info(runner, B_BAD_VALUE);
290dace24c6SIngo Weinhold	CHK(app.CountReplies() == 0);
291dace24c6SIngo Weinhold	CHK(handler->CountReplies() == 0);
292dace24c6SIngo Weinhold}
293dace24c6SIngo Weinhold
294dace24c6SIngo Weinhold/*
295dace24c6SIngo Weinhold	BMessageRunner(BMessenger target, const BMessage *message,
296dace24c6SIngo Weinhold				   bigtime_t interval, int32 count, BMessenger replyTo)
297dace24c6SIngo Weinhold	@case 2			target is valid, message is NULL, interval > 0, count > 0
298dace24c6SIngo Weinhold	@results		InitCheck() should return B_BAD_VALUE.
299dace24c6SIngo Weinhold					GetInfo() should return B_BAD_VALUE.
300dace24c6SIngo Weinhold */
301dace24c6SIngo Weinholdvoid TBMessageRunnerTester::BMessageRunnerB2()
302dace24c6SIngo Weinhold{
303dace24c6SIngo Weinhold// R5: chrashes when passing a NULL message
304dace24c6SIngo Weinhold#ifndef TEST_R5
305dace24c6SIngo Weinhold	MessageRunnerTestApp app(kTesterSignature);
306dace24c6SIngo Weinhold	MessageRunnerTestLooper *looper = app.TestLooper();
307dace24c6SIngo Weinhold	BMessenger target(looper);
308dace24c6SIngo Weinhold	bigtime_t interval = 100000;
309dace24c6SIngo Weinhold	int32 count = 5;
310dace24c6SIngo Weinhold	MessageRunnerTestHandler *handler = app.TestHandler();
311dace24c6SIngo Weinhold	BMessenger replyTo(handler);
312c890b606SIngo Weinhold	BMessageRunner runner(target, NULL, interval, count, replyTo);
313dace24c6SIngo Weinhold	CHK(runner.InitCheck() == B_BAD_VALUE);
314dace24c6SIngo Weinhold	check_message_runner_info(runner, B_BAD_VALUE);
315dace24c6SIngo Weinhold#endif
316dace24c6SIngo Weinhold}
317dace24c6SIngo Weinhold
318dace24c6SIngo Weinhold/*
319dace24c6SIngo Weinhold	BMessageRunner(BMessenger target, const BMessage *message,
320dace24c6SIngo Weinhold				   bigtime_t interval, int32 count, BMessenger replyTo)
321dace24c6SIngo Weinhold	@case 3			target is valid, message is valid, interval == 0, count > 0
322dace24c6SIngo Weinhold	@results		R5: InitCheck() should return B_ERROR.
323dace24c6SIngo Weinhold						GetInfo() should return B_BAD_VALUE.
324dace24c6SIngo Weinhold					OBOS: InitCheck() should return B_OK.
325dace24c6SIngo Weinhold						  GetInfo() should return B_OK.
326dace24c6SIngo Weinhold						  A minimal time interval is used (50000).
327dace24c6SIngo Weinhold */
328dace24c6SIngo Weinholdvoid TBMessageRunnerTester::BMessageRunnerB3()
329dace24c6SIngo Weinhold{
330dace24c6SIngo Weinhold	MessageRunnerTestApp app(kTesterSignature);
331dace24c6SIngo Weinhold	MessageRunnerTestLooper *looper = app.TestLooper();
332dace24c6SIngo Weinhold	BMessenger target(looper);
333dace24c6SIngo Weinhold	BMessage message(MSG_RUNNER_MESSAGE);
334dace24c6SIngo Weinhold	bigtime_t interval = 0;
335dace24c6SIngo Weinhold	int32 count = 5;
336dace24c6SIngo Weinhold	MessageRunnerTestHandler *handler = app.TestHandler();
337dace24c6SIngo Weinhold	BMessenger replyTo(handler);
338dace24c6SIngo Weinhold	BMessageRunner runner(target, &message, interval, count, replyTo);
339dace24c6SIngo Weinhold#ifdef TEST_R5
340dace24c6SIngo Weinhold	CHK(runner.InitCheck() == B_ERROR);
341dace24c6SIngo Weinhold	check_message_runner_info(runner, B_BAD_VALUE);
342dace24c6SIngo Weinhold#else
343dace24c6SIngo Weinhold	bigtime_t startTime = system_time();
344dace24c6SIngo Weinhold	CHK(runner.InitCheck() == B_OK);
345dace24c6SIngo Weinhold	interval = max(interval, kMinTimeInterval);
346dace24c6SIngo Weinhold	check_message_runner_info(runner, B_OK, interval, count);
347dace24c6SIngo Weinhold	snooze((count + 1) * interval + 10000);
348dace24c6SIngo Weinhold	CHK(looper->CheckMessages(startTime, interval, count));
349dace24c6SIngo Weinhold	CHK(app.CountReplies() == 0);
350dace24c6SIngo Weinhold	CHK(handler->CountReplies() == count);
351dace24c6SIngo Weinhold#endif
352dace24c6SIngo Weinhold}
353dace24c6SIngo Weinhold
354dace24c6SIngo Weinhold/*
355dace24c6SIngo Weinhold	BMessageRunner(BMessenger target, const BMessage *message,
356dace24c6SIngo Weinhold				   bigtime_t interval, int32 count, BMessenger replyTo)
357dace24c6SIngo Weinhold	@case 4			target is valid, message is valid, interval < 0, count > 0
358dace24c6SIngo Weinhold	@results		InitCheck() should return B_OK.
359dace24c6SIngo Weinhold					GetInfo() should return B_OK.
360dace24c6SIngo Weinhold					A minimal time interval is used (50000).
361dace24c6SIngo Weinhold */
362dace24c6SIngo Weinholdvoid TBMessageRunnerTester::BMessageRunnerB4()
363dace24c6SIngo Weinhold{
364dace24c6SIngo Weinhold	MessageRunnerTestApp app(kTesterSignature);
365dace24c6SIngo Weinhold	MessageRunnerTestLooper *looper = app.TestLooper();
366dace24c6SIngo Weinhold	BMessenger target(looper);
367dace24c6SIngo Weinhold	BMessage message(MSG_RUNNER_MESSAGE);
368dace24c6SIngo Weinhold	bigtime_t interval = -1;
369dace24c6SIngo Weinhold	int32 count = 5;
370dace24c6SIngo Weinhold	MessageRunnerTestHandler *handler = app.TestHandler();
371dace24c6SIngo Weinhold	BMessenger replyTo(handler);
372dace24c6SIngo Weinhold	BMessageRunner runner(target, &message, interval, count, replyTo);
373dace24c6SIngo Weinhold	bigtime_t startTime = system_time();
374dace24c6SIngo Weinhold	CHK(runner.InitCheck() == B_OK);
375dace24c6SIngo Weinhold	interval = max(interval, kMinTimeInterval);
376dace24c6SIngo Weinhold	check_message_runner_info(runner, B_OK, interval, count);
377dace24c6SIngo Weinhold	snooze((count + 1) * interval + 10000);
378dace24c6SIngo Weinhold	CHK(looper->CheckMessages(startTime, interval, count));
379dace24c6SIngo Weinhold	CHK(app.CountReplies() == 0);
380dace24c6SIngo Weinhold	CHK(handler->CountReplies() == count);
381dace24c6SIngo Weinhold}
382dace24c6SIngo Weinhold
383dace24c6SIngo Weinhold/*
384dace24c6SIngo Weinhold	BMessageRunner(BMessenger target, const BMessage *message,
385dace24c6SIngo Weinhold				   bigtime_t interval, int32 count, BMessenger replyTo)
386dace24c6SIngo Weinhold	@case 5			target is valid, message is valid,
387dace24c6SIngo Weinhold					interval == LONGLONG_MAX, count > 0
388dace24c6SIngo Weinhold	@results		InitCheck() should return B_OK.
389dace24c6SIngo Weinhold					GetInfo() should return B_OK.
390dace24c6SIngo Weinhold					No message should be delivered.
391dace24c6SIngo Weinhold */
392dace24c6SIngo Weinholdvoid TBMessageRunnerTester::BMessageRunnerB5()
393dace24c6SIngo Weinhold{
394dace24c6SIngo Weinhold// R5: doesn't behave very well. In worst case registrar time loop gets
395dace24c6SIngo Weinhold// locked up and system wide message runners don't get messages anymore.
396dace24c6SIngo Weinhold#ifndef TEST_R5
397dace24c6SIngo Weinhold	MessageRunnerTestApp app(kTesterSignature);
398dace24c6SIngo Weinhold	MessageRunnerTestLooper *looper = app.TestLooper();
399dace24c6SIngo Weinhold	BMessenger target(looper);
400dace24c6SIngo Weinhold	BMessage message(MSG_RUNNER_MESSAGE);
401dace24c6SIngo Weinhold	bigtime_t interval = LONGLONG_MAX;
402dace24c6SIngo Weinhold	int32 count = 5;
403dace24c6SIngo Weinhold	MessageRunnerTestHandler *handler = app.TestHandler();
404dace24c6SIngo Weinhold	BMessenger replyTo(handler);
405dace24c6SIngo Weinhold	BMessageRunner runner(target, &message, interval, count, replyTo);
406dace24c6SIngo Weinhold	bigtime_t startTime = system_time();
407dace24c6SIngo Weinhold	CHK(runner.InitCheck() == B_OK);
408dace24c6SIngo Weinhold	interval = max(interval, kMinTimeInterval);
409dace24c6SIngo Weinhold	check_message_runner_info(runner, B_OK, interval, count);
410dace24c6SIngo Weinhold	snooze(10000);
411dace24c6SIngo Weinhold	CHK(looper->CheckMessages(startTime, interval, 0));
412dace24c6SIngo Weinhold	CHK(app.CountReplies() == 0);
413dace24c6SIngo Weinhold	CHK(handler->CountReplies() == 0);
414dace24c6SIngo Weinhold#endif
415dace24c6SIngo Weinhold}
416dace24c6SIngo Weinhold
417dace24c6SIngo Weinhold/*
418dace24c6SIngo Weinhold	BMessageRunner(BMessenger target, const BMessage *message,
419dace24c6SIngo Weinhold				   bigtime_t interval, int32 count, BMessenger replyTo)
420dace24c6SIngo Weinhold	@case 6			target is valid, message is valid, interval > 0, count == 0
421dace24c6SIngo Weinhold	@results		InitCheck() should return B_ERROR.
422dace24c6SIngo Weinhold					GetInfo() should return B_BAD_VALUE.
423dace24c6SIngo Weinhold */
424dace24c6SIngo Weinholdvoid TBMessageRunnerTester::BMessageRunnerB6()
425dace24c6SIngo Weinhold{
426dace24c6SIngo Weinhold	MessageRunnerTestApp app(kTesterSignature);
427dace24c6SIngo Weinhold	MessageRunnerTestLooper *looper = app.TestLooper();
428dace24c6SIngo Weinhold	BMessenger target(looper);
429dace24c6SIngo Weinhold	BMessage message(MSG_RUNNER_MESSAGE);
430dace24c6SIngo Weinhold	bigtime_t interval = 100000;
431dace24c6SIngo Weinhold	int32 count = 0;
432dace24c6SIngo Weinhold	MessageRunnerTestHandler *handler = app.TestHandler();
433dace24c6SIngo Weinhold	BMessenger replyTo(handler);
434dace24c6SIngo Weinhold	BMessageRunner runner(target, &message, interval, count, replyTo);
435dace24c6SIngo Weinhold	CHK(runner.InitCheck() == B_ERROR);
436dace24c6SIngo Weinhold	check_message_runner_info(runner, B_BAD_VALUE);
437dace24c6SIngo Weinhold}
438dace24c6SIngo Weinhold
439dace24c6SIngo Weinhold/*
440dace24c6SIngo Weinhold	BMessageRunner(BMessenger target, const BMessage *message,
441dace24c6SIngo Weinhold				   bigtime_t interval, int32 count, BMessenger replyTo)
442dace24c6SIngo Weinhold	@case 7			target is valid, message is valid, interval > 0, count < 0
443dace24c6SIngo Weinhold	@results		InitCheck() should return B_OK.
444dace24c6SIngo Weinhold					GetInfo() should return B_OK.
445dace24c6SIngo Weinhold					Unlimited number of messages.
446dace24c6SIngo Weinhold */
447dace24c6SIngo Weinholdvoid TBMessageRunnerTester::BMessageRunnerB7()
448dace24c6SIngo Weinhold{
449dace24c6SIngo Weinhold	MessageRunnerTestApp app(kTesterSignature);
450dace24c6SIngo Weinhold	MessageRunnerTestLooper *looper = app.TestLooper();
451dace24c6SIngo Weinhold	BMessenger target(looper);
452dace24c6SIngo Weinhold	BMessage message(MSG_RUNNER_MESSAGE);
453dace24c6SIngo Weinhold	bigtime_t interval = 100000;
454dace24c6SIngo Weinhold	int32 count = 5;
455dace24c6SIngo Weinhold	MessageRunnerTestHandler *handler = app.TestHandler();
456dace24c6SIngo Weinhold	BMessenger replyTo(handler);
457dace24c6SIngo Weinhold	BMessageRunner runner(target, &message, interval, count, replyTo);
458dace24c6SIngo Weinhold	bigtime_t startTime = system_time();
459dace24c6SIngo Weinhold	CHK(runner.InitCheck() == B_OK);
460dace24c6SIngo Weinhold	interval = max(interval, kMinTimeInterval);
461dace24c6SIngo Weinhold	check_message_runner_info(runner, B_OK, interval, count);
462dace24c6SIngo Weinhold	int32 checkCount = 5;
463dace24c6SIngo Weinhold	snooze(checkCount * interval + 10000);
464dace24c6SIngo Weinhold	CHK(looper->CheckMessages(startTime, interval, checkCount));
465dace24c6SIngo Weinhold	CHK(app.CountReplies() == 0);
466dace24c6SIngo Weinhold	CHK(handler->CountReplies() == checkCount);
467dace24c6SIngo Weinhold}
468dace24c6SIngo Weinhold
469dace24c6SIngo Weinhold/*
470dace24c6SIngo Weinhold	BMessageRunner(BMessenger target, const BMessage *message,
471dace24c6SIngo Weinhold				   bigtime_t interval, int32 count, BMessenger replyTo)
472dace24c6SIngo Weinhold	@case 8			target is valid, message is valid, interval > 0, count > 0
473dace24c6SIngo Weinhold	@results		InitCheck() should return B_OK.
474dace24c6SIngo Weinhold					GetInfo() should return B_OK.
475dace24c6SIngo Weinhold					count messages are sent.
476dace24c6SIngo Weinhold */
477dace24c6SIngo Weinholdvoid TBMessageRunnerTester::BMessageRunnerB8()
478dace24c6SIngo Weinhold{
479dace24c6SIngo Weinhold	MessageRunnerTestApp app(kTesterSignature);
480dace24c6SIngo Weinhold	MessageRunnerTestLooper *looper = app.TestLooper();
481dace24c6SIngo Weinhold	BMessenger target(looper);
482dace24c6SIngo Weinhold	BMessage message(MSG_RUNNER_MESSAGE);
483dace24c6SIngo Weinhold	bigtime_t interval = 100000;
484dace24c6SIngo Weinhold	int32 count = 5;
485dace24c6SIngo Weinhold	MessageRunnerTestHandler *handler = app.TestHandler();
486dace24c6SIngo Weinhold	BMessenger replyTo(handler);
487dace24c6SIngo Weinhold	BMessageRunner runner(target, &message, interval, count, replyTo);
488dace24c6SIngo Weinhold	bigtime_t startTime = system_time();
489dace24c6SIngo Weinhold	CHK(runner.InitCheck() == B_OK);
490dace24c6SIngo Weinhold	interval = max(interval, kMinTimeInterval);
491dace24c6SIngo Weinhold	check_message_runner_info(runner, B_OK, interval, count);
492dace24c6SIngo Weinhold	snooze((count + 1) * interval + 10000);
493dace24c6SIngo Weinhold	CHK(looper->CheckMessages(startTime, interval, count));
494dace24c6SIngo Weinhold	CHK(app.CountReplies() == 0);
495dace24c6SIngo Weinhold	CHK(handler->CountReplies() == count);
496dace24c6SIngo Weinhold}
497dace24c6SIngo Weinhold
498dace24c6SIngo Weinhold/*
499dace24c6SIngo Weinhold	BMessageRunner(BMessenger target, const BMessage *message,
500dace24c6SIngo Weinhold				   bigtime_t interval, int32 count, BMessenger replyTo)
501dace24c6SIngo Weinhold	@case 9			target is valid, message is valid, interval > 0, count > 0,
502dace24c6SIngo Weinhold					replyTo is invalid
503dace24c6SIngo Weinhold	@results		InitCheck() should return B_OK.
504dace24c6SIngo Weinhold					GetInfo() should return B_OK.
505dace24c6SIngo Weinhold					count messages are sent. The replies go to the registrar!
506dace24c6SIngo Weinhold */
507dace24c6SIngo Weinholdvoid TBMessageRunnerTester::BMessageRunnerB9()
508dace24c6SIngo Weinhold{
509dace24c6SIngo Weinhold	MessageRunnerTestApp app(kTesterSignature);
510dace24c6SIngo Weinhold	MessageRunnerTestLooper *looper = app.TestLooper();
511dace24c6SIngo Weinhold	BMessenger target(looper);
512dace24c6SIngo Weinhold	BMessage message(MSG_RUNNER_MESSAGE);
513dace24c6SIngo Weinhold	bigtime_t interval = 100000;
514dace24c6SIngo Weinhold	int32 count = 5;
515dace24c6SIngo Weinhold	MessageRunnerTestHandler *handler = app.TestHandler();
516dace24c6SIngo Weinhold	BMessenger replyTo(handler);
517dace24c6SIngo Weinhold	BMessageRunner runner(target, &message, interval, count, replyTo);
518dace24c6SIngo Weinhold	bigtime_t startTime = system_time();
519dace24c6SIngo Weinhold	CHK(runner.InitCheck() == B_OK);
520dace24c6SIngo Weinhold	interval = max(interval, kMinTimeInterval);
521dace24c6SIngo Weinhold	check_message_runner_info(runner, B_OK, interval, count);
522dace24c6SIngo Weinhold	snooze((count + 1) * interval + 10000);
523dace24c6SIngo Weinhold	CHK(looper->CheckMessages(startTime, interval, count));
524dace24c6SIngo Weinhold	CHK(app.CountReplies() == 0);
525dace24c6SIngo Weinhold	CHK(handler->CountReplies() == count);
526dace24c6SIngo Weinhold}
527dace24c6SIngo Weinhold
528dace24c6SIngo Weinhold
529dace24c6SIngo WeinholdTest* TBMessageRunnerTester::Suite()
530dace24c6SIngo Weinhold{
531dace24c6SIngo Weinhold	TestSuite* SuiteOfTests = new TestSuite;
532dace24c6SIngo Weinhold
533dace24c6SIngo Weinhold	ADD_TEST4(BMessageRunner, SuiteOfTests, TBMessageRunnerTester,
534dace24c6SIngo Weinhold			  BMessageRunnerA1);
535dace24c6SIngo Weinhold	ADD_TEST4(BMessageRunner, SuiteOfTests, TBMessageRunnerTester,
536dace24c6SIngo Weinhold			  BMessageRunnerA2);
537dace24c6SIngo Weinhold	ADD_TEST4(BMessageRunner, SuiteOfTests, TBMessageRunnerTester,
538dace24c6SIngo Weinhold			  BMessageRunnerA3);
539dace24c6SIngo Weinhold	ADD_TEST4(BMessageRunner, SuiteOfTests, TBMessageRunnerTester,
540dace24c6SIngo Weinhold			  BMessageRunnerA4);
541dace24c6SIngo Weinhold	ADD_TEST4(BMessageRunner, SuiteOfTests, TBMessageRunnerTester,
542dace24c6SIngo Weinhold			  BMessageRunnerA5);
543dace24c6SIngo Weinhold	ADD_TEST4(BMessageRunner, SuiteOfTests, TBMessageRunnerTester,
544dace24c6SIngo Weinhold			  BMessageRunnerA6);
545dace24c6SIngo Weinhold	ADD_TEST4(BMessageRunner, SuiteOfTests, TBMessageRunnerTester,
546dace24c6SIngo Weinhold			  BMessageRunnerA7);
547dace24c6SIngo Weinhold	ADD_TEST4(BMessageRunner, SuiteOfTests, TBMessageRunnerTester,
548dace24c6SIngo Weinhold			  BMessageRunnerA8);
549dace24c6SIngo Weinhold
550dace24c6SIngo Weinhold	ADD_TEST4(BMessageRunner, SuiteOfTests, TBMessageRunnerTester,
551dace24c6SIngo Weinhold			  BMessageRunnerB1);
552dace24c6SIngo Weinhold	ADD_TEST4(BMessageRunner, SuiteOfTests, TBMessageRunnerTester,
553dace24c6SIngo Weinhold			  BMessageRunnerB2);
554dace24c6SIngo Weinhold	ADD_TEST4(BMessageRunner, SuiteOfTests, TBMessageRunnerTester,
555dace24c6SIngo Weinhold			  BMessageRunnerB3);
556dace24c6SIngo Weinhold	ADD_TEST4(BMessageRunner, SuiteOfTests, TBMessageRunnerTester,
557dace24c6SIngo Weinhold			  BMessageRunnerB4);
558dace24c6SIngo Weinhold	ADD_TEST4(BMessageRunner, SuiteOfTests, TBMessageRunnerTester,
559dace24c6SIngo Weinhold			  BMessageRunnerB5);
560dace24c6SIngo Weinhold	ADD_TEST4(BMessageRunner, SuiteOfTests, TBMessageRunnerTester,
561dace24c6SIngo Weinhold			  BMessageRunnerB6);
562dace24c6SIngo Weinhold	ADD_TEST4(BMessageRunner, SuiteOfTests, TBMessageRunnerTester,
563dace24c6SIngo Weinhold			  BMessageRunnerB7);
564dace24c6SIngo Weinhold	ADD_TEST4(BMessageRunner, SuiteOfTests, TBMessageRunnerTester,
565dace24c6SIngo Weinhold			  BMessageRunnerB8);
566dace24c6SIngo Weinhold	ADD_TEST4(BMessageRunner, SuiteOfTests, TBMessageRunnerTester,
567dace24c6SIngo Weinhold			  BMessageRunnerB9);
568dace24c6SIngo Weinhold
569dace24c6SIngo Weinhold	return SuiteOfTests;
570dace24c6SIngo Weinhold}
571dace24c6SIngo Weinhold
572