#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 "IsRunningTester.h"
void IsRunningTester::IsRunningTestA1()
{
#ifndef TEST_R5
BRoster roster;
CHK(roster.IsRunning((const char*)NULL) == false);
#endif
}
void IsRunningTester::IsRunningTestA2()
{
BRoster roster;
CHK(roster.IsRunning("application/x-vnd.obos-app-run-testapp1") == false);
}
void IsRunningTester::IsRunningTestA3()
{
AppRunner runner1(true);
AppRunner runner2(true);
CHK(runner1.Run("AppRunTestApp1") == B_OK);
CHK(runner2.Run("AppRunTestApp1") == B_OK);
BRoster roster;
CHK(roster.IsRunning("application/x-vnd.obos-app-run-testapp1") == true);
runner1.WaitFor(true);
CHK(roster.IsRunning("application/x-vnd.obos-app-run-testapp1") == true);
runner2.WaitFor(true);
CHK(roster.IsRunning("application/x-vnd.obos-app-run-testapp1") == false);
}
void IsRunningTester::IsRunningTestB1()
{
#ifndef TEST_R5
BRoster roster;
CHK(roster.IsRunning((entry_ref*)NULL) == false);
#endif
}
void IsRunningTester::IsRunningTestB2()
{
BRoster roster;
entry_ref ref;
CHK(find_test_app("AppRunTestApp1", &ref) == B_OK);
CHK(roster.IsRunning(&ref) == false);
}
void IsRunningTester::IsRunningTestB3()
{
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;
CHK(roster.IsRunning(&ref) == true);
runner1.WaitFor(true);
CHK(roster.IsRunning(&ref) == true);
runner2.WaitFor(true);
CHK(roster.IsRunning(&ref) == false);
}
Test* IsRunningTester::Suite()
{
TestSuite* SuiteOfTests = new TestSuite;
ADD_TEST4(BRoster, SuiteOfTests, IsRunningTester, IsRunningTestA1);
ADD_TEST4(BRoster, SuiteOfTests, IsRunningTester, IsRunningTestA2);
ADD_TEST4(BRoster, SuiteOfTests, IsRunningTester, IsRunningTestA3);
ADD_TEST4(BRoster, SuiteOfTests, IsRunningTester, IsRunningTestB1);
ADD_TEST4(BRoster, SuiteOfTests, IsRunningTester, IsRunningTestB2);
ADD_TEST4(BRoster, SuiteOfTests, IsRunningTester, IsRunningTestB3);
return SuiteOfTests;
}