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