xref: /haiku/src/tests/kits/app/bmessage/MessageMessengerItemTest.h (revision 51978af14a173e7fae0563b562be5603bc652aeb)
1 //------------------------------------------------------------------------------
2 //	MessageMessengerItemTest.h
3 //
4 //------------------------------------------------------------------------------
5 
6 #ifndef MESSAGEMESSENGERITEMTEST_H
7 #define MESSAGEMESSENGERITEMTEST_H
8 
9 // Standard Includes -----------------------------------------------------------
10 
11 // System Includes -------------------------------------------------------------
12 #include <Looper.h>
13 #include <Messenger.h>
14 
15 // Project Includes ------------------------------------------------------------
16 
17 // Local Includes --------------------------------------------------------------
18 #include "MessageItemTest.h"
19 
20 // Local Defines ---------------------------------------------------------------
21 
22 // Globals ---------------------------------------------------------------------
23 
24 struct TMessengerFuncPolicy
25 {
26 	static status_t Add(BMessage& msg, const char* name, BMessenger& val)
27 		{ return msg.AddMessenger(name, val); }
28 	static status_t AddData(BMessage& msg, const char* name, type_code type,
29 							BMessenger* data, ssize_t size, bool)
30 		{ return msg.AddData(name, type, data, size); }
31 	static status_t Find(BMessage& msg, const char* name, int32 index,
32 						 BMessenger* val)
33 		{ return msg.FindMessenger(name, index, val); }
34 	static status_t ShortFind(BMessage& msg, const char* name, BMessenger* val)
35 		{ return msg.FindMessenger(name, val); }
36 	static BMessenger QuickFind(BMessage& msg, const char* name, int32 index)
37 	{
38 		BMessenger msngr;
39 		msg.FindMessenger(name, index, &msngr);
40 		return msngr;
41 	}
42 	static bool Has(BMessage& msg, const char* name, int32 index)
43 		{ return msg.HasMessenger(name, index); }
44 	static status_t Replace(BMessage& msg, const char* name, int32 index,
45 							BMessenger& val)
46 		{ return msg.ReplaceMessenger(name, index, val); }
47 	static status_t FindData(BMessage& msg, const char* name, type_code type,
48 							 int32 index, const void** data, ssize_t* size)
49 		{ return msg.FindData(name, type, index, data, size); }
50 
51 	private:
52 		static BMessenger sMsg;
53 };
54 BMessenger TMessengerFuncPolicy::sMsg;
55 
56 struct TMessengerInitPolicy : public ArrayTypeBase<BMessenger>
57 {
58 	inline static BMessenger Zero()		{ return BMessenger(); }
59 	inline static BMessenger Test1()	{ return BMessenger("application/x-vnd.Be-NPOS"); }
60 	inline static BMessenger Test2()	{ return BMessenger(&sLooper); }
61 	inline static size_t SizeOf(const BMessenger&)	{ return sizeof (BMessenger); }
62 	inline static ArrayType Array()
63 	{
64 		ArrayType array;
65 		array.push_back(Zero());
66 		array.push_back(Test1());
67 		array.push_back(Test2());
68 		return array;
69 	}
70 
71 	private:
72 		static BLooper sLooper;
73 };
74 BLooper TMessengerInitPolicy::sLooper;
75 
76 struct TMessengerAssertPolicy
77 {
78 	inline static BMessenger Zero()		{ return BMessenger(); }
79 	inline static BMessenger Invalid()	{ return BMessenger(); }
80 	inline static bool Size(size_t size, BMessenger& t)
81 		{ return size == sizeof (t); }
82 };
83 
84 typedef TMessageItemTest
85 <
86 	BMessenger,
87 	B_MESSENGER_TYPE,
88 	TMessengerFuncPolicy,
89 	TMessengerInitPolicy,
90 	TMessengerAssertPolicy
91 >
92 TMessageMessengerItemTest;
93 
94 #endif	// MESSAGEMESSENGERITEMTEST_H
95 
96 /*
97  * $Log $
98  *
99  * $Id  $
100  *
101  */
102 
103