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