xref: /haiku/src/tests/kits/app/bmessage/MessagePointerItemTest.h (revision bef39d09af0c445880b7dd9cc039d39a89d66365)
1 //------------------------------------------------------------------------------
2 //	MessagePointerItemTest.h
3 //
4 //------------------------------------------------------------------------------
5 
6 #ifndef MESSAGEPOINTERITEMTEST_H
7 #define MESSAGEPOINTERITEMTEST_H
8 
9 // Standard Includes -----------------------------------------------------------
10 
11 // System Includes -------------------------------------------------------------
12 
13 // Project Includes ------------------------------------------------------------
14 
15 // Local Includes --------------------------------------------------------------
16 #include "MessageItemTest.h"
17 
18 // Local Defines ---------------------------------------------------------------
19 
20 // Globals ---------------------------------------------------------------------
21 
22 struct TPointerFuncPolicy
23 {
AddTPointerFuncPolicy24 	static status_t Add(BMessage& msg, const char* name, const void* val)
25 		{ return msg.AddPointer(name, val); }
AddDataTPointerFuncPolicy26 	static status_t AddData(BMessage& msg, const char* name, type_code type,
27 							const void* data, ssize_t size, bool)
28 		{ return msg.AddData(name, type, data, size); }
FindTPointerFuncPolicy29 	static status_t Find(BMessage& msg, const char* name, int32 index,
30 						 const void** val)
31 		{ return msg.FindPointer(name, index, (void**)val); }
ShortFindTPointerFuncPolicy32 	static status_t ShortFind(BMessage& msg, const char* name, const void** val)
33 		{ return msg.FindPointer(name, (void**)val); }
QuickFindTPointerFuncPolicy34 	static const void* QuickFind(BMessage& msg, const char* name, int32 index)
35 	{
36 		const void* ptr;
37 		msg.FindPointer(name, index, (void**)&ptr);
38 		return ptr;
39 	}
HasTPointerFuncPolicy40 	static bool Has(BMessage& msg, const char* name, int32 index)
41 		{ return msg.HasPointer(name, index); }
ReplaceTPointerFuncPolicy42 	static status_t Replace(BMessage& msg, const char* name, int32 index,
43 							const void* val)
44 		{ return msg.ReplacePointer(name, index, val); }
FindDataTPointerFuncPolicy45 	static status_t FindData(BMessage& msg, const char* name, type_code type,
46 							 int32 index, const void** data, ssize_t* size)
47 		{ return msg.FindData(name, type, index, data, size); }
48 };
49 
50 struct TPointerInitPolicy : public ArrayTypeBase<const void*>
51 {
ZeroTPointerInitPolicy52 	inline static const void* Zero()	{ return NULL; }
Test1TPointerInitPolicy53 	inline static const void* Test1()	{ return (const void*)&Test1; }
Test2TPointerInitPolicy54 	inline static const void* Test2()	{ return (const void*)&Test2; }
SizeOfTPointerInitPolicy55 	inline static size_t SizeOf(const void*)	{ return sizeof (const void*); }
ArrayTPointerInitPolicy56 	inline static ArrayType Array()
57 	{
58 		ArrayType array;
59 		array.push_back(Zero());
60 		array.push_back(Test1());
61 		array.push_back(Test2());
62 		return array;
63 	}
64 };
65 
66 struct TPointerAssertPolicy
67 {
ZeroTPointerAssertPolicy68 	inline static const void* Zero()	{ return NULL; }
InvalidTPointerAssertPolicy69 	inline static const void* Invalid()	{ return NULL; }
SizeTPointerAssertPolicy70 	inline static bool Size(size_t size, const void* t)
71 		{ return size == sizeof (t); }
72 };
73 
74 typedef TMessageItemTest
75 <
76 	const void*,
77 	B_POINTER_TYPE,
78 	TPointerFuncPolicy,
79 	TPointerInitPolicy,
80 	TPointerAssertPolicy
81 >
82 TMessagePointerItemTest;
83 
84 #endif	// MESSAGEPOINTERITEMTEST_H
85 
86 /*
87  * $Log $
88  *
89  * $Id  $
90  *
91  */
92 
93