vfs: check userland buffers before reading them.
[haiku.git] / src / tests / kits / app / broster / IsRunningTester.cpp
blob618d014d39eb336fe8041e3f0d7d0652f69823c1
1 //------------------------------------------------------------------------------
2 // IsRunningTester.cpp
3 //
4 //------------------------------------------------------------------------------
6 // Standard Includes -----------------------------------------------------------
7 #include <stdio.h>
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>
17 // Project Includes ------------------------------------------------------------
18 #include <TestShell.h>
19 #include <TestUtils.h>
20 #include <cppunit/TestAssert.h>
22 // Local Includes --------------------------------------------------------------
23 #include "AppRunner.h"
24 #include "IsRunningTester.h"
26 // Local Defines ---------------------------------------------------------------
28 // Globals ---------------------------------------------------------------------
30 //------------------------------------------------------------------------------
33 bool IsRunning(const char *signature) const
34 @case 1 signature is NULL
35 @results Should return false.
37 void IsRunningTester::IsRunningTestA1()
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
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.
52 void IsRunningTester::IsRunningTestA2()
54 BRoster roster;
55 CHK(roster.IsRunning("application/x-vnd.obos-app-run-testapp1") == false);
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.
64 void IsRunningTester::IsRunningTestA3()
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);
83 bool IsRunning(entry_ref *ref) const
84 @case 1 ref is NULL
85 @results Should return false.
87 void IsRunningTester::IsRunningTestB1()
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
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.
101 void IsRunningTester::IsRunningTestB2()
103 BRoster roster;
104 entry_ref ref;
105 CHK(find_test_app("AppRunTestApp1", &ref) == B_OK);
106 CHK(roster.IsRunning(&ref) == false);
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.
115 void IsRunningTester::IsRunningTestB3()
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);
136 Test* IsRunningTester::Suite()
138 TestSuite* SuiteOfTests = new TestSuite;
140 ADD_TEST4(BRoster, SuiteOfTests, IsRunningTester, IsRunningTestA1);
141 ADD_TEST4(BRoster, SuiteOfTests, IsRunningTester, IsRunningTestA2);
142 ADD_TEST4(BRoster, SuiteOfTests, IsRunningTester, IsRunningTestA3);
144 ADD_TEST4(BRoster, SuiteOfTests, IsRunningTester, IsRunningTestB1);
145 ADD_TEST4(BRoster, SuiteOfTests, IsRunningTester, IsRunningTestB2);
146 ADD_TEST4(BRoster, SuiteOfTests, IsRunningTester, IsRunningTestB3);
148 return SuiteOfTests;