xref: /haiku/src/tests/kits/app/bapplication/BApplicationTester.cpp (revision 32b8ee2e940cad78263723c8fd52062db2478dea)
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
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  */
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  */
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  */
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  */
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 		"application/x-vnd.obos-bapplication-testapp4-or-not)\n"
132 		"InitCheck(): 0\n";
133 	const char *output2 =
134 		"Signature in rsrc doesn't match constructor arg. "
135 		"(application/x-vnd.obos-bapplication-testapp4,"
136 		"application/x-vnd.obos-bapplication-testapp4-or-not)\n"
137 		"error: 0\n"
138 		"InitCheck(): 0\n";
139 	test_app("BApplicationTestApp4", output1);
140 	test_app("BApplicationTestApp4a", output1);
141 	test_app("BApplicationTestApp4b", output2);
142 }
143 
144 /*
145 	BApplication(const char *signature)
146 	@case 5			signature is a valid MIME string with "application"
147 					supertype, and the same as in the app attributes/resources
148 	@results		Shouldn't print anything at all and continue.
149 					InitCheck() should return B_OK.
150  */
151 void TBApplicationTester::BApplication5()
152 {
153 	const char *output1 = "InitCheck(): 0\n";
154 	const char *output2 =
155 		"error: 0\n"
156 		"InitCheck(): 0\n";
157 	test_app("BApplicationTestApp5", output1);
158 	test_app("BApplicationTestApp5a", output1);
159 	test_app("BApplicationTestApp5b", output2);
160 }
161 
162 
163 Test* TBApplicationTester::Suite()
164 {
165 	TestSuite* SuiteOfTests = new TestSuite;
166 
167 	ADD_TEST4(BApplication, SuiteOfTests, TBApplicationTester, BApplication1);
168 	ADD_TEST4(BApplication, SuiteOfTests, TBApplicationTester, BApplication2);
169 	ADD_TEST4(BApplication, SuiteOfTests, TBApplicationTester, BApplication3);
170 	ADD_TEST4(BApplication, SuiteOfTests, TBApplicationTester, BApplication4);
171 	ADD_TEST4(BApplication, SuiteOfTests, TBApplicationTester, BApplication5);
172 
173 	return SuiteOfTests;
174 }
175 
176 
177 
178