From 48bf189f5888d26779c88cb527a4a06ceb3f732f Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Fri, 4 Oct 2002 18:00:22 +0000 Subject: [PATCH] Added app flags related tests. Fixed some problems: LaunchContext doesn't have a LaunchCaller as member anymore, team = NULL parameter for BRoster::Launch() is now handled gracefully. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1370 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/tests/kits/app/broster/BRosterCases | 61 + src/tests/kits/app/broster/LaunchTester.cpp | 1244 +++++++++++++---- .../kits/app/broster/LaunchTesterHelper.cpp | 307 ++-- .../kits/app/broster/LaunchTesterHelper.h | 69 +- 4 files changed, 1281 insertions(+), 400 deletions(-) diff --git a/src/tests/kits/app/broster/BRosterCases b/src/tests/kits/app/broster/BRosterCases index afbc6f8d69..043c9cc3d3 100644 --- a/src/tests/kits/app/broster/BRosterCases +++ b/src/tests/kits/app/broster/BRosterCases @@ -256,6 +256,67 @@ case 13:mimeType is installed, but has no preferred application, case 14:installed type mimeType, preferred app, app type not installed, app has signature, app is trash => Should return B_LAUNCH_FAILED_APP_IN_TRASH. +case 15:installed type mimeType, preferred app, app type not installed, + app has signature, team is NULL => + Should return B_OK and set team to the ID of the team running the + application's executable. Should install the app type and set the + app hint on it. + +case 16:launch the app two times: B_MULTIPLE_LAUNCH | B_ARGV_ONLY => + first app: ArgvReceived(), ReadyToRun(), QuitRequested() + second app: ArgvReceived(), ReadyToRun(), QuitRequested() +case 17:launch the app two times: B_MULTIPLE_LAUNCH => + first app: {Message,Argv,Refs}Received()*, ReadyToRun(), + QuitRequested() + second app: {Message,Argv,Refs}Received()*, ReadyToRun(), + QuitRequested() +case 18:launch the app two times: B_SINGLE_LAUNCH | B_ARGV_ONLY => + first app: ArgvReceived(), ReadyToRun(), QuitRequested() + (No second ArgvReceived()!) + second app: Launch() fails with B_ALREADY_RUNNING +case 19:launch the app two times: B_SINGLE_LAUNCH => + first app: {Message,Argv,Refs}Received()*, ReadyToRun(), + {Message,Argv,Refs}Received()*, QuitRequested() + second app: Launch() fails with B_ALREADY_RUNNING +case 20:launch two apps with the same signature: + B_SINGLE_LAUNCH | B_ARGV_ONLY => + first app: ArgvReceived(), ReadyToRun(), QuitRequested() + second app: ArgvReceived(), ReadyToRun(), QuitRequested() +case 21:launch two apps with the same signature: B_SINGLE_LAUNCH => + first app: {Message,Argv,Refs}Received()*, ReadyToRun(), + QuitRequested() + second app: {Message,Argv,Refs}Received()*, ReadyToRun(), + QuitRequested() +case 22:launch the app two times: B_EXCLUSIVE_LAUNCH | B_ARGV_ONLY => + first app: ArgvReceived(), ReadyToRun(), QuitRequested() + (No second ArgvReceived()!) + second app: Launch() fails with B_ALREADY_RUNNING +case 23:launch the app two times: B_EXCLUSIVE_LAUNCH => + first app: {Message,Argv,Refs}Received()*, ReadyToRun(), + {Message,Argv,Refs}Received()*, QuitRequested() + second app: Launch() fails with B_ALREADY_RUNNING +case 24:launch two apps with the same signature: + B_EXCLUSIVE_LAUNCH | B_ARGV_ONLY => + first app: ArgvReceived(), ReadyToRun(), QuitRequested() + (No second ArgvReceived()!) + second app: Launch() fails with B_ALREADY_RUNNING +case 25:launch two apps with the same signature: B_EXCLUSIVE_LAUNCH => + first app: {Message,Argv,Refs}Received()*, ReadyToRun(), + {Message,Argv,Refs}Received()*, QuitRequested() + second app: Launch() fails with B_ALREADY_RUNNING +case 26:launch two apps with the same signature: + first: B_EXCLUSIVE_LAUNCH, + second: B_EXCLUSIVE_LAUNCH | B_ARGV_ONLY => + first app: {Message,Argv,Refs}Received()*, ReadyToRun(), + QuitRequested() + second app: Launch() fails with B_ALREADY_RUNNING +case 27:launch two apps with the same signature: + first: B_EXCLUSIVE_LAUNCH | B_ARGV_ONLY, + second: B_EXCLUSIVE_LAUNCH => + first app: ArgvReceived(), ReadyToRun(), QuitRequested() + (No second ArgvReceived()!) + second app: Launch() fails with B_ALREADY_RUNNING + status_t Launch(const char *mimeType, BMessage *initialMsg, team_id *appTeam) const diff --git a/src/tests/kits/app/broster/LaunchTester.cpp b/src/tests/kits/app/broster/LaunchTester.cpp index 9ce5a9ff3e..945e668c2a 100644 --- a/src/tests/kits/app/broster/LaunchTester.cpp +++ b/src/tests/kits/app/broster/LaunchTester.cpp @@ -140,7 +140,8 @@ ref_for_team(team_id team) static void create_app(const char *filename, const char *signature, - bool install = false, bool makeExecutable = true) + bool install = false, bool makeExecutable = true, + uint32 appFlags = B_SINGLE_LAUNCH) { BString testApp; CHK(find_test_app("RosterLaunchTestApp1", &testApp) == B_OK); @@ -152,7 +153,7 @@ create_app(const char *filename, const char *signature, BAppFileInfo appFileInfo; CHK(appFileInfo.SetTo(&file) == B_OK); CHK(appFileInfo.SetSignature(signature) == B_OK); - CHK(appFileInfo.SetAppFlags(B_SINGLE_LAUNCH) == B_OK); + CHK(appFileInfo.SetAppFlags(appFlags) == B_OK); if (install) CHK(BMimeType(signature).Install() == B_OK); // We write the signature into a separate attribute, just in case we @@ -270,10 +271,10 @@ static void CommonLaunchTest1(LaunchCaller &caller) { - LaunchContext context(caller); + LaunchContext context; BRoster roster; team_id team; - CHK(context(uninstalledType, &team) == B_LAUNCH_FAILED_APP_NOT_FOUND); + CHK(context(caller, uninstalledType, &team) == B_LAUNCH_FAILED_APP_NOT_FOUND); } /* @@ -284,11 +285,11 @@ static void CommonLaunchTest2(LaunchCaller &caller) { - LaunchContext context(caller); + LaunchContext context; BRoster roster; install_type(fileType1); team_id team; - CHK(context(fileType1, &team) == B_LAUNCH_FAILED_NO_PREFERRED_APP); + CHK(context(caller, fileType1, &team) == B_LAUNCH_FAILED_NO_PREFERRED_APP); } /* @@ -300,11 +301,11 @@ static void CommonLaunchTest3(LaunchCaller &caller) { - LaunchContext context(caller); + LaunchContext context; BRoster roster; install_type(fileType1, appType1); team_id team; - CHK(context(fileType1, &team) == B_LAUNCH_FAILED_APP_NOT_FOUND); + CHK(context(caller, fileType1, &team) == B_LAUNCH_FAILED_APP_NOT_FOUND); } /* @@ -318,25 +319,25 @@ static void CommonLaunchTest4(LaunchCaller &caller) { - LaunchContext context(caller); + LaunchContext context; BRoster roster; create_app(appFile1, appType1); install_type(fileType1, appType1); team_id team; - CHK(context(fileType1, &team) == B_OK); + CHK(context(caller, fileType1, &team) == B_OK); entry_ref ref = ref_for_team(team); CHK(ref_for_path(appFile1) == ref); check_app_type(appType1, appFile1); context.Terminate(); int32 cookie = 0; - CHK(context.CheckNextMessage(team, cookie, MSG_STARTED)); - CHK(context.CheckMessageMessages(team, cookie)); - CHK(context.CheckArgvMessage(team, cookie, &ref)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); + CHK(context.CheckMessageMessages(caller, team, cookie)); + CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); if (caller.SupportsRefs() && !caller.SupportsArgv()) - CHK(context.CheckRefsMessage(team, cookie)); - CHK(context.CheckNextMessage(team, cookie, MSG_READY_TO_RUN)); - CHK(context.CheckNextMessage(team, cookie, MSG_QUIT_REQUESTED)); - CHK(context.CheckNextMessage(team, cookie, MSG_TERMINATED)); + CHK(context.CheckRefsMessage(caller, team, cookie)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); } /* @@ -350,25 +351,25 @@ static void CommonLaunchTest5(LaunchCaller &caller) { - LaunchContext context(caller); + LaunchContext context; BRoster roster; create_app(appFile1, appType1, true); install_type(fileType1, appType1); team_id team; - CHK(context(fileType1, &team) == B_OK); + CHK(context(caller, fileType1, &team) == B_OK); entry_ref ref = ref_for_team(team); CHK(ref_for_path(appFile1) == ref); check_app_type(appType1, appFile1); context.Terminate(); int32 cookie = 0; - CHK(context.CheckNextMessage(team, cookie, MSG_STARTED)); - CHK(context.CheckMessageMessages(team, cookie)); - CHK(context.CheckArgvMessage(team, cookie, &ref)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); + CHK(context.CheckMessageMessages(caller, team, cookie)); + CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); if (caller.SupportsRefs() && !caller.SupportsArgv()) - CHK(context.CheckRefsMessage(team, cookie)); - CHK(context.CheckNextMessage(team, cookie, MSG_READY_TO_RUN)); - CHK(context.CheckNextMessage(team, cookie, MSG_QUIT_REQUESTED)); - CHK(context.CheckNextMessage(team, cookie, MSG_TERMINATED)); + CHK(context.CheckRefsMessage(caller, team, cookie)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); } /* @@ -382,25 +383,25 @@ static void CommonLaunchTest6(LaunchCaller &caller) { - LaunchContext context(caller); + LaunchContext context; BRoster roster; create_app(appFile1, appType1, true, false); install_type(fileType1, appType1); team_id team; - CHK(context(fileType1, &team) == B_OK); + CHK(context(caller, fileType1, &team) == B_OK); entry_ref ref = ref_for_team(team); CHK(ref_for_path(appFile1) == ref); check_app_type(appType1, appFile1); context.Terminate(); int32 cookie = 0; - CHK(context.CheckNextMessage(team, cookie, MSG_STARTED)); - CHK(context.CheckMessageMessages(team, cookie)); - CHK(context.CheckArgvMessage(team, cookie, &ref)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); + CHK(context.CheckMessageMessages(caller, team, cookie)); + CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); if (caller.SupportsRefs() && !caller.SupportsArgv()) - CHK(context.CheckRefsMessage(team, cookie)); - CHK(context.CheckNextMessage(team, cookie, MSG_READY_TO_RUN)); - CHK(context.CheckNextMessage(team, cookie, MSG_QUIT_REQUESTED)); - CHK(context.CheckNextMessage(team, cookie, MSG_TERMINATED)); + CHK(context.CheckRefsMessage(caller, team, cookie)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); } /* @@ -414,27 +415,27 @@ static void CommonLaunchTest7(LaunchCaller &caller) { - LaunchContext context(caller); + LaunchContext context; BRoster roster; create_app(appFile1, appType1); create_app(appFile2, appType1, true); set_file_time(appFile2, time(NULL) + 1); install_type(fileType1, appType1); team_id team; - CHK(context(fileType1, &team) == B_OK); + CHK(context(caller, fileType1, &team) == B_OK); entry_ref ref = ref_for_team(team); CHK(ref_for_path(appFile2) == ref); check_app_type(appType1, appFile2); context.Terminate(); int32 cookie = 0; - CHK(context.CheckNextMessage(team, cookie, MSG_STARTED)); - CHK(context.CheckMessageMessages(team, cookie)); - CHK(context.CheckArgvMessage(team, cookie, &ref)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); + CHK(context.CheckMessageMessages(caller, team, cookie)); + CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); if (caller.SupportsRefs() && !caller.SupportsArgv()) - CHK(context.CheckRefsMessage(team, cookie)); - CHK(context.CheckNextMessage(team, cookie, MSG_READY_TO_RUN)); - CHK(context.CheckNextMessage(team, cookie, MSG_QUIT_REQUESTED)); - CHK(context.CheckNextMessage(team, cookie, MSG_TERMINATED)); + CHK(context.CheckRefsMessage(caller, team, cookie)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); } /* @@ -449,7 +450,7 @@ static void CommonLaunchTest8(LaunchCaller &caller) { - LaunchContext context(caller); + LaunchContext context; BRoster roster; create_app(appFile1, appType1); set_version(appFile1, 1); @@ -457,20 +458,20 @@ CommonLaunchTest8(LaunchCaller &caller) set_file_time(appFile2, time(NULL) + 1); install_type(fileType1, appType1); team_id team; - CHK(context(fileType1, &team) == B_OK); + CHK(context(caller, fileType1, &team) == B_OK); entry_ref ref = ref_for_team(team); CHK(ref_for_path(appFile1) == ref); check_app_type(appType1, appFile1); context.Terminate(); int32 cookie = 0; - CHK(context.CheckNextMessage(team, cookie, MSG_STARTED)); - CHK(context.CheckMessageMessages(team, cookie)); - CHK(context.CheckArgvMessage(team, cookie, &ref)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); + CHK(context.CheckMessageMessages(caller, team, cookie)); + CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); if (caller.SupportsRefs() && !caller.SupportsArgv()) - CHK(context.CheckRefsMessage(team, cookie)); - CHK(context.CheckNextMessage(team, cookie, MSG_READY_TO_RUN)); - CHK(context.CheckNextMessage(team, cookie, MSG_QUIT_REQUESTED)); - CHK(context.CheckNextMessage(team, cookie, MSG_TERMINATED)); + CHK(context.CheckRefsMessage(caller, team, cookie)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); } /* @@ -484,7 +485,7 @@ static void CommonLaunchTest9(LaunchCaller &caller) { - LaunchContext context(caller); + LaunchContext context; BRoster roster; create_app(appFile1, appType1); set_version(appFile1, 2); @@ -493,20 +494,20 @@ CommonLaunchTest9(LaunchCaller &caller) set_file_time(appFile2, time(NULL) + 1); install_type(fileType1, appType1); team_id team; - CHK(context(fileType1, &team) == B_OK); + CHK(context(caller, fileType1, &team) == B_OK); entry_ref ref = ref_for_team(team); CHK(ref_for_path(appFile1) == ref); check_app_type(appType1, appFile1); context.Terminate(); int32 cookie = 0; - CHK(context.CheckNextMessage(team, cookie, MSG_STARTED)); - CHK(context.CheckMessageMessages(team, cookie)); - CHK(context.CheckArgvMessage(team, cookie, &ref)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); + CHK(context.CheckMessageMessages(caller, team, cookie)); + CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); if (caller.SupportsRefs() && !caller.SupportsArgv()) - CHK(context.CheckRefsMessage(team, cookie)); - CHK(context.CheckNextMessage(team, cookie, MSG_READY_TO_RUN)); - CHK(context.CheckNextMessage(team, cookie, MSG_QUIT_REQUESTED)); - CHK(context.CheckNextMessage(team, cookie, MSG_TERMINATED)); + CHK(context.CheckRefsMessage(caller, team, cookie)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); } /* @@ -522,7 +523,7 @@ static void CommonLaunchTest10(LaunchCaller &caller) { - LaunchContext context(caller); + LaunchContext context; BRoster roster; create_app(appFile1, appType2); set_type_app_hint(appType1, appFile1); @@ -530,21 +531,21 @@ CommonLaunchTest10(LaunchCaller &caller) CHK(BMimeType(appType1).GetAppHint(&appHint) == B_OK); install_type(fileType1, appType1); team_id team; - CHK(context(fileType1, &team) == B_OK); + CHK(context(caller, fileType1, &team) == B_OK); entry_ref ref = ref_for_team(team); CHK(ref_for_path(appFile1) == ref); CHK(BMimeType(appType1).GetAppHint(&appHint) == B_ENTRY_NOT_FOUND); CHK(BMimeType(appType2).IsInstalled() == false); context.Terminate(); int32 cookie = 0; - CHK(context.CheckNextMessage(team, cookie, MSG_STARTED)); - CHK(context.CheckMessageMessages(team, cookie)); - CHK(context.CheckArgvMessage(team, cookie, &ref)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); + CHK(context.CheckMessageMessages(caller, team, cookie)); + CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); if (caller.SupportsRefs() && !caller.SupportsArgv()) - CHK(context.CheckRefsMessage(team, cookie)); - CHK(context.CheckNextMessage(team, cookie, MSG_READY_TO_RUN)); - CHK(context.CheckNextMessage(team, cookie, MSG_QUIT_REQUESTED)); - CHK(context.CheckNextMessage(team, cookie, MSG_TERMINATED)); + CHK(context.CheckRefsMessage(caller, team, cookie)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); } /* @@ -559,26 +560,26 @@ static void CommonLaunchTest11(LaunchCaller &caller) { - LaunchContext context(caller); + LaunchContext context; BRoster roster; create_app(appFile1, appType1); set_type_app_hint(appType1, appFile2); install_type(fileType1, appType1); team_id team; - CHK(context(fileType1, &team) == B_OK); + CHK(context(caller, fileType1, &team) == B_OK); entry_ref ref = ref_for_team(team); CHK(ref_for_path(appFile1) == ref); check_app_type(appType1, appFile1); context.Terminate(); int32 cookie = 0; - CHK(context.CheckNextMessage(team, cookie, MSG_STARTED)); - CHK(context.CheckMessageMessages(team, cookie)); - CHK(context.CheckArgvMessage(team, cookie, &ref)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); + CHK(context.CheckMessageMessages(caller, team, cookie)); + CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); if (caller.SupportsRefs() && !caller.SupportsArgv()) - CHK(context.CheckRefsMessage(team, cookie)); - CHK(context.CheckNextMessage(team, cookie, MSG_READY_TO_RUN)); - CHK(context.CheckNextMessage(team, cookie, MSG_QUIT_REQUESTED)); - CHK(context.CheckNextMessage(team, cookie, MSG_TERMINATED)); + CHK(context.CheckRefsMessage(caller, team, cookie)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); } /* @@ -591,24 +592,24 @@ static void CommonLaunchTest12(LaunchCaller &caller) { - LaunchContext context(caller); + LaunchContext context; BRoster roster; create_app(appFile1, appType1); team_id team; - CHK(context(appType1, &team) == B_OK); + CHK(context(caller, appType1, &team) == B_OK); entry_ref ref = ref_for_team(team); CHK(ref_for_path(appFile1) == ref); check_app_type(appType1, appFile1); context.Terminate(); int32 cookie = 0; - CHK(context.CheckNextMessage(team, cookie, MSG_STARTED)); - CHK(context.CheckMessageMessages(team, cookie)); - CHK(context.CheckArgvMessage(team, cookie, &ref)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); + CHK(context.CheckMessageMessages(caller, team, cookie)); + CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); if (caller.SupportsRefs() && !caller.SupportsArgv()) - CHK(context.CheckRefsMessage(team, cookie)); - CHK(context.CheckNextMessage(team, cookie, MSG_READY_TO_RUN)); - CHK(context.CheckNextMessage(team, cookie, MSG_QUIT_REQUESTED)); - CHK(context.CheckNextMessage(team, cookie, MSG_TERMINATED)); + CHK(context.CheckRefsMessage(caller, team, cookie)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); } /* @@ -623,7 +624,7 @@ static void CommonLaunchTest13(LaunchCaller &caller) { - LaunchContext context(caller); + LaunchContext context; BRoster roster; // make sure, the original preferred app for the "text" supertype is // re-installed @@ -649,20 +650,20 @@ CommonLaunchTest13(LaunchCaller &caller) CHK(BMimeType("text").SetPreferredApp(appType1) == B_OK); install_type(textTestType); team_id team; - CHK(context(textTestType, &team) == B_OK); + CHK(context(caller, textTestType, &team) == B_OK); entry_ref ref = ref_for_team(team); CHK(ref_for_path(appFile1) == ref); check_app_type(appType1, appFile1); context.Terminate(); int32 cookie = 0; - CHK(context.CheckNextMessage(team, cookie, MSG_STARTED)); - CHK(context.CheckMessageMessages(team, cookie)); - CHK(context.CheckArgvMessage(team, cookie, &ref)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); + CHK(context.CheckMessageMessages(caller, team, cookie)); + CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); if (caller.SupportsRefs() && !caller.SupportsArgv()) - CHK(context.CheckRefsMessage(team, cookie)); - CHK(context.CheckNextMessage(team, cookie, MSG_READY_TO_RUN)); - CHK(context.CheckNextMessage(team, cookie, MSG_QUIT_REQUESTED)); - CHK(context.CheckNextMessage(team, cookie, MSG_TERMINATED)); + CHK(context.CheckRefsMessage(caller, team, cookie)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); } /* @@ -674,12 +675,611 @@ static void CommonLaunchTest14(LaunchCaller &caller) { - LaunchContext context(caller); + LaunchContext context; BRoster roster; create_app(get_trash_app_file(), appType1); install_type(fileType1, appType1); team_id team; - CHK(context(fileType1, &team) == B_LAUNCH_FAILED_APP_IN_TRASH); + CHK(context(caller, fileType1, &team) == B_LAUNCH_FAILED_APP_IN_TRASH); +} + +/* + @case 15 installed type mimeType, preferred app, app type not + installed, app has signature, team is NULL + @results Should return B_OK and set team to the ID of the team + running the application's executable. Should install the + app type and set the app hint on it. +*/ +static +void +CommonLaunchTest15(LaunchCaller &caller) +{ + LaunchContext context; + BRoster roster; + create_app(appFile1, appType1); + install_type(fileType1, appType1); + CHK(context(caller, fileType1, NULL) == B_OK); + context.WaitForMessage(MSG_STARTED, true); + team_id team = context.TeamAt(0); + CHK(team >= 0); + entry_ref ref = ref_for_team(team); + CHK(ref_for_path(appFile1) == ref); + check_app_type(appType1, appFile1); + context.Terminate(); + int32 cookie = 0; + CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); + CHK(context.CheckMessageMessages(caller, team, cookie)); + CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); + if (caller.SupportsRefs() && !caller.SupportsArgv()) + CHK(context.CheckRefsMessage(caller, team, cookie)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); +} + +/* + @case 16 launch the app two times: B_MULTIPLE_LAUNCH | B_ARGV_ONLY + @results first app: ArgvReceived(), ReadyToRun(), QuitRequested() + second app: ArgvReceived(), ReadyToRun(), QuitRequested() +*/ +static +void +CommonLaunchTest16(LaunchCaller &caller) +{ + LaunchCaller &caller2 = caller.Clone(); + LaunchContext context; + BRoster roster; + create_app(appFile1, appType1, false, true, + B_MULTIPLE_LAUNCH | B_ARGV_ONLY); + install_type(fileType1, appType1); + // launch app 1 + team_id team1; + CHK(context(caller, fileType1, &team1) == B_OK); + entry_ref ref1 = ref_for_team(team1); + CHK(ref_for_path(appFile1) == ref1); + check_app_type(appType1, appFile1); + context.WaitForMessage(team1, MSG_STARTED); + // launch app 2 + team_id team2; + CHK(context(caller2, fileType1, &team2) == B_OK); + entry_ref ref2 = ref_for_team(team2); + CHK(ref_for_path(appFile1) == ref2); + check_app_type(appType1, appFile1); + // checks 1 + context.Terminate(); + int32 cookie = 0; + CHK(context.CheckNextMessage(caller, team1, cookie, MSG_STARTED)); +// CHK(context.CheckMessageMessages(caller, team1, cookie)); + CHK(context.CheckArgvMessage(caller, team1, cookie, &ref1)); +// if (caller.SupportsRefs() && !caller.SupportsArgv()) +// CHK(context.CheckRefsMessage(caller, team1, cookie)); + CHK(context.CheckNextMessage(caller, team1, cookie, MSG_READY_TO_RUN)); + CHK(context.CheckNextMessage(caller, team1, cookie, MSG_QUIT_REQUESTED)); + CHK(context.CheckNextMessage(caller, team1, cookie, MSG_TERMINATED)); + // checks 2 + cookie = 0; + CHK(context.CheckNextMessage(caller2, team2, cookie, MSG_STARTED)); +// CHK(context.CheckMessageMessages(caller2, team2, cookie)); + CHK(context.CheckArgvMessage(caller2, team2, cookie, &ref2)); +// if (caller.SupportsRefs() && !caller.SupportsArgv()) +// CHK(context.CheckRefsMessage(caller2, team2, cookie)); + CHK(context.CheckNextMessage(caller2, team2, cookie, MSG_READY_TO_RUN)); + CHK(context.CheckNextMessage(caller2, team2, cookie, MSG_QUIT_REQUESTED)); + CHK(context.CheckNextMessage(caller2, team2, cookie, MSG_TERMINATED)); +} + +/* + @case 17 launch the app two times: B_MULTIPLE_LAUNCH | B_ARGV_ONLY + @results first app: {Message,Argv,Refs}Received()*, ReadyToRun(), + QuitRequested() + second app: {Message,Argv,Refs}Received()*, ReadyToRun(), + QuitRequested() +*/ +static +void +CommonLaunchTest17(LaunchCaller &caller) +{ + LaunchCaller &caller2 = caller.Clone(); + LaunchContext context; + BRoster roster; + create_app(appFile1, appType1, false, true, + B_MULTIPLE_LAUNCH); + install_type(fileType1, appType1); + // launch app 1 + team_id team1; + CHK(context(caller, fileType1, &team1) == B_OK); + entry_ref ref1 = ref_for_team(team1); + CHK(ref_for_path(appFile1) == ref1); + check_app_type(appType1, appFile1); + context.WaitForMessage(team1, MSG_STARTED); + // launch app 2 + team_id team2; + CHK(context(caller2, fileType1, &team2) == B_OK); + entry_ref ref2 = ref_for_team(team2); + CHK(ref_for_path(appFile1) == ref2); + check_app_type(appType1, appFile1); + // checks 1 + context.Terminate(); + int32 cookie = 0; + CHK(context.CheckNextMessage(caller, team1, cookie, MSG_STARTED)); + CHK(context.CheckMessageMessages(caller, team1, cookie)); + CHK(context.CheckArgvMessage(caller, team1, cookie, &ref1)); + if (caller.SupportsRefs() && !caller.SupportsArgv()) + CHK(context.CheckRefsMessage(caller, team1, cookie)); + CHK(context.CheckNextMessage(caller, team1, cookie, MSG_READY_TO_RUN)); + CHK(context.CheckNextMessage(caller, team1, cookie, MSG_QUIT_REQUESTED)); + CHK(context.CheckNextMessage(caller, team1, cookie, MSG_TERMINATED)); + // checks 2 + cookie = 0; + CHK(context.CheckNextMessage(caller2, team2, cookie, MSG_STARTED)); + CHK(context.CheckMessageMessages(caller2, team2, cookie)); + CHK(context.CheckArgvMessage(caller2, team2, cookie, &ref2)); + if (caller.SupportsRefs() && !caller.SupportsArgv()) + CHK(context.CheckRefsMessage(caller2, team2, cookie)); + CHK(context.CheckNextMessage(caller2, team2, cookie, MSG_READY_TO_RUN)); + CHK(context.CheckNextMessage(caller2, team2, cookie, MSG_QUIT_REQUESTED)); + CHK(context.CheckNextMessage(caller2, team2, cookie, MSG_TERMINATED)); +} + +/* + @case 18 launch the app two times: B_SINGLE_LAUNCH | B_ARGV_ONLY + @results first app: ArgvReceived(), ReadyToRun(), QuitRequested() + (No second ArgvReceived()!) + second app: Launch() fails with B_ALREADY_RUNNING +*/ +static +void +CommonLaunchTest18(LaunchCaller &caller) +{ + LaunchCaller &caller2 = caller.Clone(); + LaunchContext context; + BRoster roster; + create_app(appFile1, appType1, false, true, + B_SINGLE_LAUNCH | B_ARGV_ONLY); + install_type(fileType1, appType1); + // launch app 1 + team_id team1; + CHK(context(caller, fileType1, &team1) == B_OK); + entry_ref ref1 = ref_for_team(team1); + CHK(ref_for_path(appFile1) == ref1); + check_app_type(appType1, appFile1); + context.WaitForMessage(team1, MSG_STARTED); + // launch app 2 + team_id team2; + CHK(context(caller2, fileType1, &team2) == B_ALREADY_RUNNING); + // checks 1 + context.Terminate(); + int32 cookie = 0; + CHK(context.CheckNextMessage(caller, team1, cookie, MSG_STARTED)); +// CHK(context.CheckMessageMessages(caller, team1, cookie)); + CHK(context.CheckArgvMessage(caller, team1, cookie, &ref1)); +// if (caller.SupportsRefs() && !caller.SupportsArgv()) +// CHK(context.CheckRefsMessage(caller, team1, cookie)); + CHK(context.CheckNextMessage(caller, team1, cookie, MSG_READY_TO_RUN)); + CHK(context.CheckNextMessage(caller, team1, cookie, MSG_QUIT_REQUESTED)); + CHK(context.CheckNextMessage(caller, team1, cookie, MSG_TERMINATED)); +} + +/* + @case 19 launch the app two times: B_SINGLE_LAUNCH + @results first app: {Message,Argv,Refs}Received()*, ReadyToRun(), + {Message,Argv,Refs}Received()*, QuitRequested() + second app: Launch() fails with B_ALREADY_RUNNING +*/ +static +void +CommonLaunchTest19(LaunchCaller &caller) +{ + LaunchCaller &caller2 = caller.Clone(); + LaunchContext context; + BRoster roster; + create_app(appFile1, appType1, false, true, + B_SINGLE_LAUNCH); + install_type(fileType1, appType1); + // launch app 1 + team_id team1; + CHK(context(caller, fileType1, &team1) == B_OK); + entry_ref ref1 = ref_for_team(team1); + CHK(ref_for_path(appFile1) == ref1); + check_app_type(appType1, appFile1); + context.WaitForMessage(team1, MSG_STARTED); + // launch app 2 + team_id team2; + CHK(context(caller2, fileType1, &team2) == B_ALREADY_RUNNING); + // checks 1 + context.Terminate(); + int32 cookie = 0; + CHK(context.CheckNextMessage(caller, team1, cookie, MSG_STARTED)); + CHK(context.CheckMessageMessages(caller, team1, cookie)); + CHK(context.CheckArgvMessage(caller, team1, cookie, &ref1)); + if (caller.SupportsRefs() && !caller.SupportsArgv()) + CHK(context.CheckRefsMessage(caller, team1, cookie)); + CHK(context.CheckNextMessage(caller, team1, cookie, MSG_READY_TO_RUN)); + CHK(context.CheckMessageMessages(caller, team1, cookie)); + CHK(context.CheckArgvMessage(caller, team1, cookie, &ref1)); + if (caller.SupportsRefs() && !caller.SupportsArgv()) + CHK(context.CheckRefsMessage(caller, team1, cookie)); + CHK(context.CheckNextMessage(caller, team1, cookie, MSG_QUIT_REQUESTED)); + CHK(context.CheckNextMessage(caller, team1, cookie, MSG_TERMINATED)); +} + +/* + @case 20 launch two apps with the same signature: + B_SINGLE_LAUNCH | B_ARGV_ONLY + @results first app: ArgvReceived(), ReadyToRun(), QuitRequested() + second app: ArgvReceived(), ReadyToRun(), QuitRequested() +*/ +static +void +CommonLaunchTest20(LaunchCaller &caller) +{ + LaunchCaller &caller2 = caller.Clone(); + LaunchContext context; + BRoster roster; + // launch app 1 + create_app(appFile1, appType1, false, true, + B_SINGLE_LAUNCH | B_ARGV_ONLY); + install_type(fileType1, appType1); + team_id team1; + CHK(context(caller, fileType1, &team1) == B_OK); + entry_ref ref1 = ref_for_team(team1); + CHK(ref_for_path(appFile1) == ref1); + check_app_type(appType1, appFile1); + context.WaitForMessage(team1, MSG_STARTED); + // launch app 2 (greater modification time) + CHK(BMimeType(appType1).Delete() == B_OK); + create_app(appFile2, appType1, false, true, + B_SINGLE_LAUNCH | B_ARGV_ONLY); + set_file_time(appFile2, time(NULL) + 1); + team_id team2; + CHK(context(caller2, fileType1, &team2) == B_OK); + entry_ref ref2 = ref_for_team(team2); + CHK(ref_for_path(appFile2) == ref2); + check_app_type(appType1, appFile2); + // checks 1 + context.Terminate(); + int32 cookie = 0; + CHK(context.CheckNextMessage(caller, team1, cookie, MSG_STARTED)); +// CHK(context.CheckMessageMessages(caller, team1, cookie)); + CHK(context.CheckArgvMessage(caller, team1, cookie, &ref1)); +// if (caller.SupportsRefs() && !caller.SupportsArgv()) +// CHK(context.CheckRefsMessage(caller, team1, cookie)); + CHK(context.CheckNextMessage(caller, team1, cookie, MSG_READY_TO_RUN)); + CHK(context.CheckNextMessage(caller, team1, cookie, MSG_QUIT_REQUESTED)); + CHK(context.CheckNextMessage(caller, team1, cookie, MSG_TERMINATED)); + // checks 2 + cookie = 0; + CHK(context.CheckNextMessage(caller2, team2, cookie, MSG_STARTED)); +// CHK(context.CheckMessageMessages(caller2, team2, cookie)); + CHK(context.CheckArgvMessage(caller2, team2, cookie, &ref2)); +// if (caller.SupportsRefs() && !caller.SupportsArgv()) +// CHK(context.CheckRefsMessage(caller2, team2, cookie)); + CHK(context.CheckNextMessage(caller2, team2, cookie, MSG_READY_TO_RUN)); + CHK(context.CheckNextMessage(caller2, team2, cookie, MSG_QUIT_REQUESTED)); + CHK(context.CheckNextMessage(caller2, team2, cookie, MSG_TERMINATED)); +} + +/* + @case 21 launch two apps with the same signature: B_SINGLE_LAUNCH + @results first app: {Message,Argv,Refs}Received()*, ReadyToRun(), + QuitRequested() + second app: {Message,Argv,Refs}Received()*, ReadyToRun(), + QuitRequested() +*/ +static +void +CommonLaunchTest21(LaunchCaller &caller) +{ + LaunchCaller &caller2 = caller.Clone(); + LaunchContext context; + BRoster roster; + // launch app 1 + create_app(appFile1, appType1, false, true, + B_SINGLE_LAUNCH); + install_type(fileType1, appType1); + team_id team1; + CHK(context(caller, fileType1, &team1) == B_OK); + entry_ref ref1 = ref_for_team(team1); + CHK(ref_for_path(appFile1) == ref1); + check_app_type(appType1, appFile1); + context.WaitForMessage(team1, MSG_STARTED); + // launch app 2 (greater modification time) + CHK(BMimeType(appType1).Delete() == B_OK); + create_app(appFile2, appType1, false, true, + B_SINGLE_LAUNCH); + set_file_time(appFile2, time(NULL) + 1); + team_id team2; + CHK(context(caller2, fileType1, &team2) == B_OK); + entry_ref ref2 = ref_for_team(team2); + CHK(ref_for_path(appFile2) == ref2); + check_app_type(appType1, appFile2); + // checks 1 + context.Terminate(); + int32 cookie = 0; + CHK(context.CheckNextMessage(caller, team1, cookie, MSG_STARTED)); + CHK(context.CheckMessageMessages(caller, team1, cookie)); + CHK(context.CheckArgvMessage(caller, team1, cookie, &ref1)); + if (caller.SupportsRefs() && !caller.SupportsArgv()) + CHK(context.CheckRefsMessage(caller, team1, cookie)); + CHK(context.CheckNextMessage(caller, team1, cookie, MSG_READY_TO_RUN)); + CHK(context.CheckNextMessage(caller, team1, cookie, MSG_QUIT_REQUESTED)); + CHK(context.CheckNextMessage(caller, team1, cookie, MSG_TERMINATED)); + // checks 2 + cookie = 0; + CHK(context.CheckNextMessage(caller2, team2, cookie, MSG_STARTED)); + CHK(context.CheckMessageMessages(caller2, team2, cookie)); + CHK(context.CheckArgvMessage(caller2, team2, cookie, &ref2)); + if (caller.SupportsRefs() && !caller.SupportsArgv()) + CHK(context.CheckRefsMessage(caller2, team2, cookie)); + CHK(context.CheckNextMessage(caller2, team2, cookie, MSG_READY_TO_RUN)); + CHK(context.CheckNextMessage(caller2, team2, cookie, MSG_QUIT_REQUESTED)); + CHK(context.CheckNextMessage(caller2, team2, cookie, MSG_TERMINATED)); +} + +/* + @case 22 launch the app two times: B_EXCLUSIVE_LAUNCH | B_ARGV_ONLY + @results first app: ArgvReceived(), ReadyToRun(), QuitRequested() + (No second ArgvReceived()!) + second app: Launch() fails with B_ALREADY_RUNNING +*/ +static +void +CommonLaunchTest22(LaunchCaller &caller) +{ + LaunchCaller &caller2 = caller.Clone(); + LaunchContext context; + BRoster roster; + create_app(appFile1, appType1, false, true, + B_EXCLUSIVE_LAUNCH | B_ARGV_ONLY); + install_type(fileType1, appType1); + // launch app 1 + team_id team1; + CHK(context(caller, fileType1, &team1) == B_OK); + entry_ref ref1 = ref_for_team(team1); + CHK(ref_for_path(appFile1) == ref1); + check_app_type(appType1, appFile1); + context.WaitForMessage(team1, MSG_STARTED); + // launch app 2 + team_id team2; + CHK(context(caller2, fileType1, &team2) == B_ALREADY_RUNNING); + // checks 1 + context.Terminate(); + int32 cookie = 0; + CHK(context.CheckNextMessage(caller, team1, cookie, MSG_STARTED)); +// CHK(context.CheckMessageMessages(caller, team1, cookie)); + CHK(context.CheckArgvMessage(caller, team1, cookie, &ref1)); +// if (caller.SupportsRefs() && !caller.SupportsArgv()) +// CHK(context.CheckRefsMessage(caller, team1, cookie)); + CHK(context.CheckNextMessage(caller, team1, cookie, MSG_READY_TO_RUN)); + CHK(context.CheckNextMessage(caller, team1, cookie, MSG_QUIT_REQUESTED)); + CHK(context.CheckNextMessage(caller, team1, cookie, MSG_TERMINATED)); +} + +/* + @case 23 launch the app two times: B_EXCLUSIVE_LAUNCH + @results first app: {Message,Argv,Refs}Received()*, ReadyToRun(), + {Message,Argv,Refs}Received()*, QuitRequested() + second app: Launch() fails with B_ALREADY_RUNNING +*/ +static +void +CommonLaunchTest23(LaunchCaller &caller) +{ + LaunchCaller &caller2 = caller.Clone(); + LaunchContext context; + BRoster roster; + create_app(appFile1, appType1, false, true, + B_EXCLUSIVE_LAUNCH); + install_type(fileType1, appType1); + // launch app 1 + team_id team1; + CHK(context(caller, fileType1, &team1) == B_OK); + entry_ref ref1 = ref_for_team(team1); + CHK(ref_for_path(appFile1) == ref1); + check_app_type(appType1, appFile1); + context.WaitForMessage(team1, MSG_STARTED); + // launch app 2 + team_id team2; + CHK(context(caller2, fileType1, &team2) == B_ALREADY_RUNNING); + // checks 1 + context.Terminate(); + int32 cookie = 0; + CHK(context.CheckNextMessage(caller, team1, cookie, MSG_STARTED)); + CHK(context.CheckMessageMessages(caller, team1, cookie)); + CHK(context.CheckArgvMessage(caller, team1, cookie, &ref1)); + if (caller.SupportsRefs() && !caller.SupportsArgv()) + CHK(context.CheckRefsMessage(caller, team1, cookie)); + CHK(context.CheckNextMessage(caller, team1, cookie, MSG_READY_TO_RUN)); + CHK(context.CheckMessageMessages(caller, team1, cookie)); + CHK(context.CheckArgvMessage(caller, team1, cookie, &ref1)); + if (caller.SupportsRefs() && !caller.SupportsArgv()) + CHK(context.CheckRefsMessage(caller, team1, cookie)); + CHK(context.CheckNextMessage(caller, team1, cookie, MSG_QUIT_REQUESTED)); + CHK(context.CheckNextMessage(caller, team1, cookie, MSG_TERMINATED)); +} + +/* + @case 24 launch two apps with the same signature: + B_EXCLUSIVE_LAUNCH | B_ARGV_ONLY + @results first app: ArgvReceived(), ReadyToRun(), QuitRequested() + (No second ArgvReceived()!) + second app: Launch() fails with B_ALREADY_RUNNING +*/ +static +void +CommonLaunchTest24(LaunchCaller &caller) +{ + LaunchCaller &caller2 = caller.Clone(); + LaunchContext context; + BRoster roster; + // launch app 1 + create_app(appFile1, appType1, false, true, + B_EXCLUSIVE_LAUNCH | B_ARGV_ONLY); + install_type(fileType1, appType1); + team_id team1; + CHK(context(caller, fileType1, &team1) == B_OK); + entry_ref ref1 = ref_for_team(team1); + CHK(ref_for_path(appFile1) == ref1); + check_app_type(appType1, appFile1); + context.WaitForMessage(team1, MSG_STARTED); + // launch app 2 (greater modification time) + CHK(BMimeType(appType1).Delete() == B_OK); + create_app(appFile2, appType1, false, true, + B_EXCLUSIVE_LAUNCH | B_ARGV_ONLY); + set_file_time(appFile2, time(NULL) + 1); + team_id team2; + CHK(context(caller2, fileType1, &team2) == B_ALREADY_RUNNING); + // checks 1 + context.Terminate(); + int32 cookie = 0; + CHK(context.CheckNextMessage(caller, team1, cookie, MSG_STARTED)); +// CHK(context.CheckMessageMessages(caller, team1, cookie)); + CHK(context.CheckArgvMessage(caller, team1, cookie, &ref1)); +// if (caller.SupportsRefs() && !caller.SupportsArgv()) +// CHK(context.CheckRefsMessage(caller, team1, cookie)); + CHK(context.CheckNextMessage(caller, team1, cookie, MSG_READY_TO_RUN)); + CHK(context.CheckNextMessage(caller, team1, cookie, MSG_QUIT_REQUESTED)); + CHK(context.CheckNextMessage(caller, team1, cookie, MSG_TERMINATED)); +} + +/* + @case 25 launch two apps with the same signature: + B_EXCLUSIVE_LAUNCH + @results first app: {Message,Argv,Refs}Received()*, ReadyToRun(), + {Message,Argv,Refs}Received()*, QuitRequested() + second app: Launch() fails with B_ALREADY_RUNNING +*/ +static +void +CommonLaunchTest25(LaunchCaller &caller) +{ + LaunchCaller &caller2 = caller.Clone(); + LaunchContext context; + BRoster roster; + // launch app 1 + create_app(appFile1, appType1, false, true, + B_EXCLUSIVE_LAUNCH); + install_type(fileType1, appType1); + team_id team1; + CHK(context(caller, fileType1, &team1) == B_OK); + entry_ref ref1 = ref_for_team(team1); + CHK(ref_for_path(appFile1) == ref1); + check_app_type(appType1, appFile1); + context.WaitForMessage(team1, MSG_STARTED); + // launch app 2 (greater modification time) + CHK(BMimeType(appType1).Delete() == B_OK); + create_app(appFile2, appType1, false, true, + B_EXCLUSIVE_LAUNCH); + set_file_time(appFile2, time(NULL) + 1); + team_id team2; + CHK(context(caller2, fileType1, &team2) == B_ALREADY_RUNNING); + entry_ref ref2 = ref_for_path(appFile2); + // checks 1 + context.Terminate(); + int32 cookie = 0; + CHK(context.CheckNextMessage(caller, team1, cookie, MSG_STARTED)); + CHK(context.CheckMessageMessages(caller, team1, cookie)); + CHK(context.CheckArgvMessage(caller, team1, cookie, &ref1)); + if (caller.SupportsRefs() && !caller.SupportsArgv()) + CHK(context.CheckRefsMessage(caller, team1, cookie)); + CHK(context.CheckNextMessage(caller, team1, cookie, MSG_READY_TO_RUN)); + CHK(context.CheckMessageMessages(caller, team1, cookie)); + CHK(context.CheckArgvMessage(caller, team1, cookie, &ref2)); + if (caller.SupportsRefs() && !caller.SupportsArgv()) + CHK(context.CheckRefsMessage(caller, team1, cookie)); + CHK(context.CheckNextMessage(caller, team1, cookie, MSG_QUIT_REQUESTED)); + CHK(context.CheckNextMessage(caller, team1, cookie, MSG_TERMINATED)); +} + +/* + @case 26 launch two apps with the same signature: + first: B_EXCLUSIVE_LAUNCH, + second: B_EXCLUSIVE_LAUNCH | B_ARGV_ONLY => + @results first app: {Message,Argv,Refs}Received()*, ReadyToRun(), + {Message,Argv,Refs}Received()*, QuitRequested() + second app: Launch() fails with B_ALREADY_RUNNING +*/ +static +void +CommonLaunchTest26(LaunchCaller &caller) +{ + LaunchCaller &caller2 = caller.Clone(); + LaunchContext context; + BRoster roster; + // launch app 1 + create_app(appFile1, appType1, false, true, + B_EXCLUSIVE_LAUNCH); + install_type(fileType1, appType1); + team_id team1; + CHK(context(caller, fileType1, &team1) == B_OK); + entry_ref ref1 = ref_for_team(team1); + CHK(ref_for_path(appFile1) == ref1); + check_app_type(appType1, appFile1); + context.WaitForMessage(team1, MSG_STARTED); + // launch app 2 (greater modification time) + CHK(BMimeType(appType1).Delete() == B_OK); + create_app(appFile2, appType1, false, true, + B_EXCLUSIVE_LAUNCH | B_ARGV_ONLY); + set_file_time(appFile2, time(NULL) + 1); + team_id team2; + CHK(context(caller2, fileType1, &team2) == B_ALREADY_RUNNING); + entry_ref ref2 = ref_for_path(appFile2); + // checks 1 + context.Terminate(); + int32 cookie = 0; + CHK(context.CheckNextMessage(caller, team1, cookie, MSG_STARTED)); + CHK(context.CheckMessageMessages(caller, team1, cookie)); + CHK(context.CheckArgvMessage(caller, team1, cookie, &ref1)); + if (caller.SupportsRefs() && !caller.SupportsArgv()) + CHK(context.CheckRefsMessage(caller, team1, cookie)); + CHK(context.CheckNextMessage(caller, team1, cookie, MSG_READY_TO_RUN)); + CHK(context.CheckNextMessage(caller, team1, cookie, MSG_QUIT_REQUESTED)); + CHK(context.CheckNextMessage(caller, team1, cookie, MSG_TERMINATED)); +} + +/* + @case 27 launch two apps with the same signature: + first: B_EXCLUSIVE_LAUNCH | B_ARGV_ONLY, + second: B_EXCLUSIVE_LAUNCH + @results first app: ArgvReceived(), ReadyToRun(), QuitRequested() + (No second ArgvReceived()!) + second app: Launch() fails with B_ALREADY_RUNNING +*/ +static +void +CommonLaunchTest27(LaunchCaller &caller) +{ + LaunchCaller &caller2 = caller.Clone(); + LaunchContext context; + BRoster roster; + // launch app 1 + create_app(appFile1, appType1, false, true, + B_EXCLUSIVE_LAUNCH | B_ARGV_ONLY); + install_type(fileType1, appType1); + team_id team1; + CHK(context(caller, fileType1, &team1) == B_OK); + entry_ref ref1 = ref_for_team(team1); + CHK(ref_for_path(appFile1) == ref1); + check_app_type(appType1, appFile1); + context.WaitForMessage(team1, MSG_STARTED); + // launch app 2 (greater modification time) + CHK(BMimeType(appType1).Delete() == B_OK); + create_app(appFile2, appType1, false, true, + B_EXCLUSIVE_LAUNCH); + set_file_time(appFile2, time(NULL) + 1); + team_id team2; + CHK(context(caller2, fileType1, &team2) == B_ALREADY_RUNNING); + // checks 1 + context.Terminate(); + int32 cookie = 0; + CHK(context.CheckNextMessage(caller, team1, cookie, MSG_STARTED)); +// CHK(context.CheckMessageMessages(caller, team1, cookie)); + CHK(context.CheckArgvMessage(caller, team1, cookie, &ref1)); +// if (caller.SupportsRefs() && !caller.SupportsArgv()) +// CHK(context.CheckRefsMessage(caller, team1, cookie)); + CHK(context.CheckNextMessage(caller, team1, cookie, MSG_READY_TO_RUN)); + CHK(context.CheckNextMessage(caller, team1, cookie, MSG_QUIT_REQUESTED)); + CHK(context.CheckNextMessage(caller, team1, cookie, MSG_TERMINATED)); } typedef void commonTestFunction(LaunchCaller &caller); @@ -688,7 +1288,11 @@ static commonTestFunction *commonTestFunctions[] = { CommonLaunchTest4, CommonLaunchTest5, CommonLaunchTest6, CommonLaunchTest7, CommonLaunchTest8, CommonLaunchTest9, CommonLaunchTest10, CommonLaunchTest11, CommonLaunchTest12, - CommonLaunchTest13, CommonLaunchTest14 + CommonLaunchTest13, CommonLaunchTest14, CommonLaunchTest15, + CommonLaunchTest16, CommonLaunchTest17, CommonLaunchTest18, + CommonLaunchTest19, CommonLaunchTest20, CommonLaunchTest21, + CommonLaunchTest22, CommonLaunchTest23, CommonLaunchTest24, + CommonLaunchTest25, CommonLaunchTest26, CommonLaunchTest27 }; static int32 commonTestFunctionCount = sizeof(commonTestFunctions) / sizeof(commonTestFunction*); @@ -730,6 +1334,11 @@ public: BRoster roster; return roster.Launch(type, message, team); } + + virtual LaunchCaller *CloneInternal() + { + return new LaunchTypeCaller1; + } }; /* @@ -760,25 +1369,25 @@ void LaunchTester::LaunchTestA3() void LaunchTester::LaunchTestA4() { LaunchTypeCaller1 caller; - LaunchContext context(caller); + LaunchContext context; BRoster roster; create_app(appFile1, appType1); install_type(fileType1, appType1); team_id team; - CHK(context(fileType1, NULL, LaunchContext::kStandardArgc, + CHK(context(caller, fileType1, NULL, LaunchContext::kStandardArgc, LaunchContext::kStandardArgv, &team) == B_OK); entry_ref ref = ref_for_team(team); CHK(ref_for_path(appFile1) == ref); check_app_type(appType1, appFile1); context.Terminate(); int32 cookie = 0; - CHK(context.CheckNextMessage(team, cookie, MSG_STARTED)); -// CHK(context.CheckMessageMessages(team, cookie)); -// CHK(context.CheckArgvMessage(team, cookie, &ref)); -// CHK(context.CheckRefsMessage(team, cookie)); - CHK(context.CheckNextMessage(team, cookie, MSG_READY_TO_RUN)); - CHK(context.CheckNextMessage(team, cookie, MSG_QUIT_REQUESTED)); - CHK(context.CheckNextMessage(team, cookie, MSG_TERMINATED)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); +// CHK(context.CheckMessageMessages(caller, team, cookie)); +// CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); +// CHK(context.CheckRefsMessage(caller, team, cookie)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); } /* @@ -817,6 +1426,11 @@ public: return roster.Launch(type, messages, team); } virtual int32 SupportsMessages() const { return 1000; } + + virtual LaunchCaller *CloneInternal() + { + return new LaunchTypeCaller2; + } }; /* @@ -847,25 +1461,25 @@ void LaunchTester::LaunchTestB3() void LaunchTester::LaunchTestB4() { LaunchTypeCaller2 caller; - LaunchContext context(caller); + LaunchContext context; BRoster roster; create_app(appFile1, appType1); install_type(fileType1, appType1); team_id team; - CHK(context(fileType1, NULL, LaunchContext::kStandardArgc, + CHK(context(caller, fileType1, NULL, LaunchContext::kStandardArgc, LaunchContext::kStandardArgv, &team) == B_OK); entry_ref ref = ref_for_team(team); CHK(ref_for_path(appFile1) == ref); check_app_type(appType1, appFile1); context.Terminate(); int32 cookie = 0; - CHK(context.CheckNextMessage(team, cookie, MSG_STARTED)); -// CHK(context.CheckMessageMessages(team, cookie)); -// CHK(context.CheckArgvMessage(team, cookie, &ref)); -// CHK(context.CheckRefsMessage(team, cookie)); - CHK(context.CheckNextMessage(team, cookie, MSG_READY_TO_RUN)); - CHK(context.CheckNextMessage(team, cookie, MSG_QUIT_REQUESTED)); - CHK(context.CheckNextMessage(team, cookie, MSG_TERMINATED)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); +// CHK(context.CheckMessageMessages(caller, team, cookie)); +// CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); +// CHK(context.CheckRefsMessage(caller, team, cookie)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); } /* @@ -880,26 +1494,26 @@ void LaunchTester::LaunchTestB4() void LaunchTester::LaunchTestB5() { LaunchTypeCaller2 caller; - LaunchContext context(caller); + LaunchContext context; BRoster roster; create_app(appFile1, appType1); install_type(fileType1, appType1); team_id team; BList list; - CHK(context(fileType1, &list, LaunchContext::kStandardArgc, + CHK(context(caller, fileType1, &list, LaunchContext::kStandardArgc, LaunchContext::kStandardArgv, &team) == B_OK); entry_ref ref = ref_for_team(team); CHK(ref_for_path(appFile1) == ref); check_app_type(appType1, appFile1); context.Terminate(); int32 cookie = 0; - CHK(context.CheckNextMessage(team, cookie, MSG_STARTED)); -// CHK(context.CheckMessageMessages(team, cookie)); -// CHK(context.CheckArgvMessage(team, cookie, &ref)); -// CHK(context.CheckRefsMessage(team, cookie)); - CHK(context.CheckNextMessage(team, cookie, MSG_READY_TO_RUN)); - CHK(context.CheckNextMessage(team, cookie, MSG_QUIT_REQUESTED)); - CHK(context.CheckNextMessage(team, cookie, MSG_TERMINATED)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); +// CHK(context.CheckMessageMessages(caller, team, cookie)); +// CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); +// CHK(context.CheckRefsMessage(caller, team, cookie)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); } /* @@ -941,6 +1555,11 @@ public: return roster.Launch(type, argc, const_cast(argv), team); } virtual int32 SupportsMessages() const { return 0; } + + virtual LaunchCaller *CloneInternal() + { + return new LaunchTypeCaller3; + } }; /* @@ -971,24 +1590,24 @@ void LaunchTester::LaunchTestC3() void LaunchTester::LaunchTestC4() { LaunchTypeCaller3 caller; - LaunchContext context(caller); + LaunchContext context; BRoster roster; create_app(appFile1, appType1); install_type(fileType1, appType1); team_id team; - CHK(context(fileType1, NULL, 0, (const char**)NULL, &team) == B_OK); + CHK(context(caller, fileType1, NULL, 0, (const char**)NULL, &team) == B_OK); entry_ref ref = ref_for_team(team); CHK(ref_for_path(appFile1) == ref); check_app_type(appType1, appFile1); context.Terminate(); int32 cookie = 0; - CHK(context.CheckNextMessage(team, cookie, MSG_STARTED)); -// CHK(context.CheckMessageMessages(team, cookie)); -// CHK(context.CheckArgvMessage(team, cookie, &ref)); -// CHK(context.CheckRefsMessage(team, cookie)); - CHK(context.CheckNextMessage(team, cookie, MSG_READY_TO_RUN)); - CHK(context.CheckNextMessage(team, cookie, MSG_QUIT_REQUESTED)); - CHK(context.CheckNextMessage(team, cookie, MSG_TERMINATED)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); +// CHK(context.CheckMessageMessages(caller, team, cookie)); +// CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); +// CHK(context.CheckRefsMessage(caller, team, cookie)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); } // SimpleFileCaller1 @@ -1008,6 +1627,11 @@ public: virtual bool SupportsRefs() const { return true; } virtual const entry_ref *Ref() const { return &fRef; } + virtual LaunchCaller *CloneInternal() + { + return new SimpleFileCaller1; + } + protected: entry_ref fRef; }; @@ -1024,6 +1648,11 @@ public: fRef = create_file(testFile1, type); return roster.Launch(&fRef, message, team); } + + virtual LaunchCaller *CloneInternal() + { + return new FileWithTypeCaller1; + } }; // SniffFileTypeCaller1 @@ -1039,6 +1668,11 @@ public: install_type(fileType1, NULL, "1.0 [0] ('UnIQe pAtTeRn')"); return roster.Launch(&fRef, message, team); } + + virtual LaunchCaller *CloneInternal() + { + return new SniffFileTypeCaller1; + } }; /* @@ -1086,9 +1720,9 @@ void LaunchTester::LaunchTestD3() install_type(fileType1, appType1); entry_ref fileRef(create_file(testFile1, fileType1, appType2)); SimpleFileCaller1 caller(fileRef); - LaunchContext context(caller); + LaunchContext context; team_id team; - CHK(context(fileType1, context.StandardMessages(), + CHK(context(caller, fileType1, context.StandardMessages(), LaunchContext::kStandardArgc, LaunchContext::kStandardArgv, &team) == B_OK); entry_ref ref = ref_for_team(team); @@ -1097,13 +1731,13 @@ void LaunchTester::LaunchTestD3() context.Terminate(); int32 cookie = 0; - CHK(context.CheckNextMessage(team, cookie, MSG_STARTED)); - CHK(context.CheckMessageMessages(team, cookie)); -// CHK(context.CheckArgvMessage(team, cookie, &ref)); - CHK(context.CheckRefsMessage(team, cookie)); - CHK(context.CheckNextMessage(team, cookie, MSG_READY_TO_RUN)); - CHK(context.CheckNextMessage(team, cookie, MSG_QUIT_REQUESTED)); - CHK(context.CheckNextMessage(team, cookie, MSG_TERMINATED)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); + CHK(context.CheckMessageMessages(caller, team, cookie)); +// CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); + CHK(context.CheckRefsMessage(caller, team, cookie)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); } /* @@ -1121,12 +1755,12 @@ void LaunchTester::LaunchTestD4() create_app(appFile1, appType1); entry_ref fileRef(create_file(testFile1, NULL, appType1)); SimpleFileCaller1 caller(fileRef); - LaunchContext context(caller); + LaunchContext context; team_id team; BMessage message(MSG_1); BList messages; messages.AddItem(&message); - CHK(context(fileType1, context.StandardMessages(), + CHK(context(caller, fileType1, context.StandardMessages(), LaunchContext::kStandardArgc, LaunchContext::kStandardArgv, &team) == B_OK); entry_ref ref = ref_for_team(team); @@ -1135,13 +1769,13 @@ void LaunchTester::LaunchTestD4() context.Terminate(); int32 cookie = 0; - CHK(context.CheckNextMessage(team, cookie, MSG_STARTED)); - CHK(context.CheckMessageMessages(team, cookie)); -// CHK(context.CheckArgvMessage(team, cookie, &ref)); - CHK(context.CheckRefsMessage(team, cookie)); - CHK(context.CheckNextMessage(team, cookie, MSG_READY_TO_RUN)); - CHK(context.CheckNextMessage(team, cookie, MSG_QUIT_REQUESTED)); - CHK(context.CheckNextMessage(team, cookie, MSG_TERMINATED)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); + CHK(context.CheckMessageMessages(caller, team, cookie)); +// CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); + CHK(context.CheckRefsMessage(caller, team, cookie)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); } /* @@ -1162,12 +1796,12 @@ void LaunchTester::LaunchTestD5() install_type(fileType1, appType1); entry_ref fileRef(create_file(testFile1, fileType1, NULL, appFile2)); SimpleFileCaller1 caller(fileRef); - LaunchContext context(caller); + LaunchContext context; team_id team; BMessage message(MSG_1); BList messages; messages.AddItem(&message); - CHK(context(fileType1, context.StandardMessages(), + CHK(context(caller, fileType1, context.StandardMessages(), LaunchContext::kStandardArgc, LaunchContext::kStandardArgv, &team) == B_OK); entry_ref ref = ref_for_team(team); @@ -1176,13 +1810,13 @@ void LaunchTester::LaunchTestD5() context.Terminate(); int32 cookie = 0; - CHK(context.CheckNextMessage(team, cookie, MSG_STARTED)); - CHK(context.CheckMessageMessages(team, cookie)); -// CHK(context.CheckArgvMessage(team, cookie, &ref)); - CHK(context.CheckRefsMessage(team, cookie)); - CHK(context.CheckNextMessage(team, cookie, MSG_READY_TO_RUN)); - CHK(context.CheckNextMessage(team, cookie, MSG_QUIT_REQUESTED)); - CHK(context.CheckNextMessage(team, cookie, MSG_TERMINATED)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); + CHK(context.CheckMessageMessages(caller, team, cookie)); +// CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); + CHK(context.CheckRefsMessage(caller, team, cookie)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); } /* @@ -1228,12 +1862,12 @@ void LaunchTester::LaunchTestD7() system((string("ln -s ") + testFile1 + " " + testLink1).c_str()); entry_ref linkRef(ref_for_path(testLink1)); SimpleFileCaller1 caller(linkRef); - LaunchContext context(caller); + LaunchContext context; team_id team; BMessage message(MSG_1); BList messages; messages.AddItem(&message); - CHK(context(fileType1, context.StandardMessages(), + CHK(context(caller, fileType1, context.StandardMessages(), LaunchContext::kStandardArgc, LaunchContext::kStandardArgv, &team) == B_OK); entry_ref ref = ref_for_team(team); @@ -1242,13 +1876,13 @@ void LaunchTester::LaunchTestD7() context.Terminate(); int32 cookie = 0; - CHK(context.CheckNextMessage(team, cookie, MSG_STARTED)); - CHK(context.CheckMessageMessages(team, cookie)); -// CHK(context.CheckArgvMessage(team, cookie, &ref)); - CHK(context.CheckRefsMessage(team, cookie)); - CHK(context.CheckNextMessage(team, cookie, MSG_READY_TO_RUN)); - CHK(context.CheckNextMessage(team, cookie, MSG_QUIT_REQUESTED)); - CHK(context.CheckNextMessage(team, cookie, MSG_TERMINATED)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); + CHK(context.CheckMessageMessages(caller, team, cookie)); +// CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); + CHK(context.CheckRefsMessage(caller, team, cookie)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); } /* @@ -1305,12 +1939,12 @@ void LaunchTester::LaunchTestD10() create_app(appFile1, appType1); entry_ref fileRef(create_file(testFile1, NULL, appType1)); SimpleFileCaller1 caller(fileRef); - LaunchContext context(caller); + LaunchContext context; team_id team; BMessage message(MSG_1); BList messages; messages.AddItem(&message); - CHK(context(fileType1, NULL, LaunchContext::kStandardArgc, + CHK(context(caller, fileType1, NULL, LaunchContext::kStandardArgc, LaunchContext::kStandardArgv, &team) == B_OK); entry_ref ref = ref_for_team(team); CHK(ref_for_path(appFile1) == ref); @@ -1318,13 +1952,13 @@ void LaunchTester::LaunchTestD10() context.Terminate(); int32 cookie = 0; - CHK(context.CheckNextMessage(team, cookie, MSG_STARTED)); -// CHK(context.CheckMessageMessages(team, cookie)); -// CHK(context.CheckArgvMessage(team, cookie, &ref)); - CHK(context.CheckRefsMessage(team, cookie)); - CHK(context.CheckNextMessage(team, cookie, MSG_READY_TO_RUN)); - CHK(context.CheckNextMessage(team, cookie, MSG_QUIT_REQUESTED)); - CHK(context.CheckNextMessage(team, cookie, MSG_TERMINATED)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); +// CHK(context.CheckMessageMessages(caller, team, cookie)); +// CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); + CHK(context.CheckRefsMessage(caller, team, cookie)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); } // SimpleFileCaller2 @@ -1343,6 +1977,11 @@ public: virtual bool SupportsRefs() const { return true; } virtual const entry_ref *Ref() const { return &fRef; } + virtual LaunchCaller *CloneInternal() + { + return new SimpleFileCaller2; + } + protected: entry_ref fRef; }; @@ -1357,6 +1996,11 @@ public: fRef = create_file(testFile1, type); return roster.Launch(&fRef, messages, team); } + + virtual LaunchCaller *CloneInternal() + { + return new FileWithTypeCaller2; + } }; // SniffFileTypeCaller2 @@ -1370,6 +2014,11 @@ public: install_type(fileType1, NULL, "1.0 [0] ('UnIQe pAtTeRn')"); return roster.Launch(&fRef, messages, team); } + + virtual LaunchCaller *CloneInternal() + { + return new SniffFileTypeCaller2; + } }; /* @@ -1418,9 +2067,9 @@ void LaunchTester::LaunchTestE3() install_type(fileType1, appType1); entry_ref fileRef(create_file(testFile1, fileType1, appType2)); SimpleFileCaller2 caller(fileRef); - LaunchContext context(caller); + LaunchContext context; team_id team; - CHK(context(fileType1, context.StandardMessages(), + CHK(context(caller, fileType1, context.StandardMessages(), LaunchContext::kStandardArgc, LaunchContext::kStandardArgv, &team) == B_OK); entry_ref ref = ref_for_team(team); @@ -1429,13 +2078,13 @@ void LaunchTester::LaunchTestE3() context.Terminate(); int32 cookie = 0; - CHK(context.CheckNextMessage(team, cookie, MSG_STARTED)); - CHK(context.CheckMessageMessages(team, cookie)); -// CHK(context.CheckArgvMessage(team, cookie, &ref)); - CHK(context.CheckRefsMessage(team, cookie)); - CHK(context.CheckNextMessage(team, cookie, MSG_READY_TO_RUN)); - CHK(context.CheckNextMessage(team, cookie, MSG_QUIT_REQUESTED)); - CHK(context.CheckNextMessage(team, cookie, MSG_TERMINATED)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); + CHK(context.CheckMessageMessages(caller, team, cookie)); +// CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); + CHK(context.CheckRefsMessage(caller, team, cookie)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); } /* @@ -1453,12 +2102,12 @@ void LaunchTester::LaunchTestE4() create_app(appFile1, appType1); entry_ref fileRef(create_file(testFile1, NULL, appType1)); SimpleFileCaller2 caller(fileRef); - LaunchContext context(caller); + LaunchContext context; team_id team; BMessage message(MSG_1); BList messages; messages.AddItem(&message); - CHK(context(fileType1, context.StandardMessages(), + CHK(context(caller, fileType1, context.StandardMessages(), LaunchContext::kStandardArgc, LaunchContext::kStandardArgv, &team) == B_OK); entry_ref ref = ref_for_team(team); @@ -1467,13 +2116,13 @@ void LaunchTester::LaunchTestE4() context.Terminate(); int32 cookie = 0; - CHK(context.CheckNextMessage(team, cookie, MSG_STARTED)); - CHK(context.CheckMessageMessages(team, cookie)); -// CHK(context.CheckArgvMessage(team, cookie, &ref)); - CHK(context.CheckRefsMessage(team, cookie)); - CHK(context.CheckNextMessage(team, cookie, MSG_READY_TO_RUN)); - CHK(context.CheckNextMessage(team, cookie, MSG_QUIT_REQUESTED)); - CHK(context.CheckNextMessage(team, cookie, MSG_TERMINATED)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); + CHK(context.CheckMessageMessages(caller, team, cookie)); +// CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); + CHK(context.CheckRefsMessage(caller, team, cookie)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); } /* @@ -1494,12 +2143,12 @@ void LaunchTester::LaunchTestE5() install_type(fileType1, appType1); entry_ref fileRef(create_file(testFile1, fileType1, NULL, appFile2)); SimpleFileCaller2 caller(fileRef); - LaunchContext context(caller); + LaunchContext context; team_id team; BMessage message(MSG_1); BList messages; messages.AddItem(&message); - CHK(context(fileType1, context.StandardMessages(), + CHK(context(caller, fileType1, context.StandardMessages(), LaunchContext::kStandardArgc, LaunchContext::kStandardArgv, &team) == B_OK); entry_ref ref = ref_for_team(team); @@ -1508,13 +2157,13 @@ void LaunchTester::LaunchTestE5() context.Terminate(); int32 cookie = 0; - CHK(context.CheckNextMessage(team, cookie, MSG_STARTED)); - CHK(context.CheckMessageMessages(team, cookie)); -// CHK(context.CheckArgvMessage(team, cookie, &ref)); - CHK(context.CheckRefsMessage(team, cookie)); - CHK(context.CheckNextMessage(team, cookie, MSG_READY_TO_RUN)); - CHK(context.CheckNextMessage(team, cookie, MSG_QUIT_REQUESTED)); - CHK(context.CheckNextMessage(team, cookie, MSG_TERMINATED)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); + CHK(context.CheckMessageMessages(caller, team, cookie)); +// CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); + CHK(context.CheckRefsMessage(caller, team, cookie)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); } /* @@ -1559,12 +2208,12 @@ void LaunchTester::LaunchTestE7() system((string("ln -s ") + testFile1 + " " + testLink1).c_str()); entry_ref linkRef(ref_for_path(testLink1)); SimpleFileCaller2 caller(linkRef); - LaunchContext context(caller); + LaunchContext context; team_id team; BMessage message(MSG_1); BList messages; messages.AddItem(&message); - CHK(context(fileType1, context.StandardMessages(), + CHK(context(caller, fileType1, context.StandardMessages(), LaunchContext::kStandardArgc, LaunchContext::kStandardArgv, &team) == B_OK); entry_ref ref = ref_for_team(team); @@ -1573,13 +2222,13 @@ void LaunchTester::LaunchTestE7() context.Terminate(); int32 cookie = 0; - CHK(context.CheckNextMessage(team, cookie, MSG_STARTED)); - CHK(context.CheckMessageMessages(team, cookie)); -// CHK(context.CheckArgvMessage(team, cookie, &ref)); - CHK(context.CheckRefsMessage(team, cookie)); - CHK(context.CheckNextMessage(team, cookie, MSG_READY_TO_RUN)); - CHK(context.CheckNextMessage(team, cookie, MSG_QUIT_REQUESTED)); - CHK(context.CheckNextMessage(team, cookie, MSG_TERMINATED)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); + CHK(context.CheckMessageMessages(caller, team, cookie)); +// CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); + CHK(context.CheckRefsMessage(caller, team, cookie)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); } /* @@ -1636,12 +2285,12 @@ void LaunchTester::LaunchTestE10() create_app(appFile1, appType1); entry_ref fileRef(create_file(testFile1, NULL, appType1)); SimpleFileCaller2 caller(fileRef); - LaunchContext context(caller); + LaunchContext context; team_id team; BMessage message(MSG_1); BList messages; messages.AddItem(&message); - CHK(context(fileType1, NULL, LaunchContext::kStandardArgc, + CHK(context(caller, fileType1, NULL, LaunchContext::kStandardArgc, LaunchContext::kStandardArgv, &team) == B_OK); entry_ref ref = ref_for_team(team); CHK(ref_for_path(appFile1) == ref); @@ -1649,13 +2298,13 @@ void LaunchTester::LaunchTestE10() context.Terminate(); int32 cookie = 0; - CHK(context.CheckNextMessage(team, cookie, MSG_STARTED)); -// CHK(context.CheckMessageMessages(team, cookie)); -// CHK(context.CheckArgvMessage(team, cookie, &ref)); - CHK(context.CheckRefsMessage(team, cookie)); - CHK(context.CheckNextMessage(team, cookie, MSG_READY_TO_RUN)); - CHK(context.CheckNextMessage(team, cookie, MSG_QUIT_REQUESTED)); - CHK(context.CheckNextMessage(team, cookie, MSG_TERMINATED)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); +// CHK(context.CheckMessageMessages(caller, team, cookie)); +// CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); + CHK(context.CheckRefsMessage(caller, team, cookie)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); } /* @@ -1674,13 +2323,13 @@ void LaunchTester::LaunchTestE11() create_app(appFile1, appType1); entry_ref fileRef(create_file(testFile1, NULL, appType1)); SimpleFileCaller2 caller(fileRef); - LaunchContext context(caller); + LaunchContext context; team_id team; BMessage message(MSG_1); BList messages; messages.AddItem(&message); BList list; - CHK(context(fileType1, &list, LaunchContext::kStandardArgc, + CHK(context(caller, fileType1, &list, LaunchContext::kStandardArgc, LaunchContext::kStandardArgv, &team) == B_OK); entry_ref ref = ref_for_team(team); CHK(ref_for_path(appFile1) == ref); @@ -1688,13 +2337,13 @@ void LaunchTester::LaunchTestE11() context.Terminate(); int32 cookie = 0; - CHK(context.CheckNextMessage(team, cookie, MSG_STARTED)); -// CHK(context.CheckMessageMessages(team, cookie)); -// CHK(context.CheckArgvMessage(team, cookie, &ref)); - CHK(context.CheckRefsMessage(team, cookie)); - CHK(context.CheckNextMessage(team, cookie, MSG_READY_TO_RUN)); - CHK(context.CheckNextMessage(team, cookie, MSG_QUIT_REQUESTED)); - CHK(context.CheckNextMessage(team, cookie, MSG_TERMINATED)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); +// CHK(context.CheckMessageMessages(caller, team, cookie)); +// CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); + CHK(context.CheckRefsMessage(caller, team, cookie)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); } // SimpleFileCaller3 @@ -1713,6 +2362,11 @@ public: virtual bool SupportsRefs() const { return true; } virtual const entry_ref *Ref() const { return &fRef; } + virtual LaunchCaller *CloneInternal() + { + return new SimpleFileCaller3; + } + protected: entry_ref fRef; }; @@ -1727,6 +2381,11 @@ public: fRef = create_file(testFile1, type); return roster.Launch(&fRef, argc, argv, team); } + + virtual LaunchCaller *CloneInternal() + { + return new FileWithTypeCaller3; + } }; // SniffFileTypeCaller3 @@ -1740,6 +2399,11 @@ public: install_type(fileType1, NULL, "1.0 [0] ('UnIQe pAtTeRn')"); return roster.Launch(&fRef, argc, argv, team); } + + virtual LaunchCaller *CloneInternal() + { + return new SniffFileTypeCaller3; + } }; /* @@ -1788,9 +2452,9 @@ void LaunchTester::LaunchTestF3() install_type(fileType1, appType1); entry_ref fileRef(create_file(testFile1, fileType1, appType2)); SimpleFileCaller3 caller(fileRef); - LaunchContext context(caller); + LaunchContext context; team_id team; - CHK(context(fileType1, context.StandardMessages(), + CHK(context(caller, fileType1, context.StandardMessages(), LaunchContext::kStandardArgc, LaunchContext::kStandardArgv, &team) == B_OK); entry_ref ref = ref_for_team(team); @@ -1799,13 +2463,13 @@ void LaunchTester::LaunchTestF3() context.Terminate(); int32 cookie = 0; - CHK(context.CheckNextMessage(team, cookie, MSG_STARTED)); -// CHK(context.CheckMessageMessages(team, cookie)); - CHK(context.CheckArgvMessage(team, cookie, &ref)); -// CHK(context.CheckRefsMessage(team, cookie)); - CHK(context.CheckNextMessage(team, cookie, MSG_READY_TO_RUN)); - CHK(context.CheckNextMessage(team, cookie, MSG_QUIT_REQUESTED)); - CHK(context.CheckNextMessage(team, cookie, MSG_TERMINATED)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); +// CHK(context.CheckMessageMessages(caller, team, cookie)); + CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); +// CHK(context.CheckRefsMessage(caller, team, cookie)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); } /* @@ -1823,12 +2487,12 @@ void LaunchTester::LaunchTestF4() create_app(appFile1, appType1); entry_ref fileRef(create_file(testFile1, NULL, appType1)); SimpleFileCaller3 caller(fileRef); - LaunchContext context(caller); + LaunchContext context; team_id team; BMessage message(MSG_1); BList messages; messages.AddItem(&message); - CHK(context(fileType1, context.StandardMessages(), + CHK(context(caller, fileType1, context.StandardMessages(), LaunchContext::kStandardArgc, LaunchContext::kStandardArgv, &team) == B_OK); entry_ref ref = ref_for_team(team); @@ -1837,13 +2501,13 @@ void LaunchTester::LaunchTestF4() context.Terminate(); int32 cookie = 0; - CHK(context.CheckNextMessage(team, cookie, MSG_STARTED)); -// CHK(context.CheckMessageMessages(team, cookie)); - CHK(context.CheckArgvMessage(team, cookie, &ref)); -// CHK(context.CheckRefsMessage(team, cookie)); - CHK(context.CheckNextMessage(team, cookie, MSG_READY_TO_RUN)); - CHK(context.CheckNextMessage(team, cookie, MSG_QUIT_REQUESTED)); - CHK(context.CheckNextMessage(team, cookie, MSG_TERMINATED)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); +// CHK(context.CheckMessageMessages(caller, team, cookie)); + CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); +// CHK(context.CheckRefsMessage(caller, team, cookie)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); } /* @@ -1864,12 +2528,12 @@ void LaunchTester::LaunchTestF5() install_type(fileType1, appType1); entry_ref fileRef(create_file(testFile1, fileType1, NULL, appFile2)); SimpleFileCaller3 caller(fileRef); - LaunchContext context(caller); + LaunchContext context; team_id team; BMessage message(MSG_1); BList messages; messages.AddItem(&message); - CHK(context(fileType1, context.StandardMessages(), + CHK(context(caller, fileType1, context.StandardMessages(), LaunchContext::kStandardArgc, LaunchContext::kStandardArgv, &team) == B_OK); entry_ref ref = ref_for_team(team); @@ -1878,13 +2542,13 @@ void LaunchTester::LaunchTestF5() context.Terminate(); int32 cookie = 0; - CHK(context.CheckNextMessage(team, cookie, MSG_STARTED)); -// CHK(context.CheckMessageMessages(team, cookie)); - CHK(context.CheckArgvMessage(team, cookie, &ref)); -// CHK(context.CheckRefsMessage(team, cookie)); - CHK(context.CheckNextMessage(team, cookie, MSG_READY_TO_RUN)); - CHK(context.CheckNextMessage(team, cookie, MSG_QUIT_REQUESTED)); - CHK(context.CheckNextMessage(team, cookie, MSG_TERMINATED)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); +// CHK(context.CheckMessageMessages(caller, team, cookie)); + CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); +// CHK(context.CheckRefsMessage(caller, team, cookie)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); } /* @@ -1929,12 +2593,12 @@ void LaunchTester::LaunchTestF7() system((string("ln -s ") + testFile1 + " " + testLink1).c_str()); entry_ref linkRef(ref_for_path(testLink1)); SimpleFileCaller3 caller(linkRef); - LaunchContext context(caller); + LaunchContext context; team_id team; BMessage message(MSG_1); BList messages; messages.AddItem(&message); - CHK(context(fileType1, context.StandardMessages(), + CHK(context(caller, fileType1, context.StandardMessages(), LaunchContext::kStandardArgc, LaunchContext::kStandardArgv, &team) == B_OK); entry_ref ref = ref_for_team(team); @@ -1943,13 +2607,13 @@ void LaunchTester::LaunchTestF7() context.Terminate(); int32 cookie = 0; - CHK(context.CheckNextMessage(team, cookie, MSG_STARTED)); -// CHK(context.CheckMessageMessages(team, cookie)); - CHK(context.CheckArgvMessage(team, cookie, &ref)); -// CHK(context.CheckRefsMessage(team, cookie)); - CHK(context.CheckNextMessage(team, cookie, MSG_READY_TO_RUN)); - CHK(context.CheckNextMessage(team, cookie, MSG_QUIT_REQUESTED)); - CHK(context.CheckNextMessage(team, cookie, MSG_TERMINATED)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); +// CHK(context.CheckMessageMessages(caller, team, cookie)); + CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); +// CHK(context.CheckRefsMessage(caller, team, cookie)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); } /* @@ -2006,25 +2670,25 @@ void LaunchTester::LaunchTestF10() create_app(appFile1, appType1); entry_ref fileRef(create_file(testFile1, NULL, appType1)); SimpleFileCaller3 caller(fileRef); - LaunchContext context(caller); + LaunchContext context; team_id team; BMessage message(MSG_1); BList messages; messages.AddItem(&message); - CHK(context(fileType1, NULL, 0, NULL, &team) == B_OK); + CHK(context(caller, fileType1, NULL, 0, NULL, &team) == B_OK); entry_ref ref = ref_for_team(team); CHK(ref_for_path(appFile1) == ref); check_app_type(appType1, appFile1); context.Terminate(); int32 cookie = 0; - CHK(context.CheckNextMessage(team, cookie, MSG_STARTED)); -// CHK(context.CheckMessageMessages(team, cookie)); -// CHK(context.CheckArgvMessage(team, cookie, &ref)); - CHK(context.CheckRefsMessage(team, cookie)); - CHK(context.CheckNextMessage(team, cookie, MSG_READY_TO_RUN)); - CHK(context.CheckNextMessage(team, cookie, MSG_QUIT_REQUESTED)); - CHK(context.CheckNextMessage(team, cookie, MSG_TERMINATED)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); +// CHK(context.CheckMessageMessages(caller, team, cookie)); +// CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); + CHK(context.CheckRefsMessage(caller, team, cookie)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); } /* @@ -2043,25 +2707,25 @@ void LaunchTester::LaunchTestF11() create_app(appFile1, appType1); entry_ref fileRef(create_file(testFile1, NULL, appType1)); SimpleFileCaller3 caller(fileRef); - LaunchContext context(caller); + LaunchContext context; team_id team; BMessage message(MSG_1); BList messages; messages.AddItem(&message); - CHK(context(fileType1, NULL, 1, NULL, &team) == B_OK); + CHK(context(caller, fileType1, NULL, 1, NULL, &team) == B_OK); entry_ref ref = ref_for_team(team); CHK(ref_for_path(appFile1) == ref); check_app_type(appType1, appFile1); context.Terminate(); int32 cookie = 0; - CHK(context.CheckNextMessage(team, cookie, MSG_STARTED)); -// CHK(context.CheckMessageMessages(team, cookie)); -// CHK(context.CheckArgvMessage(team, cookie, &ref)); - CHK(context.CheckRefsMessage(team, cookie)); - CHK(context.CheckNextMessage(team, cookie, MSG_READY_TO_RUN)); - CHK(context.CheckNextMessage(team, cookie, MSG_QUIT_REQUESTED)); - CHK(context.CheckNextMessage(team, cookie, MSG_TERMINATED)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_STARTED)); +// CHK(context.CheckMessageMessages(caller, team, cookie)); +// CHK(context.CheckArgvMessage(caller, team, cookie, &ref)); + CHK(context.CheckRefsMessage(caller, team, cookie)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_READY_TO_RUN)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_QUIT_REQUESTED)); + CHK(context.CheckNextMessage(caller, team, cookie, MSG_TERMINATED)); } diff --git a/src/tests/kits/app/broster/LaunchTesterHelper.cpp b/src/tests/kits/app/broster/LaunchTesterHelper.cpp index a8f1488d22..14f6521dba 100644 --- a/src/tests/kits/app/broster/LaunchTesterHelper.cpp +++ b/src/tests/kits/app/broster/LaunchTesterHelper.cpp @@ -29,6 +29,40 @@ public: bigtime_t when; }; +// Sleeper +class LaunchContext::Sleeper { +public: + Sleeper() : fMessageCode(0), fSemaphore(-1) {} + + ~Sleeper() + { + delete_sem(fSemaphore); + } + + status_t Init(uint32 messageCode) + { + fMessageCode = messageCode; + fSemaphore = create_sem(0, "sleeper sem"); + return (fSemaphore >= 0 ? B_OK : fSemaphore); + } + + uint32 MessageCode() const { return fMessageCode; } + + status_t Sleep(bigtime_t timeout = B_INFINITE_TIMEOUT) + { + return acquire_sem_etc(fSemaphore, 1, B_RELATIVE_TIMEOUT, timeout); + } + + status_t WakeUp() + { + return release_sem(fSemaphore); + } + +private: + uint32 fMessageCode; + sem_id fSemaphore; +}; + // AppInfo class LaunchContext::AppInfo { public: @@ -76,6 +110,7 @@ public: message->message = _message; message->when = system_time(); fMessages.AddItem(message); + NotifySleepers(_message.what); } LaunchContext::Message *RemoveMessage(int32 index) @@ -88,17 +123,49 @@ public: return (LaunchContext::Message*)fMessages.ItemAt(index); } + LaunchContext::Message *FindMessage(uint32 messageCode, + int32 startIndex = 0) const + { + LaunchContext::Message *message = NULL; + for (int32 i = startIndex; (message = MessageAt(i)) != NULL; i++) { + if (message->message.what == messageCode) + break; + } + return message; + } + + void AddSleeper(Sleeper *sleeper) + { + fSleepers.AddItem(sleeper); + } + + void RemoveSleeper(Sleeper *sleeper) + { + fSleepers.RemoveItem(sleeper); + } + + void NotifySleepers(uint32 messageCode) + { + for (int32 i = 0; + Sleeper *sleeper = (Sleeper*)fSleepers.ItemAt(i); + i++) { + if (sleeper->MessageCode() == messageCode) + sleeper->WakeUp(); + } + } + private: team_id fTeam; BMessenger fMessenger; BList fMessages; bool fTerminating; + BList fSleepers; }; // constructor -LaunchContext::LaunchContext(LaunchCaller &caller) - : fCaller(caller), - fAppInfos(), +LaunchContext::LaunchContext() + : fAppInfos(), + fSleepers(), fLock(), fAppThread(B_ERROR), fTerminator(B_ERROR), @@ -133,7 +200,8 @@ LaunchContext::~LaunchContext() // () status_t -LaunchContext::operator()(const char *type, team_id *team) +LaunchContext::operator()(LaunchCaller &caller, const char *type, + team_id *team) { BMessage message1(MSG_1); BMessage message2(MSG_2); @@ -142,28 +210,20 @@ LaunchContext::operator()(const char *type, team_id *team) messages.AddItem(&message1); messages.AddItem(&message2); messages.AddItem(&message3); - return (*this)(type, &messages, kStandardArgc, kStandardArgv, team); + return (*this)(caller, type, &messages, kStandardArgc, kStandardArgv, + team); } // () status_t -LaunchContext::operator()(const char *type, BList *messages, int32 argc, - const char **argv, team_id *team) +LaunchContext::operator()(LaunchCaller &caller, const char *type, + BList *messages, int32 argc, const char **argv, + team_id *team) { BAutolock _lock(fLock); - status_t result = fCaller(type, messages, argc, argv, team); - if (result == B_OK) { - if (team) - CreateAppInfo(*team); - else { - // Note: Here's a race condition. If Terminate() is called, before - // we've received the first message from the test app, then - // there's a good chance that we quit the application before - // having received any message (or at least not all messages) - // from the test app. We wait some time to minimize the chance... - snooze(100000); - } - } + status_t result = caller(type, messages, argc, argv, team); + if (result == B_OK && team) + CreateAppInfo(*team); return result; } @@ -173,6 +233,14 @@ LaunchContext::HandleMessage(BMessage *message) { //printf("LaunchContext::HandleMessage(%6ld: %.4s)\n", //message->ReturnAddress().Team(), (char*)&message->what); +//if (message->what == MSG_MESSAGE_RECEIVED) { +// BMessage sentMessage; +// message->FindMessage("message", &sentMessage); +// team_id sender = -1; +// message->FindInt32("sender", &sender); +// printf(" <- %6ld: %.4s\n", sender, (char*)&sentMessage.what); +//} + BAutolock _lock(fLock); switch (message->what) { case MSG_STARTED: @@ -184,10 +252,20 @@ LaunchContext::HandleMessage(BMessage *message) case MSG_READY_TO_RUN: { BMessenger messenger = message->ReturnAddress(); - AppInfo *info = CreateAppInfo(messenger); - info->AddMessage(*message); - if (fTerminating) - TerminateApp(info); + // add the message to the respective team's message list + // Note: catch messages that have not been sent by us or the + // remote team. The R5 registrar seems to send a B_REPLY message + // sometimes. + team_id sender = -1; + if (message->FindInt32("sender", &sender) != B_OK + || sender == be_app->Team() + || sender == messenger.Team()) { + AppInfo *info = CreateAppInfo(messenger); + info->AddMessage(*message); + if (fTerminating) + TerminateApp(info); + } + NotifySleepers(message->what); break; } default: @@ -252,7 +330,8 @@ LaunchContext::NextMessageFrom(team_id team, int32 &cookie, bigtime_t *time) // CheckNextMessage bool -LaunchContext::CheckNextMessage(team_id team, int32 &cookie, uint32 what) +LaunchContext::CheckNextMessage(LaunchCaller &caller, team_id team, + int32 &cookie, uint32 what) { BMessage *message = NextMessageFrom(team, cookie); return (message && message->what == what); @@ -260,12 +339,13 @@ LaunchContext::CheckNextMessage(team_id team, int32 &cookie, uint32 what) // CheckArgvMessage bool -LaunchContext::CheckArgvMessage(team_id team, int32 &cookie, - const entry_ref *appRef, bool useRef) +LaunchContext::CheckArgvMessage(LaunchCaller &caller, team_id team, + int32 &cookie, const entry_ref *appRef, + bool useRef) { bool result = true; - if (fCaller.SupportsArgv()) { - result = CheckArgvMessage(team, cookie, appRef, kStandardArgc, + if (caller.SupportsArgv()) { + result = CheckArgvMessage(caller, team, cookie, appRef, kStandardArgc, kStandardArgv, useRef); } return result; @@ -273,18 +353,18 @@ LaunchContext::CheckArgvMessage(team_id team, int32 &cookie, // CheckArgvMessage bool -LaunchContext::CheckArgvMessage(team_id team, int32 &cookie, - const entry_ref *appRef, int32 argc, - const char **argv, bool useRef) +LaunchContext::CheckArgvMessage(LaunchCaller &caller, team_id team, + int32 &cookie, const entry_ref *appRef, + int32 argc, const char **argv, bool useRef) { - const entry_ref *ref = (useRef ? fCaller.Ref() : NULL); - return CheckArgvMessage(team, cookie, appRef, ref , argc, argv); + const entry_ref *ref = (useRef ? caller.Ref() : NULL); + return CheckArgvMessage(caller, team, cookie, appRef, ref , argc, argv); } // CheckArgvMessage bool -LaunchContext::CheckArgvMessage(team_id team, int32 &cookie, - const entry_ref *appRef, +LaunchContext::CheckArgvMessage(LaunchCaller &caller, team_id team, + int32 &cookie, const entry_ref *appRef, const entry_ref *ref , int32 argc, const char **argv) { @@ -330,62 +410,36 @@ printf("app paths differ: `%s' vs `%s'\n", arg, path.Path()); return result; } -// RemoveStandardArgvMessage -bool -LaunchContext::RemoveStandardArgvMessage(team_id team, const entry_ref *appRef) -{ - return RemoveArgvMessage(team, appRef, kStandardArgc, kStandardArgv); -} - -// RemoveArgvMessage -bool -LaunchContext::RemoveArgvMessage(team_id team, const entry_ref *appRef, - int32 argc, const char **argv) -{ - BAutolock _lock(fLock); - bool result = true; - if (fCaller.SupportsArgv()) { - result = false; - int32 cookie = 0; - while (BMessage *message = NextMessageFrom(team, cookie)) { - if (message->what == MSG_ARGV_RECEIVED) { - int32 index = --cookie; - result = CheckArgvMessage(team, cookie, appRef, argc, argv); - delete AppInfoFor(team)->RemoveMessage(index); - break; - } - } - } - return result; -} - // CheckMessageMessages bool -LaunchContext::CheckMessageMessages(team_id team, int32 &cookie) +LaunchContext::CheckMessageMessages(LaunchCaller &caller, team_id team, + int32 &cookie) { BAutolock _lock(fLock); bool result = true; for (int32 i = 0; i < 3; i++) - result &= CheckMessageMessage(team, cookie, i); + result &= CheckMessageMessage(caller, team, cookie, i); return result; } // CheckMessageMessage bool -LaunchContext::CheckMessageMessage(team_id team, int32 &cookie, int32 index) +LaunchContext::CheckMessageMessage(LaunchCaller &caller, team_id team, + int32 &cookie, int32 index) { bool result = true; - if (fCaller.SupportsMessages() > index && index < 3) { + if (caller.SupportsMessages() > index && index < 3) { uint32 commands[] = { MSG_1, MSG_2, MSG_3 }; BMessage message(commands[index]); - result = CheckMessageMessage(team, cookie, &message); + result = CheckMessageMessage(caller, team, cookie, &message); } return result; } // CheckMessageMessage bool -LaunchContext::CheckMessageMessage(team_id team, int32 &cookie, +LaunchContext::CheckMessageMessage(LaunchCaller &caller, team_id team, + int32 &cookie, const BMessage *expectedMessage) { BMessage *message = NextMessageFrom(team, cookie); @@ -400,18 +454,20 @@ LaunchContext::CheckMessageMessage(team_id team, int32 &cookie, // CheckRefsMessage bool -LaunchContext::CheckRefsMessage(team_id team, int32 &cookie) +LaunchContext::CheckRefsMessage(LaunchCaller &caller, team_id team, + int32 &cookie) { bool result = true; - if (fCaller.SupportsRefs()) - result = CheckRefsMessage(team, cookie, fCaller.Ref()); + if (caller.SupportsRefs()) + result = CheckRefsMessage(caller, team, cookie, caller.Ref()); return result; } // CheckRefsMessage bool -LaunchContext::CheckRefsMessage(team_id team, int32 &cookie, - const entry_ref *refs, int32 count) +LaunchContext::CheckRefsMessage(LaunchCaller &caller, team_id team, + int32 &cookie, const entry_ref *refs, + int32 count) { BMessage *message = NextMessageFrom(team, cookie); bool result = (message && message->what == MSG_REFS_RECEIVED); @@ -425,25 +481,60 @@ LaunchContext::CheckRefsMessage(team_id team, int32 &cookie, return result; } -// RemoveRefsMessage +// WaitForMessage bool -LaunchContext::RemoveRefsMessage(team_id team) +LaunchContext::WaitForMessage(uint32 messageCode, bool fromNow, + bigtime_t timeout) { - BAutolock _lock(fLock); - bool result = true; - if (fCaller.SupportsRefs()) { - result = false; - int32 cookie = 0; - while (BMessage *message = NextMessageFrom(team, cookie)) { - if (message->what == MSG_REFS_RECEIVED) { - int32 index = --cookie; - result = CheckRefsMessage(team, cookie); - delete AppInfoFor(team)->RemoveMessage(index); - break; + status_t error = B_ERROR; + fLock.Lock(); + error = B_OK; + if (fromNow || !FindMessage(messageCode)) { + // add sleeper + Sleeper *sleeper = new Sleeper; + error = sleeper->Init(messageCode); + if (error == B_OK) { + AddSleeper(sleeper); + fLock.Unlock(); + // sleep + error = sleeper->Sleep(timeout); + fLock.Lock(); + // remove sleeper + RemoveSleeper(sleeper); + delete sleeper; + } + } + fLock.Unlock(); + return (error == B_OK); +} + +// WaitForMessage +bool +LaunchContext::WaitForMessage(team_id team, uint32 messageCode, bool fromNow, + bigtime_t timeout) +{ + status_t error = B_ERROR; + fLock.Lock(); + if (AppInfo *info = AppInfoFor(team)) { + error = B_OK; + if (fromNow || !info->FindMessage(messageCode)) { + // add sleeper + Sleeper *sleeper = new Sleeper; + error = sleeper->Init(messageCode); + if (error == B_OK) { + info->AddSleeper(sleeper); + fLock.Unlock(); + // sleep + error = sleeper->Sleep(timeout); + fLock.Lock(); + // remove sleeper + info->RemoveSleeper(sleeper); + delete sleeper; } } } - return result; + fLock.Unlock(); + return (error == B_OK); } // StandardMessages @@ -541,6 +632,42 @@ LaunchContext::TerminatorEntry(void *data) return ((LaunchContext*)data)->Terminator(); } +// FindMessage +LaunchContext::Message* +LaunchContext::FindMessage(uint32 messageCode) +{ + BAutolock _lock(fLock); + Message *message = NULL; + AppInfo *info = NULL; + for (int32 i = 0; !message && (info = AppInfoAt(i)) != NULL; i++) + message = info->FindMessage(messageCode); + return message; +} + +// AddSleeper +void +LaunchContext::AddSleeper(Sleeper *sleeper) +{ + fSleepers.AddItem(sleeper); +} + +// RemoveSleeper +void +LaunchContext::RemoveSleeper(Sleeper *sleeper) +{ + fSleepers.RemoveItem(sleeper); +} + +// NotifySleepers +void +LaunchContext::NotifySleepers(uint32 messageCode) +{ + for (int32 i = 0; Sleeper *sleeper = (Sleeper*)fSleepers.ItemAt(i); i++) { + if (sleeper->MessageCode() == messageCode) + sleeper->WakeUp(); + } +} + /////////////////// // RosterLaunchApp diff --git a/src/tests/kits/app/broster/LaunchTesterHelper.h b/src/tests/kits/app/broster/LaunchTesterHelper.h index 89dc60b274..33e5db5d98 100644 --- a/src/tests/kits/app/broster/LaunchTesterHelper.h +++ b/src/tests/kits/app/broster/LaunchTesterHelper.h @@ -18,23 +18,40 @@ enum { // LaunchCaller class LaunchCaller { public: + LaunchCaller() : fNext(NULL) {} + virtual ~LaunchCaller() { if (fNext) delete fNext;} + virtual status_t operator()(const char *type, BList *messages, int32 argc, const char **argv, team_id *team) = 0; virtual int32 SupportsMessages() const { return 1; } virtual bool SupportsArgv() const { return SupportsMessages() == 0; } virtual bool SupportsRefs() const { return false; } virtual const entry_ref *Ref() const { return NULL; } + + virtual LaunchCaller &Clone() + { + LaunchCaller *newCaller = CloneInternal(); + newCaller->fNext = fNext; + fNext = newCaller; + return *newCaller; + } + + virtual LaunchCaller *CloneInternal() = 0; + +private: + LaunchCaller *fNext; }; // LaunchContext class LaunchContext { public: - LaunchContext(LaunchCaller &caller); + LaunchContext(); ~LaunchContext(); - status_t operator()(const char *type, team_id *team); - status_t operator()(const char *type, BList *messages, int32 argc, - const char **argv, team_id *team); + status_t operator()(LaunchCaller &caller, const char *type, team_id *team); + status_t operator()(LaunchCaller &caller, const char *type, + BList *messages, int32 argc, const char **argv, + team_id *team); void HandleMessage(BMessage *message); @@ -44,24 +61,30 @@ public: BMessage *NextMessageFrom(team_id team, int32 &cookie, bigtime_t *time = NULL); - bool CheckNextMessage(team_id team, int32 &cookie, uint32 what); - bool CheckArgvMessage(team_id team, int32 &cookie, + bool CheckNextMessage(LaunchCaller &caller, team_id team, int32 &cookie, + uint32 what); + bool CheckArgvMessage(LaunchCaller &caller, team_id team, int32 &cookie, const entry_ref *appRef, bool useRef = true); - bool CheckArgvMessage(team_id team, int32 &cookie, const entry_ref *appRef, + bool CheckArgvMessage(LaunchCaller &caller, team_id team, int32 &cookie, + const entry_ref *appRef, int32 argc, const char **argv, bool useRef = true); - bool CheckArgvMessage(team_id team, int32 &cookie, const entry_ref *appRef, - const entry_ref *ref, int32 argc, const char **argv); - bool RemoveStandardArgvMessage(team_id team, const entry_ref *appRef); - bool RemoveArgvMessage(team_id team, const entry_ref *appRef, int32 argc, - const char **argv); - bool CheckMessageMessages(team_id team, int32 &cookie); - bool CheckMessageMessage(team_id team, int32 &cookie, int32 index); - bool CheckMessageMessage(team_id team, int32 &cookie, + bool CheckArgvMessage(LaunchCaller &caller, team_id team, int32 &cookie, + const entry_ref *appRef, const entry_ref *ref, + int32 argc, const char **argv); + bool CheckMessageMessages(LaunchCaller &caller, team_id team, + int32 &cookie); + bool CheckMessageMessage(LaunchCaller &caller, team_id team, int32 &cookie, + int32 index); + bool CheckMessageMessage(LaunchCaller &caller, team_id team, int32 &cookie, const BMessage *message); - bool CheckRefsMessage(team_id team, int32 &cookie); - bool CheckRefsMessage(team_id team, int32 &cookie, const entry_ref *refs, - int32 count = 1); - bool RemoveRefsMessage(team_id team); + bool CheckRefsMessage(LaunchCaller &caller, team_id team, int32 &cookie); + bool CheckRefsMessage(LaunchCaller &caller, team_id team, int32 &cookie, + const entry_ref *refs, int32 count = 1); + + bool WaitForMessage(uint32 messageCode, bool fromNow = false, + bigtime_t timeout = B_INFINITE_TIMEOUT); + bool WaitForMessage(team_id team, uint32 messageCode, bool fromNow = false, + bigtime_t timeout = B_INFINITE_TIMEOUT); BList *StandardMessages(); @@ -71,6 +94,7 @@ public: private: class Message; + class Sleeper; class AppInfo; private: @@ -80,14 +104,19 @@ private: AppInfo *CreateAppInfo(BMessenger messenger); void TerminateApp(AppInfo *info); + Message *FindMessage(uint32 messageCode); + void AddSleeper(Sleeper *sleeper); + void RemoveSleeper(Sleeper *sleeper); + void NotifySleepers(uint32 messageCode); + int32 Terminator(); static int32 AppThreadEntry(void *data); static int32 TerminatorEntry(void *data); private: - LaunchCaller &fCaller; BList fAppInfos; + BList fSleepers; mutable BLocker fLock; thread_id fAppThread; thread_id fTerminator;