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 // bonefish: TODO: Sorry, but this sucks. Just loading the App Kit test add-on 75 // will already create a BLooper. 76 BLooper TMessengerInitPolicy::sLooper; 77 78 struct TMessengerAssertPolicy 79 { 80 inline static BMessenger Zero() { return BMessenger(); } 81 inline static BMessenger Invalid() { return BMessenger(); } 82 inline static bool Size(size_t size, BMessenger& t) 83 { return size == sizeof (t); } 84 }; 85 86 typedef TMessageItemTest 87 < 88 BMessenger, 89 B_MESSENGER_TYPE, 90 TMessengerFuncPolicy, 91 TMessengerInitPolicy, 92 TMessengerAssertPolicy 93 > 94 TMessageMessengerItemTest; 95 96 #endif // MESSAGEMESSENGERITEMTEST_H 97 98 /* 99 * $Log $ 100 * 101 * $Id $ 102 * 103 */ 104 105