1 //------------------------------------------------------------------------------
2 // BApplicationTester.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 <Application.h>
13 #include <Handler.h>
14 #include <Looper.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 "PipedAppRunner.h"
24 #include "BApplicationTester.h"
25
26 // Local Defines ---------------------------------------------------------------
27
28 // Globals ---------------------------------------------------------------------
29
30 //------------------------------------------------------------------------------
31
32 // test_app
33 static
34 void
test_app(const char * app,const char * expectedResult)35 test_app(const char *app, const char *expectedResult)
36 {
37 // run the app
38 PipedAppRunner runner;
39 CHK(runner.Run(app) == B_OK);
40 runner.WaitFor();
41 // get the output and compare the result
42 BString buffer;
43 CHK(runner.GetOutput(&buffer) == B_OK);
44 if (buffer != expectedResult)
45 printf("result is `%s', but should be `%s'\n", buffer.String(),
46 expectedResult);
47 CHK(buffer == expectedResult);
48 }
49
50
51 /*
52 BApplication(const char *signature)
53 @case 1 signature is NULL
54 @results Should print error message and quit.
55 */
BApplication1()56 void TBApplicationTester::BApplication1()
57 {
58 const char *output1 =
59 "bad signature ((null)), must begin with \"application/\" and "
60 "can't conflict with existing registered mime types inside "
61 "the \"application\" media type.\n";
62 const char *output2 =
63 "bad signature ((null)), must begin with \"application/\" and "
64 "can't conflict with existing registered mime types inside "
65 "the \"application\" media type.\n"
66 "error: 80000005\n"
67 "InitCheck(): 80000005\n";
68 test_app("BApplicationTestApp1", output1);
69 test_app("BApplicationTestApp1a", output1);
70 test_app("BApplicationTestApp1b", output2);
71 }
72
73 /*
74 BApplication(const char *signature)
75 @case 2 signature is no valid MIME string
76 @results Should print error message and quit.
77 */
BApplication2()78 void TBApplicationTester::BApplication2()
79 {
80 const char *output1 =
81 "bad signature (no valid MIME string), must begin with "
82 "\"application/\" and can't conflict with existing registered "
83 "mime types inside the \"application\" media type.\n";
84 const char *output2 =
85 "bad signature (no valid MIME string), must begin with "
86 "\"application/\" and can't conflict with existing registered "
87 "mime types inside the \"application\" media type.\n"
88 "error: 80000005\n"
89 "InitCheck(): 80000005\n";
90 test_app("BApplicationTestApp2", output1);
91 test_app("BApplicationTestApp2a", output1);
92 test_app("BApplicationTestApp2b", output2);
93 }
94
95 /*
96 BApplication(const char *signature)
97 @case 3 signature is a valid MIME string, but doesn't have the
98 "application" supertype
99 @results Should print error message and quit.
100 */
BApplication3()101 void TBApplicationTester::BApplication3()
102 {
103 const char *output1 =
104 "bad signature (image/gif), must begin with \"application/\" and "
105 "can't conflict with existing registered mime types inside "
106 "the \"application\" media type.\n";
107 const char *output2 =
108 "bad signature (image/gif), must begin with \"application/\" and "
109 "can't conflict with existing registered mime types inside "
110 "the \"application\" media type.\n"
111 "error: 80000005\n"
112 "InitCheck(): 80000005\n";
113 test_app("BApplicationTestApp3", output1);
114 test_app("BApplicationTestApp3a", output1);
115 test_app("BApplicationTestApp3b", output2);
116 }
117
118 /*
119 BApplication(const char *signature)
120 @case 4 signature is a valid MIME string with "application"
121 supertype, but a different one than in the app
122 attributes/resources
123 @results Should print warning message and continue.
124 InitCheck() should return B_OK.
125 */
BApplication4()126 void TBApplicationTester::BApplication4()
127 {
128 const char *output1 =
129 "Signature in rsrc doesn't match constructor arg. "
130 "(application/x-vnd.obos-bapplication-testapp4,"
131 #ifndef TEST_R5
132 " "
133 #endif
134 "application/x-vnd.obos-bapplication-testapp4-or-not)\n"
135 "InitCheck(): 0\n";
136 const char *output2 =
137 "Signature in rsrc doesn't match constructor arg. "
138 "(application/x-vnd.obos-bapplication-testapp4,"
139 #ifndef TEST_R5
140 " "
141 #endif
142 "application/x-vnd.obos-bapplication-testapp4-or-not)\n"
143 "error: 0\n"
144 "InitCheck(): 0\n";
145 test_app("BApplicationTestApp4", output1);
146 test_app("BApplicationTestApp4a", output1);
147 test_app("BApplicationTestApp4b", output2);
148 }
149
150 /*
151 BApplication(const char *signature)
152 @case 5 signature is a valid MIME string with "application"
153 supertype, and the same as in the app attributes/resources
154 @results Shouldn't print anything at all and continue.
155 InitCheck() should return B_OK.
156 */
BApplication5()157 void TBApplicationTester::BApplication5()
158 {
159 const char *output1 = "InitCheck(): 0\n";
160 const char *output2 =
161 "error: 0\n"
162 "InitCheck(): 0\n";
163 test_app("BApplicationTestApp5", output1);
164 test_app("BApplicationTestApp5a", output1);
165 test_app("BApplicationTestApp5b", output2);
166 }
167
168
Suite()169 Test* TBApplicationTester::Suite()
170 {
171 TestSuite* SuiteOfTests = new TestSuite;
172
173 ADD_TEST4(BApplication, SuiteOfTests, TBApplicationTester, BApplication1);
174 ADD_TEST4(BApplication, SuiteOfTests, TBApplicationTester, BApplication2);
175 ADD_TEST4(BApplication, SuiteOfTests, TBApplicationTester, BApplication3);
176 ADD_TEST4(BApplication, SuiteOfTests, TBApplicationTester, BApplication4);
177 ADD_TEST4(BApplication, SuiteOfTests, TBApplicationTester, BApplication5);
178
179 return SuiteOfTests;
180 }
181
182
183
184