xref: /haiku/src/tests/kits/app/bmessagerunner/MessageRunnerTestHelpers.h (revision e81a954787e50e56a7f06f72705b7859b6ab06d1)
1 // MessageRunnerTestHelpers.h
2 
3 #ifndef MESSAGE_RUNNER_TEST_HELPERS_H
4 #define MESSAGE_RUNNER_TEST_HELPERS_H
5 
6 #include <Application.h>
7 #include <List.h>
8 
9 enum {
10 	MSG_RUNNER_MESSAGE	= 'rmsg',
11 	MSG_REPLY			= 'rply',
12 };
13 
14 // MessageRunnerTestHandler
15 class MessageRunnerTestHandler : public BHandler {
16 public:
17 	MessageRunnerTestHandler();
18 	~MessageRunnerTestHandler();
19 
20 	virtual void MessageReceived(BMessage *message);
21 
22 	int32 CountReplies() const { return fReplyCount; }
23 
24 private:
25 	int32					fReplyCount;
26 };
27 
28 // MessageRunnerTestLooper
29 class MessageRunnerTestLooper : public BLooper {
30 public:
31 	MessageRunnerTestLooper();
32 	~MessageRunnerTestLooper();
33 
34 	virtual void MessageReceived(BMessage *message);
35 
36 	bool CheckMessages(bigtime_t startTime, bigtime_t interval, int32 count);
37 	bool CheckMessages(int32 skip, bigtime_t startTime, bigtime_t interval,
38 					   int32 count);
39 
40 private:
41 	struct MessageInfo;
42 
43 private:
44 	MessageInfo *MessageInfoAt(int32 index) const;
45 
46 private:
47 	BList	fMessageInfos;
48 };
49 
50 // MessageRunnerTestApp
51 class MessageRunnerTestApp : public BApplication {
52 public:
53 	MessageRunnerTestApp(const char *signature);
54 	~MessageRunnerTestApp();
55 
56 	virtual void MessageReceived(BMessage *message);
57 	virtual bool QuitRequested();
58 
59 	int32 CountReplies() const { return fReplyCount; }
60 
61 	MessageRunnerTestLooper *TestLooper() const { return fLooper; }
62 	MessageRunnerTestHandler *TestHandler() const { return fHandler; }
63 
64 private:
65 	static int32 _ThreadEntry(void *data);
66 
67 private:
68 	thread_id					fThread;
69 	int32						fReplyCount;
70 	MessageRunnerTestLooper		*fLooper;
71 	MessageRunnerTestHandler	*fHandler;
72 };
73 
74 #endif	// MESSAGE_RUNNER_TEST_HELPERS_H
75