vfs: check userland buffers before reading them.
[haiku.git] / src / tests / kits / app / bmessage / MessageMessengerItemTest.h
blobd3d05d20bbedc7f4b98eb4ac418eb76a9fae53cf
1 //------------------------------------------------------------------------------
2 // MessageMessengerItemTest.h
3 //
4 //------------------------------------------------------------------------------
6 #ifndef MESSAGEMESSENGERITEMTEST_H
7 #define MESSAGEMESSENGERITEMTEST_H
9 // Standard Includes -----------------------------------------------------------
11 // System Includes -------------------------------------------------------------
12 #include <Looper.h>
13 #include <Messenger.h>
15 // Project Includes ------------------------------------------------------------
17 // Local Includes --------------------------------------------------------------
18 #include "MessageItemTest.h"
20 // Local Defines ---------------------------------------------------------------
22 // Globals ---------------------------------------------------------------------
24 struct TMessengerFuncPolicy
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)
38 BMessenger msngr;
39 msg.FindMessenger(name, index, &msngr);
40 return msngr;
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); }
51 private:
52 static BMessenger sMsg;
54 BMessenger TMessengerFuncPolicy::sMsg;
56 struct TMessengerInitPolicy : public ArrayTypeBase<BMessenger>
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()
64 ArrayType array;
65 array.push_back(Zero());
66 array.push_back(Test1());
67 array.push_back(Test2());
68 return array;
71 private:
72 static BLooper sLooper;
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;
78 struct TMessengerAssertPolicy
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); }
86 typedef TMessageItemTest
88 BMessenger,
89 B_MESSENGER_TYPE,
90 TMessengerFuncPolicy,
91 TMessengerInitPolicy,
92 TMessengerAssertPolicy
94 TMessageMessengerItemTest;
96 #endif // MESSAGEMESSENGERITEMTEST_H
99 * $Log $
101 * $Id $