#include <stdio.h>
#include <Message.h>
#include <OS.h>
#include <Handler.h>
#include <Looper.h>
#include <Roster.h>
#include <String.h>
#include <TestShell.h>
#include <TestUtils.h>
#include <cppunit/TestAssert.h>
#include "AppRunner.h"
#include "TeamForTester.h"
void TeamForTester::TeamForTestA1()
{
#ifndef TEST_R5
BRoster roster;
CHK(roster.TeamFor((const char*)NULL) == B_BAD_VALUE);
#endif
}
void TeamForTester::TeamForTestA2()
{
BRoster roster;
CHK(roster.TeamFor("application/x-vnd.obos-app-run-testapp1") == B_ERROR);
}
void TeamForTester::TeamForTestA3()
{
AppRunner runner1(true);
AppRunner runner2(true);
CHK(runner1.Run("AppRunTestApp1") == B_OK);
CHK(runner2.Run("AppRunTestApp1") == B_OK);
BRoster roster;
team_id team = roster.TeamFor("application/x-vnd.obos-app-run-testapp1");
CHK(team == runner1.Team() || team == runner2.Team());
runner1.WaitFor(true);
CHK(roster.TeamFor("application/x-vnd.obos-app-run-testapp1")
== runner2.Team());
runner2.WaitFor(true);
CHK(roster.TeamFor("application/x-vnd.obos-app-run-testapp1") == B_ERROR);
}
void TeamForTester::TeamForTestB1()
{
#ifndef TEST_R5
BRoster roster;
CHK(roster.TeamFor((entry_ref*)NULL) == B_BAD_VALUE);
#endif
}
void TeamForTester::TeamForTestB2()
{
BRoster roster;
entry_ref ref;
CHK(find_test_app("AppRunTestApp1", &ref) == B_OK);
CHK(roster.TeamFor(&ref) == B_ERROR);
}
void TeamForTester::TeamForTestB3()
{
entry_ref ref;
CHK(find_test_app("AppRunTestApp1", &ref) == B_OK);
AppRunner runner1(true);
AppRunner runner2(true);
CHK(runner1.Run("AppRunTestApp1") == B_OK);
CHK(runner2.Run("AppRunTestApp1") == B_OK);
BRoster roster;
team_id team = roster.TeamFor(&ref);
CHK(team == runner1.Team() || team == runner2.Team());
runner1.WaitFor(true);
CHK(roster.TeamFor(&ref) == runner2.Team());
runner2.WaitFor(true);
CHK(roster.TeamFor(&ref) == B_ERROR);
}
Test* TeamForTester::Suite()
{
TestSuite* SuiteOfTests = new TestSuite;
ADD_TEST4(BRoster, SuiteOfTests, TeamForTester, TeamForTestA1);
ADD_TEST4(BRoster, SuiteOfTests, TeamForTester, TeamForTestA2);
ADD_TEST4(BRoster, SuiteOfTests, TeamForTester, TeamForTestA3);
ADD_TEST4(BRoster, SuiteOfTests, TeamForTester, TeamForTestB1);
ADD_TEST4(BRoster, SuiteOfTests, TeamForTester, TeamForTestB2);
ADD_TEST4(BRoster, SuiteOfTests, TeamForTester, TeamForTestB3);
return SuiteOfTests;
}