1 //------------------------------------------------------------------------------
2 // MessageInt32ItemTest.cpp
4 //------------------------------------------------------------------------------
6 // Standard Includes -----------------------------------------------------------
8 #include <posix/string.h>
10 // System Includes -------------------------------------------------------------
13 // Project Includes ------------------------------------------------------------
15 // Local Includes --------------------------------------------------------------
16 #include "MessageInt32ItemTest.h"
18 // Local Defines ---------------------------------------------------------------
20 // Globals ---------------------------------------------------------------------
23 //------------------------------------------------------------------------------
24 void TMessageInt32ItemTest::MessageInt32ItemTest1()
28 CPPUNIT_ASSERT(msg
.FindInt32("an int32", &out
) == B_NAME_NOT_FOUND
);
29 CPPUNIT_ASSERT(out
== 0);
30 CPPUNIT_ASSERT(msg
.FindInt32("an int32") == 0);
31 CPPUNIT_ASSERT(!msg
.HasInt32("an int32"));
32 const void* ptr
= &out
;
34 CPPUNIT_ASSERT(msg
.FindData("an int32", B_INT32_TYPE
, &ptr
, &size
) ==
36 CPPUNIT_ASSERT(ptr
== NULL
);
38 //------------------------------------------------------------------------------
39 void TMessageInt32ItemTest::MessageInt32ItemTest2()
44 CPPUNIT_ASSERT(msg
.AddInt32("an int32", in
) == B_OK
);
45 CPPUNIT_ASSERT(msg
.HasInt32("an int32"));
46 CPPUNIT_ASSERT(msg
.FindInt32("an int32") == in
);
47 CPPUNIT_ASSERT(msg
.FindInt32("an int32", &out
) == B_OK
);
48 CPPUNIT_ASSERT(out
== in
);
51 CPPUNIT_ASSERT(msg
.FindData("an int32", B_INT32_TYPE
, (const void**)&pout
,
53 CPPUNIT_ASSERT(*pout
== in
);
54 CPPUNIT_ASSERT(size
== sizeof (int32
));
56 //------------------------------------------------------------------------------
57 void TMessageInt32ItemTest::MessageInt32ItemTest3()
63 CPPUNIT_ASSERT(msg
.AddInt32("an int32", in
) == B_OK
);
64 CPPUNIT_ASSERT(msg
.ReplaceInt32("an int32", in2
) == B_OK
);
65 CPPUNIT_ASSERT(msg
.HasInt32("an int32"));
66 CPPUNIT_ASSERT(msg
.FindInt32("an int32") == in2
);
67 CPPUNIT_ASSERT(msg
.FindInt32("an int32", &out
) == B_OK
);
68 CPPUNIT_ASSERT(out
== in2
);
72 CPPUNIT_ASSERT(msg
.FindData("an int32", B_INT32_TYPE
, (const void**)&pout
,
74 CPPUNIT_ASSERT(*pout
== in2
);
75 CPPUNIT_ASSERT(size
== sizeof (int32
));
77 //------------------------------------------------------------------------------
78 void TMessageInt32ItemTest::MessageInt32ItemTest4()
82 CPPUNIT_ASSERT(msg
.FindInt32("an int32", 1, &out
) == B_NAME_NOT_FOUND
);
83 CPPUNIT_ASSERT(out
== 0);
84 CPPUNIT_ASSERT(msg
.FindInt32("an int32", 1) == 0);
85 CPPUNIT_ASSERT(!msg
.HasInt32("an int32", 1));
86 const void* ptr
= &out
;
88 CPPUNIT_ASSERT(msg
.FindData("an int32", B_INT32_TYPE
, 1, &ptr
, &size
) ==
90 CPPUNIT_ASSERT(ptr
== NULL
);
92 //------------------------------------------------------------------------------
93 void TMessageInt32ItemTest::MessageInt32ItemTest5()
96 int32 in
[] = { 123, 456, 789 };
101 for (int32 i
= 0; i
< sizeof (in
) / sizeof (int32
); ++i
)
103 CPPUNIT_ASSERT(msg
.AddInt32("an int32", in
[i
]) == B_OK
);
106 for (int32 i
= 0; i
< sizeof (in
) / sizeof (int32
); ++i
)
108 CPPUNIT_ASSERT(msg
.HasInt32("an int32", i
));
109 CPPUNIT_ASSERT(msg
.FindInt32("an int32", i
) == in
[i
]);
110 CPPUNIT_ASSERT(msg
.FindInt32("an int32", i
, &out
) == B_OK
);
111 CPPUNIT_ASSERT(out
== in
[i
]);
112 CPPUNIT_ASSERT(msg
.FindData("an int32", B_INT32_TYPE
, i
,
113 (const void**)&pout
, &size
) == B_OK
);
114 CPPUNIT_ASSERT(*pout
== in
[i
]);
115 CPPUNIT_ASSERT(size
== sizeof (int32
));
118 //------------------------------------------------------------------------------
119 void TMessageInt32ItemTest::MessageInt32ItemTest6()
122 int32 in
[] = { 123, 456, 789 };
125 const int rIndex
= 2;
127 for (int32 i
= 0; i
< sizeof (in
) / sizeof (int32
); ++i
)
129 CPPUNIT_ASSERT(msg
.AddInt32("an int32", in
[i
]) == B_OK
);
132 CPPUNIT_ASSERT(msg
.ReplaceInt32("an int32", rIndex
, in2
) == B_OK
);
133 CPPUNIT_ASSERT(msg
.HasInt32("an int32", rIndex
));
134 CPPUNIT_ASSERT(msg
.FindInt32("an int32", rIndex
) == in2
);
135 CPPUNIT_ASSERT(msg
.FindInt32("an int32", rIndex
, &out
) == B_OK
);
136 CPPUNIT_ASSERT(out
== in2
);
140 CPPUNIT_ASSERT(msg
.FindData("an int32", B_INT32_TYPE
, rIndex
,
141 (const void**)&pout
, &size
) == B_OK
);
142 CPPUNIT_ASSERT(*pout
== in2
);
143 CPPUNIT_ASSERT(size
== sizeof (int32
));
145 //------------------------------------------------------------------------------
146 void TMessageInt32ItemTest::MessageInt32ItemTest7()
151 CPPUNIT_ASSERT(msg
.AddData("an int32", B_INT32_TYPE
, (const void*)&in
,
152 sizeof (int32
)) == B_OK
);
153 CPPUNIT_ASSERT(msg
.HasInt32("an int32"));
154 CPPUNIT_ASSERT(msg
.FindInt32("an int32") == in
);
155 CPPUNIT_ASSERT(msg
.FindInt32("an int32", &out
) == B_OK
);
156 CPPUNIT_ASSERT(out
== in
);
159 CPPUNIT_ASSERT(msg
.FindData("an int32", B_INT32_TYPE
, (const void**)&pout
,
161 CPPUNIT_ASSERT(*pout
== in
);
162 CPPUNIT_ASSERT(size
== sizeof (int32
));
164 //------------------------------------------------------------------------------
165 void TMessageInt32ItemTest::MessageInt32ItemTest8()
168 int32 in
[] = { 123, 456, 789 };
173 for (int32 i
= 0; i
< sizeof (in
) / sizeof (int32
); ++i
)
175 CPPUNIT_ASSERT(msg
.AddData("an int32", B_INT32_TYPE
,
176 (const void*)&in
[i
], sizeof (int32
)) == B_OK
);
179 for (int32 i
= 0; i
< sizeof (in
) / sizeof (int32
); ++i
)
181 CPPUNIT_ASSERT(msg
.HasInt32("an int32", i
));
182 CPPUNIT_ASSERT(msg
.FindInt32("an int32", i
) == in
[i
]);
183 CPPUNIT_ASSERT(msg
.FindInt32("an int32", i
, &out
) == B_OK
);
184 CPPUNIT_ASSERT(out
== in
[i
]);
185 CPPUNIT_ASSERT(msg
.FindData("an int32", B_INT32_TYPE
, i
,
186 (const void**)&pout
, &size
) == B_OK
);
187 CPPUNIT_ASSERT(*pout
== in
[i
]);
188 CPPUNIT_ASSERT(size
== sizeof (int32
));
191 //------------------------------------------------------------------------------
192 TestSuite
* TMessageInt32ItemTest::Suite()
194 TestSuite
* suite
= new TestSuite("BMessage::Add/Find/Replace/HasRect()");
196 ADD_TEST4(BMessage
, suite
, TMessageInt32ItemTest
, MessageInt32ItemTest1
);
197 ADD_TEST4(BMessage
, suite
, TMessageInt32ItemTest
, MessageInt32ItemTest2
);
198 ADD_TEST4(BMessage
, suite
, TMessageInt32ItemTest
, MessageInt32ItemTest3
);
199 ADD_TEST4(BMessage
, suite
, TMessageInt32ItemTest
, MessageInt32ItemTest4
);
200 ADD_TEST4(BMessage
, suite
, TMessageInt32ItemTest
, MessageInt32ItemTest5
);
201 ADD_TEST4(BMessage
, suite
, TMessageInt32ItemTest
, MessageInt32ItemTest6
);
202 ADD_TEST4(BMessage
, suite
, TMessageInt32ItemTest
, MessageInt32ItemTest7
);
203 ADD_TEST4(BMessage
, suite
, TMessageInt32ItemTest
, MessageInt32ItemTest8
);
207 //------------------------------------------------------------------------------