1 //------------------------------------------------------------------------------
2 // TeamForTester.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 "TeamForTester.h"
25
26 // Local Defines ---------------------------------------------------------------
27
28 // Globals ---------------------------------------------------------------------
29
30 //------------------------------------------------------------------------------
31
32 /*
33 team_id TeamFor(const char *signature) const
34 @case 1 signature is NULL
35 @results Should return B_BAD_VALUE.
36 */
TeamForTestA1()37 void TeamForTester::TeamForTestA1()
38 {
39 // R5: crashes when passing a NULL signature
40 #ifndef TEST_R5
41 BRoster roster;
42 CHK(roster.TeamFor((const char*)NULL) == B_BAD_VALUE);
43 #endif
44 }
45
46 /*
47 team_id TeamFor(const char *signature) const
48 @case 2 signature is not NULL, but no app with this signature is
49 running
50 @results Should return B_ERROR.
51 */
TeamForTestA2()52 void TeamForTester::TeamForTestA2()
53 {
54 BRoster roster;
55 CHK(roster.TeamFor("application/x-vnd.obos-app-run-testapp1") == B_ERROR);
56 }
57
58 /*
59 team_id TeamFor(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 the ID of one of the teams;
63 the ID of the second team; B_ERROR.
64 */
TeamForTestA3()65 void TeamForTester::TeamForTestA3()
66 {
67 // run the remote apps
68 AppRunner runner1(true);
69 AppRunner runner2(true);
70 CHK(runner1.Run("AppRunTestApp1") == B_OK);
71 CHK(runner2.Run("AppRunTestApp1") == B_OK);
72 // create the BRoster and perform the tests
73 BRoster roster;
74 team_id team = roster.TeamFor("application/x-vnd.obos-app-run-testapp1");
75 CHK(team == runner1.Team() || team == runner2.Team());
76 // quit app 1
77 runner1.WaitFor(true);
78 CHK(roster.TeamFor("application/x-vnd.obos-app-run-testapp1")
79 == runner2.Team());
80 // quit app 2
81 runner2.WaitFor(true);
82 CHK(roster.TeamFor("application/x-vnd.obos-app-run-testapp1") == B_ERROR);
83 }
84
85 /*
86 team_id TeamFor(entry_ref *ref) const
87 @case 1 ref is NULL
88 @results Should return B_BAD_VALUE.
89 */
TeamForTestB1()90 void TeamForTester::TeamForTestB1()
91 {
92 // R5: crashes when passing a NULL ref
93 #ifndef TEST_R5
94 BRoster roster;
95 CHK(roster.TeamFor((entry_ref*)NULL) == B_BAD_VALUE);
96 #endif
97 }
98
99 /*
100 team_id TeamFor(entry_ref *ref) const
101 @case 2 ref is not NULL, but no app with this ref is running
102 @results Should return B_ERROR.
103 */
TeamForTestB2()104 void TeamForTester::TeamForTestB2()
105 {
106 BRoster roster;
107 entry_ref ref;
108 CHK(find_test_app("AppRunTestApp1", &ref) == B_OK);
109 CHK(roster.TeamFor(&ref) == B_ERROR);
110 }
111
112 /*
113 team_id TeamFor(entry_ref *ref) const
114 @case 3 ref is not NULL and an (two) app(s) with this ref is (are)
115 running; quit one; quit the second one
116 @results Should return the ID of one of the teams;
117 the ID of the second team; B_ERROR.
118 */
TeamForTestB3()119 void TeamForTester::TeamForTestB3()
120 {
121 entry_ref ref;
122 CHK(find_test_app("AppRunTestApp1", &ref) == B_OK);
123 // run the remote apps
124 AppRunner runner1(true);
125 AppRunner runner2(true);
126 CHK(runner1.Run("AppRunTestApp1") == B_OK);
127 CHK(runner2.Run("AppRunTestApp1") == B_OK);
128 // create the BRoster and perform the tests
129 BRoster roster;
130 team_id team = roster.TeamFor(&ref);
131 CHK(team == runner1.Team() || team == runner2.Team());
132 // quit app 1
133 runner1.WaitFor(true);
134 CHK(roster.TeamFor(&ref) == runner2.Team());
135 // quit app 2
136 runner2.WaitFor(true);
137 CHK(roster.TeamFor(&ref) == B_ERROR);
138 }
139
140
Suite()141 Test* TeamForTester::Suite()
142 {
143 TestSuite* SuiteOfTests = new TestSuite;
144
145 ADD_TEST4(BRoster, SuiteOfTests, TeamForTester, TeamForTestA1);
146 ADD_TEST4(BRoster, SuiteOfTests, TeamForTester, TeamForTestA2);
147 ADD_TEST4(BRoster, SuiteOfTests, TeamForTester, TeamForTestA3);
148
149 ADD_TEST4(BRoster, SuiteOfTests, TeamForTester, TeamForTestB1);
150 ADD_TEST4(BRoster, SuiteOfTests, TeamForTester, TeamForTestB2);
151 ADD_TEST4(BRoster, SuiteOfTests, TeamForTester, TeamForTestB3);
152
153 return SuiteOfTests;
154 }
155
156