xref: /haiku/src/tests/kits/app/bclipboard/CountTester.cpp (revision 17889a8c70dbb3d59c1412f6431968753c767bab)
1 //------------------------------------------------------------------------------
2 //	CountTester.cpp
3 //
4 //------------------------------------------------------------------------------
5 
6 // Standard Includes -----------------------------------------------------------
7 
8 // System Includes -------------------------------------------------------------
9 #include <Application.h>
10 #include <Clipboard.h>
11 
12 #define CHK	CPPUNIT_ASSERT
13 
14 // Project Includes ------------------------------------------------------------
15 
16 // Local Includes --------------------------------------------------------------
17 #include "CountTester.h"
18 
19 // Local Defines ---------------------------------------------------------------
20 
21 // Globals ---------------------------------------------------------------------
22 
23 //------------------------------------------------------------------------------
24 
25 /*
26 	LocalCount()
27 	@case 1
28 	@results		count == 0
29  */
30 void CountTester::LocalCount1()
31 {
32 	BApplication app("application/x-vnd.clipboardtest");
33 	BClipboard clip("LocalCount1");
34 
35 	CHK(clip.LocalCount() == 0);
36 }
37 
38 /*
39 	LocalCount()
40 	@case 2
41 	@results		count == +1
42  */
43 void CountTester::LocalCount2()
44 {
45 	BApplication app("application/x-vnd.clipboardtest");
46 	BClipboard clip("LocalCount2");
47 	BMessage *data;
48 
49 	uint32 oldCount = clip.SystemCount();
50 
51 	if (clip.Lock()) {
52 		clip.Clear();
53 		if ((data = clip.Data())) {
54 			data->AddData("text/plain", B_MIME_TYPE, "LocalCount2", 12);
55 			clip.Commit();
56 		}
57 		clip.Unlock();
58 	}
59 
60 	CHK(clip.LocalCount() == oldCount + 1);
61 }
62 
63 /*
64 	LocalCount()
65 	@case 3
66 	@results		both counts == +1
67  */
68 void CountTester::LocalCount3()
69 {
70 	BApplication app("application/x-vnd.clipboardtest");
71 	BClipboard clipA("LocalCount3");
72 	BClipboard clipB("LocalCount3");
73 	BMessage *data;
74 
75 	uint32 oldCount = clipA.SystemCount();
76 
77 	CHK(clipB.Lock());
78 	clipB.Clear();
79 	if ((data = clipB.Data())) {
80 		data->AddData("text/plain", B_MIME_TYPE, "LocalCount3", 12);
81 		clipB.Commit();
82 	}
83 	clipB.Unlock();
84 
85 	CHK(clipA.Lock());
86 	clipA.Unlock();
87 
88 	CHK(clipA.LocalCount() == oldCount + 1);
89 	CHK(clipB.LocalCount() == oldCount + 1);
90 }
91 
92 /*
93 	LocalCount()
94 	@case 4
95 	@results	clipA.LocalCount() == +1
96 				clipB.LocalCount() == +2
97  */
98 void CountTester::LocalCount4()
99 {
100 	BApplication app("application/x-vnd.clipboardtest");
101 	BClipboard clipA("LocalCount4");
102 	BClipboard clipB("LocalCount4");
103 	BMessage *data;
104 
105 	uint32 oldCount = clipA.SystemCount();
106 
107 	if (clipB.Lock()) {
108 		clipB.Clear();
109 		if ((data = clipB.Data())) {
110 			data->AddData("text/plain", B_MIME_TYPE, "LocalCount4", 12);
111 			clipB.Commit();
112 		}
113 		clipB.Unlock();
114 	}
115 
116 	if (clipA.Lock())
117 		clipA.Unlock();
118 
119 	if (clipB.Lock()) {
120 		clipB.Clear();
121 		if ((data = clipB.Data())) {
122 			data->AddData("text/plain",B_MIME_TYPE,"LocalCount4",12);
123 			clipB.Commit();
124 		}
125 		clipB.Unlock();
126 	}
127 
128 	CHK(clipA.LocalCount() == oldCount + 1);
129 	CHK(clipB.LocalCount() == oldCount + 2);
130 }
131 
132 /*
133 	LocalCount()
134 	@case 5
135 	@results	clipA.LocalCount() == 1
136 				clipB.LocalCount() == 2
137  */
138 void CountTester::LocalCount5()
139 {
140 	BApplication app("application/x-vnd.clipboardtest");
141 	BClipboard clipA("LocalCount5");
142 	BClipboard clipB("LocalCount5");
143 	BMessage *data;
144 
145 	uint32 oldCount = clipA.SystemCount();
146 
147 	if (clipA.Lock()) {
148 		clipA.Clear();
149 		if ((data = clipA.Data())) {
150 			data->AddData("text/plain", B_MIME_TYPE, "LocalCount5", 12);
151 			clipA.Commit();
152 		}
153 		clipA.Unlock();
154 	}
155 
156 	if (clipB.Lock()) {
157 		clipB.Clear();
158 		if ((data = clipB.Data())) {
159 			data->AddData("text/plain", B_MIME_TYPE, "LocalCount5", 12);
160 			clipB.Commit();
161 		}
162 		clipB.Unlock();
163 	}
164 
165 	CHK(clipA.LocalCount() == oldCount + 1);
166 	CHK(clipB.LocalCount() == oldCount + 2);
167 }
168 
169 /*
170 	LocalCount()
171 	@case 6
172 	@results	clipA.LocalCount() == +1
173 				clipB.LocalCount() == 0
174  */
175 void CountTester::LocalCount6()
176 {
177 	BApplication app("application/x-vnd.clipboardtest");
178 	BClipboard clipA("LocalCount6A");
179 	BClipboard clipB("LocalCount6B");
180 	BMessage *data;
181 
182 	uint32 oldCount = clipA.SystemCount();
183 
184 	if (clipA.Lock()) {
185 		clipA.Clear();
186 		if ((data = clipA.Data())) {
187 			data->AddData("text/plain", B_MIME_TYPE, "LocalCount6" ,12);
188 			clipA.Commit();
189 		}
190 		clipA.Unlock();
191 	}
192 
193 	if (clipB.Lock())
194 		clipB.Unlock();
195 
196 	CHK(clipA.LocalCount() == oldCount + 1);
197 	CHK(clipB.LocalCount() == 0);
198 }
199 
200 /*
201 	SystemCount()
202 	@case 1
203 	@results		count == 0
204  */
205 void CountTester::SystemCount1()
206 {
207 	BApplication app("application/x-vnd.clipboardtest");
208 	BClipboard clip("SystemCount1");
209 
210 	CHK(clip.SystemCount() == 0);
211 }
212 
213 /*
214 	SystemCount()
215 	@case 2
216 	@results	clipA.SystemCount() == +1
217 				clipB.SystemCount() == +1
218  */
219 void CountTester::SystemCount2()
220 {
221 	BApplication app("application/x-vnd.clipboardtest");
222 	BClipboard clipA("SystemCount2");
223 	BClipboard clipB("SystemCount2");
224 	BMessage *data;
225 
226 	uint32 oldCount = clipA.SystemCount();
227 
228 	if (clipA.Lock()) {
229 		clipA.Clear();
230 		if ((data = clipA.Data())) {
231 			data->AddData("text/plain", B_MIME_TYPE, "SystemCount2", 12);
232 			clipA.Commit();
233 		}
234 		clipA.Unlock();
235 	}
236 
237 	CHK(clipA.SystemCount() == oldCount + 1);
238 	CHK(clipB.SystemCount() == oldCount + 1);
239 }
240 
241 /*
242 	SystemCount()
243 	@case 3
244 	@results	clipA.SystemCount() == +1
245 				clipB.SystemCount() == 0
246  */
247 void CountTester::SystemCount3()
248 {
249 	BApplication app("application/x-vnd.clipboardtest");
250 	BClipboard clipA("SystemCount3A");
251 	BClipboard clipB("SystemCount3B");
252 	BMessage *data;
253 
254 	uint32 oldCount = clipA.SystemCount();
255 
256 	if (clipA.Lock()) {
257 		clipA.Clear();
258 		if ((data = clipA.Data())) {
259 			data->AddData("text/plain", B_MIME_TYPE, "SystemCount3", 12);
260 			clipA.Commit();
261 		}
262 		clipA.Unlock();
263 	}
264 
265 	CHK(clipA.SystemCount() == oldCount + 1);
266 	CHK(clipB.SystemCount() == 0);
267 }
268 
269 Test* CountTester::Suite()
270 {
271 	TestSuite* SuiteOfTests = new TestSuite;
272 
273 	ADD_TEST4(BClipboard, SuiteOfTests, CountTester, LocalCount1);
274 	ADD_TEST4(BClipboard, SuiteOfTests, CountTester, LocalCount2);
275 	ADD_TEST4(BClipboard, SuiteOfTests, CountTester, LocalCount3);
276 	ADD_TEST4(BClipboard, SuiteOfTests, CountTester, LocalCount4);
277 	ADD_TEST4(BClipboard, SuiteOfTests, CountTester, LocalCount5);
278 	ADD_TEST4(BClipboard, SuiteOfTests, CountTester, LocalCount6);
279 	ADD_TEST4(BClipboard, SuiteOfTests, CountTester, SystemCount1);
280 	ADD_TEST4(BClipboard, SuiteOfTests, CountTester, SystemCount2);
281 	ADD_TEST4(BClipboard, SuiteOfTests, CountTester, SystemCount3);
282 
283 	return SuiteOfTests;
284 }
285