1 //------------------------------------------------------------------------------ 2 // MessageItemTest.h 3 // 4 //------------------------------------------------------------------------------ 5 6 #ifndef MESSAGEITEMTEST_H 7 #define MESSAGEITEMTEST_H 8 9 // A sad attempt to get rid of the horrible and pathetic vector<bool> specialization 10 #define __SGI_STL_INTERNAL_BVECTOR_H 11 12 // Standard Includes ----------------------------------------------------------- 13 #include <iostream> 14 #include <stdio.h> 15 #include <typeinfo> 16 #include <posix/string.h> 17 18 // System Includes ------------------------------------------------------------- 19 #include <Message.h> 20 21 // Project Includes ------------------------------------------------------------ 22 23 // Local Includes -------------------------------------------------------------- 24 #include "../common.h" 25 26 // Local Defines --------------------------------------------------------------- 27 #define TEMPLATE_TEST_PARAMS <Type, TypeCode, FuncPolicy, InitPolicy, AssertPolicy, ComparePolicy> 28 #define ADD_TEMPLATE_TEST(classbeingtested, suitename, classname, funcname) \ 29 (suitename)->addTest(new TestCaller<classname>(((string(#classbeingtested) + "::" + #funcname + "::" + typeid(Type).name()).c_str() ), \ 30 &classname::funcname)); 31 32 // Globals --------------------------------------------------------------------- 33 template 34 < 35 class Type, // int32 36 type_code TypeCode, // B_INT32_TYPE 37 class FuncPolicy, // status_t Add(BMessage&, const char*, Type&) 38 // status_t Find(BMessage&, const char*, int32, Type*) 39 // Type QuickFind(BMessage&, const char*, int32) 40 // bool Has(BMessage&, const char*, int32) 41 // status_t Replace(BMessage&, const char*, int32, Type) 42 class InitPolicy, // Type Zero() 43 // Type Test1() 44 // Type Test2() 45 // size_t SizeOf(const Type&) 46 // ArrayType Array() 47 // typedef XXX ArrayType 48 class AssertPolicy, // Type Zero() 49 // Type Invalid() 50 class ComparePolicy // bool Compare(const Type& lhs, const Type& rhs) 51 > 52 class TMessageItemTest; 53 54 55 //------------------------------------------------------------------------------ 56 template<class T> 57 struct ArrayTypeBase 58 { 59 typedef vector<T> ArrayType; 60 typedef typename ArrayType::size_type SizeType; 61 static SizeType Size(ArrayType& array) { return array.size(); } 62 }; 63 //------------------------------------------------------------------------------ 64 template<class Type> 65 struct TypePolicy 66 { 67 enum { FixedSize = true }; 68 inline Type& Dereference(Type* p) 69 { 70 return *p; 71 } 72 inline Type* AddressOf(Type& t) { return &t; } 73 }; 74 //------------------------------------------------------------------------------ 75 template 76 < 77 typename Type, 78 status_t (BMessage::*AddFunc)(const char*, Type), 79 status_t (BMessage::*FindFunc)(const char*, int32, Type*) const, 80 status_t (BMessage::*ShortFindFunc)(const char*, Type*) const, 81 Type (BMessage::*QuickFindFunc)(const char*, int32) const, 82 bool (BMessage::*HasFunc)(const char*, int32) const, 83 status_t (BMessage::*ReplaceFunc)(const char*, int32, Type), 84 status_t (BMessage::*AddDataFunc)(const char*, type_code, const void*, 85 ssize_t, bool, int32) = &BMessage::AddData, 86 status_t (BMessage::*FindDataFunc)(const char*, type_code, int32, 87 const void**, ssize_t*) const = &BMessage::FindData 88 > 89 struct TMessageItemFuncPolicy : public TypePolicy<Type> 90 { 91 static status_t Add(BMessage& msg, const char* name, Type& val) 92 { 93 return (msg.*AddFunc)(name, val); 94 } 95 static status_t AddData(BMessage& msg, const char* name, type_code type, 96 Type* val, ssize_t size, bool fixedSize = true) 97 { 98 return (msg.*AddDataFunc)(name, type, (const void*)val, size, fixedSize, 1); 99 } 100 static status_t Find(BMessage& msg, const char* name, int32 index, Type* val) 101 { 102 return (msg.*FindFunc)(name, index, val); 103 } 104 static status_t ShortFind(BMessage& msg, const char* name, Type* val) 105 { 106 return (msg.*ShortFindFunc)(name, val); 107 } 108 static Type QuickFind(BMessage& msg, const char* name, int32 index) 109 { 110 return (msg.*QuickFindFunc)(name, index); 111 } 112 static bool Has(BMessage& msg, const char* name, int32 index) 113 { 114 return (msg.*HasFunc)(name, index); 115 } 116 static status_t Replace(BMessage& msg, const char* name, int32 index, Type& val) 117 { 118 return (msg.*ReplaceFunc)(name, index, val); 119 } 120 static status_t FindData(BMessage& msg, const char* name, type_code type, 121 int32 index, const void** data, ssize_t* size) 122 { 123 return (msg.*FindDataFunc)(name, type, index, data, size); 124 } 125 }; 126 //------------------------------------------------------------------------------ 127 template<class T, T zero = T(), T invalid = T()> 128 struct TMessageItemAssertPolicy 129 { 130 inline static T Zero() { return zero; } 131 inline static T Invalid() { return invalid; } 132 inline static bool Size(size_t size, T& t) 133 { return size == sizeof (t); } 134 }; 135 //------------------------------------------------------------------------------ 136 template<class T> 137 struct TMessageItemComparePolicy 138 { 139 inline static bool Compare(const T& lhs, const T& rhs); 140 // { return lhs == rhs; } 141 }; 142 template<class T> 143 bool 144 TMessageItemComparePolicy<T>::Compare(const T &lhs, const T &rhs) 145 { 146 return lhs == rhs; 147 } 148 //------------------------------------------------------------------------------ 149 template 150 < 151 class Type, // int32 152 type_code TypeCode, // B_INT32_TYPE 153 class FuncPolicy, // status_t Add(BMessage&, const char*, Type&) 154 // status_t Find(BMessage&, const char*, int32, Type*) 155 // Type QuickFind(BMessage&, const char*, int32) 156 // bool Has(BMessage&, const char*, int32) 157 // status_t Replace(BMessage&, const char*, int32, Type) 158 // status_t FindData(BMessage&, const char*, type_code, int32, const void**, ssize_t*) 159 class InitPolicy, // Type Zero() 160 // Type Test1() 161 // Type Test2() 162 // size_t SizeOf(const Type&) 163 // ArrayType Array() 164 // typedef XXX ArrayType 165 class AssertPolicy, // Type Zero() 166 // Type Invalid() 167 // bool Size(size_t, T&) 168 class ComparePolicy // bool Compare(const Type& lhs, const Type& rhs) 169 = TMessageItemComparePolicy<Type> 170 > 171 class TMessageItemTest : public TestCase, public TypePolicy<Type> 172 { 173 public: 174 TMessageItemTest() {;} 175 TMessageItemTest(std::string name) : TestCase(name) {;} 176 177 void MessageItemTest1(); 178 void MessageItemTest2(); 179 void MessageItemTest3(); 180 void MessageItemTest4(); 181 void MessageItemTest5(); 182 void MessageItemTest6(); 183 void MessageItemTest7(); 184 void MessageItemTest8(); 185 void MessageItemTest9(); 186 void MessageItemTest10(); 187 void MessageItemTest11(); 188 void MessageItemTest12(); 189 190 static TestSuite* Suite(); 191 192 typedef typename InitPolicy::ArrayType ArrayType; 193 }; 194 195 196 //------------------------------------------------------------------------------ 197 template 198 < 199 class Type, 200 type_code TypeCode, 201 class FuncPolicy, 202 class InitPolicy, 203 class AssertPolicy, 204 class ComparePolicy 205 > 206 void 207 TMessageItemTest<Type, TypeCode, FuncPolicy, InitPolicy, AssertPolicy, ComparePolicy>:: 208 MessageItemTest1() 209 { 210 BMessage msg; 211 Type out = InitPolicy::Zero(); 212 CPPUNIT_ASSERT(FuncPolicy::ShortFind(msg, "item", &out) == B_NAME_NOT_FOUND); 213 CPPUNIT_ASSERT(FuncPolicy::Find(msg, "item", 0, &out) == B_NAME_NOT_FOUND); 214 CPPUNIT_ASSERT(ComparePolicy::Compare(out, AssertPolicy::Invalid())); 215 CPPUNIT_ASSERT(ComparePolicy::Compare(FuncPolicy::QuickFind(msg, "item", 0), 216 AssertPolicy::Invalid())); 217 CPPUNIT_ASSERT(!FuncPolicy::Has(msg, "item", 0)); 218 const void* ptr = &out; 219 ssize_t size; 220 CPPUNIT_ASSERT(FuncPolicy::FindData(msg, "item", TypeCode, 0, &ptr, &size) == 221 B_NAME_NOT_FOUND); 222 CPPUNIT_ASSERT(ptr == NULL); 223 } 224 //------------------------------------------------------------------------------ 225 template 226 < 227 class Type, 228 type_code TypeCode, 229 class FuncPolicy, 230 class InitPolicy, 231 class AssertPolicy, 232 class ComparePolicy 233 > 234 void 235 TMessageItemTest<Type, TypeCode, FuncPolicy, InitPolicy, AssertPolicy, ComparePolicy>:: 236 MessageItemTest2() 237 { 238 BMessage msg; 239 Type in = InitPolicy::Test1(); 240 Type out = InitPolicy::Zero(); 241 CPPUNIT_ASSERT(FuncPolicy::Add(msg, "item", in) == B_OK); 242 CPPUNIT_ASSERT(FuncPolicy::Has(msg, "item", 0)); 243 CPPUNIT_ASSERT(ComparePolicy::Compare(FuncPolicy::QuickFind(msg, "item", 0), in)); 244 CPPUNIT_ASSERT(FuncPolicy::ShortFind(msg, "item", &out) == B_OK); 245 CPPUNIT_ASSERT(FuncPolicy::Find(msg, "item", 0, &out) == B_OK); 246 CPPUNIT_ASSERT(ComparePolicy::Compare(out, in)); 247 Type* pout = NULL; 248 ssize_t size; 249 status_t err = FuncPolicy::FindData(msg, "item", TypeCode, 0, 250 (const void**)&pout, &size); 251 CPPUNIT_ASSERT(err == B_OK); 252 CPPUNIT_ASSERT(ComparePolicy::Compare(Dereference(pout), in)); 253 CPPUNIT_ASSERT(AssertPolicy::Size(size, Dereference(pout))); 254 } 255 //------------------------------------------------------------------------------ 256 template 257 < 258 class Type, 259 type_code TypeCode, 260 class FuncPolicy, 261 class InitPolicy, 262 class AssertPolicy, 263 class ComparePolicy 264 > 265 void 266 TMessageItemTest<Type, TypeCode, FuncPolicy, InitPolicy, AssertPolicy, ComparePolicy>:: 267 MessageItemTest3() 268 { 269 BMessage msg; 270 Type in = InitPolicy::Test1(); 271 Type in2 = InitPolicy::Test2(); 272 Type out = InitPolicy::Zero(); 273 CPPUNIT_ASSERT(FuncPolicy::Add(msg, "item", in) == B_OK); 274 CPPUNIT_ASSERT(FuncPolicy::Replace(msg, "item", 0, in2) == B_OK); 275 CPPUNIT_ASSERT(FuncPolicy::Has(msg, "item", 0)); 276 CPPUNIT_ASSERT(ComparePolicy::Compare(FuncPolicy::QuickFind(msg, "item", 0), in2)); 277 CPPUNIT_ASSERT(FuncPolicy::ShortFind(msg, "item", &out) == B_OK); 278 CPPUNIT_ASSERT(FuncPolicy::Find(msg, "item", 0, &out) == B_OK); 279 CPPUNIT_ASSERT(ComparePolicy::Compare(out, in2)); 280 out = InitPolicy::Zero(); 281 Type* pout; 282 ssize_t size; 283 CPPUNIT_ASSERT(FuncPolicy::FindData(msg, "item", TypeCode, 0, 284 (const void**)&pout, &size) == B_OK); 285 CPPUNIT_ASSERT(ComparePolicy::Compare(Dereference(pout), in2)); 286 CPPUNIT_ASSERT(AssertPolicy::Size(size, Dereference(pout))); 287 } 288 //------------------------------------------------------------------------------ 289 template 290 < 291 class Type, 292 type_code TypeCode, 293 class FuncPolicy, 294 class InitPolicy, 295 class AssertPolicy, 296 class ComparePolicy 297 > 298 void 299 TMessageItemTest<Type, TypeCode, FuncPolicy, InitPolicy, AssertPolicy, ComparePolicy>:: 300 MessageItemTest4() 301 { 302 BMessage msg; 303 Type out = InitPolicy::Zero(); 304 CPPUNIT_ASSERT(FuncPolicy::Find(msg, "item", 1, &out) == B_NAME_NOT_FOUND); 305 CPPUNIT_ASSERT(ComparePolicy::Compare(out, AssertPolicy::Invalid())); 306 CPPUNIT_ASSERT(ComparePolicy::Compare(FuncPolicy::QuickFind(msg, "item", 1), 307 AssertPolicy::Invalid())); 308 CPPUNIT_ASSERT(!FuncPolicy::Has(msg, "item", 1)); 309 const void* ptr = &out; 310 ssize_t size; 311 CPPUNIT_ASSERT(FuncPolicy::FindData(msg, "item", TypeCode, 1, &ptr, &size) == 312 B_NAME_NOT_FOUND); 313 CPPUNIT_ASSERT(ptr == NULL); 314 } 315 //------------------------------------------------------------------------------ 316 template 317 < 318 class Type, 319 type_code TypeCode, 320 class FuncPolicy, 321 class InitPolicy, 322 class AssertPolicy, 323 class ComparePolicy 324 > 325 void 326 TMessageItemTest<Type, TypeCode, FuncPolicy, InitPolicy, AssertPolicy, ComparePolicy>:: 327 MessageItemTest5() 328 { 329 BMessage msg; 330 ArrayType in = InitPolicy::Array(); 331 Type out = InitPolicy::Zero(); 332 Type* pout; 333 ssize_t size; 334 335 for (uint32 ii = 0; ii < InitPolicy::Size(in); ++ii) 336 { 337 CPPUNIT_ASSERT(FuncPolicy::Add(msg, "item", in[ii]) == B_OK); 338 } 339 340 for (uint32 i = 0; i < InitPolicy::Size(in); ++i) 341 { 342 CPPUNIT_ASSERT(FuncPolicy::Has(msg, "item", i)); 343 CPPUNIT_ASSERT(ComparePolicy::Compare(FuncPolicy::QuickFind(msg, "item", i), 344 in[i])); 345 CPPUNIT_ASSERT(FuncPolicy::Find(msg, "item", i, &out) == B_OK); 346 CPPUNIT_ASSERT(ComparePolicy::Compare(out, in[i])); 347 CPPUNIT_ASSERT(FuncPolicy::FindData(msg, "item", TypeCode, i, 348 (const void**)&pout, &size) == B_OK); 349 CPPUNIT_ASSERT(ComparePolicy::Compare(Dereference(pout), in[i])); 350 CPPUNIT_ASSERT(AssertPolicy::Size(size, Dereference(pout))); 351 } 352 } 353 //------------------------------------------------------------------------------ 354 template 355 < 356 class Type, 357 type_code TypeCode, 358 class FuncPolicy, 359 class InitPolicy, 360 class AssertPolicy, 361 class ComparePolicy 362 > 363 void 364 TMessageItemTest<Type, TypeCode, FuncPolicy, InitPolicy, AssertPolicy, ComparePolicy>:: 365 MessageItemTest6() 366 { 367 BMessage msg; 368 ArrayType in = InitPolicy::Array(); 369 Type in2 = InitPolicy::Test2(); 370 Type out = InitPolicy::Zero(); 371 const int rIndex = 2; 372 373 for (uint32 i = 0; i < InitPolicy::Size(in); ++i) 374 { 375 CPPUNIT_ASSERT(FuncPolicy::Add(msg, "item", in[i]) == B_OK); 376 } 377 378 CPPUNIT_ASSERT(FuncPolicy::Replace(msg, "item", rIndex, in2) == B_OK); 379 CPPUNIT_ASSERT(FuncPolicy::Has(msg, "item", rIndex)); 380 CPPUNIT_ASSERT(ComparePolicy::Compare(FuncPolicy::QuickFind(msg, "item", rIndex), 381 in2)); 382 CPPUNIT_ASSERT(FuncPolicy::Find(msg, "item", rIndex, &out) == B_OK); 383 CPPUNIT_ASSERT(ComparePolicy::Compare(out, in2)); 384 out = InitPolicy::Zero(); 385 Type* pout; 386 ssize_t size; 387 CPPUNIT_ASSERT(FuncPolicy::FindData(msg, "item", TypeCode, rIndex, 388 (const void**)&pout, &size) == B_OK); 389 CPPUNIT_ASSERT(ComparePolicy::Compare(Dereference(pout), in2)); 390 CPPUNIT_ASSERT(AssertPolicy::Size(size, Dereference(pout))); 391 } 392 //------------------------------------------------------------------------------ 393 template 394 < 395 class Type, 396 type_code TypeCode, 397 class FuncPolicy, 398 class InitPolicy, 399 class AssertPolicy, 400 class ComparePolicy 401 > 402 void 403 TMessageItemTest<Type, TypeCode, FuncPolicy, InitPolicy, AssertPolicy, ComparePolicy>:: 404 MessageItemTest7() 405 { 406 BMessage msg; 407 Type in = InitPolicy::Test1(); 408 Type out = InitPolicy::Zero(); 409 CPPUNIT_ASSERT(FuncPolicy::AddData(msg, "item", TypeCode, AddressOf(in), 410 InitPolicy::SizeOf(in), 411 TypePolicy<Type>::FixedSize) == B_OK); 412 CPPUNIT_ASSERT(FuncPolicy::Has(msg, "item", 0)); 413 CPPUNIT_ASSERT(ComparePolicy::Compare(FuncPolicy::QuickFind(msg, "item", 0), 414 in)); 415 CPPUNIT_ASSERT(FuncPolicy::ShortFind(msg, "item", &out) == B_OK); 416 CPPUNIT_ASSERT(FuncPolicy::Find(msg, "item", 0, &out) == B_OK); 417 CPPUNIT_ASSERT(ComparePolicy::Compare(out, in)); 418 Type* pout = NULL; 419 ssize_t size; 420 CPPUNIT_ASSERT(FuncPolicy::FindData(msg, "item", TypeCode, 0, 421 (const void**)&pout, &size) == B_OK); 422 CPPUNIT_ASSERT(ComparePolicy::Compare(Dereference(pout), in)); 423 CPPUNIT_ASSERT(AssertPolicy::Size(size, Dereference(pout))); 424 } 425 //------------------------------------------------------------------------------ 426 #include <stdio.h> 427 template 428 < 429 class Type, 430 type_code TypeCode, 431 class FuncPolicy, 432 class InitPolicy, 433 class AssertPolicy, 434 class ComparePolicy 435 > 436 void 437 TMessageItemTest<Type, TypeCode, FuncPolicy, InitPolicy, AssertPolicy, ComparePolicy>:: 438 MessageItemTest8() 439 { 440 BMessage msg; 441 ArrayType in = InitPolicy::Array(); 442 Type out = InitPolicy::Zero(); 443 Type* pout; 444 ssize_t size; 445 for (uint32 i = 0; i < InitPolicy::Size(in); ++i) 446 { 447 CPPUNIT_ASSERT(FuncPolicy::AddData(msg, "item", TypeCode, 448 AddressOf(in[i]), InitPolicy::SizeOf(in[i]), 449 TypePolicy<Type>::FixedSize) == B_OK); 450 } 451 452 for (uint32 i = 0; i < InitPolicy::Size(in); ++i) 453 { 454 CPPUNIT_ASSERT(FuncPolicy::Has(msg, "item", i)); 455 CPPUNIT_ASSERT(ComparePolicy::Compare(FuncPolicy::QuickFind(msg, "item", i), 456 in[i])); 457 CPPUNIT_ASSERT(FuncPolicy::Find(msg, "item", i, &out) == B_OK); 458 CPPUNIT_ASSERT(ComparePolicy::Compare(out, in[i])); 459 CPPUNIT_ASSERT(FuncPolicy::FindData(msg, "item", TypeCode, i, 460 (const void**)&pout, &size) == B_OK); 461 CPPUNIT_ASSERT(ComparePolicy::Compare(Dereference(pout), in[i])); 462 CPPUNIT_ASSERT(AssertPolicy::Size(size, Dereference(pout))); 463 } 464 } 465 //------------------------------------------------------------------------------ 466 template 467 < 468 class Type, 469 type_code TypeCode, 470 class FuncPolicy, 471 class InitPolicy, 472 class AssertPolicy, 473 class ComparePolicy 474 > 475 void 476 TMessageItemTest<Type, TypeCode, FuncPolicy, InitPolicy, AssertPolicy, ComparePolicy>:: 477 MessageItemTest9() 478 { 479 BMessage msg; 480 Type in = InitPolicy::Test1(); 481 CPPUNIT_ASSERT(FuncPolicy::Add(msg, NULL, in) == B_BAD_VALUE); 482 } 483 //------------------------------------------------------------------------------ 484 template 485 < 486 class Type, 487 type_code TypeCode, 488 class FuncPolicy, 489 class InitPolicy, 490 class AssertPolicy, 491 class ComparePolicy 492 > 493 void 494 TMessageItemTest<Type, TypeCode, FuncPolicy, InitPolicy, AssertPolicy, ComparePolicy>:: 495 MessageItemTest10() 496 { 497 BMessage msg; 498 Type in = InitPolicy::Test1(); 499 Type out = InitPolicy::Zero(); 500 CPPUNIT_ASSERT(FuncPolicy::Add(msg, "item", in) == B_OK); 501 CPPUNIT_ASSERT(FuncPolicy::Has(msg, NULL, 0) == false); 502 CPPUNIT_ASSERT(ComparePolicy::Compare(FuncPolicy::QuickFind(msg, NULL, 0), 503 AssertPolicy::Invalid())); 504 CPPUNIT_ASSERT(FuncPolicy::ShortFind(msg, NULL, &out) == B_BAD_VALUE); 505 CPPUNIT_ASSERT(FuncPolicy::Find(msg, NULL, 0, &out) == B_BAD_VALUE); 506 Type* pout = NULL; 507 ssize_t size; 508 status_t err = FuncPolicy::FindData(msg, NULL, TypeCode, 0, 509 (const void**)&pout, &size); 510 CPPUNIT_ASSERT(err == B_BAD_VALUE); 511 } 512 //------------------------------------------------------------------------------ 513 template 514 < 515 class Type, 516 type_code TypeCode, 517 class FuncPolicy, 518 class InitPolicy, 519 class AssertPolicy, 520 class ComparePolicy 521 > 522 void 523 TMessageItemTest<Type, TypeCode, FuncPolicy, InitPolicy, AssertPolicy, ComparePolicy>:: 524 MessageItemTest11() 525 { 526 BMessage msg; 527 Type in = InitPolicy::Test1(); 528 CPPUNIT_ASSERT(FuncPolicy::Add(msg, "item", in) == B_OK); 529 530 ssize_t flatSize = msg.FlattenedSize(); 531 char* buf = new char[flatSize]; 532 CPPUNIT_ASSERT(buf); 533 534 CPPUNIT_ASSERT(msg.Flatten(buf, flatSize) == B_OK); 535 536 BMessage msg2; 537 Type out = InitPolicy::Zero(); 538 CPPUNIT_ASSERT(msg2.Unflatten(buf) == B_OK); 539 CPPUNIT_ASSERT(FuncPolicy::ShortFind(msg, "item", &out) == B_OK); 540 CPPUNIT_ASSERT(ComparePolicy::Compare(in, out)); 541 542 delete[] buf; 543 } 544 //------------------------------------------------------------------------------ 545 template 546 < 547 class Type, 548 type_code TypeCode, 549 class FuncPolicy, 550 class InitPolicy, 551 class AssertPolicy, 552 class ComparePolicy 553 > 554 void 555 TMessageItemTest<Type, TypeCode, FuncPolicy, InitPolicy, AssertPolicy, ComparePolicy>:: 556 MessageItemTest12() 557 { 558 BMessage msg; 559 ArrayType in = InitPolicy::Array(); 560 561 for (uint32 ii = 0; ii < InitPolicy::Size(in); ++ii) 562 { 563 CPPUNIT_ASSERT(FuncPolicy::Add(msg, "item", in[ii]) == B_OK); 564 } 565 566 ssize_t flatSize = msg.FlattenedSize(); 567 char* buf = new char[flatSize]; 568 CPPUNIT_ASSERT(buf); 569 570 CPPUNIT_ASSERT(msg.Flatten(buf, flatSize) == B_OK); 571 572 BMessage msg2; 573 Type out = InitPolicy::Zero(); 574 Type* pout; 575 ssize_t size; 576 CPPUNIT_ASSERT(msg2.Unflatten(buf) == B_OK); 577 578 for (uint32 i = 0; i < InitPolicy::Size(in); ++i) 579 { 580 CPPUNIT_ASSERT(FuncPolicy::Has(msg, "item", i)); 581 CPPUNIT_ASSERT(ComparePolicy::Compare(FuncPolicy::QuickFind(msg, "item", i), 582 in[i])); 583 CPPUNIT_ASSERT(FuncPolicy::Find(msg, "item", i, &out) == B_OK); 584 CPPUNIT_ASSERT(ComparePolicy::Compare(out, in[i])); 585 CPPUNIT_ASSERT(FuncPolicy::FindData(msg, "item", TypeCode, i, 586 (const void**)&pout, &size) == B_OK); 587 CPPUNIT_ASSERT(ComparePolicy::Compare(Dereference(pout), in[i])); 588 CPPUNIT_ASSERT(AssertPolicy::Size(size, Dereference(pout))); 589 } 590 591 delete[] buf; 592 } 593 //------------------------------------------------------------------------------ 594 template 595 < 596 class Type, 597 type_code TypeCode, 598 class FuncPolicy, 599 class InitPolicy, 600 class AssertPolicy, 601 class ComparePolicy 602 > 603 TestSuite* 604 TMessageItemTest<Type, TypeCode, FuncPolicy, InitPolicy, AssertPolicy, ComparePolicy>:: 605 Suite() 606 { 607 TestSuite* suite = new TestSuite("BMessage::Add/Find/Replace/HasRect()"); 608 609 ADD_TEMPLATE_TEST(BMessage, suite, TMessageItemTest TEMPLATE_TEST_PARAMS, MessageItemTest1); 610 ADD_TEMPLATE_TEST(BMessage, suite, TMessageItemTest TEMPLATE_TEST_PARAMS, MessageItemTest2); 611 ADD_TEMPLATE_TEST(BMessage, suite, TMessageItemTest TEMPLATE_TEST_PARAMS, MessageItemTest3); 612 ADD_TEMPLATE_TEST(BMessage, suite, TMessageItemTest TEMPLATE_TEST_PARAMS, MessageItemTest4); 613 ADD_TEMPLATE_TEST(BMessage, suite, TMessageItemTest TEMPLATE_TEST_PARAMS, MessageItemTest5); 614 ADD_TEMPLATE_TEST(BMessage, suite, TMessageItemTest TEMPLATE_TEST_PARAMS, MessageItemTest6); 615 ADD_TEMPLATE_TEST(BMessage, suite, TMessageItemTest TEMPLATE_TEST_PARAMS, MessageItemTest7); 616 ADD_TEMPLATE_TEST(BMessage, suite, TMessageItemTest TEMPLATE_TEST_PARAMS, MessageItemTest8); 617 #ifndef TEST_R5 618 ADD_TEMPLATE_TEST(BMessage, suite, TMessageItemTest TEMPLATE_TEST_PARAMS, MessageItemTest9); 619 ADD_TEMPLATE_TEST(BMessage, suite, TMessageItemTest TEMPLATE_TEST_PARAMS, MessageItemTest10); 620 #endif 621 ADD_TEMPLATE_TEST(BMessage, suite, TMessageItemTest TEMPLATE_TEST_PARAMS, MessageItemTest11); 622 ADD_TEMPLATE_TEST(BMessage, suite, TMessageItemTest TEMPLATE_TEST_PARAMS, MessageItemTest12); 623 624 return suite; 625 } 626 //------------------------------------------------------------------------------ 627 628 #endif // MESSAGEITEMTEST_H 629 630 /* 631 * $Log $ 632 * 633 * $Id $ 634 * 635 636 */ 637