xref: /haiku/src/tests/kits/app/bmessage/MessageCStringItemTest.h (revision d5cd5d63ff0ad395989db6cf4841a64d5b545d1d)
1 //------------------------------------------------------------------------------
2 //	MessageCStringItemTest.h
3 //
4 //------------------------------------------------------------------------------
5 
6 #ifndef MESSAGECSTRINGITEMTEST_H
7 #define MESSAGECSTRINGITEMTEST_H
8 
9 // Standard Includes -----------------------------------------------------------
10 
11 // System Includes -------------------------------------------------------------
12 #include <Debug.h>
13 
14 // Project Includes ------------------------------------------------------------
15 
16 // Local Includes --------------------------------------------------------------
17 #include "MessageItemTest.h"
18 
19 // Local Defines ---------------------------------------------------------------
20 
21 // Globals ---------------------------------------------------------------------
22 
23 typedef TMessageItemFuncPolicy
24 <
25 	const char*,
26 	&BMessage::AddString,
27 	&BMessage::FindString,
28 	&BMessage::FindString,
29 	&BMessage::FindString,
30 	&BMessage::HasString,
31 	&BMessage::ReplaceString
32 >
33 TCStringFuncPolicy;
34 
35 struct TCStringInitPolicy : public ArrayTypeBase<const char*>
36 {
37 	typedef const char*	TypePtr;
38 
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()
44 	{
45 		ArrayType array;
46 		array.push_back(Zero());
47 		array.push_back(Test1());
48 		array.push_back(Test2());
49 		return array;
50 	}
51 
52 	private:
53 		static const char* sStr1;
54 		static const char* sStr2;
55 		static const char* sStr3;
56 };
57 const char* TCStringInitPolicy::sStr1 = "";
58 const char* TCStringInitPolicy::sStr2 = "cstring one";
59 const char* TCStringInitPolicy::sStr3 = "Bibbity-bobbity-boo!";
60 //------------------------------------------------------------------------------
61 struct TCStringAssertPolicy
62 {
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(); }
67 };
68 bool TCStringAssertPolicy::Size(size_t size, const char* data)
69 {
70 	return size == strlen(data) + 1;
71 }
72 //------------------------------------------------------------------------------
73 struct TCStringComparePolicy
74 {
75 	static bool Compare(const char* lhs, const char* rhs);
76 };
77 bool TCStringComparePolicy::Compare(const char* lhs, const char* rhs)
78 {
79 	if (!lhs)
80 		return rhs;
81 	if (!rhs)
82 		return lhs;
83 	return strcmp(lhs, rhs) == 0;
84 }
85 //------------------------------------------------------------------------------
86 template<>
87 struct TypePolicy<const char*>
88 {
89 	typedef const char* TypePtr;
90 	enum { FixedSize = false };
91 	inline const char* Dereference(TypePtr p) { return p; }
92 	inline const char* AddressOf(const char*& t) { return t; }
93 };
94 //------------------------------------------------------------------------------
95 typedef TMessageItemTest
96 <
97 	const char*,
98 	B_STRING_TYPE,
99 	TCStringFuncPolicy,
100 	TCStringInitPolicy,
101 	TCStringAssertPolicy,
102 	TCStringComparePolicy
103 >
104 TMessageCStringItemTest;
105 
106 
107 #endif	// MESSAGECSTRINGITEMTEST_H
108 
109 /*
110  * $Log $
111  *
112  * $Id  $
113  *
114  */
115 
116