Added BRoster::TeamFor()/GetAppInfo()/GetRunningAppInfo()/GetAppList() tests.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@672 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -79,7 +79,10 @@ CommonTestLib libapptest.so
|
|||||||
|
|
||||||
# BRoster
|
# BRoster
|
||||||
RosterTest.cpp
|
RosterTest.cpp
|
||||||
|
GetAppInfoTester.cpp
|
||||||
|
GetAppListTester.cpp
|
||||||
IsRunningTester.cpp
|
IsRunningTester.cpp
|
||||||
|
TeamForTester.cpp
|
||||||
|
|
||||||
# common
|
# common
|
||||||
AppRunner.cpp
|
AppRunner.cpp
|
||||||
|
|||||||
@@ -0,0 +1,289 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// GetAppInfoTester.cpp
|
||||||
|
//
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Standard Includes -----------------------------------------------------------
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
// System Includes -------------------------------------------------------------
|
||||||
|
#include <be/app/Message.h>
|
||||||
|
#include <be/kernel/OS.h>
|
||||||
|
|
||||||
|
#include <Handler.h>
|
||||||
|
#include <Looper.h>
|
||||||
|
#include <Roster.h>
|
||||||
|
#include <String.h>
|
||||||
|
|
||||||
|
// Project Includes ------------------------------------------------------------
|
||||||
|
#include <TestShell.h>
|
||||||
|
#include <TestUtils.h>
|
||||||
|
#include <cppunit/TestAssert.h>
|
||||||
|
|
||||||
|
// Local Includes --------------------------------------------------------------
|
||||||
|
#include "AppRunner.h"
|
||||||
|
#include "GetAppInfoTester.h"
|
||||||
|
|
||||||
|
// Local Defines ---------------------------------------------------------------
|
||||||
|
|
||||||
|
// Globals ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// check_app_info
|
||||||
|
static
|
||||||
|
bool
|
||||||
|
check_app_info(app_info &info, AppRunner &runner, const char *signature,
|
||||||
|
uint32 flags)
|
||||||
|
{
|
||||||
|
team_id team = runner.Team();
|
||||||
|
// get the thread
|
||||||
|
thread_id thread = -1;
|
||||||
|
int32 cookie = 0;
|
||||||
|
thread_info threadInfo;
|
||||||
|
while (get_next_thread_info(team, &cookie, &threadInfo) == B_OK) {
|
||||||
|
if (thread < 0 || threadInfo.thread < thread)
|
||||||
|
thread = threadInfo.thread;
|
||||||
|
}
|
||||||
|
// get port and ref
|
||||||
|
port_id port = runner.AppLooperPort();
|
||||||
|
entry_ref ref;
|
||||||
|
runner.GetRef(&ref);
|
||||||
|
// compare
|
||||||
|
//printf("check_app_info(): "
|
||||||
|
//" thread: %ld vs %ld\n"
|
||||||
|
//" team: %ld vs %ld\n"
|
||||||
|
//" port: %ld vs %ld\n"
|
||||||
|
//" flags: %lx vs %lx\n"
|
||||||
|
//" signature: `%s' vs `%s'\n", info.thread, thread, info.team, team,
|
||||||
|
//info.port, port, info.flags, flags, info.signature, signature);
|
||||||
|
//printf(" ref: (%ld, %lld, `%s') vs (%ld, %lld, `%s')\n",
|
||||||
|
//info.ref.device, info.ref.directory, info.ref.name,
|
||||||
|
//ref.device, ref.directory, ref.name);
|
||||||
|
return (info.thread == thread && info.team == team && info.port == port
|
||||||
|
&& info.flags == flags && info.ref == ref
|
||||||
|
&& !strncmp(info.signature, signature, B_MIME_TYPE_LENGTH));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
status_t GetAppInfo(const char *signature, app_info *info) const
|
||||||
|
@case 1 signature is NULL or info is NULL
|
||||||
|
@results Should return B_BAD_VALUE.
|
||||||
|
*/
|
||||||
|
void GetAppInfoTester::GetAppInfoTestA1()
|
||||||
|
{
|
||||||
|
BRoster roster;
|
||||||
|
app_info info;
|
||||||
|
CHK(roster.GetAppInfo((const char*)NULL, NULL) == B_BAD_VALUE);
|
||||||
|
CHK(roster.GetAppInfo((const char*)NULL, &info) == B_BAD_VALUE);
|
||||||
|
// R5: crashes when passing a NULL app_info
|
||||||
|
#ifndef TEST_R5
|
||||||
|
CHK(roster.GetAppInfo("application/x-vnd.obos-app-run-testapp1",
|
||||||
|
NULL) == B_BAD_VALUE);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
status_t GetAppInfo(const char *signature, app_info *info) const
|
||||||
|
@case 2 signature/info are not NULL, but no app with this
|
||||||
|
signature is running
|
||||||
|
@results Should return B_ERROR.
|
||||||
|
*/
|
||||||
|
void GetAppInfoTester::GetAppInfoTestA2()
|
||||||
|
{
|
||||||
|
BRoster roster;
|
||||||
|
app_info info;
|
||||||
|
CHK(roster.GetAppInfo("application/x-vnd.obos-app-run-testapp1", &info)
|
||||||
|
== B_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
status_t GetAppInfo(const char *signature, app_info *info) const
|
||||||
|
@case 3 signature/info are not NULL and an (two) app(s) with this
|
||||||
|
signature is (are) running; quit one; quit the second one
|
||||||
|
@results Should
|
||||||
|
- fill the app info with the data of one of the apps and
|
||||||
|
return B_OK;
|
||||||
|
- fill the app info with the data of the second apps and
|
||||||
|
return B_OK;
|
||||||
|
- return B_ERROR.
|
||||||
|
*/
|
||||||
|
void GetAppInfoTester::GetAppInfoTestA3()
|
||||||
|
{
|
||||||
|
const char *signature = "application/x-vnd.obos-app-run-testapp1";
|
||||||
|
uint32 flags = B_MULTIPLE_LAUNCH | B_ARGV_ONLY;
|
||||||
|
// run the remote apps
|
||||||
|
AppRunner runner1(true);
|
||||||
|
AppRunner runner2(true);
|
||||||
|
CHK(runner1.Run("AppRunTestApp1") == B_OK);
|
||||||
|
CHK(runner2.Run("AppRunTestApp1") == B_OK);
|
||||||
|
// create the BRoster and perform the tests
|
||||||
|
BRoster roster;
|
||||||
|
app_info info1;
|
||||||
|
CHK(roster.GetAppInfo(signature, &info1) == B_OK);
|
||||||
|
CHK(check_app_info(info1, runner1, signature, flags)
|
||||||
|
|| check_app_info(info1, runner2, signature, flags));
|
||||||
|
// quit app 1
|
||||||
|
runner1.WaitFor(true);
|
||||||
|
app_info info2;
|
||||||
|
CHK(roster.GetAppInfo(signature, &info2) == B_OK);
|
||||||
|
CHK(check_app_info(info2, runner2, signature, flags));
|
||||||
|
// quit app 2
|
||||||
|
runner2.WaitFor(true);
|
||||||
|
CHK(roster.GetAppInfo(signature, &info1) == B_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
status_t GetAppInfo(entry_ref *ref, app_info *info) const
|
||||||
|
@case 1 ref is NULL or info is NULL
|
||||||
|
@results Should return B_BAD_VALUE.
|
||||||
|
*/
|
||||||
|
void GetAppInfoTester::GetAppInfoTestB1()
|
||||||
|
{
|
||||||
|
BRoster roster;
|
||||||
|
entry_ref ref;
|
||||||
|
CHK(find_test_app("AppRunTestApp1", &ref) == B_OK);
|
||||||
|
app_info info;
|
||||||
|
CHK(roster.GetAppInfo((entry_ref*)NULL, NULL) == B_BAD_VALUE);
|
||||||
|
CHK(roster.GetAppInfo((entry_ref*)NULL, &info) == B_BAD_VALUE);
|
||||||
|
// R5: crashes when passing a NULL app_info
|
||||||
|
#ifndef TEST_R5
|
||||||
|
CHK(roster.GetAppInfo(&ref, NULL) == B_BAD_VALUE);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
status_t GetAppInfo(entry_ref *ref, app_info *info) const
|
||||||
|
@case 2 ref/info are not NULL, but no app with this ref is running
|
||||||
|
@results Should return B_ERROR.
|
||||||
|
*/
|
||||||
|
void GetAppInfoTester::GetAppInfoTestB2()
|
||||||
|
{
|
||||||
|
BRoster roster;
|
||||||
|
entry_ref ref;
|
||||||
|
CHK(find_test_app("AppRunTestApp1", &ref) == B_OK);
|
||||||
|
app_info info;
|
||||||
|
CHK(roster.GetAppInfo(&ref, &info) == B_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
status_t GetAppInfo(entry_ref *ref, app_info *info) const
|
||||||
|
@case 3 ref/info are not NULL and an (two) app(s) with this ref
|
||||||
|
is (are) running; quit one; quit the second one
|
||||||
|
@results Should
|
||||||
|
- fill the app info with the data of one of the apps and
|
||||||
|
return B_OK;
|
||||||
|
- fill the app info with the data of the second apps and
|
||||||
|
return B_OK;
|
||||||
|
- return B_ERROR.
|
||||||
|
*/
|
||||||
|
void GetAppInfoTester::GetAppInfoTestB3()
|
||||||
|
{
|
||||||
|
const char *signature = "application/x-vnd.obos-app-run-testapp1";
|
||||||
|
uint32 flags = B_MULTIPLE_LAUNCH | B_ARGV_ONLY;
|
||||||
|
entry_ref ref;
|
||||||
|
CHK(find_test_app("AppRunTestApp1", &ref) == B_OK);
|
||||||
|
// run the remote apps
|
||||||
|
AppRunner runner1(true);
|
||||||
|
AppRunner runner2(true);
|
||||||
|
CHK(runner1.Run("AppRunTestApp1") == B_OK);
|
||||||
|
CHK(runner2.Run("AppRunTestApp1") == B_OK);
|
||||||
|
// create the BRoster and perform the tests
|
||||||
|
BRoster roster;
|
||||||
|
app_info info1;
|
||||||
|
CHK(roster.GetAppInfo(&ref, &info1) == B_OK);
|
||||||
|
CHK(check_app_info(info1, runner1, signature, flags)
|
||||||
|
|| check_app_info(info1, runner2, signature, flags));
|
||||||
|
// quit app 1
|
||||||
|
runner1.WaitFor(true);
|
||||||
|
app_info info2;
|
||||||
|
CHK(roster.GetAppInfo(&ref, &info2) == B_OK);
|
||||||
|
CHK(check_app_info(info2, runner2, signature, flags));
|
||||||
|
// quit app 2
|
||||||
|
runner2.WaitFor(true);
|
||||||
|
CHK(roster.GetAppInfo(&ref, &info1) == B_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
status_t GetRunningAppInfo(team_id team, app_info *info) const
|
||||||
|
@case 1 info is NULL
|
||||||
|
@results Should return B_BAD_VALUE.
|
||||||
|
*/
|
||||||
|
void GetAppInfoTester::GetRunningAppInfoTest1()
|
||||||
|
{
|
||||||
|
// R5: crashes when passing a NULL app_info
|
||||||
|
#ifndef TEST_R5
|
||||||
|
BRoster roster;
|
||||||
|
// invalid team ID
|
||||||
|
CHK(roster.GetRunningAppInfo(-1, NULL) == B_BAD_VALUE);
|
||||||
|
// valid team ID
|
||||||
|
AppRunner runner(true);
|
||||||
|
CHK(runner.Run("AppRunTestApp1") == B_OK);
|
||||||
|
CHK(roster.GetRunningAppInfo(runner.Team(), NULL) == B_BAD_VALUE);
|
||||||
|
runner.WaitFor(true);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
status_t GetRunningAppInfo(team_id team, app_info *info) const
|
||||||
|
@case 2 info is not NULL, but no app with the team ID is running
|
||||||
|
@results Should return B_BAD_TEAM_ID.
|
||||||
|
*/
|
||||||
|
void GetAppInfoTester::GetRunningAppInfoTest2()
|
||||||
|
{
|
||||||
|
BRoster roster;
|
||||||
|
// invalid team ID
|
||||||
|
app_info info;
|
||||||
|
CHK(roster.GetRunningAppInfo(-1, &info) == B_ERROR);
|
||||||
|
// originally valid team ID -- app terminates before call
|
||||||
|
AppRunner runner(true);
|
||||||
|
CHK(runner.Run("AppRunTestApp1") == B_OK);
|
||||||
|
team_id team = runner.Team();
|
||||||
|
runner.WaitFor(true);
|
||||||
|
CHK(roster.GetRunningAppInfo(team, &info) == B_BAD_TEAM_ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
status_t GetRunningAppInfo(team_id team, app_info *info) const
|
||||||
|
@case 3 info is not NULL, and an app with the team ID is running
|
||||||
|
@results Should fill the app info and return B_OK.
|
||||||
|
*/
|
||||||
|
void GetAppInfoTester::GetRunningAppInfoTest3()
|
||||||
|
{
|
||||||
|
const char *signature = "application/x-vnd.obos-app-run-testapp1";
|
||||||
|
uint32 flags = B_MULTIPLE_LAUNCH | B_ARGV_ONLY;
|
||||||
|
// run the app
|
||||||
|
AppRunner runner(true);
|
||||||
|
CHK(runner.Run("AppRunTestApp1") == B_OK);
|
||||||
|
// get and check the info
|
||||||
|
BRoster roster;
|
||||||
|
app_info info;
|
||||||
|
CHK(roster.GetRunningAppInfo(runner.Team(), &info) == B_OK);
|
||||||
|
CHK(check_app_info(info, runner, signature, flags));
|
||||||
|
// quit the app
|
||||||
|
runner.WaitFor(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Test* GetAppInfoTester::Suite()
|
||||||
|
{
|
||||||
|
TestSuite* SuiteOfTests = new TestSuite;
|
||||||
|
|
||||||
|
ADD_TEST4(BApplication, SuiteOfTests, GetAppInfoTester, GetAppInfoTestA1);
|
||||||
|
ADD_TEST4(BApplication, SuiteOfTests, GetAppInfoTester, GetAppInfoTestA2);
|
||||||
|
ADD_TEST4(BApplication, SuiteOfTests, GetAppInfoTester, GetAppInfoTestA3);
|
||||||
|
|
||||||
|
ADD_TEST4(BApplication, SuiteOfTests, GetAppInfoTester, GetAppInfoTestB1);
|
||||||
|
ADD_TEST4(BApplication, SuiteOfTests, GetAppInfoTester, GetAppInfoTestB2);
|
||||||
|
ADD_TEST4(BApplication, SuiteOfTests, GetAppInfoTester, GetAppInfoTestB3);
|
||||||
|
|
||||||
|
ADD_TEST4(BApplication, SuiteOfTests, GetAppInfoTester,
|
||||||
|
GetRunningAppInfoTest1);
|
||||||
|
ADD_TEST4(BApplication, SuiteOfTests, GetAppInfoTester,
|
||||||
|
GetRunningAppInfoTest2);
|
||||||
|
ADD_TEST4(BApplication, SuiteOfTests, GetAppInfoTester,
|
||||||
|
GetRunningAppInfoTest3);
|
||||||
|
|
||||||
|
return SuiteOfTests;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// GetAppInfoTester.h
|
||||||
|
//
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#ifndef GET_APP_INFO_TESTER_H
|
||||||
|
#define GET_APP_INFO_TESTER_H
|
||||||
|
|
||||||
|
// Standard Includes -----------------------------------------------------------
|
||||||
|
|
||||||
|
// System Includes -------------------------------------------------------------
|
||||||
|
|
||||||
|
// Project Includes ------------------------------------------------------------
|
||||||
|
|
||||||
|
// Local Includes --------------------------------------------------------------
|
||||||
|
#include "../common.h"
|
||||||
|
|
||||||
|
// Local Defines ---------------------------------------------------------------
|
||||||
|
|
||||||
|
// Globals ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
class GetAppInfoTester : public TestCase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
GetAppInfoTester() {;}
|
||||||
|
GetAppInfoTester(std::string name) : TestCase(name) {;}
|
||||||
|
|
||||||
|
void GetAppInfoTestA1();
|
||||||
|
void GetAppInfoTestA2();
|
||||||
|
void GetAppInfoTestA3();
|
||||||
|
|
||||||
|
void GetAppInfoTestB1();
|
||||||
|
void GetAppInfoTestB2();
|
||||||
|
void GetAppInfoTestB3();
|
||||||
|
|
||||||
|
void GetRunningAppInfoTest1();
|
||||||
|
void GetRunningAppInfoTest2();
|
||||||
|
void GetRunningAppInfoTest3();
|
||||||
|
|
||||||
|
static Test* Suite();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // GET_APP_INFO_TESTER_H
|
||||||
|
|
||||||
@@ -0,0 +1,296 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// GetAppListTester.cpp
|
||||||
|
//
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Standard Includes -----------------------------------------------------------
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
// System Includes -------------------------------------------------------------
|
||||||
|
#include <be/app/Message.h>
|
||||||
|
#include <be/kernel/OS.h>
|
||||||
|
|
||||||
|
#include <Handler.h>
|
||||||
|
#include <List.h>
|
||||||
|
#include <Looper.h>
|
||||||
|
#include <Roster.h>
|
||||||
|
#include <String.h>
|
||||||
|
|
||||||
|
// Project Includes ------------------------------------------------------------
|
||||||
|
#include <TestShell.h>
|
||||||
|
#include <TestUtils.h>
|
||||||
|
#include <cppunit/TestAssert.h>
|
||||||
|
|
||||||
|
// Local Includes --------------------------------------------------------------
|
||||||
|
#include "AppRunner.h"
|
||||||
|
#include "GetAppListTester.h"
|
||||||
|
|
||||||
|
// Local Defines ---------------------------------------------------------------
|
||||||
|
|
||||||
|
// Globals ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// contains_list
|
||||||
|
static
|
||||||
|
bool
|
||||||
|
contains_list(const BList &a, const BList &b)
|
||||||
|
{
|
||||||
|
int32 bCount = b.CountItems();
|
||||||
|
bool contains = true;
|
||||||
|
for (int32 i = 0; contains && i < bCount; i++)
|
||||||
|
contains = a.HasItem(b.ItemAt(i));
|
||||||
|
return contains;
|
||||||
|
}
|
||||||
|
|
||||||
|
// check_list
|
||||||
|
static
|
||||||
|
void
|
||||||
|
check_list(const BList &toCheck, const BList &base, const BList &extendedBase,
|
||||||
|
const BList &expected)
|
||||||
|
{
|
||||||
|
// toCheck and extendedBase must have prefix base
|
||||||
|
int32 baseCount = base.CountItems();
|
||||||
|
for (int32 i = 0; i < baseCount; i++) {
|
||||||
|
CHK(base.ItemAt(i) == toCheck.ItemAt(i));
|
||||||
|
CHK(base.ItemAt(i) == extendedBase.ItemAt(i));
|
||||||
|
}
|
||||||
|
// toCheck must have correct size
|
||||||
|
int32 toCheckCount = toCheck.CountItems();
|
||||||
|
int32 extendedBaseCount = extendedBase.CountItems();
|
||||||
|
int32 expectedCount = expected.CountItems();
|
||||||
|
CHK(toCheckCount == extendedBaseCount + expectedCount);
|
||||||
|
// toCheck must contain all elements of extendedBase and expected
|
||||||
|
// (arbitrary order)
|
||||||
|
BList list(extendedBase);
|
||||||
|
list.AddList((BList*)&expected);
|
||||||
|
CHK(contains_list(toCheck, list));
|
||||||
|
CHK(contains_list(list, toCheck));
|
||||||
|
}
|
||||||
|
|
||||||
|
// check_list
|
||||||
|
static
|
||||||
|
void
|
||||||
|
check_list(const BList &toCheck, const BList &base, const BList &expected)
|
||||||
|
{
|
||||||
|
check_list(toCheck, base, base, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
// check_list
|
||||||
|
static
|
||||||
|
void
|
||||||
|
check_list(const BList &toCheck, const BList &expected)
|
||||||
|
{
|
||||||
|
BList base;
|
||||||
|
check_list(toCheck, base, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
void GetAppList(BList *teamIDList) const
|
||||||
|
@case 1 teamIDList is NULL
|
||||||
|
@results Should do nothing.
|
||||||
|
*/
|
||||||
|
void GetAppListTester::GetAppListTestA1()
|
||||||
|
{
|
||||||
|
// R5: crashes when passing a NULL BList
|
||||||
|
#ifndef TEST_R5
|
||||||
|
BRoster roster;
|
||||||
|
roster.GetAppList(NULL);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
void GetAppList(BList *teamIDList) const
|
||||||
|
@case 2 teamIDList is not NULL and not empty
|
||||||
|
@results Should append the team IDs of all running apps to
|
||||||
|
teamIDList.
|
||||||
|
*/
|
||||||
|
void GetAppListTester::GetAppListTestA2()
|
||||||
|
{
|
||||||
|
// create a list with some dummy entries
|
||||||
|
BList list;
|
||||||
|
list.AddItem((void*)-7);
|
||||||
|
list.AddItem((void*)-42);
|
||||||
|
// get a list of running applications for reference
|
||||||
|
BRoster roster;
|
||||||
|
BList list1(list);
|
||||||
|
roster.GetAppList(&list1);
|
||||||
|
// run some apps
|
||||||
|
AppRunner runner1(true);
|
||||||
|
AppRunner runner2(true);
|
||||||
|
AppRunner runner3(true);
|
||||||
|
CHK(runner1.Run("AppRunTestApp1") == B_OK);
|
||||||
|
CHK(runner2.Run("AppRunTestApp2") == B_OK);
|
||||||
|
CHK(runner3.Run("BMessengerTestApp1") == B_OK);
|
||||||
|
BList expectedApps;
|
||||||
|
expectedApps.AddItem((void*)runner1.Team());
|
||||||
|
expectedApps.AddItem((void*)runner2.Team());
|
||||||
|
expectedApps.AddItem((void*)runner3.Team());
|
||||||
|
// get a new app list and check it
|
||||||
|
BList list2(list);
|
||||||
|
roster.GetAppList(&list2);
|
||||||
|
check_list(list2, list, list1, expectedApps);
|
||||||
|
// quit app 1
|
||||||
|
runner1.WaitFor(true);
|
||||||
|
expectedApps.RemoveItem((void*)runner1.Team());
|
||||||
|
BList list3(list);
|
||||||
|
roster.GetAppList(&list3);
|
||||||
|
check_list(list3, list, list1, expectedApps);
|
||||||
|
// quit app 2
|
||||||
|
runner2.WaitFor(true);
|
||||||
|
expectedApps.RemoveItem((void*)runner2.Team());
|
||||||
|
BList list4(list);
|
||||||
|
roster.GetAppList(&list4);
|
||||||
|
check_list(list4, list, list1, expectedApps);
|
||||||
|
// quit app 3
|
||||||
|
runner3.WaitFor(true);
|
||||||
|
expectedApps.RemoveItem((void*)runner3.Team());
|
||||||
|
BList list5(list);
|
||||||
|
roster.GetAppList(&list5);
|
||||||
|
check_list(list5, list, list1, expectedApps);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
void GetAppList(const char *signature, BList *teamIDList) const
|
||||||
|
@case 1 signature or teamIDList are NULL
|
||||||
|
@results Should do nothing/should not modify teamIDList.
|
||||||
|
*/
|
||||||
|
void GetAppListTester::GetAppListTestB1()
|
||||||
|
{
|
||||||
|
// R5: crashes when passing a NULL signature/BList
|
||||||
|
#ifndef TEST_R5
|
||||||
|
const char *signature = "application/x-vnd.obos-app-run-testapp1";
|
||||||
|
// create a list with some dummy entries
|
||||||
|
BList emptyList;
|
||||||
|
BList list;
|
||||||
|
list.AddItem((void*)-7);
|
||||||
|
list.AddItem((void*)-42);
|
||||||
|
// NULL signature and list
|
||||||
|
BRoster roster;
|
||||||
|
roster.GetAppList(NULL, NULL);
|
||||||
|
// NULL signature
|
||||||
|
BList list1(list);
|
||||||
|
roster.GetAppList(NULL, &list1);
|
||||||
|
check_list(list1, list, list, emptyList);
|
||||||
|
// NULL list
|
||||||
|
AppRunner runner(true);
|
||||||
|
CHK(runner.Run("AppRunTestApp1") == B_OK);
|
||||||
|
roster.GetAppList(signature, NULL);
|
||||||
|
runner.WaitFor(true);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
void GetAppList(const char *signature, BList *teamIDList) const
|
||||||
|
@case 2 teamIDList is not NULL and not empty, signature is not
|
||||||
|
NULL, but no app with this signature is running
|
||||||
|
@results Should not modify teamIDList.
|
||||||
|
*/
|
||||||
|
void GetAppListTester::GetAppListTestB2()
|
||||||
|
{
|
||||||
|
const char *signature = "application/x-vnd.obos-does-not-exist";
|
||||||
|
// create a list with some dummy entries
|
||||||
|
BList list;
|
||||||
|
list.AddItem((void*)-7);
|
||||||
|
list.AddItem((void*)-42);
|
||||||
|
// get a list of running applications for reference
|
||||||
|
BRoster roster;
|
||||||
|
BList list1(list);
|
||||||
|
roster.GetAppList(signature, &list1);
|
||||||
|
// run some apps
|
||||||
|
AppRunner runner1(true);
|
||||||
|
AppRunner runner2(true);
|
||||||
|
AppRunner runner3(true);
|
||||||
|
CHK(runner1.Run("AppRunTestApp1") == B_OK);
|
||||||
|
CHK(runner2.Run("AppRunTestApp2") == B_OK);
|
||||||
|
CHK(runner3.Run("BMessengerTestApp1") == B_OK);
|
||||||
|
BList expectedApps;
|
||||||
|
// get a new app list and check it
|
||||||
|
BList list2(list);
|
||||||
|
roster.GetAppList(signature, &list2);
|
||||||
|
check_list(list2, list, list1, expectedApps);
|
||||||
|
// quit app 1
|
||||||
|
runner1.WaitFor(true);
|
||||||
|
BList list3(list);
|
||||||
|
roster.GetAppList(signature, &list3);
|
||||||
|
check_list(list3, list, list1, expectedApps);
|
||||||
|
// quit app 2
|
||||||
|
runner2.WaitFor(true);
|
||||||
|
BList list4(list);
|
||||||
|
roster.GetAppList(signature, &list4);
|
||||||
|
check_list(list4, list, list1, expectedApps);
|
||||||
|
// quit app 3
|
||||||
|
runner3.WaitFor(true);
|
||||||
|
BList list5(list);
|
||||||
|
roster.GetAppList(signature, &list5);
|
||||||
|
check_list(list5, list, list1, expectedApps);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
void GetAppList(const char *signature, BList *teamIDList) const
|
||||||
|
@case 3 teamIDList is not NULL and not empty, signature is not
|
||||||
|
NULL and app(s) with this signature is (are) running
|
||||||
|
@results Should append the team IDs of all running apps with the
|
||||||
|
supplied signature to teamIDList.
|
||||||
|
*/
|
||||||
|
void GetAppListTester::GetAppListTestB3()
|
||||||
|
{
|
||||||
|
const char *signature = "application/x-vnd.obos-app-run-testapp1";
|
||||||
|
// create a list with some dummy entries
|
||||||
|
BList list;
|
||||||
|
list.AddItem((void*)-7);
|
||||||
|
list.AddItem((void*)-42);
|
||||||
|
// get a list of running applications for reference
|
||||||
|
BRoster roster;
|
||||||
|
BList list1(list);
|
||||||
|
roster.GetAppList(signature, &list1);
|
||||||
|
check_list(list1, list);
|
||||||
|
// run some apps
|
||||||
|
AppRunner runner1(true);
|
||||||
|
AppRunner runner2(true);
|
||||||
|
AppRunner runner3(true);
|
||||||
|
CHK(runner1.Run("AppRunTestApp1") == B_OK);
|
||||||
|
CHK(runner2.Run("AppRunTestApp2") == B_OK);
|
||||||
|
CHK(runner3.Run("BMessengerTestApp1") == B_OK);
|
||||||
|
BList expectedApps;
|
||||||
|
expectedApps.AddItem((void*)runner1.Team());
|
||||||
|
expectedApps.AddItem((void*)runner2.Team());
|
||||||
|
// get a new app list and check it
|
||||||
|
BList list2(list);
|
||||||
|
roster.GetAppList(signature, &list2);
|
||||||
|
check_list(list2, list, expectedApps);
|
||||||
|
// quit app 1
|
||||||
|
runner1.WaitFor(true);
|
||||||
|
expectedApps.RemoveItem((void*)runner1.Team());
|
||||||
|
BList list3(list);
|
||||||
|
roster.GetAppList(signature, &list3);
|
||||||
|
check_list(list3, list, expectedApps);
|
||||||
|
// quit app 2
|
||||||
|
runner2.WaitFor(true);
|
||||||
|
expectedApps.RemoveItem((void*)runner2.Team());
|
||||||
|
BList list4(list);
|
||||||
|
roster.GetAppList(signature, &list4);
|
||||||
|
check_list(list4, list, expectedApps);
|
||||||
|
// quit app 3
|
||||||
|
runner3.WaitFor(true);
|
||||||
|
BList list5(list);
|
||||||
|
roster.GetAppList(signature, &list5);
|
||||||
|
check_list(list5, list, expectedApps);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Test* GetAppListTester::Suite()
|
||||||
|
{
|
||||||
|
TestSuite* SuiteOfTests = new TestSuite;
|
||||||
|
|
||||||
|
ADD_TEST4(BApplication, SuiteOfTests, GetAppListTester, GetAppListTestA1);
|
||||||
|
ADD_TEST4(BApplication, SuiteOfTests, GetAppListTester, GetAppListTestA2);
|
||||||
|
|
||||||
|
ADD_TEST4(BApplication, SuiteOfTests, GetAppListTester, GetAppListTestB1);
|
||||||
|
ADD_TEST4(BApplication, SuiteOfTests, GetAppListTester, GetAppListTestB2);
|
||||||
|
ADD_TEST4(BApplication, SuiteOfTests, GetAppListTester, GetAppListTestB3);
|
||||||
|
|
||||||
|
return SuiteOfTests;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// GetAppListTester.h
|
||||||
|
//
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#ifndef GET_APP_LIST_TESTER_H
|
||||||
|
#define GET_APP_LIST_TESTER_H
|
||||||
|
|
||||||
|
// Standard Includes -----------------------------------------------------------
|
||||||
|
|
||||||
|
// System Includes -------------------------------------------------------------
|
||||||
|
|
||||||
|
// Project Includes ------------------------------------------------------------
|
||||||
|
|
||||||
|
// Local Includes --------------------------------------------------------------
|
||||||
|
#include "../common.h"
|
||||||
|
|
||||||
|
// Local Defines ---------------------------------------------------------------
|
||||||
|
|
||||||
|
// Globals ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
class GetAppListTester : public TestCase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
GetAppListTester() {;}
|
||||||
|
GetAppListTester(std::string name) : TestCase(name) {;}
|
||||||
|
|
||||||
|
void GetAppListTestA1();
|
||||||
|
void GetAppListTestA2();
|
||||||
|
|
||||||
|
void GetAppListTestB1();
|
||||||
|
void GetAppListTestB2();
|
||||||
|
void GetAppListTestB3();
|
||||||
|
|
||||||
|
static Test* Suite();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // GET_APP_LIST_TESTER_H
|
||||||
|
|
||||||
@@ -1,11 +1,17 @@
|
|||||||
#include "../common.h"
|
#include "../common.h"
|
||||||
|
#include "GetAppInfoTester.h"
|
||||||
|
#include "GetAppListTester.h"
|
||||||
#include "IsRunningTester.h"
|
#include "IsRunningTester.h"
|
||||||
|
#include "TeamForTester.h"
|
||||||
|
|
||||||
CppUnit::Test* RosterTestSuite()
|
CppUnit::Test* RosterTestSuite()
|
||||||
{
|
{
|
||||||
CppUnit::TestSuite *testSuite = new CppUnit::TestSuite();
|
CppUnit::TestSuite *testSuite = new CppUnit::TestSuite();
|
||||||
|
|
||||||
|
testSuite->addTest(GetAppInfoTester::Suite());
|
||||||
|
testSuite->addTest(GetAppListTester::Suite());
|
||||||
testSuite->addTest(IsRunningTester::Suite());
|
testSuite->addTest(IsRunningTester::Suite());
|
||||||
|
testSuite->addTest(TeamForTester::Suite());
|
||||||
|
|
||||||
return testSuite;
|
return testSuite;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,156 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// TeamForTester.cpp
|
||||||
|
//
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Standard Includes -----------------------------------------------------------
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
// System Includes -------------------------------------------------------------
|
||||||
|
#include <be/app/Message.h>
|
||||||
|
#include <be/kernel/OS.h>
|
||||||
|
|
||||||
|
#include <Handler.h>
|
||||||
|
#include <Looper.h>
|
||||||
|
#include <Roster.h>
|
||||||
|
#include <String.h>
|
||||||
|
|
||||||
|
// Project Includes ------------------------------------------------------------
|
||||||
|
#include <TestShell.h>
|
||||||
|
#include <TestUtils.h>
|
||||||
|
#include <cppunit/TestAssert.h>
|
||||||
|
|
||||||
|
// Local Includes --------------------------------------------------------------
|
||||||
|
#include "AppRunner.h"
|
||||||
|
#include "TeamForTester.h"
|
||||||
|
|
||||||
|
// Local Defines ---------------------------------------------------------------
|
||||||
|
|
||||||
|
// Globals ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/*
|
||||||
|
team_id TeamFor(const char *signature) const
|
||||||
|
@case 1 signature is NULL
|
||||||
|
@results Should return B_BAD_VALUE.
|
||||||
|
*/
|
||||||
|
void TeamForTester::TeamForTestA1()
|
||||||
|
{
|
||||||
|
// R5: crashes when passing a NULL signature
|
||||||
|
#ifndef TEST_R5
|
||||||
|
BRoster roster;
|
||||||
|
CHK(roster.TeamFor((const char*)NULL) == B_BAD_VALUE);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
team_id TeamFor(const char *signature) const
|
||||||
|
@case 2 signature is not NULL, but no app with this signature is
|
||||||
|
running
|
||||||
|
@results Should return B_ERROR.
|
||||||
|
*/
|
||||||
|
void TeamForTester::TeamForTestA2()
|
||||||
|
{
|
||||||
|
BRoster roster;
|
||||||
|
CHK(roster.TeamFor("application/x-vnd.obos-app-run-testapp1") == B_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
team_id TeamFor(const char *signature) const
|
||||||
|
@case 3 signature is not NULL and an (two) app(s) with this
|
||||||
|
signature is (are) running; quit one; quit the second one
|
||||||
|
@results Should return the ID of one of the teams;
|
||||||
|
the ID of the second team; B_ERROR.
|
||||||
|
*/
|
||||||
|
void TeamForTester::TeamForTestA3()
|
||||||
|
{
|
||||||
|
// run the remote apps
|
||||||
|
AppRunner runner1(true);
|
||||||
|
AppRunner runner2(true);
|
||||||
|
CHK(runner1.Run("AppRunTestApp1") == B_OK);
|
||||||
|
CHK(runner2.Run("AppRunTestApp1") == B_OK);
|
||||||
|
// create the BRoster and perform the tests
|
||||||
|
BRoster roster;
|
||||||
|
team_id team = roster.TeamFor("application/x-vnd.obos-app-run-testapp1");
|
||||||
|
CHK(team == runner1.Team() || team == runner2.Team());
|
||||||
|
// quit app 1
|
||||||
|
runner1.WaitFor(true);
|
||||||
|
CHK(roster.TeamFor("application/x-vnd.obos-app-run-testapp1")
|
||||||
|
== runner2.Team());
|
||||||
|
// quit app 2
|
||||||
|
runner2.WaitFor(true);
|
||||||
|
CHK(roster.TeamFor("application/x-vnd.obos-app-run-testapp1") == B_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
team_id TeamFor(entry_ref *ref) const
|
||||||
|
@case 1 ref is NULL
|
||||||
|
@results Should return B_BAD_VALUE.
|
||||||
|
*/
|
||||||
|
void TeamForTester::TeamForTestB1()
|
||||||
|
{
|
||||||
|
// R5: crashes when passing a NULL ref
|
||||||
|
#ifndef TEST_R5
|
||||||
|
BRoster roster;
|
||||||
|
CHK(roster.TeamFor((entry_ref*)NULL) == B_BAD_VALUE);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
team_id TeamFor(entry_ref *ref) const
|
||||||
|
@case 2 ref is not NULL, but no app with this ref is running
|
||||||
|
@results Should return B_ERROR.
|
||||||
|
*/
|
||||||
|
void TeamForTester::TeamForTestB2()
|
||||||
|
{
|
||||||
|
BRoster roster;
|
||||||
|
entry_ref ref;
|
||||||
|
CHK(find_test_app("AppRunTestApp1", &ref) == B_OK);
|
||||||
|
CHK(roster.TeamFor(&ref) == B_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
team_id TeamFor(entry_ref *ref) const
|
||||||
|
@case 3 ref is not NULL and an (two) app(s) with this ref is (are)
|
||||||
|
running; quit one; quit the second one
|
||||||
|
@results Should return the ID of one of the teams;
|
||||||
|
the ID of the second team; B_ERROR.
|
||||||
|
*/
|
||||||
|
void TeamForTester::TeamForTestB3()
|
||||||
|
{
|
||||||
|
entry_ref ref;
|
||||||
|
CHK(find_test_app("AppRunTestApp1", &ref) == B_OK);
|
||||||
|
// run the remote apps
|
||||||
|
AppRunner runner1(true);
|
||||||
|
AppRunner runner2(true);
|
||||||
|
CHK(runner1.Run("AppRunTestApp1") == B_OK);
|
||||||
|
CHK(runner2.Run("AppRunTestApp1") == B_OK);
|
||||||
|
// create the BRoster and perform the tests
|
||||||
|
BRoster roster;
|
||||||
|
team_id team = roster.TeamFor(&ref);
|
||||||
|
CHK(team == runner1.Team() || team == runner2.Team());
|
||||||
|
// quit app 1
|
||||||
|
runner1.WaitFor(true);
|
||||||
|
CHK(roster.TeamFor(&ref) == runner2.Team());
|
||||||
|
// quit app 2
|
||||||
|
runner2.WaitFor(true);
|
||||||
|
CHK(roster.TeamFor(&ref) == B_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Test* TeamForTester::Suite()
|
||||||
|
{
|
||||||
|
TestSuite* SuiteOfTests = new TestSuite;
|
||||||
|
|
||||||
|
ADD_TEST4(BApplication, SuiteOfTests, TeamForTester, TeamForTestA1);
|
||||||
|
ADD_TEST4(BApplication, SuiteOfTests, TeamForTester, TeamForTestA2);
|
||||||
|
ADD_TEST4(BApplication, SuiteOfTests, TeamForTester, TeamForTestA3);
|
||||||
|
|
||||||
|
ADD_TEST4(BApplication, SuiteOfTests, TeamForTester, TeamForTestB1);
|
||||||
|
ADD_TEST4(BApplication, SuiteOfTests, TeamForTester, TeamForTestB2);
|
||||||
|
ADD_TEST4(BApplication, SuiteOfTests, TeamForTester, TeamForTestB3);
|
||||||
|
|
||||||
|
return SuiteOfTests;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// TeamForTester.h
|
||||||
|
//
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#ifndef TEAM_FOR_TESTER_H
|
||||||
|
#define TEAM_FOR_TESTER_H
|
||||||
|
|
||||||
|
// Standard Includes -----------------------------------------------------------
|
||||||
|
|
||||||
|
// System Includes -------------------------------------------------------------
|
||||||
|
|
||||||
|
// Project Includes ------------------------------------------------------------
|
||||||
|
|
||||||
|
// Local Includes --------------------------------------------------------------
|
||||||
|
#include "../common.h"
|
||||||
|
|
||||||
|
// Local Defines ---------------------------------------------------------------
|
||||||
|
|
||||||
|
// Globals ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
class TeamForTester : public TestCase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TeamForTester() {;}
|
||||||
|
TeamForTester(std::string name) : TestCase(name) {;}
|
||||||
|
|
||||||
|
void TeamForTestA1();
|
||||||
|
void TeamForTestA2();
|
||||||
|
void TeamForTestA3();
|
||||||
|
|
||||||
|
void TeamForTestB1();
|
||||||
|
void TeamForTestB2();
|
||||||
|
void TeamForTestB3();
|
||||||
|
|
||||||
|
static Test* Suite();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // TEAM_FOR_TESTER_H
|
||||||
|
|
||||||
Reference in New Issue
Block a user