vfs: check userland buffers before reading them.
[haiku.git] / src / tests / kits / app / bmessage / MessageCStringItemTest.h
blob912d5bf0f5734ad01377320f88e7b96562d42b40
1 //------------------------------------------------------------------------------
2 // MessageCStringItemTest.h
3 //
4 //------------------------------------------------------------------------------
6 #ifndef MESSAGECSTRINGITEMTEST_H
7 #define MESSAGECSTRINGITEMTEST_H
9 // Standard Includes -----------------------------------------------------------
11 // System Includes -------------------------------------------------------------
12 #include <Debug.h>
14 // Project Includes ------------------------------------------------------------
16 // Local Includes --------------------------------------------------------------
17 #include "MessageItemTest.h"
19 // Local Defines ---------------------------------------------------------------
21 // Globals ---------------------------------------------------------------------
23 typedef TMessageItemFuncPolicy
25 const char*,
26 &BMessage::AddString,
27 &BMessage::FindString,
28 &BMessage::FindString,
29 &BMessage::FindString,
30 &BMessage::HasString,
31 &BMessage::ReplaceString
33 TCStringFuncPolicy;
35 struct TCStringInitPolicy : public ArrayTypeBase<const char*>
37 typedef const char* TypePtr;
39 inline static const char* Zero() { return sStr1; }
40 inline static const char* Test1() { return sStr2; }
41 inline static const char* Test2() { return sStr3; }
42 inline static size_t SizeOf(const char*& data) { return strlen(data) + 1; }
43 inline static ArrayType Array()
45 ArrayType array;
46 array.push_back(Zero());
47 array.push_back(Test1());
48 array.push_back(Test2());
49 return array;
52 private:
53 static const char* sStr1;
54 static const char* sStr2;
55 static const char* sStr3;
57 const char* TCStringInitPolicy::sStr1 = "";
58 const char* TCStringInitPolicy::sStr2 = "cstring one";
59 const char* TCStringInitPolicy::sStr3 = "Bibbity-bobbity-boo!";
60 //------------------------------------------------------------------------------
61 struct TCStringAssertPolicy
63 inline static const char* Zero() { return ""; }
64 inline static const char* Invalid() { return ""; }
65 static bool Size(size_t size, const char* data)
66 ;//{ return size == msg.FlattenedSize(); }
68 bool TCStringAssertPolicy::Size(size_t size, const char* data)
70 return size == strlen(data) + 1;
72 //------------------------------------------------------------------------------
73 struct TCStringComparePolicy
75 static bool Compare(const char* lhs, const char* rhs);
77 bool TCStringCtypedef const char* TypePtr;
78 omparePolicy::Compare(const char* lhs, const char* rhs)
80 if (!lhs)
81 return rhs;
82 if (!rhs)
83 return lhs;
84 return strcmp(lhs, rhs) == 0;
86 //------------------------------------------------------------------------------
87 template<>
88 struct TypePolicy<const char*>
90 typedef const char* TypePtr;
91 enum { FixedSize = false };
92 inline const char* Dereference(TypePtr p) { return p; }
93 inline const char* AddressOf(const char*& t) { return t; }
95 //------------------------------------------------------------------------------
96 typedef TMessageItemTest
98 const char*,
99 B_STRING_TYPE,
100 TCStringFuncPolicy,
101 TCStringInitPolicy,
102 TCStringAssertPolicy,
103 TCStringComparePolicy
105 TMessageCStringItemTest;
108 #endif // MESSAGECSTRINGITEMTEST_H
111 * $Log $
113 * $Id $