1 //------------------------------------------------------------------------------ 2 // LaunchTester.cpp 3 // 4 //------------------------------------------------------------------------------ 5 6 // Standard Includes ----------------------------------------------------------- 7 #include <stdio.h> 8 #include <utime.h> 9 10 // System Includes ------------------------------------------------------------- 11 #include <Message.h> 12 #include <OS.h> 13 #include <AppFileInfo.h> 14 #include <Application.h> 15 #include <File.h> 16 #include <FindDirectory.h> 17 #include <Handler.h> 18 #include <Looper.h> 19 #include <Message.h> 20 #include <MessageQueue.h> 21 #include <Path.h> 22 #include <Roster.h> 23 #include <String.h> 24 25 // Project Includes ------------------------------------------------------------ 26 #include <TestShell.h> 27 #include <TestUtils.h> 28 #include <cppunit/TestAssert.h> 29 30 // Local Includes -------------------------------------------------------------- 31 #include "AppRunner.h" 32 #include "LaunchTester.h" 33 #include "LaunchTesterHelper.h" 34 #include "RosterTestAppDefs.h" 35 36 // Local Defines --------------------------------------------------------------- 37 38 // Globals --------------------------------------------------------------------- 39 40 //------------------------------------------------------------------------------ 41 42 static const char *testerSignature 43 = "application/x-vnd.obos-roster-launch-test"; 44 static const char *uninstalledType 45 = "application/x-vnd.obos-roster-launch-uninstalled"; 46 static const char *appType1 = "application/x-vnd.obos-roster-launch-app1"; 47 static const char *appType2 = "application/x-vnd.obos-roster-launch-app2"; 48 static const char *fileType1 = "application/x-vnd.obos-roster-launch-file1"; 49 static const char *fileType2 = "application/x-vnd.obos-roster-launch-file2"; 50 static const char *textTestType = "text/x-vnd.obos-roster-launch"; 51 52 static const char *testDir = "/tmp/testdir"; 53 static const char *appFile1 = "/tmp/testdir/app1"; 54 static const char *appFile2 = "/tmp/testdir/app2"; 55 static const char *testFile1 = "/tmp/testdir/testFile1"; 56 static const char *testLink1 = "/tmp/testdir/testLink1"; 57 static const char *trashAppName = "roster-launch-app"; 58 59 // dump_messenger 60 /*static 61 void 62 dump_messenger(BMessenger messenger) 63 { 64 struct fake_messenger { 65 port_id fPort; 66 int32 fHandlerToken; 67 team_id fTeam; 68 int32 extra0; 69 int32 extra1; 70 bool fPreferredTarget; 71 bool extra2; 72 bool extra3; 73 bool extra4; 74 } &fake = *(fake_messenger*)&messenger; 75 printf("BMessenger: fPort: %ld\n" 76 " fHandlerToken: %ld\n" 77 " fTeam: %ld\n" 78 " fPreferredTarget: %d\n", 79 fake.fPort, fake.fHandlerToken, fake.fTeam, fake.fPreferredTarget); 80 }*/ 81 82 83 // get_trash_app_file 84 static 85 const char* 86 get_trash_app_file() 87 { 88 static char trashAppFile[B_PATH_NAME_LENGTH]; 89 static bool initialized = false; 90 if (!initialized) { 91 BPath path; 92 CHK(find_directory(B_TRASH_DIRECTORY, &path) == B_OK); 93 CHK(path.Append(trashAppName) == B_OK); 94 strcpy(trashAppFile, path.Path()); 95 initialized = true; 96 } 97 return trashAppFile; 98 } 99 100 // install_type 101 static 102 void 103 install_type(const char *type, const char *preferredApp = NULL, 104 const char *snifferRule = NULL) 105 { 106 BMimeType mimeType(type); 107 if (!mimeType.IsInstalled()) 108 CHK(mimeType.Install() == B_OK); 109 if (preferredApp) 110 CHK(mimeType.SetPreferredApp(preferredApp) == B_OK); 111 if (snifferRule) 112 CHK(mimeType.SetSnifferRule(snifferRule) == B_OK); 113 } 114 115 // ref_for_path 116 static 117 entry_ref 118 ref_for_path(const char *filename, bool traverse = true) 119 { 120 entry_ref ref; 121 BEntry entry; 122 CHK(entry.SetTo(filename, traverse) == B_OK); 123 CHK(entry.GetRef(&ref) == B_OK); 124 return ref; 125 } 126 127 // ref_for_team 128 static 129 entry_ref 130 ref_for_team(team_id team) 131 { 132 BRoster roster; 133 app_info info; 134 CHK(roster.GetRunningAppInfo(team, &info) == B_OK); 135 return info.ref; 136 } 137 138 // create_app 139 static 140 void 141 create_app(const char *filename, const char *signature, 142 bool install = false, bool makeExecutable = true, 143 uint32 appFlags = B_SINGLE_LAUNCH) 144 { 145 BString testApp; 146 CHK(find_test_app("RosterLaunchTestApp1", &testApp) == B_OK); 147 system((string("cp ") + testApp.String() + " " + filename).c_str()); 148 if (makeExecutable) 149 system((string("chmod a+x ") + filename).c_str()); 150 BFile file; 151 CHK(file.SetTo(filename, B_READ_WRITE) == B_OK); 152 BAppFileInfo appFileInfo; 153 CHK(appFileInfo.SetTo(&file) == B_OK); 154 if (signature) 155 CHK(appFileInfo.SetSignature(signature) == B_OK); 156 CHK(appFileInfo.SetAppFlags(appFlags) == B_OK); 157 if (install && signature) 158 CHK(BMimeType(signature).Install() == B_OK); 159 // We write the signature into a separate attribute, just in case we 160 // decide to also test files without BEOS:APP_SIG attribute. 161 BString signatureString(signature); 162 file.WriteAttrString("signature", &signatureString); 163 } 164 165 // create_file 166 static 167 entry_ref 168 create_file(const char *filename, const char *type, 169 const char *preferredApp = NULL, const char *appHintPath = NULL, 170 const char *contents = NULL) 171 { 172 if (contents) 173 system((string("echo -n \"") + contents + "\" > " + filename).c_str()); 174 else 175 system((string("touch ") + filename).c_str()); 176 if (type || preferredApp || appHintPath) { 177 BFile file; 178 CHK(file.SetTo(filename, B_READ_WRITE) == B_OK); 179 BNodeInfo nodeInfo; 180 CHK(nodeInfo.SetTo(&file) == B_OK); 181 if (type) 182 CHK(nodeInfo.SetType(type) == B_OK); 183 if (preferredApp) 184 CHK(nodeInfo.SetPreferredApp(preferredApp) == B_OK); 185 if (appHintPath) { 186 entry_ref appHint(ref_for_path(appHintPath)); 187 CHK(nodeInfo.SetAppHint(&appHint) == B_OK); 188 } 189 } 190 return ref_for_path(filename); 191 } 192 193 // check_app_type 194 static 195 void 196 check_app_type(const char *signature, const char *filename) 197 { 198 BMimeType type(signature); 199 CHK(type.IsInstalled() == true); 200 if (filename) { 201 entry_ref appHint; 202 CHK(type.GetAppHint(&appHint) == B_OK); 203 CHK(ref_for_path(filename) == appHint); 204 } 205 } 206 207 // set_file_time 208 static 209 void 210 set_file_time(const char *filename, time_t time) 211 { 212 utimbuf buffer; 213 buffer.actime = time; 214 buffer.modtime = time; 215 CHK(utime(filename, &buffer) == 0); 216 } 217 218 // set_version 219 static 220 void 221 set_version(const char *filename, uint32 version) 222 { 223 version_info versionInfo = { 1, 1, 1, 1, version, "short1", "long1" }; 224 BFile file; 225 CHK(file.SetTo(filename, B_READ_WRITE) == B_OK); 226 BAppFileInfo appFileInfo; 227 CHK(appFileInfo.SetTo(&file) == B_OK); 228 CHK(appFileInfo.SetVersionInfo(&versionInfo, B_APP_VERSION_KIND) == B_OK); 229 } 230 231 // set_type_app_hint 232 static 233 void 234 set_type_app_hint(const char *signature, const char *filename) 235 { 236 BMimeType type(signature); 237 if (!type.IsInstalled()); 238 CHK(type.Install() == B_OK); 239 entry_ref fileRef(ref_for_path(filename)); 240 CHK(type.SetAppHint(&fileRef) == B_OK); 241 } 242 243 // setUp 244 void 245 LaunchTester::setUp() 246 { 247 fApplication = new RosterLaunchApp(testerSignature); 248 system((string("mkdir ") + testDir).c_str()); 249 } 250 251 // tearDown 252 void 253 LaunchTester::tearDown() 254 { 255 BMimeType(uninstalledType).Delete(); 256 BMimeType(appType1).Delete(); 257 BMimeType(appType2).Delete(); 258 BMimeType(fileType1).Delete(); 259 BMimeType(fileType2).Delete(); 260 BMimeType(textTestType).Delete(); 261 delete fApplication; 262 system((string("rm -rf ") + testDir).c_str()); 263 system((string("rm -f ") + get_trash_app_file()).c_str()); 264 } 265 266 /* 267 @case 1 uninstalled type mimeType 268 @results Should return B_LAUNCH_FAILED_APP_NOT_FOUND. 269 */ 270 static 271 void 272 CommonLaunchTest1(LaunchCaller &caller) 273 { 274 LaunchContext context; 275 BRoster roster; 276 team_id team; 277 CHK(context(caller, uninstalledType, &team) == B_LAUNCH_FAILED_APP_NOT_FOUND); 278 } 279 280 /* 281 @case 2 installed type mimeType, no preferred app 282 @results Should return B_LAUNCH_FAILED_NO_PREFERRED_APP. 283 */ 284 static 285 void 286 CommonLaunchTest2(LaunchCaller &caller) 287 { 288 LaunchContext context; 289 BRoster roster; 290 install_type(fileType1); 291 team_id team; 292 CHK(context(caller, fileType1, &team) == B_LAUNCH_FAILED_NO_PREFERRED_APP); 293 } 294 295 /* 296 @case 3 installed type mimeType, preferred app, app type not 297 installed, app has no signature 298 @results Should return B_LAUNCH_FAILED_APP_NOT_FOUND. 299 */ 300 static 301 void 302 CommonLaunchTest3(LaunchCaller &caller) 303 { 304 LaunchContext context; 305 BRoster roster; 306 install_type(fileType1, appType1); 307 team_id team; 308 CHK(context(caller, fileType1, &team) == B_LAUNCH_FAILED_APP_NOT_FOUND); 309 } 310 311 /* 312 @case 4 installed type mimeType, preferred app, app type not 313 installed, app has signature 314 @results Should return B_OK and set team to the ID of the team 315 running the application's executable. Should install the 316 app type and set the app hint on it. 317 */ 318 static 319 void 320 CommonLaunchTest4(LaunchCaller &caller) 321 { 322 LaunchContext context; 323 BRoster roster; 324 create_app(appFile1, appType1); 325 install_type(fileType1, appType1); 326 team_id team; 327 CHK(context(caller, fileType1, &team) == B_OK); 328 entry_ref ref = ref_for_team(team); 329 CHK(ref_for_path(appFile1) == ref); 330 check_app_type(appType1, appFile1); 331 context.Terminate(); 332 int32 cookie = 0; 333 CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); 334 CHK(context.CheckMainArgsMessage(caller, team, cookie, &ref)); 335 CHK(context.CheckMessageMessages(caller, team, cookie)); 336 CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); 337 if (caller.SupportsRefs() && !caller.SupportsArgv()) 338 CHK(context.CheckRefsMessage(caller, team, cookie)); 339 CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); 340 CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); 341 CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); 342 } 343 344 /* 345 @case 5 installed type mimeType, preferred app, app type installed, 346 app has signature 347 @results Should return B_OK and set team to the ID of the team 348 running the application's executable. Should set the app 349 hint on the app type. 350 */ 351 static 352 void 353 CommonLaunchTest5(LaunchCaller &caller) 354 { 355 LaunchContext context; 356 BRoster roster; 357 create_app(appFile1, appType1, true); 358 install_type(fileType1, appType1); 359 team_id team; 360 CHK(context(caller, fileType1, &team) == B_OK); 361 entry_ref ref = ref_for_team(team); 362 CHK(ref_for_path(appFile1) == ref); 363 check_app_type(appType1, appFile1); 364 context.Terminate(); 365 int32 cookie = 0; 366 CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); 367 CHK(context.CheckMainArgsMessage(caller, team, cookie, &ref)); 368 CHK(context.CheckMessageMessages(caller, team, cookie)); 369 CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); 370 if (caller.SupportsRefs() && !caller.SupportsArgv()) 371 CHK(context.CheckRefsMessage(caller, team, cookie)); 372 CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); 373 CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); 374 CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); 375 } 376 377 /* 378 @case 6 installed type mimeType, preferred app, app type installed, 379 app has signature, app has no execute permission 380 @results Should return B_OK and set team to the ID of the team 381 running the application's executable. Should set the app 382 hint on the app type. 383 */ 384 static 385 void 386 CommonLaunchTest6(LaunchCaller &caller) 387 { 388 LaunchContext context; 389 BRoster roster; 390 create_app(appFile1, appType1, true, false); 391 install_type(fileType1, appType1); 392 team_id team; 393 CHK(context(caller, fileType1, &team) == B_OK); 394 entry_ref ref = ref_for_team(team); 395 CHK(ref_for_path(appFile1) == ref); 396 check_app_type(appType1, appFile1); 397 context.Terminate(); 398 int32 cookie = 0; 399 CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); 400 CHK(context.CheckMainArgsMessage(caller, team, cookie, &ref)); 401 CHK(context.CheckMessageMessages(caller, team, cookie)); 402 CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); 403 if (caller.SupportsRefs() && !caller.SupportsArgv()) 404 CHK(context.CheckRefsMessage(caller, team, cookie)); 405 CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); 406 CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); 407 CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); 408 } 409 410 /* 411 @case 7 installed type mimeType, preferred app, app type installed, 412 two apps have the signature 413 @results Should return B_OK and set team to the ID of the team 414 running the application executable with the most recent 415 modification time. Should set the app hint on the app type. 416 */ 417 static 418 void 419 CommonLaunchTest7(LaunchCaller &caller) 420 { 421 LaunchContext context; 422 BRoster roster; 423 create_app(appFile1, appType1); 424 create_app(appFile2, appType1, true); 425 set_file_time(appFile2, time(NULL) + 1); 426 install_type(fileType1, appType1); 427 team_id team; 428 CHK(context(caller, fileType1, &team) == B_OK); 429 entry_ref ref = ref_for_team(team); 430 CHK(ref_for_path(appFile2) == ref); 431 check_app_type(appType1, appFile2); 432 context.Terminate(); 433 int32 cookie = 0; 434 CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); 435 CHK(context.CheckMainArgsMessage(caller, team, cookie, &ref)); 436 CHK(context.CheckMessageMessages(caller, team, cookie)); 437 CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); 438 if (caller.SupportsRefs() && !caller.SupportsArgv()) 439 CHK(context.CheckRefsMessage(caller, team, cookie)); 440 CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); 441 CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); 442 CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); 443 } 444 445 /* 446 @case 8 installed type mimeType, preferred app, app type installed, 447 two apps have the signature, one has a version info, the 448 other one is newer 449 @results Should return B_OK and set team to the ID of the team 450 running the application executable with version info. 451 Should set the app hint on the app type. 452 */ 453 static 454 void 455 CommonLaunchTest8(LaunchCaller &caller) 456 { 457 LaunchContext context; 458 BRoster roster; 459 create_app(appFile1, appType1); 460 set_version(appFile1, 1); 461 create_app(appFile2, appType1, true); 462 set_file_time(appFile2, time(NULL) + 1); 463 install_type(fileType1, appType1); 464 team_id team; 465 CHK(context(caller, fileType1, &team) == B_OK); 466 entry_ref ref = ref_for_team(team); 467 CHK(ref_for_path(appFile1) == ref); 468 check_app_type(appType1, appFile1); 469 context.Terminate(); 470 int32 cookie = 0; 471 CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); 472 CHK(context.CheckMainArgsMessage(caller, team, cookie, &ref)); 473 CHK(context.CheckMessageMessages(caller, team, cookie)); 474 CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); 475 if (caller.SupportsRefs() && !caller.SupportsArgv()) 476 CHK(context.CheckRefsMessage(caller, team, cookie)); 477 CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); 478 CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); 479 CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); 480 } 481 482 /* 483 @case 9 installed type mimeType, preferred app, app type installed, 484 two apps have the signature, both apps have a version info 485 @results Should return B_OK and set team to the ID of the team 486 running the application executable with the greater 487 version. Should set the app hint on the app type. 488 */ 489 static 490 void 491 CommonLaunchTest9(LaunchCaller &caller) 492 { 493 LaunchContext context; 494 BRoster roster; 495 create_app(appFile1, appType1); 496 set_version(appFile1, 2); 497 create_app(appFile2, appType1, true); 498 set_version(appFile1, 1); 499 set_file_time(appFile2, time(NULL) + 1); 500 install_type(fileType1, appType1); 501 team_id team; 502 CHK(context(caller, fileType1, &team) == B_OK); 503 entry_ref ref = ref_for_team(team); 504 CHK(ref_for_path(appFile1) == ref); 505 check_app_type(appType1, appFile1); 506 context.Terminate(); 507 int32 cookie = 0; 508 CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); 509 CHK(context.CheckMainArgsMessage(caller, team, cookie, &ref)); 510 CHK(context.CheckMessageMessages(caller, team, cookie)); 511 CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); 512 if (caller.SupportsRefs() && !caller.SupportsArgv()) 513 CHK(context.CheckRefsMessage(caller, team, cookie)); 514 CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); 515 CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); 516 CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); 517 } 518 519 /* 520 @case 10 installed type mimeType, preferred app, app type installed, 521 preferred app type has an app hint that points to an app 522 with a different signature 523 @results Should return B_OK and set team to the ID of the team 524 running the application's executable. Should remove the 525 incorrect app hint on the app type. (OBOS: Should set the 526 correct app hint. Don't even return the wrong app?) 527 */ 528 static 529 void 530 CommonLaunchTest10(LaunchCaller &caller) 531 { 532 LaunchContext context; 533 BRoster roster; 534 create_app(appFile1, appType2); 535 set_type_app_hint(appType1, appFile1); 536 entry_ref appHint; 537 CHK(BMimeType(appType1).GetAppHint(&appHint) == B_OK); 538 install_type(fileType1, appType1); 539 team_id team; 540 CHK(context(caller, fileType1, &team) == B_OK); 541 entry_ref ref = ref_for_team(team); 542 CHK(ref_for_path(appFile1) == ref); 543 CHK(BMimeType(appType1).GetAppHint(&appHint) == B_ENTRY_NOT_FOUND); 544 // OBOS: We set the app hint for app type 2. There's no reason not to do it. 545 #ifdef TEST_R5 546 CHK(BMimeType(appType2).IsInstalled() == false); 547 #else 548 check_app_type(appType2, appFile1); 549 #endif 550 context.Terminate(); 551 int32 cookie = 0; 552 CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); 553 CHK(context.CheckMainArgsMessage(caller, team, cookie, &ref)); 554 CHK(context.CheckMessageMessages(caller, team, cookie)); 555 CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); 556 if (caller.SupportsRefs() && !caller.SupportsArgv()) 557 CHK(context.CheckRefsMessage(caller, team, cookie)); 558 CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); 559 CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); 560 CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); 561 } 562 563 /* 564 @case 11 installed type mimeType, preferred app, app type installed, 565 preferred app type has an app hint pointing to void, 566 a differently named app with this signature exists 567 @results Should return B_OK and set team to the ID of the team 568 running the application's executable. Should update the 569 app hint on the app type. 570 */ 571 static 572 void 573 CommonLaunchTest11(LaunchCaller &caller) 574 { 575 LaunchContext context; 576 BRoster roster; 577 create_app(appFile1, appType1); 578 set_type_app_hint(appType1, appFile2); 579 install_type(fileType1, appType1); 580 team_id team; 581 CHK(context(caller, fileType1, &team) == B_OK); 582 entry_ref ref = ref_for_team(team); 583 CHK(ref_for_path(appFile1) == ref); 584 check_app_type(appType1, appFile1); 585 context.Terminate(); 586 int32 cookie = 0; 587 CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); 588 CHK(context.CheckMainArgsMessage(caller, team, cookie, &ref)); 589 CHK(context.CheckMessageMessages(caller, team, cookie)); 590 CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); 591 if (caller.SupportsRefs() && !caller.SupportsArgv()) 592 CHK(context.CheckRefsMessage(caller, team, cookie)); 593 CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); 594 CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); 595 CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); 596 } 597 598 /* 599 @case 12 mimeType is app signature, not installed 600 @results Should return B_OK and set team to the ID of the team 601 running the application executable. Should set the app 602 hint on the app type. 603 */ 604 static 605 void 606 CommonLaunchTest12(LaunchCaller &caller) 607 { 608 LaunchContext context; 609 BRoster roster; 610 create_app(appFile1, appType1); 611 team_id team; 612 CHK(context(caller, appType1, &team) == B_OK); 613 entry_ref ref = ref_for_team(team); 614 CHK(ref_for_path(appFile1) == ref); 615 check_app_type(appType1, appFile1); 616 context.Terminate(); 617 int32 cookie = 0; 618 CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); 619 CHK(context.CheckMainArgsMessage(caller, team, cookie, &ref)); 620 CHK(context.CheckMessageMessages(caller, team, cookie)); 621 CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); 622 if (caller.SupportsRefs() && !caller.SupportsArgv()) 623 CHK(context.CheckRefsMessage(caller, team, cookie)); 624 CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); 625 CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); 626 CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); 627 } 628 629 /* 630 @case 13 mimeType is installed, but has no preferred application, 631 super type has preferred application 632 @results Should return B_OK and set team to the ID of the team 633 running the application executable associated with the 634 preferred app of the supertype. Should set the app hint 635 on the app type. 636 */ 637 static 638 void 639 CommonLaunchTest13(LaunchCaller &caller) 640 { 641 LaunchContext context; 642 BRoster roster; 643 // make sure, the original preferred app for the "text" supertype is 644 // re-installed 645 struct TextTypeSaver { 646 TextTypeSaver() 647 { 648 BMimeType textType("text"); 649 hasPreferredApp 650 = (textType.GetPreferredApp(preferredApp) == B_OK); 651 } 652 653 ~TextTypeSaver() 654 { 655 BMimeType textType("text"); 656 textType.SetPreferredApp(hasPreferredApp ? preferredApp : NULL); 657 } 658 659 bool hasPreferredApp; 660 char preferredApp[B_MIME_TYPE_LENGTH]; 661 } _saver; 662 663 create_app(appFile1, appType1); 664 CHK(BMimeType("text").SetPreferredApp(appType1) == B_OK); 665 install_type(textTestType); 666 team_id team; 667 CHK(context(caller, textTestType, &team) == B_OK); 668 entry_ref ref = ref_for_team(team); 669 CHK(ref_for_path(appFile1) == ref); 670 check_app_type(appType1, appFile1); 671 context.Terminate(); 672 int32 cookie = 0; 673 CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); 674 CHK(context.CheckMainArgsMessage(caller, team, cookie, &ref)); 675 CHK(context.CheckMessageMessages(caller, team, cookie)); 676 CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); 677 if (caller.SupportsRefs() && !caller.SupportsArgv()) 678 CHK(context.CheckRefsMessage(caller, team, cookie)); 679 CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); 680 CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); 681 CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); 682 } 683 684 /* 685 @case 14 installed type mimeType, preferred app, app type not 686 installed, app has signature, app is trash 687 @results Should return B_LAUNCH_FAILED_APP_IN_TRASH. 688 */ 689 static 690 void 691 CommonLaunchTest14(LaunchCaller &caller) 692 { 693 LaunchContext context; 694 BRoster roster; 695 create_app(get_trash_app_file(), appType1); 696 install_type(fileType1, appType1); 697 team_id team; 698 CHK(context(caller, fileType1, &team) == B_LAUNCH_FAILED_APP_IN_TRASH); 699 } 700 701 /* 702 @case 15 installed type mimeType, preferred app, app type not 703 installed, app has signature, team is NULL 704 @results Should return B_OK and set team to the ID of the team 705 running the application's executable. Should install the 706 app type and set the app hint on it. 707 */ 708 static 709 void 710 CommonLaunchTest15(LaunchCaller &caller) 711 { 712 LaunchContext context; 713 BRoster roster; 714 create_app(appFile1, appType1); 715 install_type(fileType1, appType1); 716 CHK(context(caller, fileType1, NULL) == B_OK); 717 context.WaitForMessage(MSG_STARTED, true); 718 team_id team = context.TeamAt(0); 719 CHK(team >= 0); 720 entry_ref ref = ref_for_team(team); 721 CHK(ref_for_path(appFile1) == ref); 722 check_app_type(appType1, appFile1); 723 context.Terminate(); 724 int32 cookie = 0; 725 CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); 726 CHK(context.CheckMainArgsMessage(caller, team, cookie, &ref)); 727 CHK(context.CheckMessageMessages(caller, team, cookie)); 728 CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); 729 if (caller.SupportsRefs() && !caller.SupportsArgv()) 730 CHK(context.CheckRefsMessage(caller, team, cookie)); 731 CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); 732 CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); 733 CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); 734 } 735 736 /* 737 @case 16 launch the app two times: B_MULTIPLE_LAUNCH | B_ARGV_ONLY 738 @results first app: ArgvReceived(), ReadyToRun(), QuitRequested() 739 second app: ArgvReceived(), ReadyToRun(), QuitRequested() 740 */ 741 static 742 void 743 CommonLaunchTest16(LaunchCaller &caller) 744 { 745 LaunchCaller &caller2 = caller.Clone(); 746 LaunchContext context; 747 BRoster roster; 748 create_app(appFile1, appType1, false, true, 749 B_MULTIPLE_LAUNCH | B_ARGV_ONLY); 750 install_type(fileType1, appType1); 751 // launch app 1 752 team_id team1; 753 CHK(context(caller, fileType1, &team1) == B_OK); 754 entry_ref ref1 = ref_for_team(team1); 755 CHK(ref_for_path(appFile1) == ref1); 756 check_app_type(appType1, appFile1); 757 context.WaitForMessage(team1, MSG_STARTED); 758 // launch app 2 759 team_id team2; 760 CHK(context(caller2, fileType1, &team2) == B_OK); 761 entry_ref ref2 = ref_for_team(team2); 762 CHK(ref_for_path(appFile1) == ref2); 763 check_app_type(appType1, appFile1); 764 // checks 1 765 context.Terminate(); 766 int32 cookie = 0; 767 CHK(context.CheckNextMessage(caller, team1, cookie, MSG_STARTED)); 768 CHK(context.CheckMainArgsMessage(caller, team1, cookie, &ref1)); 769 // CHK(context.CheckMessageMessages(caller, team1, cookie)); 770 CHK(context.CheckArgvMessage(caller, team1, cookie, &ref1)); 771 // if (caller.SupportsRefs() && !caller.SupportsArgv()) 772 // CHK(context.CheckRefsMessage(caller, team1, cookie)); 773 CHK(context.CheckNextMessage(caller, team1, cookie, MSG_READY_TO_RUN)); 774 CHK(context.CheckNextMessage(caller, team1, cookie, MSG_QUIT_REQUESTED)); 775 CHK(context.CheckNextMessage(caller, team1, cookie, MSG_TERMINATED)); 776 // checks 2 777 cookie = 0; 778 CHK(context.CheckNextMessage(caller2, team2, cookie, MSG_STARTED)); 779 CHK(context.CheckMainArgsMessage(caller2, team2, cookie, &ref2)); 780 // CHK(context.CheckMessageMessages(caller2, team2, cookie)); 781 CHK(context.CheckArgvMessage(caller2, team2, cookie, &ref2)); 782 // if (caller.SupportsRefs() && !caller.SupportsArgv()) 783 // CHK(context.CheckRefsMessage(caller2, team2, cookie)); 784 CHK(context.CheckNextMessage(caller2, team2, cookie, MSG_READY_TO_RUN)); 785 CHK(context.CheckNextMessage(caller2, team2, cookie, MSG_QUIT_REQUESTED)); 786 CHK(context.CheckNextMessage(caller2, team2, cookie, MSG_TERMINATED)); 787 } 788 789 /* 790 @case 17 launch the app two times: B_MULTIPLE_LAUNCH | B_ARGV_ONLY 791 @results first app: {Message,Argv,Refs}Received()*, ReadyToRun(), 792 QuitRequested() 793 second app: {Message,Argv,Refs}Received()*, ReadyToRun(), 794 QuitRequested() 795 */ 796 static 797 void 798 CommonLaunchTest17(LaunchCaller &caller) 799 { 800 LaunchCaller &caller2 = caller.Clone(); 801 LaunchContext context; 802 BRoster roster; 803 create_app(appFile1, appType1, false, true, 804 B_MULTIPLE_LAUNCH); 805 install_type(fileType1, appType1); 806 // launch app 1 807 team_id team1; 808 CHK(context(caller, fileType1, &team1) == B_OK); 809 entry_ref ref1 = ref_for_team(team1); 810 CHK(ref_for_path(appFile1) == ref1); 811 check_app_type(appType1, appFile1); 812 context.WaitForMessage(team1, MSG_STARTED); 813 // launch app 2 814 team_id team2; 815 CHK(context(caller2, fileType1, &team2) == B_OK); 816 entry_ref ref2 = ref_for_team(team2); 817 CHK(ref_for_path(appFile1) == ref2); 818 check_app_type(appType1, appFile1); 819 // checks 1 820 context.Terminate(); 821 int32 cookie = 0; 822 CHK(context.CheckNextMessage(caller, team1, cookie, MSG_STARTED)); 823 CHK(context.CheckMainArgsMessage(caller, team1, cookie, &ref1)); 824 CHK(context.CheckMessageMessages(caller, team1, cookie)); 825 CHK(context.CheckArgvMessage(caller, team1, cookie, &ref1)); 826 if (caller.SupportsRefs() && !caller.SupportsArgv()) 827 CHK(context.CheckRefsMessage(caller, team1, cookie)); 828 CHK(context.CheckNextMessage(caller, team1, cookie, MSG_READY_TO_RUN)); 829 CHK(context.CheckNextMessage(caller, team1, cookie, MSG_QUIT_REQUESTED)); 830 CHK(context.CheckNextMessage(caller, team1, cookie, MSG_TERMINATED)); 831 // checks 2 832 cookie = 0; 833 CHK(context.CheckNextMessage(caller2, team2, cookie, MSG_STARTED)); 834 CHK(context.CheckMainArgsMessage(caller2, team2, cookie, &ref2)); 835 CHK(context.CheckMessageMessages(caller2, team2, cookie)); 836 CHK(context.CheckArgvMessage(caller2, team2, cookie, &ref2)); 837 if (caller.SupportsRefs() && !caller.SupportsArgv()) 838 CHK(context.CheckRefsMessage(caller2, team2, cookie)); 839 CHK(context.CheckNextMessage(caller2, team2, cookie, MSG_READY_TO_RUN)); 840 CHK(context.CheckNextMessage(caller2, team2, cookie, MSG_QUIT_REQUESTED)); 841 CHK(context.CheckNextMessage(caller2, team2, cookie, MSG_TERMINATED)); 842 } 843 844 /* 845 @case 18 launch the app two times: B_SINGLE_LAUNCH | B_ARGV_ONLY 846 @results first app: ArgvReceived(), ReadyToRun(), QuitRequested() 847 (No second ArgvReceived()!) 848 second app: Launch() fails with B_ALREADY_RUNNING 849 */ 850 static 851 void 852 CommonLaunchTest18(LaunchCaller &caller) 853 { 854 LaunchCaller &caller2 = caller.Clone(); 855 LaunchContext context; 856 BRoster roster; 857 create_app(appFile1, appType1, false, true, 858 B_SINGLE_LAUNCH | B_ARGV_ONLY); 859 install_type(fileType1, appType1); 860 // launch app 1 861 team_id team1; 862 CHK(context(caller, fileType1, &team1) == B_OK); 863 entry_ref ref1 = ref_for_team(team1); 864 CHK(ref_for_path(appFile1) == ref1); 865 check_app_type(appType1, appFile1); 866 context.WaitForMessage(team1, MSG_STARTED); 867 // launch app 2 868 team_id team2; 869 CHK(context(caller2, fileType1, &team2) == B_ALREADY_RUNNING); 870 // checks 1 871 context.Terminate(); 872 int32 cookie = 0; 873 CHK(context.CheckNextMessage(caller, team1, cookie, MSG_STARTED)); 874 CHK(context.CheckMainArgsMessage(caller, team1, cookie, &ref1)); 875 // CHK(context.CheckMessageMessages(caller, team1, cookie)); 876 CHK(context.CheckArgvMessage(caller, team1, cookie, &ref1)); 877 // if (caller.SupportsRefs() && !caller.SupportsArgv()) 878 // CHK(context.CheckRefsMessage(caller, team1, cookie)); 879 CHK(context.CheckNextMessage(caller, team1, cookie, MSG_READY_TO_RUN)); 880 CHK(context.CheckNextMessage(caller, team1, cookie, MSG_QUIT_REQUESTED)); 881 CHK(context.CheckNextMessage(caller, team1, cookie, MSG_TERMINATED)); 882 } 883 884 /* 885 @case 19 launch the app two times: B_SINGLE_LAUNCH 886 @results first app: {Message,Argv,Refs}Received()*, ReadyToRun(), 887 {Message,Argv,Refs}Received()*, QuitRequested() 888 second app: Launch() fails with B_ALREADY_RUNNING 889 */ 890 static 891 void 892 CommonLaunchTest19(LaunchCaller &caller) 893 { 894 LaunchCaller &caller2 = caller.Clone(); 895 LaunchContext context; 896 BRoster roster; 897 create_app(appFile1, appType1, false, true, 898 B_SINGLE_LAUNCH); 899 install_type(fileType1, appType1); 900 // launch app 1 901 team_id team1; 902 CHK(context(caller, fileType1, &team1) == B_OK); 903 entry_ref ref1 = ref_for_team(team1); 904 CHK(ref_for_path(appFile1) == ref1); 905 check_app_type(appType1, appFile1); 906 context.WaitForMessage(team1, MSG_STARTED); 907 // launch app 2 908 team_id team2; 909 CHK(context(caller2, fileType1, &team2) == B_ALREADY_RUNNING); 910 // checks 1 911 context.Terminate(); 912 int32 cookie = 0; 913 CHK(context.CheckNextMessage(caller, team1, cookie, MSG_STARTED)); 914 CHK(context.CheckMainArgsMessage(caller, team1, cookie, &ref1)); 915 CHK(context.CheckMessageMessages(caller, team1, cookie)); 916 CHK(context.CheckArgvMessage(caller, team1, cookie, &ref1)); 917 if (caller.SupportsRefs() && !caller.SupportsArgv()) 918 CHK(context.CheckRefsMessage(caller, team1, cookie)); 919 CHK(context.CheckNextMessage(caller, team1, cookie, MSG_READY_TO_RUN)); 920 CHK(context.CheckMessageMessages(caller, team1, cookie)); 921 CHK(context.CheckArgvMessage(caller, team1, cookie, &ref1)); 922 if (caller.SupportsRefs() && !caller.SupportsArgv()) 923 CHK(context.CheckRefsMessage(caller, team1, cookie)); 924 CHK(context.CheckNextMessage(caller, team1, cookie, MSG_QUIT_REQUESTED)); 925 CHK(context.CheckNextMessage(caller, team1, cookie, MSG_TERMINATED)); 926 } 927 928 /* 929 @case 20 launch two apps with the same signature: 930 B_SINGLE_LAUNCH | B_ARGV_ONLY 931 @results first app: ArgvReceived(), ReadyToRun(), QuitRequested() 932 second app: ArgvReceived(), ReadyToRun(), QuitRequested() 933 */ 934 static 935 void 936 CommonLaunchTest20(LaunchCaller &caller) 937 { 938 LaunchCaller &caller2 = caller.Clone(); 939 LaunchContext context; 940 BRoster roster; 941 // launch app 1 942 create_app(appFile1, appType1, false, true, 943 B_SINGLE_LAUNCH | B_ARGV_ONLY); 944 install_type(fileType1, appType1); 945 team_id team1; 946 CHK(context(caller, fileType1, &team1) == B_OK); 947 entry_ref ref1 = ref_for_team(team1); 948 CHK(ref_for_path(appFile1) == ref1); 949 check_app_type(appType1, appFile1); 950 context.WaitForMessage(team1, MSG_STARTED); 951 // launch app 2 (greater modification time) 952 CHK(BMimeType(appType1).Delete() == B_OK); 953 create_app(appFile2, appType1, false, true, 954 B_SINGLE_LAUNCH | B_ARGV_ONLY); 955 set_file_time(appFile2, time(NULL) + 1); 956 team_id team2; 957 CHK(context(caller2, fileType1, &team2) == B_OK); 958 entry_ref ref2 = ref_for_team(team2); 959 CHK(ref_for_path(appFile2) == ref2); 960 check_app_type(appType1, appFile2); 961 // checks 1 962 context.Terminate(); 963 int32 cookie = 0; 964 CHK(context.CheckNextMessage(caller, team1, cookie, MSG_STARTED)); 965 CHK(context.CheckMainArgsMessage(caller, team1, cookie, &ref1)); 966 // CHK(context.CheckMessageMessages(caller, team1, cookie)); 967 CHK(context.CheckArgvMessage(caller, team1, cookie, &ref1)); 968 // if (caller.SupportsRefs() && !caller.SupportsArgv()) 969 // CHK(context.CheckRefsMessage(caller, team1, cookie)); 970 CHK(context.CheckNextMessage(caller, team1, cookie, MSG_READY_TO_RUN)); 971 CHK(context.CheckNextMessage(caller, team1, cookie, MSG_QUIT_REQUESTED)); 972 CHK(context.CheckNextMessage(caller, team1, cookie, MSG_TERMINATED)); 973 // checks 2 974 cookie = 0; 975 CHK(context.CheckNextMessage(caller2, team2, cookie, MSG_STARTED)); 976 CHK(context.CheckMainArgsMessage(caller2, team2, cookie, &ref2)); 977 // CHK(context.CheckMessageMessages(caller2, team2, cookie)); 978 CHK(context.CheckArgvMessage(caller2, team2, cookie, &ref2)); 979 // if (caller.SupportsRefs() && !caller.SupportsArgv()) 980 // CHK(context.CheckRefsMessage(caller2, team2, cookie)); 981 CHK(context.CheckNextMessage(caller2, team2, cookie, MSG_READY_TO_RUN)); 982 CHK(context.CheckNextMessage(caller2, team2, cookie, MSG_QUIT_REQUESTED)); 983 CHK(context.CheckNextMessage(caller2, team2, cookie, MSG_TERMINATED)); 984 } 985 986 /* 987 @case 21 launch two apps with the same signature: B_SINGLE_LAUNCH 988 @results first app: {Message,Argv,Refs}Received()*, ReadyToRun(), 989 QuitRequested() 990 second app: {Message,Argv,Refs}Received()*, ReadyToRun(), 991 QuitRequested() 992 */ 993 static 994 void 995 CommonLaunchTest21(LaunchCaller &caller) 996 { 997 LaunchCaller &caller2 = caller.Clone(); 998 LaunchContext context; 999 BRoster roster; 1000 // launch app 1 1001 create_app(appFile1, appType1, false, true, 1002 B_SINGLE_LAUNCH); 1003 install_type(fileType1, appType1); 1004 team_id team1; 1005 CHK(context(caller, fileType1, &team1) == B_OK); 1006 entry_ref ref1 = ref_for_team(team1); 1007 CHK(ref_for_path(appFile1) == ref1); 1008 check_app_type(appType1, appFile1); 1009 context.WaitForMessage(team1, MSG_STARTED); 1010 // launch app 2 (greater modification time) 1011 CHK(BMimeType(appType1).Delete() == B_OK); 1012 create_app(appFile2, appType1, false, true, 1013 B_SINGLE_LAUNCH); 1014 set_file_time(appFile2, time(NULL) + 1); 1015 team_id team2; 1016 CHK(context(caller2, fileType1, &team2) == B_OK); 1017 entry_ref ref2 = ref_for_team(team2); 1018 CHK(ref_for_path(appFile2) == ref2); 1019 check_app_type(appType1, appFile2); 1020 // checks 1 1021 context.Terminate(); 1022 int32 cookie = 0; 1023 CHK(context.CheckNextMessage(caller, team1, cookie, MSG_STARTED)); 1024 CHK(context.CheckMainArgsMessage(caller, team1, cookie, &ref1)); 1025 CHK(context.CheckMessageMessages(caller, team1, cookie)); 1026 CHK(context.CheckArgvMessage(caller, team1, cookie, &ref1)); 1027 if (caller.SupportsRefs() && !caller.SupportsArgv()) 1028 CHK(context.CheckRefsMessage(caller, team1, cookie)); 1029 CHK(context.CheckNextMessage(caller, team1, cookie, MSG_READY_TO_RUN)); 1030 CHK(context.CheckNextMessage(caller, team1, cookie, MSG_QUIT_REQUESTED)); 1031 CHK(context.CheckNextMessage(caller, team1, cookie, MSG_TERMINATED)); 1032 // checks 2 1033 cookie = 0; 1034 CHK(context.CheckNextMessage(caller2, team2, cookie, MSG_STARTED)); 1035 CHK(context.CheckMainArgsMessage(caller2, team2, cookie, &ref2)); 1036 CHK(context.CheckMessageMessages(caller2, team2, cookie)); 1037 CHK(context.CheckArgvMessage(caller2, team2, cookie, &ref2)); 1038 if (caller.SupportsRefs() && !caller.SupportsArgv()) 1039 CHK(context.CheckRefsMessage(caller2, team2, cookie)); 1040 CHK(context.CheckNextMessage(caller2, team2, cookie, MSG_READY_TO_RUN)); 1041 CHK(context.CheckNextMessage(caller2, team2, cookie, MSG_QUIT_REQUESTED)); 1042 CHK(context.CheckNextMessage(caller2, team2, cookie, MSG_TERMINATED)); 1043 } 1044 1045 /* 1046 @case 22 launch the app two times: B_EXCLUSIVE_LAUNCH | B_ARGV_ONLY 1047 @results first app: ArgvReceived(), ReadyToRun(), QuitRequested() 1048 (No second ArgvReceived()!) 1049 second app: Launch() fails with B_ALREADY_RUNNING 1050 */ 1051 static 1052 void 1053 CommonLaunchTest22(LaunchCaller &caller) 1054 { 1055 LaunchCaller &caller2 = caller.Clone(); 1056 LaunchContext context; 1057 BRoster roster; 1058 create_app(appFile1, appType1, false, true, 1059 B_EXCLUSIVE_LAUNCH | B_ARGV_ONLY); 1060 install_type(fileType1, appType1); 1061 // launch app 1 1062 team_id team1; 1063 CHK(context(caller, fileType1, &team1) == B_OK); 1064 entry_ref ref1 = ref_for_team(team1); 1065 CHK(ref_for_path(appFile1) == ref1); 1066 check_app_type(appType1, appFile1); 1067 context.WaitForMessage(team1, MSG_STARTED); 1068 // launch app 2 1069 team_id team2; 1070 CHK(context(caller2, fileType1, &team2) == B_ALREADY_RUNNING); 1071 // checks 1 1072 context.Terminate(); 1073 int32 cookie = 0; 1074 CHK(context.CheckNextMessage(caller, team1, cookie, MSG_STARTED)); 1075 CHK(context.CheckMainArgsMessage(caller, team1, cookie, &ref1)); 1076 // CHK(context.CheckMessageMessages(caller, team1, cookie)); 1077 CHK(context.CheckArgvMessage(caller, team1, cookie, &ref1)); 1078 // if (caller.SupportsRefs() && !caller.SupportsArgv()) 1079 // CHK(context.CheckRefsMessage(caller, team1, cookie)); 1080 CHK(context.CheckNextMessage(caller, team1, cookie, MSG_READY_TO_RUN)); 1081 CHK(context.CheckNextMessage(caller, team1, cookie, MSG_QUIT_REQUESTED)); 1082 CHK(context.CheckNextMessage(caller, team1, cookie, MSG_TERMINATED)); 1083 } 1084 1085 /* 1086 @case 23 launch the app two times: B_EXCLUSIVE_LAUNCH 1087 @results first app: {Message,Argv,Refs}Received()*, ReadyToRun(), 1088 {Message,Argv,Refs}Received()*, QuitRequested() 1089 second app: Launch() fails with B_ALREADY_RUNNING 1090 */ 1091 static 1092 void 1093 CommonLaunchTest23(LaunchCaller &caller) 1094 { 1095 LaunchCaller &caller2 = caller.Clone(); 1096 LaunchContext context; 1097 BRoster roster; 1098 create_app(appFile1, appType1, false, true, 1099 B_EXCLUSIVE_LAUNCH); 1100 install_type(fileType1, appType1); 1101 // launch app 1 1102 team_id team1; 1103 CHK(context(caller, fileType1, &team1) == B_OK); 1104 entry_ref ref1 = ref_for_team(team1); 1105 CHK(ref_for_path(appFile1) == ref1); 1106 check_app_type(appType1, appFile1); 1107 context.WaitForMessage(team1, MSG_STARTED); 1108 // launch app 2 1109 team_id team2; 1110 CHK(context(caller2, fileType1, &team2) == B_ALREADY_RUNNING); 1111 // checks 1 1112 context.Terminate(); 1113 int32 cookie = 0; 1114 CHK(context.CheckNextMessage(caller, team1, cookie, MSG_STARTED)); 1115 CHK(context.CheckMainArgsMessage(caller, team1, cookie, &ref1)); 1116 CHK(context.CheckMessageMessages(caller, team1, cookie)); 1117 CHK(context.CheckArgvMessage(caller, team1, cookie, &ref1)); 1118 if (caller.SupportsRefs() && !caller.SupportsArgv()) 1119 CHK(context.CheckRefsMessage(caller, team1, cookie)); 1120 CHK(context.CheckNextMessage(caller, team1, cookie, MSG_READY_TO_RUN)); 1121 CHK(context.CheckMessageMessages(caller, team1, cookie)); 1122 CHK(context.CheckArgvMessage(caller, team1, cookie, &ref1)); 1123 if (caller.SupportsRefs() && !caller.SupportsArgv()) 1124 CHK(context.CheckRefsMessage(caller, team1, cookie)); 1125 CHK(context.CheckNextMessage(caller, team1, cookie, MSG_QUIT_REQUESTED)); 1126 CHK(context.CheckNextMessage(caller, team1, cookie, MSG_TERMINATED)); 1127 } 1128 1129 /* 1130 @case 24 launch two apps with the same signature: 1131 B_EXCLUSIVE_LAUNCH | B_ARGV_ONLY 1132 @results first app: ArgvReceived(), ReadyToRun(), QuitRequested() 1133 (No second ArgvReceived()!) 1134 second app: Launch() fails with B_ALREADY_RUNNING 1135 */ 1136 static 1137 void 1138 CommonLaunchTest24(LaunchCaller &caller) 1139 { 1140 LaunchCaller &caller2 = caller.Clone(); 1141 LaunchContext context; 1142 BRoster roster; 1143 // launch app 1 1144 create_app(appFile1, appType1, false, true, 1145 B_EXCLUSIVE_LAUNCH | B_ARGV_ONLY); 1146 install_type(fileType1, appType1); 1147 team_id team1; 1148 CHK(context(caller, fileType1, &team1) == B_OK); 1149 entry_ref ref1 = ref_for_team(team1); 1150 CHK(ref_for_path(appFile1) == ref1); 1151 check_app_type(appType1, appFile1); 1152 context.WaitForMessage(team1, MSG_STARTED); 1153 // launch app 2 (greater modification time) 1154 CHK(BMimeType(appType1).Delete() == B_OK); 1155 create_app(appFile2, appType1, false, true, 1156 B_EXCLUSIVE_LAUNCH | B_ARGV_ONLY); 1157 set_file_time(appFile2, time(NULL) + 1); 1158 team_id team2; 1159 CHK(context(caller2, fileType1, &team2) == B_ALREADY_RUNNING); 1160 // checks 1 1161 context.Terminate(); 1162 int32 cookie = 0; 1163 CHK(context.CheckNextMessage(caller, team1, cookie, MSG_STARTED)); 1164 CHK(context.CheckMainArgsMessage(caller, team1, cookie, &ref1)); 1165 // CHK(context.CheckMessageMessages(caller, team1, cookie)); 1166 CHK(context.CheckArgvMessage(caller, team1, cookie, &ref1)); 1167 // if (caller.SupportsRefs() && !caller.SupportsArgv()) 1168 // CHK(context.CheckRefsMessage(caller, team1, cookie)); 1169 CHK(context.CheckNextMessage(caller, team1, cookie, MSG_READY_TO_RUN)); 1170 CHK(context.CheckNextMessage(caller, team1, cookie, MSG_QUIT_REQUESTED)); 1171 CHK(context.CheckNextMessage(caller, team1, cookie, MSG_TERMINATED)); 1172 } 1173 1174 /* 1175 @case 25 launch two apps with the same signature: 1176 B_EXCLUSIVE_LAUNCH 1177 @results first app: {Message,Argv,Refs}Received()*, ReadyToRun(), 1178 {Message,Argv,Refs}Received()*, QuitRequested() 1179 second app: Launch() fails with B_ALREADY_RUNNING 1180 */ 1181 static 1182 void 1183 CommonLaunchTest25(LaunchCaller &caller) 1184 { 1185 LaunchCaller &caller2 = caller.Clone(); 1186 LaunchContext context; 1187 BRoster roster; 1188 // launch app 1 1189 create_app(appFile1, appType1, false, true, 1190 B_EXCLUSIVE_LAUNCH); 1191 install_type(fileType1, appType1); 1192 team_id team1; 1193 CHK(context(caller, fileType1, &team1) == B_OK); 1194 entry_ref ref1 = ref_for_team(team1); 1195 CHK(ref_for_path(appFile1) == ref1); 1196 check_app_type(appType1, appFile1); 1197 context.WaitForMessage(team1, MSG_STARTED); 1198 // launch app 2 (greater modification time) 1199 CHK(BMimeType(appType1).Delete() == B_OK); 1200 create_app(appFile2, appType1, false, true, 1201 B_EXCLUSIVE_LAUNCH); 1202 set_file_time(appFile2, time(NULL) + 1); 1203 team_id team2; 1204 CHK(context(caller2, fileType1, &team2) == B_ALREADY_RUNNING); 1205 entry_ref ref2 = ref_for_path(appFile2); 1206 // checks 1 1207 context.Terminate(); 1208 int32 cookie = 0; 1209 CHK(context.CheckNextMessage(caller, team1, cookie, MSG_STARTED)); 1210 CHK(context.CheckMainArgsMessage(caller, team1, cookie, &ref1)); 1211 CHK(context.CheckMessageMessages(caller, team1, cookie)); 1212 CHK(context.CheckArgvMessage(caller, team1, cookie, &ref1)); 1213 if (caller.SupportsRefs() && !caller.SupportsArgv()) 1214 CHK(context.CheckRefsMessage(caller, team1, cookie)); 1215 CHK(context.CheckNextMessage(caller, team1, cookie, MSG_READY_TO_RUN)); 1216 CHK(context.CheckMessageMessages(caller, team1, cookie)); 1217 CHK(context.CheckArgvMessage(caller, team1, cookie, &ref2)); 1218 if (caller.SupportsRefs() && !caller.SupportsArgv()) 1219 CHK(context.CheckRefsMessage(caller, team1, cookie)); 1220 CHK(context.CheckNextMessage(caller, team1, cookie, MSG_QUIT_REQUESTED)); 1221 CHK(context.CheckNextMessage(caller, team1, cookie, MSG_TERMINATED)); 1222 } 1223 1224 /* 1225 @case 26 launch two apps with the same signature: 1226 first: B_EXCLUSIVE_LAUNCH, 1227 second: B_EXCLUSIVE_LAUNCH | B_ARGV_ONLY => 1228 @results first app: {Message,Argv,Refs}Received()*, ReadyToRun(), 1229 QuitRequested() 1230 second app: Launch() fails with B_ALREADY_RUNNING 1231 */ 1232 static 1233 void 1234 CommonLaunchTest26(LaunchCaller &caller) 1235 { 1236 LaunchCaller &caller2 = caller.Clone(); 1237 LaunchContext context; 1238 BRoster roster; 1239 // launch app 1 1240 create_app(appFile1, appType1, false, true, 1241 B_EXCLUSIVE_LAUNCH); 1242 install_type(fileType1, appType1); 1243 team_id team1; 1244 CHK(context(caller, fileType1, &team1) == B_OK); 1245 entry_ref ref1 = ref_for_team(team1); 1246 CHK(ref_for_path(appFile1) == ref1); 1247 check_app_type(appType1, appFile1); 1248 context.WaitForMessage(team1, MSG_STARTED); 1249 // launch app 2 (greater modification time) 1250 CHK(BMimeType(appType1).Delete() == B_OK); 1251 create_app(appFile2, appType1, false, true, 1252 B_EXCLUSIVE_LAUNCH | B_ARGV_ONLY); 1253 set_file_time(appFile2, time(NULL) + 1); 1254 team_id team2; 1255 CHK(context(caller2, fileType1, &team2) == B_ALREADY_RUNNING); 1256 entry_ref ref2 = ref_for_path(appFile2); 1257 // checks 1 1258 context.Terminate(); 1259 int32 cookie = 0; 1260 CHK(context.CheckNextMessage(caller, team1, cookie, MSG_STARTED)); 1261 CHK(context.CheckMainArgsMessage(caller, team1, cookie, &ref1)); 1262 CHK(context.CheckMessageMessages(caller, team1, cookie)); 1263 CHK(context.CheckArgvMessage(caller, team1, cookie, &ref1)); 1264 if (caller.SupportsRefs() && !caller.SupportsArgv()) 1265 CHK(context.CheckRefsMessage(caller, team1, cookie)); 1266 CHK(context.CheckNextMessage(caller, team1, cookie, MSG_READY_TO_RUN)); 1267 CHK(context.CheckNextMessage(caller, team1, cookie, MSG_QUIT_REQUESTED)); 1268 CHK(context.CheckNextMessage(caller, team1, cookie, MSG_TERMINATED)); 1269 } 1270 1271 /* 1272 @case 27 launch two apps with the same signature: 1273 first: B_EXCLUSIVE_LAUNCH | B_ARGV_ONLY, 1274 second: B_EXCLUSIVE_LAUNCH 1275 @results first app: ArgvReceived(), ReadyToRun(), QuitRequested() 1276 (No second ArgvReceived()!) 1277 second app: Launch() fails with B_ALREADY_RUNNING 1278 */ 1279 static 1280 void 1281 CommonLaunchTest27(LaunchCaller &caller) 1282 { 1283 LaunchCaller &caller2 = caller.Clone(); 1284 LaunchContext context; 1285 BRoster roster; 1286 // launch app 1 1287 create_app(appFile1, appType1, false, true, 1288 B_EXCLUSIVE_LAUNCH | B_ARGV_ONLY); 1289 install_type(fileType1, appType1); 1290 team_id team1; 1291 CHK(context(caller, fileType1, &team1) == B_OK); 1292 entry_ref ref1 = ref_for_team(team1); 1293 CHK(ref_for_path(appFile1) == ref1); 1294 check_app_type(appType1, appFile1); 1295 context.WaitForMessage(team1, MSG_STARTED); 1296 // launch app 2 (greater modification time) 1297 CHK(BMimeType(appType1).Delete() == B_OK); 1298 create_app(appFile2, appType1, false, true, 1299 B_EXCLUSIVE_LAUNCH); 1300 set_file_time(appFile2, time(NULL) + 1); 1301 team_id team2; 1302 CHK(context(caller2, fileType1, &team2) == B_ALREADY_RUNNING); 1303 // checks 1 1304 context.Terminate(); 1305 int32 cookie = 0; 1306 CHK(context.CheckNextMessage(caller, team1, cookie, MSG_STARTED)); 1307 CHK(context.CheckMainArgsMessage(caller, team1, cookie, &ref1)); 1308 // CHK(context.CheckMessageMessages(caller, team1, cookie)); 1309 CHK(context.CheckArgvMessage(caller, team1, cookie, &ref1)); 1310 // if (caller.SupportsRefs() && !caller.SupportsArgv()) 1311 // CHK(context.CheckRefsMessage(caller, team1, cookie)); 1312 CHK(context.CheckNextMessage(caller, team1, cookie, MSG_READY_TO_RUN)); 1313 CHK(context.CheckNextMessage(caller, team1, cookie, MSG_QUIT_REQUESTED)); 1314 CHK(context.CheckNextMessage(caller, team1, cookie, MSG_TERMINATED)); 1315 } 1316 1317 /* 1318 @case 28 installed type mimeType, preferred app, app type installed, 1319 preferred app type has an app hint pointing to void, 1320 no app with this signature exists 1321 @results Should return B_LAUNCH_FAILED_APP_NOT_FOUND and unset the 1322 app type's app hint. 1323 */ 1324 static 1325 void 1326 CommonLaunchTest28(LaunchCaller &caller) 1327 { 1328 LaunchContext context; 1329 BRoster roster; 1330 set_type_app_hint(appType1, appFile1); 1331 install_type(fileType1, appType1); 1332 team_id team; 1333 CHK(context(caller, fileType1, &team) == B_LAUNCH_FAILED_APP_NOT_FOUND); 1334 entry_ref appHint; 1335 CHK(BMimeType(appType1).GetAppHint(&appHint) == B_ENTRY_NOT_FOUND); 1336 } 1337 1338 /* 1339 @case 29 installed type mimeType, preferred app, app type installed, 1340 preferred app type has an app hint pointing to a cyclic 1341 link, no app with this signature exists 1342 @results Should return 1343 OBOS: B_LAUNCH_FAILED_APP_NOT_FOUND and unset the app 1344 type's app hint. 1345 R5: B_ENTRY_NOT_FOUND or B_LAUNCH_FAILED_NO_RESOLVE_LINK. 1346 */ 1347 static 1348 void 1349 CommonLaunchTest29(LaunchCaller &caller) 1350 { 1351 LaunchContext context; 1352 BRoster roster; 1353 set_type_app_hint(appType1, appFile1); 1354 install_type(fileType1, appType1); 1355 system((string("ln -s ") + appFile1 + " " + appFile1).c_str()); 1356 team_id team; 1357 entry_ref appHint; 1358 #if TEST_R5 1359 if (caller.SupportsRefs()) { 1360 CHK(context(caller, fileType1, &team) 1361 == B_LAUNCH_FAILED_NO_RESOLVE_LINK); 1362 } else 1363 CHK(context(caller, fileType1, &team) == B_ENTRY_NOT_FOUND); 1364 CHK(BMimeType(appType1).GetAppHint(&appHint) == B_OK); 1365 CHK(appHint == ref_for_path(appFile1, false)); 1366 #else 1367 CHK(context(caller, fileType1, &team) == B_LAUNCH_FAILED_APP_NOT_FOUND); 1368 CHK(BMimeType(appType1).GetAppHint(&appHint) == B_ENTRY_NOT_FOUND); 1369 #endif 1370 } 1371 1372 /* 1373 @case 30 installed type mimeType, preferred app, app type installed, 1374 preferred app type has an app hint that points to an app 1375 without a signature, app will pass a different signature 1376 to the BApplication constructor 1377 @results Should return B_OK and set team to the ID of the team 1378 running the application's executable. Should remove the 1379 incorrect app hint on the app type. 1380 BRoster::GetRunningAppInfo() should return an app_info 1381 with the signature passed to the BApplication constructor. 1382 */ 1383 static 1384 void 1385 CommonLaunchTest30(LaunchCaller &caller) 1386 { 1387 LaunchContext context; 1388 BRoster roster; 1389 create_app(appFile1, NULL); 1390 set_type_app_hint(appType1, appFile1); 1391 entry_ref appHint; 1392 CHK(BMimeType(appType1).GetAppHint(&appHint) == B_OK); 1393 install_type(fileType1, appType1); 1394 team_id team; 1395 CHK(context(caller, fileType1, &team) == B_OK); 1396 entry_ref ref = ref_for_team(team); 1397 CHK(ref_for_path(appFile1) == ref); 1398 // OBOS: We unset the app hint for the app type. R5 leaves it untouched. 1399 #ifdef TEST_R5 1400 check_app_type(appType1, appFile1); 1401 #else 1402 CHK(BMimeType(appType1).GetAppHint(&appHint) == B_ENTRY_NOT_FOUND); 1403 #endif 1404 context.WaitForMessage(team, MSG_STARTED, true); 1405 app_info appInfo; 1406 CHK(roster.GetRunningAppInfo(team, &appInfo) == B_OK); 1407 // R5 keeps appType1, OBOS updates the signature 1408 #ifdef TEST_R5 1409 CHK(!strcmp(appInfo.signature, appType1)); 1410 #else 1411 CHK(!strcmp(appInfo.signature, kDefaultTestAppSignature)); 1412 #endif 1413 context.Terminate(); 1414 int32 cookie = 0; 1415 CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); 1416 CHK(context.CheckMainArgsMessage(caller, team, cookie, &ref)); 1417 CHK(context.CheckMessageMessages(caller, team, cookie)); 1418 CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); 1419 if (caller.SupportsRefs() && !caller.SupportsArgv()) 1420 CHK(context.CheckRefsMessage(caller, team, cookie)); 1421 CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); 1422 CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); 1423 CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); 1424 } 1425 1426 typedef void commonTestFunction(LaunchCaller &caller); 1427 static commonTestFunction *commonTestFunctions[] = { 1428 CommonLaunchTest1, CommonLaunchTest2, CommonLaunchTest3, 1429 CommonLaunchTest4, CommonLaunchTest5, CommonLaunchTest6, 1430 CommonLaunchTest7, CommonLaunchTest8, CommonLaunchTest9, 1431 CommonLaunchTest10, CommonLaunchTest11, CommonLaunchTest12, 1432 CommonLaunchTest13, CommonLaunchTest14, CommonLaunchTest15, 1433 CommonLaunchTest16, CommonLaunchTest17, CommonLaunchTest18, 1434 CommonLaunchTest19, CommonLaunchTest20, CommonLaunchTest21, 1435 CommonLaunchTest22, CommonLaunchTest23, CommonLaunchTest24, 1436 CommonLaunchTest25, CommonLaunchTest26, CommonLaunchTest27, 1437 CommonLaunchTest28, CommonLaunchTest29, CommonLaunchTest30 1438 }; 1439 static int32 commonTestFunctionCount 1440 = sizeof(commonTestFunctions) / sizeof(commonTestFunction*); 1441 1442 /* 1443 status_t Launch(const char *mimeType, BMessage *initialMsgs, 1444 team_id *appTeam) const 1445 @case 1 mimeType is NULL 1446 @results Should return B_BAD_VALUE. 1447 */ 1448 void LaunchTester::LaunchTestA1() 1449 { 1450 BRoster roster; 1451 BMessage message; 1452 CHK(roster.Launch((const char*)NULL, &message, NULL) == B_BAD_VALUE); 1453 } 1454 1455 /* 1456 status_t Launch(const char *mimeType, BMessage *initialMsgs, 1457 team_id *appTeam) const 1458 @case 2 mimeType is invalid 1459 @results Should return B_BAD_VALUE. 1460 */ 1461 void LaunchTester::LaunchTestA2() 1462 { 1463 BRoster roster; 1464 BMessage message; 1465 CHK(roster.Launch("invalid/mine/type", &message, NULL) == B_BAD_VALUE); 1466 } 1467 1468 // LaunchTypeCaller1 1469 class LaunchTypeCaller1 : public LaunchCaller { 1470 public: 1471 virtual status_t operator()(const char *type, BList *messages, int32 argc, 1472 const char **argv, team_id *team) 1473 { 1474 BMessage *message = (messages ? (BMessage*)messages->ItemAt(0L) 1475 : NULL); 1476 BRoster roster; 1477 return roster.Launch(type, message, team); 1478 } 1479 1480 virtual LaunchCaller *CloneInternal() 1481 { 1482 return new LaunchTypeCaller1; 1483 } 1484 }; 1485 1486 /* 1487 status_t Launch(const char *mimeType, BMessage *initialMsgs, 1488 team_id *appTeam) const 1489 @case 3 common cases 1-14 1490 */ 1491 void LaunchTester::LaunchTestA3() 1492 { 1493 LaunchTypeCaller1 caller; 1494 for (int32 i = 0; i < commonTestFunctionCount; i++) { 1495 NextSubTest(); 1496 (*commonTestFunctions[i])(caller); 1497 tearDown(); 1498 setUp(); 1499 } 1500 } 1501 1502 /* 1503 status_t Launch(const char *mimeType, BMessage *initialMsgs, 1504 team_id *appTeam) const 1505 @case 4 installed type mimeType, preferred app, app type not 1506 installed, app has signature, NULL initialMsg 1507 @results Should return B_OK and set team to the ID of the team 1508 running the application's executable. Should install the 1509 app type and set the app hint on it. 1510 */ 1511 void LaunchTester::LaunchTestA4() 1512 { 1513 LaunchTypeCaller1 caller; 1514 LaunchContext context; 1515 BRoster roster; 1516 create_app(appFile1, appType1); 1517 install_type(fileType1, appType1); 1518 team_id team; 1519 CHK(context(caller, fileType1, NULL, LaunchContext::kStandardArgc, 1520 LaunchContext::kStandardArgv, &team) == B_OK); 1521 entry_ref ref = ref_for_team(team); 1522 CHK(ref_for_path(appFile1) == ref); 1523 check_app_type(appType1, appFile1); 1524 context.Terminate(); 1525 int32 cookie = 0; 1526 CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); 1527 CHK(context.CheckMainArgsMessage(caller, team, cookie, &ref)); 1528 // CHK(context.CheckMessageMessages(caller, team, cookie)); 1529 // CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); 1530 // CHK(context.CheckRefsMessage(caller, team, cookie)); 1531 CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); 1532 CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); 1533 CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); 1534 } 1535 1536 /* 1537 status_t Launch(const char *mimeType, BList *messageList, 1538 team_id *appTeam) const 1539 @case 1 mimeType is NULL 1540 @results Should return B_BAD_VALUE. 1541 */ 1542 void LaunchTester::LaunchTestB1() 1543 { 1544 BRoster roster; 1545 BList list; 1546 CHK(roster.Launch((const char*)NULL, &list, NULL) == B_BAD_VALUE); 1547 } 1548 1549 /* 1550 status_t Launch(const char *mimeType, BMessage *initialMsgs, 1551 team_id *appTeam) const 1552 @case 2 mimeType is invalid 1553 @results Should return B_BAD_VALUE. 1554 */ 1555 void LaunchTester::LaunchTestB2() 1556 { 1557 BRoster roster; 1558 BList list; 1559 CHK(roster.Launch("invalid/mine/type", &list, NULL) == B_BAD_VALUE); 1560 } 1561 1562 // LaunchTypeCaller2 1563 class LaunchTypeCaller2 : public LaunchCaller { 1564 public: 1565 virtual status_t operator()(const char *type, BList *messages, int32 argc, 1566 const char **argv, team_id *team) 1567 { 1568 BRoster roster; 1569 return roster.Launch(type, messages, team); 1570 } 1571 virtual int32 SupportsMessages() const { return 1000; } 1572 1573 virtual LaunchCaller *CloneInternal() 1574 { 1575 return new LaunchTypeCaller2; 1576 } 1577 }; 1578 1579 /* 1580 status_t Launch(const char *mimeType, BList *messageList, 1581 team_id *appTeam) const 1582 @case 3 common cases 1-14 1583 */ 1584 void LaunchTester::LaunchTestB3() 1585 { 1586 LaunchTypeCaller2 caller; 1587 for (int32 i = 0; i < commonTestFunctionCount; i++) { 1588 NextSubTest(); 1589 (*commonTestFunctions[i])(caller); 1590 tearDown(); 1591 setUp(); 1592 } 1593 } 1594 1595 /* 1596 status_t Launch(const char *mimeType, BList *messageList, 1597 team_id *appTeam) const 1598 @case 4 installed type mimeType, preferred app, app type not 1599 installed, app has signature, NULL messageList 1600 @results Should return B_OK and set team to the ID of the team 1601 running the application's executable. Should install the 1602 app type and set the app hint on it. 1603 */ 1604 void LaunchTester::LaunchTestB4() 1605 { 1606 LaunchTypeCaller2 caller; 1607 LaunchContext context; 1608 BRoster roster; 1609 create_app(appFile1, appType1); 1610 install_type(fileType1, appType1); 1611 team_id team; 1612 CHK(context(caller, fileType1, NULL, LaunchContext::kStandardArgc, 1613 LaunchContext::kStandardArgv, &team) == B_OK); 1614 entry_ref ref = ref_for_team(team); 1615 CHK(ref_for_path(appFile1) == ref); 1616 check_app_type(appType1, appFile1); 1617 context.Terminate(); 1618 int32 cookie = 0; 1619 CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); 1620 CHK(context.CheckMainArgsMessage(caller, team, cookie, &ref)); 1621 // CHK(context.CheckMessageMessages(caller, team, cookie)); 1622 // CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); 1623 // CHK(context.CheckRefsMessage(caller, team, cookie)); 1624 CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); 1625 CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); 1626 CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); 1627 } 1628 1629 /* 1630 status_t Launch(const char *mimeType, BList *messageList, 1631 team_id *appTeam) const 1632 @case 5 installed type mimeType, preferred app, app type not 1633 installed, app has signature, empty messageList 1634 @results Should return B_OK and set team to the ID of the team 1635 running the application's executable. Should install the 1636 app type and set the app hint on it. 1637 */ 1638 void LaunchTester::LaunchTestB5() 1639 { 1640 LaunchTypeCaller2 caller; 1641 LaunchContext context; 1642 BRoster roster; 1643 create_app(appFile1, appType1); 1644 install_type(fileType1, appType1); 1645 team_id team; 1646 BList list; 1647 CHK(context(caller, fileType1, &list, LaunchContext::kStandardArgc, 1648 LaunchContext::kStandardArgv, &team) == B_OK); 1649 entry_ref ref = ref_for_team(team); 1650 CHK(ref_for_path(appFile1) == ref); 1651 check_app_type(appType1, appFile1); 1652 context.Terminate(); 1653 int32 cookie = 0; 1654 CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); 1655 CHK(context.CheckMainArgsMessage(caller, team, cookie, &ref)); 1656 // CHK(context.CheckMessageMessages(caller, team, cookie)); 1657 // CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); 1658 // CHK(context.CheckRefsMessage(caller, team, cookie)); 1659 CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); 1660 CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); 1661 CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); 1662 } 1663 1664 /* 1665 status_t Launch(const char *mimeType, int argc, char **args, 1666 team_id *appTeam) const 1667 @case 1 mimeType is NULL or argc > 0 and args is NULL 1668 @results Should return B_BAD_VALUE. 1669 */ 1670 void LaunchTester::LaunchTestC1() 1671 { 1672 BRoster roster; 1673 char *argv[] = { "Hey!" }; 1674 CHK(roster.Launch((const char*)NULL, 1, argv, NULL) == B_BAD_VALUE); 1675 CHK(roster.Launch((const char*)NULL, 1, (char**)NULL, NULL) 1676 == B_BAD_VALUE); 1677 } 1678 1679 /* 1680 status_t Launch(const char *mimeType, int argc, char **args, 1681 team_id *appTeam) const 1682 @case 2 mimeType is invalid 1683 @results Should return B_BAD_VALUE. 1684 */ 1685 void LaunchTester::LaunchTestC2() 1686 { 1687 BRoster roster; 1688 BList list; 1689 char *argv[] = { "Hey!" }; 1690 CHK(roster.Launch("invalid/mine/type", 1, argv, NULL) == B_BAD_VALUE); 1691 } 1692 1693 // LaunchTypeCaller3 1694 class LaunchTypeCaller3 : public LaunchCaller { 1695 public: 1696 virtual status_t operator()(const char *type, BList *messages, int32 argc, 1697 const char **argv, team_id *team) 1698 { 1699 BRoster roster; 1700 return roster.Launch(type, argc, const_cast<char**>(argv), team); 1701 } 1702 virtual int32 SupportsMessages() const { return 0; } 1703 1704 virtual LaunchCaller *CloneInternal() 1705 { 1706 return new LaunchTypeCaller3; 1707 } 1708 }; 1709 1710 /* 1711 status_t Launch(const char *mimeType, int argc, char **args, 1712 team_id *appTeam) const 1713 @case 3 common cases 1-14 1714 */ 1715 void LaunchTester::LaunchTestC3() 1716 { 1717 LaunchTypeCaller3 caller; 1718 for (int32 i = 0; i < commonTestFunctionCount; i++) { 1719 NextSubTest(); 1720 (*commonTestFunctions[i])(caller); 1721 tearDown(); 1722 setUp(); 1723 } 1724 } 1725 1726 /* 1727 status_t Launch(const char *mimeType, int argc, char **args, 1728 team_id *appTeam) const 1729 @case 4 installed type mimeType, preferred app, app type not 1730 installed, app has signature, NULL args, argc is 0 1731 @results Should return B_OK and set team to the ID of the team 1732 running the application's executable. Should install the 1733 app type and set the app hint on it. 1734 */ 1735 void LaunchTester::LaunchTestC4() 1736 { 1737 LaunchTypeCaller3 caller; 1738 LaunchContext context; 1739 BRoster roster; 1740 create_app(appFile1, appType1); 1741 install_type(fileType1, appType1); 1742 team_id team; 1743 CHK(context(caller, fileType1, NULL, 0, (const char**)NULL, &team) == B_OK); 1744 entry_ref ref = ref_for_team(team); 1745 CHK(ref_for_path(appFile1) == ref); 1746 check_app_type(appType1, appFile1); 1747 context.Terminate(); 1748 int32 cookie = 0; 1749 CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); 1750 CHK(context.CheckMainArgsMessage(caller, team, cookie, &ref, 0, NULL)); 1751 // CHK(context.CheckMessageMessages(caller, team, cookie)); 1752 // CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); 1753 // CHK(context.CheckRefsMessage(caller, team, cookie)); 1754 CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); 1755 CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); 1756 CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); 1757 } 1758 1759 // SimpleFileCaller1 1760 class SimpleFileCaller1 : public LaunchCaller { 1761 public: 1762 SimpleFileCaller1() : fRef() {} 1763 SimpleFileCaller1(const entry_ref &ref) : fRef(ref) {} 1764 virtual ~SimpleFileCaller1() {} 1765 virtual status_t operator()(const char *type, BList *messages, int32 argc, 1766 const char **argv, team_id *team) 1767 { 1768 BRoster roster; 1769 BMessage *message = (messages ? (BMessage*)messages->ItemAt(0L) 1770 : NULL); 1771 return roster.Launch(&fRef, message, team); 1772 } 1773 virtual bool SupportsRefs() const { return true; } 1774 virtual const entry_ref *Ref() const { return &fRef; } 1775 1776 virtual LaunchCaller *CloneInternal() 1777 { 1778 return new SimpleFileCaller1; 1779 } 1780 1781 protected: 1782 entry_ref fRef; 1783 }; 1784 1785 // FileWithTypeCaller1 1786 class FileWithTypeCaller1 : public SimpleFileCaller1 { 1787 public: 1788 virtual status_t operator()(const char *type, BList *messages, int32 argc, 1789 const char **argv, team_id *team) 1790 { 1791 BRoster roster; 1792 BMessage *message = (messages ? (BMessage*)messages->ItemAt(0L) 1793 : NULL); 1794 fRef = create_file(testFile1, type); 1795 return roster.Launch(&fRef, message, team); 1796 } 1797 1798 virtual LaunchCaller *CloneInternal() 1799 { 1800 return new FileWithTypeCaller1; 1801 } 1802 }; 1803 1804 // SniffFileTypeCaller1 1805 class SniffFileTypeCaller1 : public SimpleFileCaller1 { 1806 public: 1807 virtual status_t operator()(const char *type, BList *messages, int32 argc, 1808 const char **argv, team_id *team) 1809 { 1810 BRoster roster; 1811 BMessage *message = (messages ? (BMessage*)messages->ItemAt(0L) 1812 : NULL); 1813 fRef = create_file(testFile1, type, NULL, NULL, "UnIQe pAtTeRn"); 1814 install_type(fileType1, NULL, "1.0 [0] ('UnIQe pAtTeRn')"); 1815 return roster.Launch(&fRef, message, team); 1816 } 1817 1818 virtual LaunchCaller *CloneInternal() 1819 { 1820 return new SniffFileTypeCaller1; 1821 } 1822 }; 1823 1824 /* 1825 status_t Launch(const entry_ref *ref, const BMessage *initialMessage, 1826 team_id *app_team) const 1827 @case 1 ref is NULL 1828 @results Should return B_BAD_VALUE. 1829 */ 1830 void LaunchTester::LaunchTestD1() 1831 { 1832 BRoster roster; 1833 BMessage message; 1834 CHK(roster.Launch((const entry_ref*)NULL, &message, NULL) == B_BAD_VALUE); 1835 } 1836 1837 /* 1838 status_t Launch(const entry_ref *ref, const BMessage *initialMessage, 1839 team_id *app_team) const 1840 @case 2 ref doesn't refer to an existing entry 1841 @results Should return B_ENTRY_NOT_FOUND. 1842 */ 1843 void LaunchTester::LaunchTestD2() 1844 { 1845 BRoster roster; 1846 BMessage message; 1847 entry_ref fileRef(ref_for_path(testFile1)); 1848 CHK(roster.Launch(&fileRef, &message, NULL) == B_ENTRY_NOT_FOUND); 1849 } 1850 1851 /* 1852 status_t Launch(const entry_ref *ref, const BMessage *initialMessage, 1853 team_id *app_team) const 1854 @case 3 ref is valid, file has type and preferred app, app type is 1855 not installed, app exists and has signature 1856 @results Should return B_OK and set team to the ID of the team 1857 running the file's (not the file type's) preferred 1858 application's executable. 1859 Should install the app type and set the app hint on it. 1860 */ 1861 void LaunchTester::LaunchTestD3() 1862 { 1863 BRoster roster; 1864 create_app(appFile1, appType1); 1865 create_app(appFile2, appType2); 1866 install_type(fileType1, appType1); 1867 entry_ref fileRef(create_file(testFile1, fileType1, appType2)); 1868 SimpleFileCaller1 caller(fileRef); 1869 LaunchContext context; 1870 team_id team; 1871 CHK(context(caller, fileType1, context.StandardMessages(), 1872 LaunchContext::kStandardArgc, LaunchContext::kStandardArgv, 1873 &team) == B_OK); 1874 entry_ref ref = ref_for_team(team); 1875 CHK(ref_for_path(appFile2) == ref); 1876 check_app_type(appType2, appFile2); 1877 1878 context.Terminate(); 1879 int32 cookie = 0; 1880 CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); 1881 CHK(context.CheckMainArgsMessage(caller, team, cookie, &ref)); 1882 CHK(context.CheckMessageMessages(caller, team, cookie)); 1883 // CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); 1884 CHK(context.CheckRefsMessage(caller, team, cookie)); 1885 CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); 1886 CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); 1887 CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); 1888 } 1889 1890 /* 1891 status_t Launch(const entry_ref *ref, const BMessage *initialMessage, 1892 team_id *app_team) const 1893 @case 4 ref is valid, file has no type, but preferred app, 1894 app type is not installed, app exists and has signature 1895 @results Should return B_OK and set team to the ID of the team 1896 running the application's executable. Should install the 1897 app type and set the app hint on it. 1898 */ 1899 void LaunchTester::LaunchTestD4() 1900 { 1901 BRoster roster; 1902 create_app(appFile1, appType1); 1903 entry_ref fileRef(create_file(testFile1, NULL, appType1)); 1904 SimpleFileCaller1 caller(fileRef); 1905 LaunchContext context; 1906 team_id team; 1907 CHK(context(caller, fileType1, context.StandardMessages(), 1908 LaunchContext::kStandardArgc, LaunchContext::kStandardArgv, 1909 &team) == B_OK); 1910 entry_ref ref = ref_for_team(team); 1911 CHK(ref_for_path(appFile1) == ref); 1912 check_app_type(appType1, appFile1); 1913 1914 context.Terminate(); 1915 int32 cookie = 0; 1916 CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); 1917 CHK(context.CheckMainArgsMessage(caller, team, cookie, &ref)); 1918 CHK(context.CheckMessageMessages(caller, team, cookie)); 1919 // CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); 1920 CHK(context.CheckRefsMessage(caller, team, cookie)); 1921 CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); 1922 CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); 1923 CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); 1924 } 1925 1926 /* 1927 status_t Launch(const entry_ref *ref, const BMessage *initialMessage, 1928 team_id *app_team) const 1929 @case 5 ref is valid, file has type and app hint, the type's 1930 preferred app type is not installed, app exists and has 1931 signature 1932 @results Should return B_OK and set team to the ID of the team 1933 running the file type's preferred application's executable. 1934 Should install the app type and set the app hint on it. 1935 */ 1936 void LaunchTester::LaunchTestD5() 1937 { 1938 BRoster roster; 1939 create_app(appFile1, appType1); 1940 create_app(appFile2, appType2); 1941 install_type(fileType1, appType1); 1942 entry_ref fileRef(create_file(testFile1, fileType1, NULL, appFile2)); 1943 SimpleFileCaller1 caller(fileRef); 1944 LaunchContext context; 1945 team_id team; 1946 CHK(context(caller, fileType1, context.StandardMessages(), 1947 LaunchContext::kStandardArgc, LaunchContext::kStandardArgv, 1948 &team) == B_OK); 1949 entry_ref ref = ref_for_team(team); 1950 CHK(ref_for_path(appFile1) == ref); 1951 check_app_type(appType1, appFile1); 1952 1953 context.Terminate(); 1954 int32 cookie = 0; 1955 CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); 1956 CHK(context.CheckMainArgsMessage(caller, team, cookie, &ref)); 1957 CHK(context.CheckMessageMessages(caller, team, cookie)); 1958 // CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); 1959 CHK(context.CheckRefsMessage(caller, team, cookie)); 1960 CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); 1961 CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); 1962 CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); 1963 } 1964 1965 /* 1966 status_t Launch(const entry_ref *ref, const BMessage *initialMessage, 1967 team_id *app_team) const 1968 @case 6 ref is valid, file has type, the type's preferred app 1969 type is not installed, app exists and has signature, file 1970 has executable permission, but is not executable 1971 @results Should return B_LAUNCH_FAILED_EXECUTABLE. 1972 Should not set the app hint on the app or file type. 1973 */ 1974 void LaunchTester::LaunchTestD6() 1975 { 1976 BRoster roster; 1977 create_app(appFile1, appType1); 1978 install_type(fileType1, appType1); 1979 entry_ref fileRef(create_file(testFile1, fileType1)); 1980 system((string("chmod a+x ") + testFile1).c_str()); 1981 BMessage message; 1982 team_id team; 1983 CHK(roster.Launch(&fileRef, &message, &team) 1984 == B_LAUNCH_FAILED_EXECUTABLE); 1985 CHK(BMimeType(appType1).IsInstalled() == false); 1986 CHK(BMimeType(fileType1).GetAppHint(&fileRef) == B_ENTRY_NOT_FOUND); 1987 } 1988 1989 /* 1990 status_t Launch(const entry_ref *ref, const BMessage *initialMessage, 1991 team_id *app_team) const 1992 @case 7 ref is valid and refers to a link to a file, file has type, 1993 the type's preferred app type is not installed, 1994 app exists and has signature 1995 @results Should return B_OK and set team to the ID of the team 1996 running the file type's preferred application's executable. 1997 Should install the app type and set the app hint on it. 1998 */ 1999 void LaunchTester::LaunchTestD7() 2000 { 2001 BRoster roster; 2002 create_app(appFile1, appType1); 2003 install_type(fileType1, appType1); 2004 create_file(testFile1, fileType1); 2005 system((string("ln -s ") + testFile1 + " " + testLink1).c_str()); 2006 entry_ref fileRef(ref_for_path(testFile1, false)); 2007 entry_ref linkRef(ref_for_path(testLink1, false)); 2008 SimpleFileCaller1 caller(linkRef); 2009 LaunchContext context; 2010 team_id team; 2011 CHK(context(caller, fileType1, context.StandardMessages(), 2012 LaunchContext::kStandardArgc, LaunchContext::kStandardArgv, 2013 &team) == B_OK); 2014 entry_ref ref = ref_for_team(team); 2015 CHK(ref_for_path(appFile1) == ref); 2016 check_app_type(appType1, appFile1); 2017 2018 context.Terminate(); 2019 int32 cookie = 0; 2020 CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); 2021 CHK(context.CheckMainArgsMessage(caller, team, cookie, &ref)); 2022 CHK(context.CheckMessageMessages(caller, team, cookie)); 2023 // CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); 2024 CHK(context.CheckRefsMessage(caller, team, cookie, &fileRef)); 2025 CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); 2026 CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); 2027 CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); 2028 } 2029 2030 /* 2031 status_t Launch(const entry_ref *ref, const BMessage *initialMessage, 2032 team_id *app_team) const 2033 @case 8 ref is valid, file has no type, sniffing results in a type, 2034 type is set on file, 2035 Launch(const char*, entry_ref*) cases 4-16 2036 (== common cases 2-14) 2037 */ 2038 void LaunchTester::LaunchTestD8() 2039 { 2040 FileWithTypeCaller1 caller; 2041 for (int32 i = 0; i < commonTestFunctionCount; i++) { 2042 NextSubTest(); 2043 (*commonTestFunctions[i])(caller); 2044 tearDown(); 2045 setUp(); 2046 } 2047 } 2048 2049 /* 2050 status_t Launch(const entry_ref *ref, const BMessage *initialMessage, 2051 team_id *app_team) const 2052 @case 9 ref is valid, file has no type, sniffing results in a type, 2053 type is set on file, 2054 Launch(const char*, entry_ref*) cases 3-16 2055 (== common cases 1-14) 2056 */ 2057 void LaunchTester::LaunchTestD9() 2058 { 2059 SniffFileTypeCaller1 caller; 2060 for (int32 i = 1; i < commonTestFunctionCount; i++) { 2061 NextSubTest(); 2062 (*commonTestFunctions[i])(caller); 2063 tearDown(); 2064 setUp(); 2065 } 2066 } 2067 2068 /* 2069 status_t Launch(const entry_ref *ref, const BMessage *initialMessage, 2070 team_id *app_team) const 2071 @case 10 ref is valid, file has no type, but preferred app, app 2072 type is not installed, app exists and has signature, 2073 NULL initialMessage 2074 @results Should return B_OK and set team to the ID of the team 2075 running the application's executable. Should install the 2076 app type and set the app hint on it. 2077 */ 2078 void LaunchTester::LaunchTestD10() 2079 { 2080 BRoster roster; 2081 create_app(appFile1, appType1); 2082 entry_ref fileRef(create_file(testFile1, NULL, appType1)); 2083 SimpleFileCaller1 caller(fileRef); 2084 LaunchContext context; 2085 team_id team; 2086 CHK(context(caller, fileType1, NULL, LaunchContext::kStandardArgc, 2087 LaunchContext::kStandardArgv, &team) == B_OK); 2088 entry_ref ref = ref_for_team(team); 2089 CHK(ref_for_path(appFile1) == ref); 2090 check_app_type(appType1, appFile1); 2091 2092 context.Terminate(); 2093 int32 cookie = 0; 2094 CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); 2095 CHK(context.CheckMainArgsMessage(caller, team, cookie, &ref)); 2096 // CHK(context.CheckMessageMessages(caller, team, cookie)); 2097 // CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); 2098 CHK(context.CheckRefsMessage(caller, team, cookie)); 2099 CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); 2100 CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); 2101 CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); 2102 } 2103 2104 /* 2105 status_t Launch(const entry_ref *ref, const BMessage *initialMessage, 2106 team_id *app_team) const 2107 @case 11 ref is valid and refers to a cyclic link 2108 @results Should return B_LAUNCH_FAILED_NO_RESOLVE_LINK. 2109 */ 2110 void LaunchTester::LaunchTestD11() 2111 { 2112 BRoster roster; 2113 system((string("ln -s ") + testLink1 + " " + testLink1).c_str()); 2114 entry_ref linkRef(ref_for_path(testLink1, false)); 2115 BMessage message; 2116 team_id team; 2117 CHK(roster.Launch(&linkRef, &message, &team) 2118 == B_LAUNCH_FAILED_NO_RESOLVE_LINK); 2119 } 2120 2121 /* 2122 status_t Launch(const entry_ref *ref, const BMessage *initialMessage, 2123 team_id *app_team) const 2124 @case 12 ref is valid and refers to a link to void 2125 @results Should return B_LAUNCH_FAILED_NO_RESOLVE_LINK. 2126 */ 2127 void LaunchTester::LaunchTestD12() 2128 { 2129 BRoster roster; 2130 system((string("ln -s ") + testFile1 + " " + testLink1).c_str()); 2131 entry_ref linkRef(ref_for_path(testLink1, false)); 2132 BMessage message; 2133 team_id team; 2134 CHK(roster.Launch(&linkRef, &message, &team) 2135 == B_LAUNCH_FAILED_NO_RESOLVE_LINK); 2136 } 2137 2138 /* 2139 status_t Launch(const entry_ref *ref, const BMessage *initialMessage, 2140 team_id *app_team) const 2141 @case 13 ref is valid and refers to an executable without signature 2142 @results Should return B_OK and set team to the ID of the team 2143 running the application's executable. 2144 */ 2145 void LaunchTester::LaunchTestD13() 2146 { 2147 BRoster roster; 2148 create_app(appFile1, NULL); 2149 entry_ref fileRef(ref_for_path(appFile1)); 2150 SimpleFileCaller1 caller(fileRef); 2151 LaunchContext context; 2152 team_id team; 2153 CHK(context(caller, appType1, context.StandardMessages(), 2154 LaunchContext::kStandardArgc, LaunchContext::kStandardArgv, 2155 &team) == B_OK); 2156 entry_ref ref = ref_for_team(team); 2157 CHK(ref_for_path(appFile1) == ref); 2158 context.WaitForMessage(team, MSG_STARTED, true); 2159 app_info appInfo; 2160 CHK(roster.GetRunningAppInfo(team, &appInfo) == B_OK); 2161 CHK(!strcmp(appInfo.signature, kDefaultTestAppSignature)); 2162 2163 context.Terminate(); 2164 int32 cookie = 0; 2165 CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); 2166 // CHK(context.CheckMainArgsMessage(caller, team, cookie, &ref)); 2167 CHK(context.CheckArgsMessage(caller, team, cookie, &ref, NULL, 2168 0, NULL, MSG_MAIN_ARGS)); 2169 CHK(context.CheckMessageMessages(caller, team, cookie)); 2170 // CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); 2171 // CHK(context.CheckArgsMessage(caller, team, cookie, &ref, NULL, 2172 // LaunchContext::kStandardArgc, 2173 // LaunchContext::kStandardArgv, 2174 // MSG_ARGV_RECEIVED)); 2175 CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); 2176 CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); 2177 CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); 2178 } 2179 2180 // SimpleFileCaller2 2181 class SimpleFileCaller2 : public LaunchCaller { 2182 public: 2183 SimpleFileCaller2() : fRef() {} 2184 SimpleFileCaller2(const entry_ref &ref) : fRef(ref) {} 2185 virtual ~SimpleFileCaller2() {} 2186 virtual status_t operator()(const char *type, BList *messages, int32 argc, 2187 const char **argv, team_id *team) 2188 { 2189 BRoster roster; 2190 return roster.Launch(&fRef, messages, team); 2191 } 2192 virtual int32 SupportsMessages() const { return 1000; } 2193 virtual bool SupportsRefs() const { return true; } 2194 virtual const entry_ref *Ref() const { return &fRef; } 2195 2196 virtual LaunchCaller *CloneInternal() 2197 { 2198 return new SimpleFileCaller2; 2199 } 2200 2201 protected: 2202 entry_ref fRef; 2203 }; 2204 2205 // FileWithTypeCaller2 2206 class FileWithTypeCaller2 : public SimpleFileCaller2 { 2207 public: 2208 virtual status_t operator()(const char *type, BList *messages, int32 argc, 2209 const char **argv, team_id *team) 2210 { 2211 BRoster roster; 2212 fRef = create_file(testFile1, type); 2213 return roster.Launch(&fRef, messages, team); 2214 } 2215 2216 virtual LaunchCaller *CloneInternal() 2217 { 2218 return new FileWithTypeCaller2; 2219 } 2220 }; 2221 2222 // SniffFileTypeCaller2 2223 class SniffFileTypeCaller2 : public SimpleFileCaller2 { 2224 public: 2225 virtual status_t operator()(const char *type, BList *messages, int32 argc, 2226 const char **argv, team_id *team) 2227 { 2228 BRoster roster; 2229 fRef = create_file(testFile1, type, NULL, NULL, "UnIQe pAtTeRn"); 2230 install_type(fileType1, NULL, "1.0 [0] ('UnIQe pAtTeRn')"); 2231 return roster.Launch(&fRef, messages, team); 2232 } 2233 2234 virtual LaunchCaller *CloneInternal() 2235 { 2236 return new SniffFileTypeCaller2; 2237 } 2238 }; 2239 2240 /* 2241 status_t Launch(const entry_ref *ref, const BList *messageList, 2242 team_id *appTeam) const 2243 @case 1 ref is NULL 2244 @results Should return B_BAD_VALUE. 2245 */ 2246 void LaunchTester::LaunchTestE1() 2247 { 2248 BRoster roster; 2249 BList list; 2250 CHK(roster.Launch((const entry_ref*)NULL, &list, NULL) == B_BAD_VALUE); 2251 } 2252 2253 /* 2254 status_t Launch(const entry_ref *ref, const BList *messageList, 2255 team_id *appTeam) const 2256 @case 2 ref doesn't refer to an existing entry 2257 @results Should return B_ENTRY_NOT_FOUND. 2258 */ 2259 void LaunchTester::LaunchTestE2() 2260 { 2261 BRoster roster; 2262 BMessage message; 2263 entry_ref fileRef(ref_for_path(testFile1)); 2264 BList list; 2265 CHK(roster.Launch(&fileRef, &list, NULL) == B_ENTRY_NOT_FOUND); 2266 } 2267 2268 /* 2269 status_t Launch(const entry_ref *ref, const BList *messageList, 2270 team_id *appTeam) const 2271 @case 3 ref is valid, file has type and preferred app, app type is 2272 not installed, app exists and has signature 2273 @results Should return B_OK and set team to the ID of the team 2274 running the file's (not the file type's) preferred 2275 application's executable. 2276 Should install the app type and set the app hint on it. 2277 */ 2278 void LaunchTester::LaunchTestE3() 2279 { 2280 BRoster roster; 2281 create_app(appFile1, appType1); 2282 create_app(appFile2, appType2); 2283 install_type(fileType1, appType1); 2284 entry_ref fileRef(create_file(testFile1, fileType1, appType2)); 2285 SimpleFileCaller2 caller(fileRef); 2286 LaunchContext context; 2287 team_id team; 2288 CHK(context(caller, fileType1, context.StandardMessages(), 2289 LaunchContext::kStandardArgc, LaunchContext::kStandardArgv, 2290 &team) == B_OK); 2291 entry_ref ref = ref_for_team(team); 2292 CHK(ref_for_path(appFile2) == ref); 2293 check_app_type(appType2, appFile2); 2294 2295 context.Terminate(); 2296 int32 cookie = 0; 2297 CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); 2298 CHK(context.CheckMainArgsMessage(caller, team, cookie, &ref)); 2299 CHK(context.CheckMessageMessages(caller, team, cookie)); 2300 // CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); 2301 CHK(context.CheckRefsMessage(caller, team, cookie)); 2302 CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); 2303 CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); 2304 CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); 2305 } 2306 2307 /* 2308 status_t Launch(const entry_ref *ref, const BList *messageList, 2309 team_id *appTeam) const 2310 @case 4 ref is valid, file has no type, but preferred app, 2311 app type is not installed, app exists and has signature 2312 @results Should return B_OK and set team to the ID of the team 2313 running the application's executable. Should install the 2314 app type and set the app hint on it. 2315 */ 2316 void LaunchTester::LaunchTestE4() 2317 { 2318 BRoster roster; 2319 create_app(appFile1, appType1); 2320 entry_ref fileRef(create_file(testFile1, NULL, appType1)); 2321 SimpleFileCaller2 caller(fileRef); 2322 LaunchContext context; 2323 team_id team; 2324 CHK(context(caller, fileType1, context.StandardMessages(), 2325 LaunchContext::kStandardArgc, LaunchContext::kStandardArgv, 2326 &team) == B_OK); 2327 entry_ref ref = ref_for_team(team); 2328 CHK(ref_for_path(appFile1) == ref); 2329 check_app_type(appType1, appFile1); 2330 2331 context.Terminate(); 2332 int32 cookie = 0; 2333 CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); 2334 CHK(context.CheckMainArgsMessage(caller, team, cookie, &ref)); 2335 CHK(context.CheckMessageMessages(caller, team, cookie)); 2336 // CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); 2337 CHK(context.CheckRefsMessage(caller, team, cookie)); 2338 CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); 2339 CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); 2340 CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); 2341 } 2342 2343 /* 2344 status_t Launch(const entry_ref *ref, const BList *messageList, 2345 team_id *appTeam) const 2346 @case 5 ref is valid, file has type and app hint, the type's 2347 preferred app type is not installed, app exists and has 2348 signature 2349 @results Should return B_OK and set team to the ID of the team 2350 running the file type's preferred application's executable. 2351 Should install the app type and set the app hint on it. 2352 */ 2353 void LaunchTester::LaunchTestE5() 2354 { 2355 BRoster roster; 2356 create_app(appFile1, appType1); 2357 create_app(appFile2, appType2); 2358 install_type(fileType1, appType1); 2359 entry_ref fileRef(create_file(testFile1, fileType1, NULL, appFile2)); 2360 SimpleFileCaller2 caller(fileRef); 2361 LaunchContext context; 2362 team_id team; 2363 CHK(context(caller, fileType1, context.StandardMessages(), 2364 LaunchContext::kStandardArgc, LaunchContext::kStandardArgv, 2365 &team) == B_OK); 2366 entry_ref ref = ref_for_team(team); 2367 CHK(ref_for_path(appFile1) == ref); 2368 check_app_type(appType1, appFile1); 2369 2370 context.Terminate(); 2371 int32 cookie = 0; 2372 CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); 2373 CHK(context.CheckMainArgsMessage(caller, team, cookie, &ref)); 2374 CHK(context.CheckMessageMessages(caller, team, cookie)); 2375 // CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); 2376 CHK(context.CheckRefsMessage(caller, team, cookie)); 2377 CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); 2378 CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); 2379 CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); 2380 } 2381 2382 /* 2383 status_t Launch(const entry_ref *ref, const BList *messageList, 2384 team_id *appTeam) const 2385 @case 6 ref is valid, file has type, the type's preferred app 2386 type is not installed, app exists and has signature, file 2387 has executable permission, but is not executable 2388 @results Should return B_LAUNCH_FAILED_EXECUTABLE. 2389 Should not set the app hint on the app or file type. 2390 */ 2391 void LaunchTester::LaunchTestE6() 2392 { 2393 BRoster roster; 2394 create_app(appFile1, appType1); 2395 install_type(fileType1, appType1); 2396 entry_ref fileRef(create_file(testFile1, fileType1)); 2397 system((string("chmod a+x ") + testFile1).c_str()); 2398 BList list; 2399 team_id team; 2400 CHK(roster.Launch(&fileRef, &list, &team) == B_LAUNCH_FAILED_EXECUTABLE); 2401 CHK(BMimeType(appType1).IsInstalled() == false); 2402 CHK(BMimeType(fileType1).GetAppHint(&fileRef) == B_ENTRY_NOT_FOUND); 2403 } 2404 2405 /* 2406 status_t Launch(const entry_ref *ref, const BList *messageList, 2407 team_id *appTeam) const 2408 @case 7 ref is valid and refers to a link to a file, file has type, 2409 the type's preferred app type is not installed, 2410 app exists and has signature 2411 @results Should return B_OK and set team to the ID of the team 2412 running the file type's preferred application's executable. 2413 Should install the app type and set the app hint on it. 2414 */ 2415 void LaunchTester::LaunchTestE7() 2416 { 2417 BRoster roster; 2418 create_app(appFile1, appType1); 2419 install_type(fileType1, appType1); 2420 create_file(testFile1, fileType1); 2421 system((string("ln -s ") + testFile1 + " " + testLink1).c_str()); 2422 entry_ref fileRef(ref_for_path(testFile1, false)); 2423 entry_ref linkRef(ref_for_path(testLink1, false)); 2424 SimpleFileCaller2 caller(linkRef); 2425 LaunchContext context; 2426 team_id team; 2427 CHK(context(caller, fileType1, context.StandardMessages(), 2428 LaunchContext::kStandardArgc, LaunchContext::kStandardArgv, 2429 &team) == B_OK); 2430 entry_ref ref = ref_for_team(team); 2431 CHK(ref_for_path(appFile1) == ref); 2432 check_app_type(appType1, appFile1); 2433 2434 context.Terminate(); 2435 int32 cookie = 0; 2436 CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); 2437 CHK(context.CheckMainArgsMessage(caller, team, cookie, &ref)); 2438 CHK(context.CheckMessageMessages(caller, team, cookie)); 2439 // CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); 2440 CHK(context.CheckRefsMessage(caller, team, cookie, &fileRef)); 2441 CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); 2442 CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); 2443 CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); 2444 } 2445 2446 /* 2447 status_t Launch(const entry_ref *ref, const BList *messageList, 2448 team_id *appTeam) const 2449 @case 8 ref is valid, file has no type, sniffing results in a type, 2450 type is set on file, 2451 Launch(const char*, entry_ref*) cases 4-16 2452 (== common cases 2-14) 2453 */ 2454 void LaunchTester::LaunchTestE8() 2455 { 2456 FileWithTypeCaller2 caller; 2457 for (int32 i = 0; i < commonTestFunctionCount; i++) { 2458 NextSubTest(); 2459 (*commonTestFunctions[i])(caller); 2460 tearDown(); 2461 setUp(); 2462 } 2463 } 2464 2465 /* 2466 status_t Launch(const entry_ref *ref, const BList *messageList, 2467 team_id *appTeam) const 2468 @case 9 ref is valid, file has no type, sniffing results in a type, 2469 type is set on file, 2470 Launch(const char*, entry_ref*) cases 3-16 2471 (== common cases 1-14) 2472 */ 2473 void LaunchTester::LaunchTestE9() 2474 { 2475 SniffFileTypeCaller2 caller; 2476 for (int32 i = 1; i < commonTestFunctionCount; i++) { 2477 NextSubTest(); 2478 (*commonTestFunctions[i])(caller); 2479 tearDown(); 2480 setUp(); 2481 } 2482 } 2483 2484 /* 2485 status_t Launch(const entry_ref *ref, const BList *messageList, 2486 team_id *appTeam) const 2487 @case 10 ref is valid, file has no type, but preferred app, app 2488 type is not installed, app exists and has signature, 2489 NULL messageList 2490 @results Should return B_OK and set team to the ID of the team 2491 running the application's executable. Should install the 2492 app type and set the app hint on it. 2493 */ 2494 void LaunchTester::LaunchTestE10() 2495 { 2496 BRoster roster; 2497 create_app(appFile1, appType1); 2498 entry_ref fileRef(create_file(testFile1, NULL, appType1)); 2499 SimpleFileCaller2 caller(fileRef); 2500 LaunchContext context; 2501 team_id team; 2502 CHK(context(caller, fileType1, NULL, LaunchContext::kStandardArgc, 2503 LaunchContext::kStandardArgv, &team) == B_OK); 2504 entry_ref ref = ref_for_team(team); 2505 CHK(ref_for_path(appFile1) == ref); 2506 check_app_type(appType1, appFile1); 2507 2508 context.Terminate(); 2509 int32 cookie = 0; 2510 CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); 2511 CHK(context.CheckMainArgsMessage(caller, team, cookie, &ref)); 2512 // CHK(context.CheckMessageMessages(caller, team, cookie)); 2513 // CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); 2514 CHK(context.CheckRefsMessage(caller, team, cookie)); 2515 CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); 2516 CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); 2517 CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); 2518 } 2519 2520 /* 2521 status_t Launch(const entry_ref *ref, const BList *messageList, 2522 team_id *appTeam) const 2523 @case 11 ref is valid, file has no type, but preferred app, app 2524 type is not installed, app exists and has signature, 2525 empty messageList 2526 @results Should return B_OK and set team to the ID of the team 2527 running the application's executable. Should install the 2528 app type and set the app hint on it. 2529 */ 2530 void LaunchTester::LaunchTestE11() 2531 { 2532 BRoster roster; 2533 create_app(appFile1, appType1); 2534 entry_ref fileRef(create_file(testFile1, NULL, appType1)); 2535 SimpleFileCaller2 caller(fileRef); 2536 LaunchContext context; 2537 team_id team; 2538 BList list; 2539 CHK(context(caller, fileType1, &list, LaunchContext::kStandardArgc, 2540 LaunchContext::kStandardArgv, &team) == B_OK); 2541 entry_ref ref = ref_for_team(team); 2542 CHK(ref_for_path(appFile1) == ref); 2543 check_app_type(appType1, appFile1); 2544 2545 context.Terminate(); 2546 int32 cookie = 0; 2547 CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); 2548 CHK(context.CheckMainArgsMessage(caller, team, cookie, &ref)); 2549 // CHK(context.CheckMessageMessages(caller, team, cookie)); 2550 // CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); 2551 CHK(context.CheckRefsMessage(caller, team, cookie)); 2552 CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); 2553 CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); 2554 CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); 2555 } 2556 2557 /* 2558 status_t Launch(const entry_ref *ref, const BList *messageList, 2559 team_id *appTeam) const 2560 @case 12 ref is valid and refers to a cyclic link 2561 @results Should return B_LAUNCH_FAILED_NO_RESOLVE_LINK. 2562 */ 2563 void LaunchTester::LaunchTestE12() 2564 { 2565 BRoster roster; 2566 system((string("ln -s ") + testLink1 + " " + testLink1).c_str()); 2567 entry_ref linkRef(ref_for_path(testLink1, false)); 2568 BMessage message; 2569 team_id team; 2570 BList list; 2571 CHK(roster.Launch(&linkRef, &list, &team) 2572 == B_LAUNCH_FAILED_NO_RESOLVE_LINK); 2573 } 2574 2575 /* 2576 status_t Launch(const entry_ref *ref, const BList *messageList, 2577 team_id *appTeam) const 2578 @case 13 ref is valid and refers to a link to void 2579 @results Should return B_LAUNCH_FAILED_NO_RESOLVE_LINK. 2580 */ 2581 void LaunchTester::LaunchTestE13() 2582 { 2583 BRoster roster; 2584 system((string("ln -s ") + testFile1 + " " + testLink1).c_str()); 2585 entry_ref linkRef(ref_for_path(testLink1, false)); 2586 BMessage message; 2587 team_id team; 2588 BList list; 2589 CHK(roster.Launch(&linkRef, &list, &team) 2590 == B_LAUNCH_FAILED_NO_RESOLVE_LINK); 2591 } 2592 2593 /* 2594 status_t Launch(const entry_ref *ref, const BList *messageList, 2595 team_id *appTeam) const 2596 @case 14 ref is valid and refers to an executable without signature 2597 @results Should return B_OK and set team to the ID of the team 2598 running the application's executable. 2599 */ 2600 void LaunchTester::LaunchTestE14() 2601 { 2602 BRoster roster; 2603 create_app(appFile1, NULL); 2604 entry_ref fileRef(ref_for_path(appFile1)); 2605 SimpleFileCaller2 caller(fileRef); 2606 LaunchContext context; 2607 team_id team; 2608 CHK(context(caller, appType1, context.StandardMessages(), 2609 LaunchContext::kStandardArgc, LaunchContext::kStandardArgv, 2610 &team) == B_OK); 2611 entry_ref ref = ref_for_team(team); 2612 CHK(ref_for_path(appFile1) == ref); 2613 context.WaitForMessage(team, MSG_STARTED, true); 2614 app_info appInfo; 2615 CHK(roster.GetRunningAppInfo(team, &appInfo) == B_OK); 2616 CHK(!strcmp(appInfo.signature, kDefaultTestAppSignature)); 2617 2618 context.Terminate(); 2619 int32 cookie = 0; 2620 CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); 2621 // CHK(context.CheckMainArgsMessage(caller, team, cookie, &ref)); 2622 CHK(context.CheckArgsMessage(caller, team, cookie, &ref, NULL, 2623 0, NULL, MSG_MAIN_ARGS)); 2624 CHK(context.CheckMessageMessages(caller, team, cookie)); 2625 // CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); 2626 // CHK(context.CheckArgsMessage(caller, team, cookie, &ref, NULL, 2627 // LaunchContext::kStandardArgc, 2628 // LaunchContext::kStandardArgv, 2629 // MSG_ARGV_RECEIVED)); 2630 CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); 2631 CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); 2632 CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); 2633 } 2634 2635 // SimpleFileCaller3 2636 class SimpleFileCaller3 : public LaunchCaller { 2637 public: 2638 SimpleFileCaller3() : fRef() {} 2639 SimpleFileCaller3(const entry_ref &ref) : fRef(ref) {} 2640 virtual ~SimpleFileCaller3() {} 2641 virtual status_t operator()(const char *type, BList *messages, int32 argc, 2642 const char **argv, team_id *team) 2643 { 2644 BRoster roster; 2645 return roster.Launch(&fRef, argc, argv, team); 2646 } 2647 virtual int32 SupportsMessages() const { return 0; } 2648 virtual bool SupportsRefs() const { return true; } 2649 virtual const entry_ref *Ref() const { return &fRef; } 2650 2651 virtual LaunchCaller *CloneInternal() 2652 { 2653 return new SimpleFileCaller3; 2654 } 2655 2656 protected: 2657 entry_ref fRef; 2658 }; 2659 2660 // FileWithTypeCaller3 2661 class FileWithTypeCaller3 : public SimpleFileCaller3 { 2662 public: 2663 virtual status_t operator()(const char *type, BList *messages, int32 argc, 2664 const char **argv, team_id *team) 2665 { 2666 BRoster roster; 2667 fRef = create_file(testFile1, type); 2668 return roster.Launch(&fRef, argc, argv, team); 2669 } 2670 2671 virtual LaunchCaller *CloneInternal() 2672 { 2673 return new FileWithTypeCaller3; 2674 } 2675 }; 2676 2677 // SniffFileTypeCaller3 2678 class SniffFileTypeCaller3 : public SimpleFileCaller3 { 2679 public: 2680 virtual status_t operator()(const char *type, BList *messages, int32 argc, 2681 const char **argv, team_id *team) 2682 { 2683 BRoster roster; 2684 fRef = create_file(testFile1, type, NULL, NULL, "UnIQe pAtTeRn"); 2685 install_type(fileType1, NULL, "1.0 [0] ('UnIQe pAtTeRn')"); 2686 return roster.Launch(&fRef, argc, argv, team); 2687 } 2688 2689 virtual LaunchCaller *CloneInternal() 2690 { 2691 return new SniffFileTypeCaller3; 2692 } 2693 }; 2694 2695 /* 2696 status_t Launch(const entry_ref *ref, int argc, const char * const *args, 2697 team_id *appTeam) const 2698 @case 1 ref is NULL 2699 @results Should return B_BAD_VALUE. 2700 */ 2701 void LaunchTester::LaunchTestF1() 2702 { 2703 BRoster roster; 2704 char *argv[] = { "Hey!" }; 2705 CHK(roster.Launch((const entry_ref*)NULL, 1, argv, NULL) == B_BAD_VALUE); 2706 } 2707 2708 /* 2709 status_t Launch(const entry_ref *ref, int argc, const char * const *args, 2710 team_id *appTeam) const 2711 @case 2 ref doesn't refer to an existing entry 2712 @results Should return B_ENTRY_NOT_FOUND. 2713 */ 2714 void LaunchTester::LaunchTestF2() 2715 { 2716 BRoster roster; 2717 BMessage message; 2718 entry_ref fileRef(ref_for_path(testFile1)); 2719 char *argv[] = { "Hey!" }; 2720 CHK(roster.Launch(&fileRef, 1, argv, NULL) == B_ENTRY_NOT_FOUND); 2721 } 2722 2723 /* 2724 status_t Launch(const entry_ref *ref, int argc, const char * const *args, 2725 team_id *appTeam) const 2726 @case 3 ref is valid, file has type and preferred app, app type is 2727 not installed, app exists and has signature 2728 @results Should return B_OK and set team to the ID of the team 2729 running the file's (not the file type's) preferred 2730 application's executable. 2731 Should install the app type and set the app hint on it. 2732 */ 2733 void LaunchTester::LaunchTestF3() 2734 { 2735 BRoster roster; 2736 create_app(appFile1, appType1); 2737 create_app(appFile2, appType2); 2738 install_type(fileType1, appType1); 2739 entry_ref fileRef(create_file(testFile1, fileType1, appType2)); 2740 SimpleFileCaller3 caller(fileRef); 2741 LaunchContext context; 2742 team_id team; 2743 CHK(context(caller, fileType1, context.StandardMessages(), 2744 LaunchContext::kStandardArgc, LaunchContext::kStandardArgv, 2745 &team) == B_OK); 2746 entry_ref ref = ref_for_team(team); 2747 CHK(ref_for_path(appFile2) == ref); 2748 check_app_type(appType2, appFile2); 2749 2750 context.Terminate(); 2751 int32 cookie = 0; 2752 CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); 2753 CHK(context.CheckMainArgsMessage(caller, team, cookie, &ref)); 2754 // CHK(context.CheckMessageMessages(caller, team, cookie)); 2755 CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); 2756 // CHK(context.CheckRefsMessage(caller, team, cookie)); 2757 CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); 2758 CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); 2759 CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); 2760 } 2761 2762 /* 2763 status_t Launch(const entry_ref *ref, int argc, const char * const *args, 2764 team_id *appTeam) const 2765 @case 4 ref is valid, file has no type, but preferred app, 2766 app type is not installed, app exists and has signature 2767 @results Should return B_OK and set team to the ID of the team 2768 running the application's executable. Should install the 2769 app type and set the app hint on it. 2770 */ 2771 void LaunchTester::LaunchTestF4() 2772 { 2773 BRoster roster; 2774 create_app(appFile1, appType1); 2775 entry_ref fileRef(create_file(testFile1, NULL, appType1)); 2776 SimpleFileCaller3 caller(fileRef); 2777 LaunchContext context; 2778 team_id team; 2779 CHK(context(caller, fileType1, context.StandardMessages(), 2780 LaunchContext::kStandardArgc, LaunchContext::kStandardArgv, 2781 &team) == B_OK); 2782 entry_ref ref = ref_for_team(team); 2783 CHK(ref_for_path(appFile1) == ref); 2784 check_app_type(appType1, appFile1); 2785 2786 context.Terminate(); 2787 int32 cookie = 0; 2788 CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); 2789 CHK(context.CheckMainArgsMessage(caller, team, cookie, &ref)); 2790 // CHK(context.CheckMessageMessages(caller, team, cookie)); 2791 CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); 2792 // CHK(context.CheckRefsMessage(caller, team, cookie)); 2793 CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); 2794 CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); 2795 CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); 2796 } 2797 2798 /* 2799 status_t Launch(const entry_ref *ref, int argc, const char * const *args, 2800 team_id *appTeam) const 2801 @case 5 ref is valid, file has type and app hint, the type's 2802 preferred app type is not installed, app exists and has 2803 signature 2804 @results Should return B_OK and set team to the ID of the team 2805 running the file type's preferred application's executable. 2806 Should install the app type and set the app hint on it. 2807 */ 2808 void LaunchTester::LaunchTestF5() 2809 { 2810 BRoster roster; 2811 create_app(appFile1, appType1); 2812 create_app(appFile2, appType2); 2813 install_type(fileType1, appType1); 2814 entry_ref fileRef(create_file(testFile1, fileType1, NULL, appFile2)); 2815 SimpleFileCaller3 caller(fileRef); 2816 LaunchContext context; 2817 team_id team; 2818 CHK(context(caller, fileType1, context.StandardMessages(), 2819 LaunchContext::kStandardArgc, LaunchContext::kStandardArgv, 2820 &team) == B_OK); 2821 entry_ref ref = ref_for_team(team); 2822 CHK(ref_for_path(appFile1) == ref); 2823 check_app_type(appType1, appFile1); 2824 2825 context.Terminate(); 2826 int32 cookie = 0; 2827 CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); 2828 CHK(context.CheckMainArgsMessage(caller, team, cookie, &ref)); 2829 // CHK(context.CheckMessageMessages(caller, team, cookie)); 2830 CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); 2831 // CHK(context.CheckRefsMessage(caller, team, cookie)); 2832 CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); 2833 CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); 2834 CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); 2835 } 2836 2837 /* 2838 status_t Launch(const entry_ref *ref, int argc, const char * const *args, 2839 team_id *appTeam) const 2840 @case 6 ref is valid, file has type, the type's preferred app 2841 type is not installed, app exists and has signature, file 2842 has executable permission, but is not executable 2843 @results Should return B_LAUNCH_FAILED_EXECUTABLE. 2844 Should not set the app hint on the app or file type. 2845 */ 2846 void LaunchTester::LaunchTestF6() 2847 { 2848 BRoster roster; 2849 create_app(appFile1, appType1); 2850 install_type(fileType1, appType1); 2851 entry_ref fileRef(create_file(testFile1, fileType1)); 2852 system((string("chmod a+x ") + testFile1).c_str()); 2853 team_id team; 2854 char *argv[] = { "Hey!" }; 2855 CHK(roster.Launch(&fileRef, 1, argv, &team) == B_LAUNCH_FAILED_EXECUTABLE); 2856 CHK(BMimeType(appType1).IsInstalled() == false); 2857 CHK(BMimeType(fileType1).GetAppHint(&fileRef) == B_ENTRY_NOT_FOUND); 2858 } 2859 2860 /* 2861 status_t Launch(const entry_ref *ref, int argc, const char * const *args, 2862 team_id *appTeam) const 2863 @case 7 ref is valid and refers to a link to a file, file has type, 2864 the type's preferred app type is not installed, 2865 app exists and has signature 2866 @results Should return B_OK and set team to the ID of the team 2867 running the file type's preferred application's executable. 2868 Should install the app type and set the app hint on it. 2869 */ 2870 void LaunchTester::LaunchTestF7() 2871 { 2872 BRoster roster; 2873 create_app(appFile1, appType1); 2874 install_type(fileType1, appType1); 2875 create_file(testFile1, fileType1); 2876 system((string("ln -s ") + testFile1 + " " + testLink1).c_str()); 2877 entry_ref fileRef(ref_for_path(testFile1, false)); 2878 entry_ref linkRef(ref_for_path(testLink1, false)); 2879 SimpleFileCaller3 caller(linkRef); 2880 LaunchContext context; 2881 team_id team; 2882 CHK(context(caller, fileType1, context.StandardMessages(), 2883 LaunchContext::kStandardArgc, LaunchContext::kStandardArgv, 2884 &team) == B_OK); 2885 entry_ref ref = ref_for_team(team); 2886 CHK(ref_for_path(appFile1) == ref); 2887 check_app_type(appType1, appFile1); 2888 2889 context.Terminate(); 2890 int32 cookie = 0; 2891 CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); 2892 // CHK(context.CheckMainArgsMessage(caller, team, cookie, &ref)); 2893 CHK(context.CheckArgsMessage(caller, team, cookie, &ref, &fileRef, 2894 LaunchContext::kStandardArgc, 2895 LaunchContext::kStandardArgv, MSG_MAIN_ARGS)); 2896 // CHK(context.CheckMessageMessages(caller, team, cookie)); 2897 // CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); 2898 CHK(context.CheckArgsMessage(caller, team, cookie, &ref, &fileRef, 2899 LaunchContext::kStandardArgc, 2900 LaunchContext::kStandardArgv, 2901 MSG_ARGV_RECEIVED)); 2902 // CHK(context.CheckRefsMessage(caller, team, cookie)); 2903 CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); 2904 CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); 2905 CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); 2906 } 2907 2908 /* 2909 status_t Launch(const entry_ref *ref, int argc, const char * const *args, 2910 team_id *appTeam) const 2911 @case 8 ref is valid, file has no type, sniffing results in a type, 2912 type is set on file, 2913 Launch(const char*, entry_ref*) cases 4-16 2914 (== common cases 2-14) 2915 */ 2916 void LaunchTester::LaunchTestF8() 2917 { 2918 FileWithTypeCaller3 caller; 2919 for (int32 i = 0; i < commonTestFunctionCount; i++) { 2920 NextSubTest(); 2921 (*commonTestFunctions[i])(caller); 2922 tearDown(); 2923 setUp(); 2924 } 2925 } 2926 2927 /* 2928 status_t Launch(const entry_ref *ref, int argc, const char * const *args, 2929 team_id *appTeam) const 2930 @case 9 ref is valid, file has no type, sniffing results in a type, 2931 type is set on file, 2932 Launch(const char*, entry_ref*) cases 3-16 2933 (== common cases 1-14) 2934 */ 2935 void LaunchTester::LaunchTestF9() 2936 { 2937 SniffFileTypeCaller3 caller; 2938 for (int32 i = 1; i < commonTestFunctionCount; i++) { 2939 NextSubTest(); 2940 (*commonTestFunctions[i])(caller); 2941 tearDown(); 2942 setUp(); 2943 } 2944 } 2945 2946 /* 2947 status_t Launch(const entry_ref *ref, int argc, const char * const *args, 2948 team_id *appTeam) const 2949 @case 10 ref is valid, file has no type, but preferred app, app 2950 type is not installed, app exists and has signature, 2951 NULL args, argc is 0 2952 @results Should return B_OK and set team to the ID of the team 2953 running the application's executable. Should install the 2954 app type and set the app hint on it. argv are ignored. 2955 */ 2956 void LaunchTester::LaunchTestF10() 2957 { 2958 BRoster roster; 2959 create_app(appFile1, appType1); 2960 entry_ref fileRef(create_file(testFile1, NULL, appType1)); 2961 SimpleFileCaller3 caller(fileRef); 2962 LaunchContext context; 2963 team_id team; 2964 CHK(context(caller, fileType1, NULL, 0, NULL, &team) == B_OK); 2965 entry_ref ref = ref_for_team(team); 2966 CHK(ref_for_path(appFile1) == ref); 2967 check_app_type(appType1, appFile1); 2968 2969 context.Terminate(); 2970 int32 cookie = 0; 2971 CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); 2972 CHK(context.CheckMainArgsMessage(caller, team, cookie, &ref, 0, NULL)); 2973 // CHK(context.CheckMessageMessages(caller, team, cookie)); 2974 // CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); 2975 CHK(context.CheckRefsMessage(caller, team, cookie)); 2976 CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); 2977 CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); 2978 CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); 2979 } 2980 2981 /* 2982 status_t Launch(const entry_ref *ref, int argc, const char * const *args, 2983 team_id *appTeam) const 2984 @case 11 ref is valid, file has no type, but preferred app, app 2985 type is not installed, app exists and has signature, 2986 NULL args, argc > 0 2987 @results Should return B_OK and set team to the ID of the team 2988 running the application's executable. Should install the 2989 app type and set the app hint on it. argv are ignored. 2990 */ 2991 void LaunchTester::LaunchTestF11() 2992 { 2993 BRoster roster; 2994 create_app(appFile1, appType1); 2995 entry_ref fileRef(create_file(testFile1, NULL, appType1)); 2996 SimpleFileCaller3 caller(fileRef); 2997 LaunchContext context; 2998 team_id team; 2999 CHK(context(caller, fileType1, NULL, 1, NULL, &team) == B_OK); 3000 entry_ref ref = ref_for_team(team); 3001 CHK(ref_for_path(appFile1) == ref); 3002 check_app_type(appType1, appFile1); 3003 3004 context.Terminate(); 3005 int32 cookie = 0; 3006 CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); 3007 CHK(context.CheckMainArgsMessage(caller, team, cookie, &ref, 0, NULL)); 3008 // CHK(context.CheckMessageMessages(caller, team, cookie)); 3009 // CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); 3010 CHK(context.CheckRefsMessage(caller, team, cookie)); 3011 CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); 3012 CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); 3013 CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); 3014 } 3015 3016 /* 3017 status_t Launch(const entry_ref *ref, int argc, const char * const *args, 3018 team_id *appTeam) const 3019 @case 12 ref is valid and refers to a cyclic link 3020 @results Should return B_LAUNCH_FAILED_NO_RESOLVE_LINK. 3021 */ 3022 void LaunchTester::LaunchTestF12() 3023 { 3024 BRoster roster; 3025 system((string("ln -s ") + testLink1 + " " + testLink1).c_str()); 3026 entry_ref linkRef(ref_for_path(testLink1, false)); 3027 BMessage message; 3028 team_id team; 3029 CHK(roster.Launch(&linkRef, LaunchContext::kStandardArgc, 3030 LaunchContext::kStandardArgv, &team) 3031 == B_LAUNCH_FAILED_NO_RESOLVE_LINK); 3032 } 3033 3034 /* 3035 status_t Launch(const entry_ref *ref, int argc, const char * const *args, 3036 team_id *appTeam) const 3037 @case 13 ref is valid and refers to a link to void 3038 @results Should return B_LAUNCH_FAILED_NO_RESOLVE_LINK. 3039 */ 3040 void LaunchTester::LaunchTestF13() 3041 { 3042 BRoster roster; 3043 system((string("ln -s ") + testFile1 + " " + testLink1).c_str()); 3044 entry_ref linkRef(ref_for_path(testLink1, false)); 3045 BMessage message; 3046 team_id team; 3047 CHK(roster.Launch(&linkRef, LaunchContext::kStandardArgc, 3048 LaunchContext::kStandardArgv, &team) 3049 == B_LAUNCH_FAILED_NO_RESOLVE_LINK); 3050 } 3051 3052 /* 3053 status_t Launch(const entry_ref *ref, int argc, const char * const *args, 3054 team_id *appTeam) const 3055 @case 14 ref is valid and refers to an executable without signature 3056 @results Should return B_OK and set team to the ID of the team 3057 running the application's executable. 3058 */ 3059 void LaunchTester::LaunchTestF14() 3060 { 3061 BRoster roster; 3062 create_app(appFile1, NULL); 3063 entry_ref fileRef(ref_for_path(appFile1)); 3064 SimpleFileCaller3 caller(fileRef); 3065 LaunchContext context; 3066 team_id team; 3067 CHK(context(caller, appType1, context.StandardMessages(), 3068 LaunchContext::kStandardArgc, LaunchContext::kStandardArgv, 3069 &team) == B_OK); 3070 entry_ref ref = ref_for_team(team); 3071 CHK(ref_for_path(appFile1) == ref); 3072 context.WaitForMessage(team, MSG_STARTED, true); 3073 app_info appInfo; 3074 CHK(roster.GetRunningAppInfo(team, &appInfo) == B_OK); 3075 CHK(!strcmp(appInfo.signature, kDefaultTestAppSignature)); 3076 3077 context.Terminate(); 3078 int32 cookie = 0; 3079 CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); 3080 // CHK(context.CheckMainArgsMessage(caller, team, cookie, &ref)); 3081 CHK(context.CheckArgsMessage(caller, team, cookie, &ref, NULL, 3082 LaunchContext::kStandardArgc, 3083 LaunchContext::kStandardArgv, 3084 MSG_MAIN_ARGS)); 3085 // CHK(context.CheckMessageMessages(caller, team, cookie)); 3086 // CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); 3087 CHK(context.CheckArgsMessage(caller, team, cookie, &ref, NULL, 3088 LaunchContext::kStandardArgc, 3089 LaunchContext::kStandardArgv, 3090 MSG_ARGV_RECEIVED)); 3091 CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); 3092 CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); 3093 CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); 3094 } 3095 3096 3097 Test* LaunchTester::Suite() 3098 { 3099 TestSuite* SuiteOfTests = new TestSuite; 3100 3101 ADD_TEST4(BRoster, SuiteOfTests, LaunchTester, LaunchTestA1); 3102 ADD_TEST4(BRoster, SuiteOfTests, LaunchTester, LaunchTestA2); 3103 ADD_TEST4(BRoster, SuiteOfTests, LaunchTester, LaunchTestA3); 3104 ADD_TEST4(BRoster, SuiteOfTests, LaunchTester, LaunchTestA4); 3105 3106 ADD_TEST4(BRoster, SuiteOfTests, LaunchTester, LaunchTestB1); 3107 ADD_TEST4(BRoster, SuiteOfTests, LaunchTester, LaunchTestB2); 3108 ADD_TEST4(BRoster, SuiteOfTests, LaunchTester, LaunchTestB3); 3109 ADD_TEST4(BRoster, SuiteOfTests, LaunchTester, LaunchTestB4); 3110 ADD_TEST4(BRoster, SuiteOfTests, LaunchTester, LaunchTestB5); 3111 3112 ADD_TEST4(BRoster, SuiteOfTests, LaunchTester, LaunchTestC1); 3113 ADD_TEST4(BRoster, SuiteOfTests, LaunchTester, LaunchTestC2); 3114 ADD_TEST4(BRoster, SuiteOfTests, LaunchTester, LaunchTestC3); 3115 ADD_TEST4(BRoster, SuiteOfTests, LaunchTester, LaunchTestC4); 3116 3117 ADD_TEST4(BRoster, SuiteOfTests, LaunchTester, LaunchTestD1); 3118 ADD_TEST4(BRoster, SuiteOfTests, LaunchTester, LaunchTestD2); 3119 ADD_TEST4(BRoster, SuiteOfTests, LaunchTester, LaunchTestD3); 3120 ADD_TEST4(BRoster, SuiteOfTests, LaunchTester, LaunchTestD4); 3121 ADD_TEST4(BRoster, SuiteOfTests, LaunchTester, LaunchTestD5); 3122 ADD_TEST4(BRoster, SuiteOfTests, LaunchTester, LaunchTestD6); 3123 ADD_TEST4(BRoster, SuiteOfTests, LaunchTester, LaunchTestD7); 3124 ADD_TEST4(BRoster, SuiteOfTests, LaunchTester, LaunchTestD8); 3125 ADD_TEST4(BRoster, SuiteOfTests, LaunchTester, LaunchTestD9); 3126 ADD_TEST4(BRoster, SuiteOfTests, LaunchTester, LaunchTestD10); 3127 ADD_TEST4(BRoster, SuiteOfTests, LaunchTester, LaunchTestD11); 3128 ADD_TEST4(BRoster, SuiteOfTests, LaunchTester, LaunchTestD12); 3129 ADD_TEST4(BRoster, SuiteOfTests, LaunchTester, LaunchTestD13); 3130 3131 ADD_TEST4(BRoster, SuiteOfTests, LaunchTester, LaunchTestE1); 3132 ADD_TEST4(BRoster, SuiteOfTests, LaunchTester, LaunchTestE2); 3133 ADD_TEST4(BRoster, SuiteOfTests, LaunchTester, LaunchTestE3); 3134 ADD_TEST4(BRoster, SuiteOfTests, LaunchTester, LaunchTestE4); 3135 ADD_TEST4(BRoster, SuiteOfTests, LaunchTester, LaunchTestE5); 3136 ADD_TEST4(BRoster, SuiteOfTests, LaunchTester, LaunchTestE6); 3137 ADD_TEST4(BRoster, SuiteOfTests, LaunchTester, LaunchTestE7); 3138 ADD_TEST4(BRoster, SuiteOfTests, LaunchTester, LaunchTestE8); 3139 ADD_TEST4(BRoster, SuiteOfTests, LaunchTester, LaunchTestE9); 3140 ADD_TEST4(BRoster, SuiteOfTests, LaunchTester, LaunchTestE10); 3141 ADD_TEST4(BRoster, SuiteOfTests, LaunchTester, LaunchTestE11); 3142 ADD_TEST4(BRoster, SuiteOfTests, LaunchTester, LaunchTestE12); 3143 ADD_TEST4(BRoster, SuiteOfTests, LaunchTester, LaunchTestE13); 3144 ADD_TEST4(BRoster, SuiteOfTests, LaunchTester, LaunchTestE14); 3145 3146 ADD_TEST4(BRoster, SuiteOfTests, LaunchTester, LaunchTestF1); 3147 ADD_TEST4(BRoster, SuiteOfTests, LaunchTester, LaunchTestF2); 3148 ADD_TEST4(BRoster, SuiteOfTests, LaunchTester, LaunchTestF3); 3149 ADD_TEST4(BRoster, SuiteOfTests, LaunchTester, LaunchTestF4); 3150 ADD_TEST4(BRoster, SuiteOfTests, LaunchTester, LaunchTestF5); 3151 ADD_TEST4(BRoster, SuiteOfTests, LaunchTester, LaunchTestF6); 3152 ADD_TEST4(BRoster, SuiteOfTests, LaunchTester, LaunchTestF7); 3153 ADD_TEST4(BRoster, SuiteOfTests, LaunchTester, LaunchTestF8); 3154 ADD_TEST4(BRoster, SuiteOfTests, LaunchTester, LaunchTestF9); 3155 ADD_TEST4(BRoster, SuiteOfTests, LaunchTester, LaunchTestF10); 3156 ADD_TEST4(BRoster, SuiteOfTests, LaunchTester, LaunchTestF11); 3157 ADD_TEST4(BRoster, SuiteOfTests, LaunchTester, LaunchTestF12); 3158 ADD_TEST4(BRoster, SuiteOfTests, LaunchTester, LaunchTestF13); 3159 ADD_TEST4(BRoster, SuiteOfTests, LaunchTester, LaunchTestF14); 3160 3161 return SuiteOfTests; 3162 } 3163 3164