diff --git a/src/tests/kits/app/Jamfile b/src/tests/kits/app/Jamfile index 6d2eb09d24..37c33f320c 100644 --- a/src/tests/kits/app/Jamfile +++ b/src/tests/kits/app/Jamfile @@ -105,6 +105,7 @@ CommonTestLib libapptest.so LaunchTester.cpp LaunchTesterHelper.cpp RecentAppsTestApp.cpp + RosterWatchingTester.cpp TeamForTester.cpp # RegistrarThreadManager diff --git a/src/tests/kits/app/broster/BRosterCases b/src/tests/kits/app/broster/BRosterCases index e7c4e6a3f1..e2f7c62220 100644 --- a/src/tests/kits/app/broster/BRosterCases +++ b/src/tests/kits/app/broster/BRosterCases @@ -582,4 +582,16 @@ case 3: valid message, several apps, one is B_ARGV_ONLY, invalid replyTo => B_ARGV_ONLY) apps. Replies go to the roster! +status_t StartWatching(BMessenger target, uint32 eventMask) const +status_t StopWatching(BMessenger target) const +case 1: {Start,Stop}Watching() with invalid messenger or invalid flags, + StopWatching() non-watching messenger => + Should return B_OK/B_BAD_VALUE. +case 2: several apps, several watchers, different eventMasks => + Should return B_OK... + Watching ends, when target has become invalid and the next watching + message is tried to be sent. +case 3: call StartWatching() twice, second time with different mask => + Should return B_OK. The second call simply overrides the first one. +TODO: Watching app activation. diff --git a/src/tests/kits/app/broster/LaunchTesterHelper.cpp b/src/tests/kits/app/broster/LaunchTesterHelper.cpp index 8f88dd9302..c72771cb7c 100644 --- a/src/tests/kits/app/broster/LaunchTesterHelper.cpp +++ b/src/tests/kits/app/broster/LaunchTesterHelper.cpp @@ -312,6 +312,18 @@ LaunchContext::Terminate() wait_for_thread(fTerminator, &dummy); } +// TerminateApp +void +LaunchContext::TerminateApp(team_id team, bool wait) +{ + fLock.Lock(); + if (AppInfo *info = AppInfoFor(team)) + TerminateApp(info); + fLock.Unlock(); + if (wait) + WaitForMessage(team, MSG_TERMINATED); +} + // TeamAt team_id LaunchContext::TeamAt(int32 index) const @@ -323,6 +335,50 @@ LaunchContext::TeamAt(int32 index) const return team; } +// AppMessengerFor +BMessenger +LaunchContext::AppMessengerFor(team_id team) const +{ + BAutolock _lock(fLock); + BMessenger result; + if (AppInfo *info = AppInfoFor(team)) { + // We need to do some hacking. + BMessenger messenger; + struct fake_messenger { + port_id fPort; + int32 fHandlerToken; + team_id fTeam; + int32 extra0; + int32 extra1; + bool fPreferredTarget; + bool extra2; + bool extra3; + bool extra4; + } &fake = *(fake_messenger*)&messenger; + status_t error = B_OK; + fake.fTeam = team; + // find app looper port + bool found = false; + int32 cookie = 0; + port_info info; + while (error == B_OK && !found) { + error = get_next_port_info(fake.fTeam, &cookie, &info); + found = (error == B_OK + && (!strcmp("AppLooperPort", info.name) + || !strcmp("rAppLooperPort", info.name))); + } + // init messenger + if (error == B_OK) { + fake.fPort = info.port; + fake.fHandlerToken = 0; + fake.fPreferredTarget = true; + } + if (error == B_OK) + result = messenger; + } + return result; +} + // NextMessageFrom BMessage* LaunchContext::NextMessageFrom(team_id team, int32 &cookie, bigtime_t *time) @@ -342,11 +398,6 @@ LaunchContext::CheckNextMessage(LaunchCaller &caller, team_id team, int32 &cookie, uint32 what) { BMessage *message = NextMessageFrom(team, cookie); -if (!message) -printf("LaunchContext::CheckNextMessage(): no more messages\n"); -else if (message->what != what) -printf("LaunchContext::CheckNextMessage(): %.4s vs %.4s\n", -(char*)&message->what, (char*)&what); return (message && message->what == what); } @@ -563,13 +614,13 @@ LaunchContext::WaitForMessage(uint32 messageCode, bool fromNow, // WaitForMessage bool LaunchContext::WaitForMessage(team_id team, uint32 messageCode, bool fromNow, - bigtime_t timeout) + bigtime_t timeout, int32 startIndex) { status_t error = B_ERROR; fLock.Lock(); if (AppInfo *info = AppInfoFor(team)) { error = B_OK; - if (fromNow || !info->FindMessage(messageCode)) { + if (fromNow || !info->FindMessage(messageCode, startIndex)) { // add sleeper Sleeper *sleeper = new Sleeper; error = sleeper->Init(messageCode); diff --git a/src/tests/kits/app/broster/LaunchTesterHelper.h b/src/tests/kits/app/broster/LaunchTesterHelper.h index 85bb94f648..7580cc33af 100644 --- a/src/tests/kits/app/broster/LaunchTesterHelper.h +++ b/src/tests/kits/app/broster/LaunchTesterHelper.h @@ -50,9 +50,12 @@ public: void HandleMessage(BMessage *message); void Terminate(); + void TerminateApp(team_id team, bool wait = true); team_id TeamAt(int32 index) const; + BMessenger AppMessengerFor(team_id team) const; + BMessage *NextMessageFrom(team_id team, int32 &cookie, bigtime_t *time = NULL); bool CheckNextMessage(LaunchCaller &caller, team_id team, int32 &cookie, @@ -88,7 +91,8 @@ public: 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); + bigtime_t timeout = B_INFINITE_TIMEOUT, + int32 startIndex = 0); BList *StandardMessages(); diff --git a/src/tests/kits/app/broster/RosterTest.cpp b/src/tests/kits/app/broster/RosterTest.cpp index 784fd83ac9..faf042ad95 100644 --- a/src/tests/kits/app/broster/RosterTest.cpp +++ b/src/tests/kits/app/broster/RosterTest.cpp @@ -6,6 +6,7 @@ #include "GetRecentTester.h" #include "IsRunningTester.h" #include "LaunchTester.h" +#include "RosterWatchingTester.h" #include "TeamForTester.h" CppUnit::Test* RosterTestSuite() @@ -19,6 +20,7 @@ CppUnit::Test* RosterTestSuite() testSuite->addTest(GetRecentTester::Suite()); testSuite->addTest(IsRunningTester::Suite()); testSuite->addTest(LaunchTester::Suite()); + testSuite->addTest(RosterWatchingTester::Suite()); testSuite->addTest(TeamForTester::Suite()); return testSuite; diff --git a/src/tests/kits/app/broster/testapps/Jamfile b/src/tests/kits/app/broster/testapps/Jamfile index 4186990f4d..204d2818e9 100644 --- a/src/tests/kits/app/broster/testapps/Jamfile +++ b/src/tests/kits/app/broster/testapps/Jamfile @@ -73,3 +73,4 @@ SimpleBRosterTestApp RecentAppsTestEmptyApp.cpp RecentAppsTestApp.cpp ; SimpleBRosterTestApp RecentAppsTestControlApp.cpp RecentAppsTestApp.cpp ; SimpleBRosterTestApp RosterBroadcastTestApp1.cpp ; SimpleBRosterTestApp RosterLaunchTestApp1.cpp ; +SimpleBRosterTestApp RosterWatchingTestApp1.cpp ;