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