1//------------------------------------------------------------------------------
2//	IsRunningTester.cpp
3//
4//------------------------------------------------------------------------------
5
6// Standard Includes -----------------------------------------------------------
7#include <stdio.h>
8
9// System Includes -------------------------------------------------------------
10#include <Message.h>
11#include <OS.h>
12#include <Handler.h>
13#include <Looper.h>
14#include <Roster.h>
15#include <String.h>
16
17// Project Includes ------------------------------------------------------------
18#include <TestShell.h>
19#include <TestUtils.h>
20#include <cppunit/TestAssert.h>
21
22// Local Includes --------------------------------------------------------------
23#include "AppRunner.h"
24#include "IsRunningTester.h"
25
26// Local Defines ---------------------------------------------------------------
27
28// Globals ---------------------------------------------------------------------
29
30//------------------------------------------------------------------------------
31
32/*
33	bool IsRunning(const char *signature) const
34	@case 1			signature is NULL
35	@results		Should return false.
36*/
37void IsRunningTester::IsRunningTestA1()
38{
39// R5: crashes when passing a NULL signature
40#ifndef TEST_R5
41	BRoster roster;
42	CHK(roster.IsRunning((const char*)NULL) == false);
43#endif
44}
45
46/*
47	bool IsRunning(const char *signature) const
48	@case 2			signature is not NULL, but no app with this signature is
49					running
50	@results		Should return false.
51*/
52void IsRunningTester::IsRunningTestA2()
53{
54	BRoster roster;
55	CHK(roster.IsRunning("application/x-vnd.obos-app-run-testapp1") == false);
56}
57
58/*
59	bool IsRunning(const char *signature) const
60	@case 3			signature is not NULL and an (two) app(s) with this
61					signature is (are) running; quit one; quit the second one
62	@results		Should return true; true; false.
63*/
64void IsRunningTester::IsRunningTestA3()
65{
66	// run the remote apps
67	AppRunner runner1(true);
68	AppRunner runner2(true);
69	CHK(runner1.Run("AppRunTestApp1") == B_OK);
70	CHK(runner2.Run("AppRunTestApp1") == B_OK);
71	// create the BRoster and perform the tests
72	BRoster roster;
73	CHK(roster.IsRunning("application/x-vnd.obos-app-run-testapp1") == true);
74	// quit app 1
75	runner1.WaitFor(true);
76	CHK(roster.IsRunning("application/x-vnd.obos-app-run-testapp1") == true);
77	// quit app 2
78	runner2.WaitFor(true);
79	CHK(roster.IsRunning("application/x-vnd.obos-app-run-testapp1") == false);
80}
81
82/*
83	bool IsRunning(entry_ref *ref) const
84	@case 1			ref is NULL
85	@results		Should return false.
86*/
87void IsRunningTester::IsRunningTestB1()
88{
89// R5: crashes when passing a NULL ref
90#ifndef TEST_R5
91	BRoster roster;
92	CHK(roster.IsRunning((entry_ref*)NULL) == false);
93#endif
94}
95
96/*
97	bool IsRunning(entry_ref *ref) const
98	@case 2			ref is not NULL, but no app with this ref is running
99	@results		Should return false.
100*/
101void IsRunningTester::IsRunningTestB2()
102{
103	BRoster roster;
104	entry_ref ref;
105	CHK(find_test_app("AppRunTestApp1", &ref) == B_OK);
106	CHK(roster.IsRunning(&ref) == false);
107}
108
109/*
110	bool IsRunning(entry_ref *ref) const
111	@case 3			ref is not NULL and an (two) app(s) with this ref is (are)
112					running; quit one; quit the second one
113	@results		Should return true; true; false.
114*/
115void IsRunningTester::IsRunningTestB3()
116{
117	entry_ref ref;
118	CHK(find_test_app("AppRunTestApp1", &ref) == B_OK);
119	// run the remote apps
120	AppRunner runner1(true);
121	AppRunner runner2(true);
122	CHK(runner1.Run("AppRunTestApp1") == B_OK);
123	CHK(runner2.Run("AppRunTestApp1") == B_OK);
124	// create the BRoster and perform the tests
125	BRoster roster;
126	CHK(roster.IsRunning(&ref) == true);
127	// quit app 1
128	runner1.WaitFor(true);
129	CHK(roster.IsRunning(&ref) == true);
130	// quit app 2
131	runner2.WaitFor(true);
132	CHK(roster.IsRunning(&ref) == false);
133}
134
135
136Test* IsRunningTester::Suite()
137{
138	TestSuite* SuiteOfTests = new TestSuite;
139
140	ADD_TEST4(BRoster, SuiteOfTests, IsRunningTester, IsRunningTestA1);
141	ADD_TEST4(BRoster, SuiteOfTests, IsRunningTester, IsRunningTestA2);
142	ADD_TEST4(BRoster, SuiteOfTests, IsRunningTester, IsRunningTestA3);
143
144	ADD_TEST4(BRoster, SuiteOfTests, IsRunningTester, IsRunningTestB1);
145	ADD_TEST4(BRoster, SuiteOfTests, IsRunningTester, IsRunningTestB2);
146	ADD_TEST4(BRoster, SuiteOfTests, IsRunningTester, IsRunningTestB3);
147
148	return SuiteOfTests;
149}
150
151