1 // ResourceStringsTest.cpp 2 3 #include <stdio.h> 4 #include <string> 5 #include <unistd.h> 6 #include <vector> 7 8 9 #include <ResourceStringsTest.h> 10 11 #include <ByteOrder.h> 12 #include <Entry.h> 13 #include <File.h> 14 #include <image.h> 15 #include <Mime.h> 16 #include <Resources.h> 17 #include <ResourceStrings.h> 18 #include <String.h> 19 #include <TypeConstants.h> 20 #include <TestShell.h> 21 22 23 static const char *testDir = "/tmp/testDir"; 24 static const char *x86ResFile = "/tmp/testDir/x86.rsrc"; 25 static const char *ppcResFile = "/tmp/testDir/ppc.rsrc"; 26 static const char *elfFile = "/tmp/testDir/elf"; 27 static const char *pefFile = "/tmp/testDir/pef"; 28 static const char *emptyFile = "/tmp/testDir/empty-file"; 29 static const char *noResFile = "/tmp/testDir/no-res-file"; 30 static const char *testFile1 = "/tmp/testDir/testFile1"; 31 static const char *testFile2 = "/tmp/testDir/testFile2"; 32 static const char *noSuchFile = "/tmp/testDir/no-such-file"; 33 static const char *x86ResName = "x86.rsrc"; 34 static const char *ppcResName = "ppc.rsrc"; 35 static const char *elfName = "elf"; 36 static const char *elfNoResName = "elf-no-res"; 37 static const char *pefName = "pef"; 38 static const char *pefNoResName = "pef-no-res"; 39 40 41 struct ResourceInfo { 42 ResourceInfo(type_code type, int32 id, const void *data, size_t size, 43 const char *name = NULL) 44 : type(type), 45 id(id), 46 name(NULL), 47 data(NULL), 48 size(size) 49 { 50 if (data) { 51 this->data = new char[size]; 52 memcpy(this->data, data, size); 53 } 54 if (name) { 55 int32 len = strlen(name); 56 this->name = new char[len + 1]; 57 strcpy(this->name, name); 58 } 59 } 60 61 ~ResourceInfo() 62 { 63 delete[] name; 64 delete[] data; 65 } 66 67 type_code type; 68 int32 id; 69 char *name; 70 char *data; 71 size_t size; 72 }; 73 74 struct StringResourceInfo : public ResourceInfo { 75 StringResourceInfo(int32 id, const char *data, const char *name = NULL) 76 : ResourceInfo(B_STRING_TYPE, id, data, strlen(data) + 1, name) 77 { 78 } 79 }; 80 81 static const char *testResData1 = "I like strings, especially cellos."; 82 static const int32 testResSize1 = strlen(testResData1) + 1; 83 static const int32 testResData2 = 42; 84 static const int32 testResSize2 = sizeof(int32); 85 static const char *testResData3 = "application/bread-roll-counter"; 86 static const int32 testResSize3 = strlen(testResData3) + 1; 87 static const char *testResData4 = "This is a long string. At least longer " 88 "than the first one"; 89 static const int32 testResSize4 = strlen(testResData1) + 1; 90 static const char *testResData6 = "Short, but true."; 91 static const int32 testResSize6 = strlen(testResData6) + 1; 92 93 static const ResourceInfo testResource1(B_STRING_TYPE, 74, testResData1, 94 testResSize1, "a string resource"); 95 static const ResourceInfo testResource2(B_INT32_TYPE, 17, &testResData2, 96 testResSize2, "just a resource"); 97 static const ResourceInfo testResource3(B_MIME_STRING_TYPE, 29, testResData3, 98 testResSize3, "another resource"); 99 static const ResourceInfo testResource4(B_STRING_TYPE, 75, &testResData4, 100 testResSize4, 101 "a second string resource"); 102 static const ResourceInfo testResource5(B_MIME_STRING_TYPE, 74, &testResData1, 103 testResSize1, "a string resource"); 104 static const ResourceInfo testResource6(B_STRING_TYPE, 74, &testResData6, 105 testResSize6, 106 "a third string resource"); 107 108 static const StringResourceInfo stringResource1(0, "What?"); 109 static const StringResourceInfo stringResource2(12, "What?", "string 2"); 110 static const StringResourceInfo stringResource3(19, "Who cares?", "string 3"); 111 static const StringResourceInfo stringResource4(23, "a little bit longer than " 112 "the others", "string 4"); 113 static const StringResourceInfo stringResource5(24, "a lot longer than " 114 "the other strings, but it " 115 "it doesn't have a name"); 116 static const StringResourceInfo stringResource6(26, "short"); 117 static const StringResourceInfo stringResource7(27, ""); 118 static const StringResourceInfo stringResource8(123, "the very last resource", 119 "last resource"); 120 121 // get_app_path 122 static 123 string 124 get_app_path() 125 { 126 string result; 127 image_info info; 128 int32 cookie = 0; 129 bool found = false; 130 while (!found && get_next_image_info(0, &cookie, &info) == B_OK) { 131 if (info.type == B_APP_IMAGE) { 132 result = info.name; 133 found = true; 134 } 135 } 136 return result; 137 } 138 139 // ref_for 140 static 141 entry_ref 142 ref_for(const char *path) 143 { 144 entry_ref ref; 145 get_ref_for_path(path, &ref); 146 return ref; 147 } 148 149 // get_app_ref 150 static 151 entry_ref 152 get_app_ref() 153 { 154 return ref_for(get_app_path().c_str()); 155 } 156 157 158 // Suite 159 CppUnit::Test* 160 ResourceStringsTest::Suite() { 161 CppUnit::TestSuite *suite = new CppUnit::TestSuite(); 162 typedef CppUnit::TestCaller<ResourceStringsTest> TC; 163 164 suite->addTest( new TC("BResourceStrings::Init Test1", 165 &ResourceStringsTest::InitTest1) ); 166 suite->addTest( new TC("BResourceStrings::Init Test2", 167 &ResourceStringsTest::InitTest2) ); 168 suite->addTest( new TC("BResourceString::FindString Test", 169 &ResourceStringsTest::FindStringTest) ); 170 171 return suite; 172 } 173 174 // add_resource 175 static 176 void 177 add_resource(BResources &resources, const ResourceInfo &resource) 178 { 179 resources.AddResource(resource.type, resource.id, resource.data, 180 resource.size, resource.name); 181 } 182 183 // setUp 184 void 185 ResourceStringsTest::setUp() 186 { 187 BasicTest::setUp(); 188 string resourcesTestDir(BTestShell::GlobalTestDir()); 189 resourcesTestDir += "/resources"; 190 execCommand(string("mkdir ") + testDir 191 + " ; cp " + resourcesTestDir + "/" + x86ResName + " " 192 + resourcesTestDir + "/" + ppcResName + " " 193 + resourcesTestDir + "/" + elfName + " " 194 + resourcesTestDir + "/" + elfNoResName + " " 195 + resourcesTestDir + "/" + pefName + " " 196 + resourcesTestDir + "/" + pefNoResName + " " 197 + testDir 198 + " ; touch " + emptyFile 199 + " ; echo \"That's not a resource file.\" > " + noResFile 200 ); 201 // prepare the test files 202 BFile file(testFile1, B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE); 203 BResources resources(&file, true); 204 add_resource(resources, stringResource1); 205 add_resource(resources, stringResource2); 206 add_resource(resources, testResource2); 207 add_resource(resources, stringResource3); 208 add_resource(resources, stringResource4); 209 add_resource(resources, stringResource5); 210 add_resource(resources, testResource3); 211 resources.Sync(); 212 file.SetTo(testFile2, B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE); 213 resources.SetTo(&file, true); 214 add_resource(resources, testResource3); 215 add_resource(resources, stringResource4); 216 add_resource(resources, stringResource5); 217 add_resource(resources, stringResource6); 218 add_resource(resources, testResource2); 219 add_resource(resources, stringResource7); 220 add_resource(resources, stringResource8); 221 resources.Sync(); 222 } 223 224 // tearDown 225 void 226 ResourceStringsTest::tearDown() 227 { 228 execCommand(string("rm -rf ") + testDir); 229 BasicTest::tearDown(); 230 } 231 232 // InitTest1 233 void 234 ResourceStringsTest::InitTest1() 235 { 236 // default constructor 237 NextSubTest(); 238 { 239 BResourceStrings resourceStrings; 240 CPPUNIT_ASSERT( resourceStrings.InitCheck() == B_OK ); 241 entry_ref ref; 242 CPPUNIT_ASSERT( resourceStrings.GetStringFile(&ref) 243 == B_ENTRY_NOT_FOUND ); 244 } 245 // application file 246 NextSubTest(); 247 { 248 entry_ref ref = get_app_ref(); 249 BResourceStrings resourceStrings(ref); 250 CPPUNIT_ASSERT( resourceStrings.InitCheck() == B_OK ); 251 entry_ref ref2; 252 CPPUNIT_ASSERT( resourceStrings.GetStringFile(&ref2) == B_OK ); 253 CPPUNIT_ASSERT( BEntry(&ref, true) == BEntry(&ref2, true) ); 254 } 255 // x86 resource file 256 NextSubTest(); 257 { 258 entry_ref ref; 259 CPPUNIT_ASSERT( get_ref_for_path(x86ResFile, &ref) == B_OK ); 260 BResourceStrings resourceStrings(ref); 261 CPPUNIT_ASSERT( resourceStrings.InitCheck() == B_OK ); 262 entry_ref ref2; 263 CPPUNIT_ASSERT( resourceStrings.GetStringFile(&ref2) == B_OK ); 264 CPPUNIT_ASSERT( BEntry(&ref, true) == BEntry(&ref2, true) ); 265 } 266 // ppc resource file 267 NextSubTest(); 268 { 269 entry_ref ref; 270 CPPUNIT_ASSERT( get_ref_for_path(ppcResFile, &ref) == B_OK ); 271 BResourceStrings resourceStrings(ref); 272 CPPUNIT_ASSERT( resourceStrings.InitCheck() == B_OK ); 273 entry_ref ref2; 274 CPPUNIT_ASSERT( resourceStrings.GetStringFile(&ref2) == B_OK ); 275 CPPUNIT_ASSERT( BEntry(&ref, true) == BEntry(&ref2, true) ); 276 } 277 // ELF executable 278 NextSubTest(); 279 { 280 entry_ref ref; 281 CPPUNIT_ASSERT( get_ref_for_path(elfFile, &ref) == B_OK ); 282 BResourceStrings resourceStrings(ref); 283 CPPUNIT_ASSERT( resourceStrings.InitCheck() == B_OK ); 284 entry_ref ref2; 285 CPPUNIT_ASSERT( resourceStrings.GetStringFile(&ref2) == B_OK ); 286 CPPUNIT_ASSERT( BEntry(&ref, true) == BEntry(&ref2, true) ); 287 } 288 // PEF executable 289 NextSubTest(); 290 { 291 entry_ref ref; 292 CPPUNIT_ASSERT( get_ref_for_path(pefFile, &ref) == B_OK ); 293 BResourceStrings resourceStrings(ref); 294 CPPUNIT_ASSERT( resourceStrings.InitCheck() == B_OK ); 295 entry_ref ref2; 296 CPPUNIT_ASSERT( resourceStrings.GetStringFile(&ref2) == B_OK ); 297 CPPUNIT_ASSERT( BEntry(&ref, true) == BEntry(&ref2, true) ); 298 } 299 // test file 1 300 NextSubTest(); 301 { 302 entry_ref ref; 303 CPPUNIT_ASSERT( get_ref_for_path(testFile1, &ref) == B_OK ); 304 BResourceStrings resourceStrings(ref); 305 CPPUNIT_ASSERT( resourceStrings.InitCheck() == B_OK ); 306 entry_ref ref2; 307 CPPUNIT_ASSERT( resourceStrings.GetStringFile(&ref2) == B_OK ); 308 CPPUNIT_ASSERT( BEntry(&ref, true) == BEntry(&ref2, true) ); 309 } 310 // test file 2 311 NextSubTest(); 312 { 313 entry_ref ref; 314 CPPUNIT_ASSERT( get_ref_for_path(testFile1, &ref) == B_OK ); 315 BResourceStrings resourceStrings(ref); 316 CPPUNIT_ASSERT( resourceStrings.InitCheck() == B_OK ); 317 entry_ref ref2; 318 CPPUNIT_ASSERT( resourceStrings.GetStringFile(&ref2) == B_OK ); 319 CPPUNIT_ASSERT( BEntry(&ref, true) == BEntry(&ref2, true) ); 320 } 321 // empty file 322 NextSubTest(); 323 { 324 entry_ref ref; 325 CPPUNIT_ASSERT( get_ref_for_path(emptyFile, &ref) == B_OK ); 326 BResourceStrings resourceStrings(ref); 327 CPPUNIT_ASSERT( resourceStrings.InitCheck() == B_OK ); 328 entry_ref ref2; 329 CPPUNIT_ASSERT( resourceStrings.GetStringFile(&ref2) == B_OK ); 330 CPPUNIT_ASSERT( BEntry(&ref, true) == BEntry(&ref2, true) ); 331 } 332 // non-resource file 333 NextSubTest(); 334 { 335 entry_ref ref; 336 CPPUNIT_ASSERT( get_ref_for_path(noResFile, &ref) == B_OK ); 337 BResourceStrings resourceStrings(ref); 338 CPPUNIT_ASSERT( equals(resourceStrings.InitCheck(), B_ERROR, 339 B_IO_ERROR) ); 340 entry_ref ref2; 341 CPPUNIT_ASSERT( equals(resourceStrings.GetStringFile(&ref2), B_ERROR, 342 B_IO_ERROR) ); 343 } 344 // non-existing file 345 NextSubTest(); 346 { 347 entry_ref ref; 348 CPPUNIT_ASSERT( get_ref_for_path(noSuchFile, &ref) == B_OK ); 349 BResourceStrings resourceStrings(ref); 350 CPPUNIT_ASSERT( resourceStrings.InitCheck() == B_ENTRY_NOT_FOUND ); 351 entry_ref ref2; 352 CPPUNIT_ASSERT( resourceStrings.GetStringFile(&ref2) 353 == B_ENTRY_NOT_FOUND ); 354 } 355 // bad args (GetStringFile) 356 // R5: crashes 357 #if !TEST_R5 358 NextSubTest(); 359 { 360 entry_ref ref; 361 CPPUNIT_ASSERT( get_ref_for_path(testFile1, &ref) == B_OK ); 362 BResourceStrings resourceStrings(ref); 363 CPPUNIT_ASSERT( resourceStrings.InitCheck() == B_OK ); 364 CPPUNIT_ASSERT( resourceStrings.GetStringFile(NULL) == B_BAD_VALUE ); 365 } 366 #endif 367 } 368 369 // InitTest2 370 void 371 ResourceStringsTest::InitTest2() 372 { 373 // application file 374 NextSubTest(); 375 { 376 entry_ref ref = get_app_ref(); 377 BResourceStrings resourceStrings; 378 CPPUNIT_ASSERT( resourceStrings.SetStringFile(&ref) == B_OK ); 379 CPPUNIT_ASSERT( resourceStrings.InitCheck() == B_OK ); 380 entry_ref ref2; 381 CPPUNIT_ASSERT( resourceStrings.GetStringFile(&ref2) == B_OK ); 382 CPPUNIT_ASSERT( BEntry(&ref, true) == BEntry(&ref2, true) ); 383 } 384 // x86 resource file 385 NextSubTest(); 386 { 387 entry_ref ref; 388 CPPUNIT_ASSERT( get_ref_for_path(x86ResFile, &ref) == B_OK ); 389 BResourceStrings resourceStrings; 390 CPPUNIT_ASSERT( resourceStrings.SetStringFile(&ref) == B_OK ); 391 CPPUNIT_ASSERT( resourceStrings.InitCheck() == B_OK ); 392 entry_ref ref2; 393 CPPUNIT_ASSERT( resourceStrings.GetStringFile(&ref2) == B_OK ); 394 CPPUNIT_ASSERT( BEntry(&ref, true) == BEntry(&ref2, true) ); 395 } 396 // ppc resource file 397 NextSubTest(); 398 { 399 entry_ref ref; 400 CPPUNIT_ASSERT( get_ref_for_path(ppcResFile, &ref) == B_OK ); 401 BResourceStrings resourceStrings; 402 CPPUNIT_ASSERT( resourceStrings.SetStringFile(&ref) == B_OK ); 403 CPPUNIT_ASSERT( resourceStrings.InitCheck() == B_OK ); 404 entry_ref ref2; 405 CPPUNIT_ASSERT( resourceStrings.GetStringFile(&ref2) == B_OK ); 406 CPPUNIT_ASSERT( BEntry(&ref, true) == BEntry(&ref2, true) ); 407 } 408 // ELF executable 409 NextSubTest(); 410 { 411 entry_ref ref; 412 CPPUNIT_ASSERT( get_ref_for_path(elfFile, &ref) == B_OK ); 413 BResourceStrings resourceStrings; 414 CPPUNIT_ASSERT( resourceStrings.SetStringFile(&ref) == B_OK ); 415 CPPUNIT_ASSERT( resourceStrings.InitCheck() == B_OK ); 416 entry_ref ref2; 417 CPPUNIT_ASSERT( resourceStrings.GetStringFile(&ref2) == B_OK ); 418 CPPUNIT_ASSERT( BEntry(&ref, true) == BEntry(&ref2, true) ); 419 } 420 // PEF executable 421 NextSubTest(); 422 { 423 entry_ref ref; 424 CPPUNIT_ASSERT( get_ref_for_path(pefFile, &ref) == B_OK ); 425 BResourceStrings resourceStrings; 426 CPPUNIT_ASSERT( resourceStrings.SetStringFile(&ref) == B_OK ); 427 CPPUNIT_ASSERT( resourceStrings.InitCheck() == B_OK ); 428 entry_ref ref2; 429 CPPUNIT_ASSERT( resourceStrings.GetStringFile(&ref2) == B_OK ); 430 CPPUNIT_ASSERT( BEntry(&ref, true) == BEntry(&ref2, true) ); 431 } 432 // test file 1 433 NextSubTest(); 434 { 435 entry_ref ref; 436 CPPUNIT_ASSERT( get_ref_for_path(testFile1, &ref) == B_OK ); 437 BResourceStrings resourceStrings; 438 CPPUNIT_ASSERT( resourceStrings.SetStringFile(&ref) == B_OK ); 439 CPPUNIT_ASSERT( resourceStrings.InitCheck() == B_OK ); 440 entry_ref ref2; 441 CPPUNIT_ASSERT( resourceStrings.GetStringFile(&ref2) == B_OK ); 442 CPPUNIT_ASSERT( BEntry(&ref, true) == BEntry(&ref2, true) ); 443 } 444 // test file 2 445 NextSubTest(); 446 { 447 entry_ref ref; 448 CPPUNIT_ASSERT( get_ref_for_path(testFile1, &ref) == B_OK ); 449 BResourceStrings resourceStrings; 450 CPPUNIT_ASSERT( resourceStrings.SetStringFile(&ref) == B_OK ); 451 CPPUNIT_ASSERT( resourceStrings.InitCheck() == B_OK ); 452 entry_ref ref2; 453 CPPUNIT_ASSERT( resourceStrings.GetStringFile(&ref2) == B_OK ); 454 CPPUNIT_ASSERT( BEntry(&ref, true) == BEntry(&ref2, true) ); 455 } 456 // empty file 457 NextSubTest(); 458 { 459 entry_ref ref; 460 CPPUNIT_ASSERT( get_ref_for_path(emptyFile, &ref) == B_OK ); 461 BResourceStrings resourceStrings; 462 CPPUNIT_ASSERT( resourceStrings.SetStringFile(&ref) == B_OK ); 463 CPPUNIT_ASSERT( resourceStrings.InitCheck() == B_OK ); 464 entry_ref ref2; 465 CPPUNIT_ASSERT( resourceStrings.GetStringFile(&ref2) == B_OK ); 466 CPPUNIT_ASSERT( BEntry(&ref, true) == BEntry(&ref2, true) ); 467 } 468 // non-resource file 469 NextSubTest(); 470 { 471 entry_ref ref; 472 CPPUNIT_ASSERT( get_ref_for_path(noResFile, &ref) == B_OK ); 473 BResourceStrings resourceStrings; 474 CPPUNIT_ASSERT( equals(resourceStrings.SetStringFile(&ref), B_ERROR, 475 B_IO_ERROR) ); 476 CPPUNIT_ASSERT( equals(resourceStrings.InitCheck(), B_ERROR, 477 B_IO_ERROR) ); 478 entry_ref ref2; 479 CPPUNIT_ASSERT( equals(resourceStrings.GetStringFile(&ref2), B_ERROR, 480 B_IO_ERROR) ); 481 } 482 // non-existing file 483 NextSubTest(); 484 { 485 entry_ref ref; 486 CPPUNIT_ASSERT( get_ref_for_path(noSuchFile, &ref) == B_OK ); 487 BResourceStrings resourceStrings; 488 CPPUNIT_ASSERT( resourceStrings.SetStringFile(&ref) 489 == B_ENTRY_NOT_FOUND ); 490 CPPUNIT_ASSERT( resourceStrings.InitCheck() == B_ENTRY_NOT_FOUND ); 491 entry_ref ref2; 492 CPPUNIT_ASSERT( resourceStrings.GetStringFile(&ref2) 493 == B_ENTRY_NOT_FOUND ); 494 } 495 // NULL ref -> app file 496 NextSubTest(); 497 { 498 BResourceStrings resourceStrings; 499 CPPUNIT_ASSERT( resourceStrings.SetStringFile(NULL) == B_OK ); 500 CPPUNIT_ASSERT( resourceStrings.InitCheck() == B_OK ); 501 entry_ref ref2; 502 CPPUNIT_ASSERT( resourceStrings.GetStringFile(&ref2) 503 == B_ENTRY_NOT_FOUND ); 504 } 505 } 506 507 // FindStringTest 508 static 509 void 510 FindStringTest(BResourceStrings &resourceStrings, const ResourceInfo &resource, 511 bool ok) 512 { 513 BString *newString = resourceStrings.NewString(resource.id); 514 const char *foundString = resourceStrings.FindString(resource.id); 515 if (ok) { 516 CPPUNIT_ASSERT( newString != NULL && foundString != NULL ); 517 CPPUNIT_ASSERT( *newString == (const char*)resource.data ); 518 CPPUNIT_ASSERT( *newString == foundString ); 519 delete newString; 520 } else 521 CPPUNIT_ASSERT( newString == NULL && foundString == NULL ); 522 } 523 524 // FindStringTest 525 void 526 ResourceStringsTest::FindStringTest() 527 { 528 // app file (default constructor) 529 NextSubTest(); 530 { 531 BResourceStrings resourceStrings; 532 CPPUNIT_ASSERT( resourceStrings.InitCheck() == B_OK ); 533 ::FindStringTest(resourceStrings, stringResource1, false); 534 ::FindStringTest(resourceStrings, stringResource2, false); 535 ::FindStringTest(resourceStrings, stringResource3, false); 536 ::FindStringTest(resourceStrings, stringResource4, false); 537 ::FindStringTest(resourceStrings, stringResource5, false); 538 ::FindStringTest(resourceStrings, stringResource6, false); 539 ::FindStringTest(resourceStrings, stringResource7, false); 540 ::FindStringTest(resourceStrings, stringResource8, false); 541 ::FindStringTest(resourceStrings, testResource1, false); 542 } 543 // app file (explicitely) 544 NextSubTest(); 545 { 546 entry_ref ref = get_app_ref(); 547 BResourceStrings resourceStrings(ref); 548 CPPUNIT_ASSERT( resourceStrings.InitCheck() == B_OK ); 549 ::FindStringTest(resourceStrings, stringResource1, false); 550 ::FindStringTest(resourceStrings, stringResource2, false); 551 ::FindStringTest(resourceStrings, stringResource3, false); 552 ::FindStringTest(resourceStrings, stringResource4, false); 553 ::FindStringTest(resourceStrings, stringResource5, false); 554 ::FindStringTest(resourceStrings, stringResource6, false); 555 ::FindStringTest(resourceStrings, stringResource7, false); 556 ::FindStringTest(resourceStrings, stringResource8, false); 557 ::FindStringTest(resourceStrings, testResource1, false); 558 } 559 // test file 1 560 NextSubTest(); 561 { 562 entry_ref ref = ref_for(testFile1); 563 BResourceStrings resourceStrings(ref); 564 CPPUNIT_ASSERT( resourceStrings.InitCheck() == B_OK ); 565 ::FindStringTest(resourceStrings, stringResource1, true); 566 ::FindStringTest(resourceStrings, stringResource2, true); 567 ::FindStringTest(resourceStrings, stringResource3, true); 568 ::FindStringTest(resourceStrings, stringResource4, true); 569 ::FindStringTest(resourceStrings, stringResource5, true); 570 ::FindStringTest(resourceStrings, stringResource6, false); 571 ::FindStringTest(resourceStrings, stringResource7, false); 572 ::FindStringTest(resourceStrings, stringResource8, false); 573 ::FindStringTest(resourceStrings, testResource1, false); 574 } 575 // test file 2 576 NextSubTest(); 577 { 578 entry_ref ref = ref_for(testFile2); 579 BResourceStrings resourceStrings(ref); 580 CPPUNIT_ASSERT( resourceStrings.InitCheck() == B_OK ); 581 ::FindStringTest(resourceStrings, stringResource1, false); 582 ::FindStringTest(resourceStrings, stringResource2, false); 583 ::FindStringTest(resourceStrings, stringResource3, false); 584 ::FindStringTest(resourceStrings, stringResource4, true); 585 ::FindStringTest(resourceStrings, stringResource5, true); 586 ::FindStringTest(resourceStrings, stringResource6, true); 587 ::FindStringTest(resourceStrings, stringResource7, true); 588 ::FindStringTest(resourceStrings, stringResource8, true); 589 ::FindStringTest(resourceStrings, testResource1, false); 590 } 591 // x86 resource file 592 NextSubTest(); 593 { 594 entry_ref ref = ref_for(x86ResFile); 595 BResourceStrings resourceStrings(ref); 596 CPPUNIT_ASSERT( resourceStrings.InitCheck() == B_OK ); 597 ::FindStringTest(resourceStrings, stringResource1, false); 598 ::FindStringTest(resourceStrings, stringResource2, false); 599 ::FindStringTest(resourceStrings, stringResource3, false); 600 ::FindStringTest(resourceStrings, stringResource4, false); 601 ::FindStringTest(resourceStrings, stringResource5, false); 602 ::FindStringTest(resourceStrings, stringResource6, false); 603 ::FindStringTest(resourceStrings, stringResource7, false); 604 ::FindStringTest(resourceStrings, stringResource8, false); 605 ::FindStringTest(resourceStrings, testResource1, true); 606 } 607 // ppc resource file 608 NextSubTest(); 609 { 610 entry_ref ref = ref_for(ppcResFile); 611 BResourceStrings resourceStrings(ref); 612 CPPUNIT_ASSERT( resourceStrings.InitCheck() == B_OK ); 613 ::FindStringTest(resourceStrings, stringResource1, false); 614 ::FindStringTest(resourceStrings, stringResource2, false); 615 ::FindStringTest(resourceStrings, stringResource3, false); 616 ::FindStringTest(resourceStrings, stringResource4, false); 617 ::FindStringTest(resourceStrings, stringResource5, false); 618 ::FindStringTest(resourceStrings, stringResource6, false); 619 ::FindStringTest(resourceStrings, stringResource7, false); 620 ::FindStringTest(resourceStrings, stringResource8, false); 621 ::FindStringTest(resourceStrings, testResource1, true); 622 } 623 // ELF executable 624 NextSubTest(); 625 { 626 entry_ref ref = ref_for(elfFile); 627 BResourceStrings resourceStrings(ref); 628 CPPUNIT_ASSERT( resourceStrings.InitCheck() == B_OK ); 629 ::FindStringTest(resourceStrings, stringResource1, false); 630 ::FindStringTest(resourceStrings, stringResource2, false); 631 ::FindStringTest(resourceStrings, stringResource3, false); 632 ::FindStringTest(resourceStrings, stringResource4, false); 633 ::FindStringTest(resourceStrings, stringResource5, false); 634 ::FindStringTest(resourceStrings, stringResource6, false); 635 ::FindStringTest(resourceStrings, stringResource7, false); 636 ::FindStringTest(resourceStrings, stringResource8, false); 637 ::FindStringTest(resourceStrings, testResource1, true); 638 } 639 // PEF executable 640 NextSubTest(); 641 { 642 entry_ref ref = ref_for(pefFile); 643 BResourceStrings resourceStrings(ref); 644 CPPUNIT_ASSERT( resourceStrings.InitCheck() == B_OK ); 645 ::FindStringTest(resourceStrings, stringResource1, false); 646 ::FindStringTest(resourceStrings, stringResource2, false); 647 ::FindStringTest(resourceStrings, stringResource3, false); 648 ::FindStringTest(resourceStrings, stringResource4, false); 649 ::FindStringTest(resourceStrings, stringResource5, false); 650 ::FindStringTest(resourceStrings, stringResource6, false); 651 ::FindStringTest(resourceStrings, stringResource7, false); 652 ::FindStringTest(resourceStrings, stringResource8, false); 653 ::FindStringTest(resourceStrings, testResource1, true); 654 } 655 // empty file 656 NextSubTest(); 657 { 658 entry_ref ref = ref_for(emptyFile); 659 BResourceStrings resourceStrings(ref); 660 CPPUNIT_ASSERT( resourceStrings.InitCheck() == B_OK ); 661 ::FindStringTest(resourceStrings, stringResource1, false); 662 ::FindStringTest(resourceStrings, stringResource2, false); 663 ::FindStringTest(resourceStrings, stringResource3, false); 664 ::FindStringTest(resourceStrings, stringResource4, false); 665 ::FindStringTest(resourceStrings, stringResource5, false); 666 ::FindStringTest(resourceStrings, stringResource6, false); 667 ::FindStringTest(resourceStrings, stringResource7, false); 668 ::FindStringTest(resourceStrings, stringResource8, false); 669 ::FindStringTest(resourceStrings, testResource1, false); 670 } 671 // non-resource file 672 NextSubTest(); 673 { 674 entry_ref ref = ref_for(noResFile); 675 BResourceStrings resourceStrings(ref); 676 CPPUNIT_ASSERT( equals(resourceStrings.InitCheck(), B_ERROR, 677 B_IO_ERROR) ); 678 ::FindStringTest(resourceStrings, stringResource1, false); 679 ::FindStringTest(resourceStrings, stringResource2, false); 680 ::FindStringTest(resourceStrings, stringResource3, false); 681 ::FindStringTest(resourceStrings, stringResource4, false); 682 ::FindStringTest(resourceStrings, stringResource5, false); 683 ::FindStringTest(resourceStrings, stringResource6, false); 684 ::FindStringTest(resourceStrings, stringResource7, false); 685 ::FindStringTest(resourceStrings, stringResource8, false); 686 ::FindStringTest(resourceStrings, testResource1, false); 687 } 688 // non-existing file 689 NextSubTest(); 690 { 691 entry_ref ref = ref_for(noSuchFile); 692 BResourceStrings resourceStrings(ref); 693 CPPUNIT_ASSERT( resourceStrings.InitCheck() == B_ENTRY_NOT_FOUND ); 694 ::FindStringTest(resourceStrings, stringResource1, false); 695 ::FindStringTest(resourceStrings, stringResource2, false); 696 ::FindStringTest(resourceStrings, stringResource3, false); 697 ::FindStringTest(resourceStrings, stringResource4, false); 698 ::FindStringTest(resourceStrings, stringResource5, false); 699 ::FindStringTest(resourceStrings, stringResource6, false); 700 ::FindStringTest(resourceStrings, stringResource7, false); 701 ::FindStringTest(resourceStrings, stringResource8, false); 702 ::FindStringTest(resourceStrings, testResource1, false); 703 } 704 } 705 706 707 708 709 710