vfs: check userland buffers before reading them.
[haiku.git] / src / tests / kits / app / bmessage / MessageBoolItemTest.h
blob3487daf6c8008f8f06aa871a6022f9c10a113a92
1 //------------------------------------------------------------------------------
2 // MessageBoolItemTest.h
3 //
4 //------------------------------------------------------------------------------
6 #ifndef MESSAGEBOOLITEMTEST_H
7 #define MESSAGEBOOLITEMTEST_H
9 // Standard Includes -----------------------------------------------------------
11 // System Includes -------------------------------------------------------------
13 // Project Includes ------------------------------------------------------------
15 // Local Includes --------------------------------------------------------------
16 #include "MessageItemTest.h"
18 // Local Defines ---------------------------------------------------------------
20 // Globals ---------------------------------------------------------------------
22 typedef TMessageItemFuncPolicy
24 bool,
25 &BMessage::AddBool,
26 &BMessage::FindBool,
27 &BMessage::FindBool,
28 &BMessage::FindBool,
29 &BMessage::HasBool,
30 &BMessage::ReplaceBool
32 TBoolFuncPolicy;
34 template<>
35 struct ArrayTypeBase<bool>
37 class ArrayType
39 public:
40 ArrayType() : array(NULL), size(0) {;}
41 ArrayType(const ArrayType& rhs) : array(NULL), size(0)
42 { *this = rhs; }
43 ArrayType(bool* data, uint32 len) : array(NULL), size(0)
44 { Assign(data, len); }
45 ~ArrayType() { if (array) delete[] array; }
47 ArrayType& operator=(const ArrayType& rhs)
49 if (this != &rhs)
50 Assign(rhs.array, rhs.size);
51 return *this;
54 uint32 Size() { return size; }
55 bool& operator[](int index)
57 // We're just gonna let a segfault happen
58 return array[index];
61 private:
62 void Assign(bool* data, uint32 len)
64 size = len;
66 if (array)
67 delete[] array;
68 array = new bool[Size()];
69 memcpy(array, data, Size());
71 bool* array;
72 uint32 size;
75 typedef uint32 SizeType;
76 static SizeType Size(ArrayType& array) { return array.Size(); }
79 struct TBoolInitPolicy : public ArrayTypeBase<bool>
81 inline static bool Zero() { return false; }
82 inline static bool Test1() { return true; }
83 inline static bool Test2() { return false; }
84 inline static size_t SizeOf(const bool&) { return sizeof (bool); }
85 inline static ArrayType Array()
87 static bool array[] = { true, true, true };
88 return ArrayType(array, 3);
92 //struct TBoolAssertPolicy
93 //{
94 // inline static bool Zero() { return false; }
95 // inline static bool Invalid() { return false;}
96 //};
97 typedef TMessageItemAssertPolicy
99 bool//,
100 // false,
101 // false
103 TBoolAssertPolicy;
105 typedef TMessageItemTest
107 bool,
108 B_BOOL_TYPE,
109 TBoolFuncPolicy,
110 TBoolInitPolicy,
111 TBoolAssertPolicy
113 TMessageBoolItemTest;
115 #endif // MESSAGEBOOLITEMTEST_H
118 * $Log $
120 * $Id $