vfs: check userland buffers before reading them.
[haiku.git] / src / tests / kits / app / bmessage / MessageBStringItemTest.h
blobaf036cfec9ccca9b873f4f1cc2c434fa487c3267
1 //------------------------------------------------------------------------------
2 // MessageStringItemTest.h
3 //
4 //------------------------------------------------------------------------------
6 #ifndef MESSAGESTRINGITEMTEST_H
7 #define MESSAGESTRINGITEMTEST_H
9 // Standard Includes -----------------------------------------------------------
11 // System Includes -------------------------------------------------------------
12 #include <Debug.h>
13 #include <String.h>
15 // Project Includes ------------------------------------------------------------
17 // Local Includes --------------------------------------------------------------
18 #include "MessageItemTest.h"
20 // Local Defines ---------------------------------------------------------------
22 // Globals ---------------------------------------------------------------------
24 struct TBStringFuncPolicy
26 static status_t Add(BMessage& msg, const char* name, BString& data);
27 static status_t Find(BMessage& msg, const char* name, int32 index,
28 BString* data);
29 static status_t ShortFind(BMessage& msg, const char* name, BString* data);
30 static BString QuickFind(BMessage& msg, const char* name, int32 index);
31 static bool Has(BMessage& msg, const char* name, int32 index);
32 static status_t Replace(BMessage& msg, const char* name, int32 index,
33 BString& data);
34 static status_t AddData(BMessage& msg, const char* name, type_code type,
35 const BString* data, ssize_t size, bool);
36 static status_t FindData(BMessage& msg, const char* name, type_code type,
37 int32 index, const void** data, ssize_t* size);
39 private:
40 static BString sStr;
42 BString TBStringFuncPolicy::sStr;
43 //------------------------------------------------------------------------------
44 status_t TBStringFuncPolicy::Add(BMessage& msg, const char* name,
45 BString& data)
47 return msg.AddString(name, data);
49 //------------------------------------------------------------------------------
50 status_t TBStringFuncPolicy::Find(BMessage& msg, const char* name,
51 int32 index, BString* data)
53 return msg.FindString(name, index, data);
55 //------------------------------------------------------------------------------
56 inline status_t TBStringFuncPolicy::ShortFind(BMessage& msg, const char* name,
57 BString* data)
59 return msg.FindString(name, data);
61 //------------------------------------------------------------------------------
62 BString TBStringFuncPolicy::QuickFind(BMessage& msg, const char* name,
63 int32 index)
65 BString data;
66 msg.FindString(name, index, &data);
67 return data;
69 //------------------------------------------------------------------------------
70 bool TBStringFuncPolicy::Has(BMessage& msg, const char* name,
71 int32 index)
73 return msg.HasString(name, index);
75 //------------------------------------------------------------------------------
76 status_t TBStringFuncPolicy::Replace(BMessage& msg, const char* name,
77 int32 index, BString& data)
79 return msg.ReplaceString(name, index, data);
81 //------------------------------------------------------------------------------
82 status_t TBStringFuncPolicy::AddData(BMessage& msg, const char* name,
83 type_code type, const BString* data,
84 ssize_t size, bool)
86 return msg.AddData(name, type, (const void*)data->String(), size,
87 false);
89 //------------------------------------------------------------------------------
90 status_t TBStringFuncPolicy::FindData(BMessage& msg, const char* name,
91 type_code type, int32 index,
92 const void** data, ssize_t* size)
94 *data = NULL;
95 char* ptr;
96 status_t err = msg.FindData(name, type, index, (const void**)&ptr, size);
97 if (!err)
99 sStr = ptr;
100 *(BString**)data = &sStr;
103 return err;
105 //------------------------------------------------------------------------------
108 struct TBStringInitPolicy : public ArrayTypeBase<BString>
110 inline static BString Zero() { return BString(); }
111 inline static BString Test1() { return "Test1"; }
112 inline static BString Test2() { return "Supercalafragilistricexpialadocious"; }
113 inline static size_t SizeOf(const BString& s) { return s.Length() + 1; }
114 inline static ArrayType Array()
116 ArrayType array;
117 array.push_back(Zero());
118 array.push_back(Test1());
119 array.push_back(Test2());
120 return array;
123 //------------------------------------------------------------------------------
124 struct TBStringAssertPolicy
126 inline static BString Zero() { return BString(); }
127 inline static BString Invalid() { return BString(); }
128 static bool Size(size_t size, BString& msg)
129 ;//{ return size == msg.FlattenedSize(); }
131 bool TBStringAssertPolicy::Size(size_t size, BString& data)
133 return size == (size_t)data.Length() + 1;
135 //------------------------------------------------------------------------------
136 typedef TMessageItemTest
138 BString,
139 B_STRING_TYPE,
140 TBStringFuncPolicy,
141 TBStringInitPolicy,
142 TBStringAssertPolicy
144 TMessageBStringItemTest;
146 #endif // MESSAGESTRINGITEMTEST_H
149 * $Log $
151 * $Id $