xref: /haiku/src/tests/kits/app/bcursor/BCursorTester.cpp (revision 1d9d47fc72028bb71b5f232a877231e59cfe2438)
1 //------------------------------------------------------------------------------
2 //	BCursorTester.cpp
3 //
4 //------------------------------------------------------------------------------
5 
6 // Standard Includes -----------------------------------------------------------
7 
8 // System Includes -------------------------------------------------------------
9 #include <Application.h>
10 #include <Cursor.h>
11 #include <Message.h>
12 
13 #define CHK	CPPUNIT_ASSERT
14 
15 // Project Includes ------------------------------------------------------------
16 
17 // Local Includes --------------------------------------------------------------
18 #include "BCursorTester.h"
19 
20 // Local Defines ---------------------------------------------------------------
21 
22 // Globals ---------------------------------------------------------------------
23 
24 //------------------------------------------------------------------------------
25 
26 /*
27 	BCursor(const void *cursorData)
28 	@case 1
29 	@results		nothing apparent (no segfault)
30  */
31 void BCursorTester::BCursor1()
32 {
33   BApplication app("application/x-vnd.cursortest");
34   BCursor cur((void *)NULL);
35 }
36 
37 /*
38 	BCursor(const void *cursorData)
39 	@case 2
40 	@results		nothing apparent
41  */
42 void BCursorTester::BCursor2()
43 {
44   BApplication app("application/x-vnd.cursortest");
45   char data[68];
46   int i;
47 
48   data[0] = 16;
49   data[1] = 1;
50   data[2] = 0;
51   data[3] = 0;
52   for (i=4; i<68; i++)
53     data[i] = 1;
54 
55   BCursor cur(data);
56 }
57 
58 /*
59 	BCursor(const void *cursorData)
60 	@case 3
61 	@results		nothing apparent (no segfaults)
62  */
63 void BCursorTester::BCursor3()
64 {
65   BApplication app("application/x-vnd.cursortest");
66   int x;
67   BCursor cur1(&x);
68   char data[68];
69   data[0] = 32;
70   BCursor cur2(data);
71   data[0] = 16;
72   data[1] = 8;
73   BCursor cur3(data);
74   data[1] = 1;
75   data[2] = 16;
76   data[3] = 16;
77   BCursor cur4(data);
78 }
79 
80 /*
81 	BCursor(BMessage *archive)
82 	@case 1
83 	@results		nothing apparent (no segfault)
84  */
85 void BCursorTester::BCursor4()
86 {
87   BApplication app("application/x-vnd.cursortest");
88   BCursor cur((BMessage *)NULL);
89 }
90 
91 /*
92 	BCursor(BMessage *archive)
93 	@case 2
94 	@results		nothing apparent (empty cursor)
95  */
96 void BCursorTester::BCursor5()
97 {
98   BApplication app("application/x-vnd.cursortest");
99   /* The message really should contain a valid archive, but Cursor doesn't
100      support archiving anyway, so until R2, this is a moot point.
101   */
102   BMessage msg;
103   BCursor cur(&msg);
104 }
105 
106 /*
107 	static BArchivable *Instantiate(BMessage *archive)
108 	@case 1
109 	@results		return NULL
110  */
111 void BCursorTester::Instantiate1()
112 {
113   BApplication app("application/x-vnd.cursortest");
114   CHK(BCursor::Instantiate(NULL) == NULL);
115 }
116 
117 /*
118 	static BArchivable *Instantiate(BMessage *archive)
119 	@case 2
120 	@results		return NULL
121  */
122 void BCursorTester::Instantiate2()
123 {
124   BApplication app("application/x-vnd.cursortest");
125   /* The message really should contain a valid archive, but Cursor doesn't
126      support archiving anyway, so until R2, this is a moot point.
127   */
128   BMessage msg;
129   CHK(BCursor::Instantiate(&msg) == NULL);
130 }
131 
132 /*
133 	status_t Archive(BMessage* into, bool deep = true)
134 	@case 1
135 	@results		return B_OK
136  */
137 void BCursorTester::Archive1()
138 {
139   BApplication app("application/x-vnd.cursortest");
140   char data[68];
141   int i;
142 
143   data[0] = 16;
144   data[1] = 1;
145   data[2] = 0;
146   data[3] = 0;
147   for (i=4; i<68; i++)
148     data[i] = 1;
149 
150   BCursor cur(data);
151   CHK(cur.Archive(NULL) == B_OK);
152 }
153 
154 /*
155 	status_t Archive(BMessage* into, bool deep = true)
156 	@case 2
157 	@results		return B_OK
158  */
159 void BCursorTester::Archive2()
160 {
161   BApplication app("application/x-vnd.cursortest");
162   char data[68];
163   int i;
164 
165   data[0] = 16;
166   data[1] = 1;
167   data[2] = 0;
168   data[3] = 0;
169   for (i=4; i<68; i++)
170     data[i] = 1;
171 
172   BCursor cur(data);
173   BMessage msg;
174   CHK(cur.Archive(&msg) == B_OK);
175 }
176 
177 /*
178 	status_t Perform(perform_code d, void* arg)
179 	@case 1
180 	@results		return B_OK
181  */
182 void BCursorTester::Perform1()
183 {
184   BApplication app("application/x-vnd.cursortest");
185   char data[68];
186   int i;
187 
188   data[0] = 16;
189   data[1] = 1;
190   data[2] = 0;
191   data[3] = 0;
192   for (i=4; i<68; i++)
193     data[i] = 1;
194 
195   BCursor cur(data);
196   CHK(cur.Perform(0,NULL) == B_OK);
197 }
198 
199 /*
200 	status_t Perform(perform_code d, void* arg)
201 	@case 2
202 	@results		return B_OK
203  */
204 void BCursorTester::Perform2()
205 {
206   BApplication app("application/x-vnd.cursortest");
207   char data[68];
208   int i;
209 
210   data[0] = 16;
211   data[1] = 1;
212   data[2] = 0;
213   data[3] = 0;
214   for (i=4; i<68; i++)
215     data[i] = 1;
216 
217   BCursor cur(data);
218   CHK(cur.Perform(0,&i) == B_OK);
219 }
220 
221 Test* BCursorTester::Suite()
222 {
223 	TestSuite* SuiteOfTests = new TestSuite;
224 
225 	ADD_TEST4(BCursor, SuiteOfTests, BCursorTester, BCursor1);
226 	ADD_TEST4(BCursor, SuiteOfTests, BCursorTester, BCursor2);
227 	ADD_TEST4(BCursor, SuiteOfTests, BCursorTester, BCursor3);
228 	ADD_TEST4(BCursor, SuiteOfTests, BCursorTester, BCursor4);
229 	ADD_TEST4(BCursor, SuiteOfTests, BCursorTester, BCursor5);
230 	ADD_TEST4(BCursor, SuiteOfTests, BCursorTester, Instantiate1);
231 	ADD_TEST4(BCursor, SuiteOfTests, BCursorTester, Instantiate2);
232 	ADD_TEST4(BCursor, SuiteOfTests, BCursorTester, Archive1);
233 	ADD_TEST4(BCursor, SuiteOfTests, BCursorTester, Archive2);
234 	ADD_TEST4(BCursor, SuiteOfTests, BCursorTester, Perform1);
235 	ADD_TEST4(BCursor, SuiteOfTests, BCursorTester, Perform2);
236 
237 	return SuiteOfTests;
238 }
239 
240 
241 
242