xref: /haiku/src/tests/kits/app/bclipboard/CountTester.cpp (revision d5cd5d63ff0ad395989db6cf4841a64d5b545d1d)
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   if ( clip.Lock() )
50   {
51     clip.Clear();
52     if ( (data = clip.Data()) )
53     {
54       data->AddData("text/plain",B_MIME_TYPE,"LocalCount2",12);
55       clip.Commit();
56     }
57     clip.Unlock();
58   }
59 
60   CHK(clip.LocalCount() == 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   if ( clipB.Lock() )
76   {
77     clipB.Clear();
78     if ( (data = clipB.Data()) )
79     {
80       data->AddData("text/plain",B_MIME_TYPE,"LocalCount3",12);
81       clipB.Commit();
82     }
83     clipB.Unlock();
84   }
85   if ( clipA.Lock() )
86   {
87     clipA.Unlock();
88   }
89 
90   CHK(clipA.LocalCount() == 1);
91   CHK(clipB.LocalCount() == 1);
92 }
93 
94 /*
95 	LocalCount()
96 	@case 4
97 	@results		clipA.LocalCount() == 1
98 				clipB.LocalCount() == 2
99  */
100 void CountTester::LocalCount4()
101 {
102   BApplication app("application/x-vnd.clipboardtest");
103   BClipboard clipA("LocalCount4");
104   BClipboard clipB("LocalCount4");
105   BMessage *data;
106 
107   if ( clipB.Lock() )
108   {
109     clipB.Clear();
110     if ( (data = clipB.Data()) )
111     {
112       data->AddData("text/plain",B_MIME_TYPE,"LocalCount4",12);
113       clipB.Commit();
114     }
115     clipB.Unlock();
116   }
117   if ( clipA.Lock() )
118   {
119     clipA.Unlock();
120   }
121   if ( clipB.Lock() )
122   {
123     clipB.Clear();
124     if ( (data = clipB.Data()) )
125     {
126       data->AddData("text/plain",B_MIME_TYPE,"LocalCount4",12);
127       clipB.Commit();
128     }
129     clipB.Unlock();
130   }
131 
132   CHK(clipA.LocalCount() == 1);
133   CHK(clipB.LocalCount() == 2);
134 }
135 
136 /*
137 	LocalCount()
138 	@case 5
139 	@results		clipA.LocalCount() == 1
140 				clipB.LocalCount() == 2
141  */
142 void CountTester::LocalCount5()
143 {
144   BApplication app("application/x-vnd.clipboardtest");
145   BClipboard clipA("LocalCount5");
146   BClipboard clipB("LocalCount5");
147   BMessage *data;
148 
149   if ( clipA.Lock() )
150   {
151     clipA.Clear();
152     if ( (data = clipA.Data()) )
153     {
154       data->AddData("text/plain",B_MIME_TYPE,"LocalCount5",12);
155       clipA.Commit();
156     }
157     clipA.Unlock();
158   }
159   if ( clipB.Lock() )
160   {
161     clipB.Clear();
162     if ( (data = clipB.Data()) )
163     {
164       data->AddData("text/plain",B_MIME_TYPE,"LocalCount5",12);
165       clipB.Commit();
166     }
167     clipB.Unlock();
168   }
169 
170   CHK(clipA.LocalCount() == 1);
171   CHK(clipB.LocalCount() == 2);
172 }
173 
174 /*
175 	LocalCount()
176 	@case 6
177 	@results		clipA.LocalCount() == 1
178 				clipB.LocalCount() == 0
179  */
180 void CountTester::LocalCount6()
181 {
182   BApplication app("application/x-vnd.clipboardtest");
183   BClipboard clipA("LocalCount6A");
184   BClipboard clipB("LocalCount6B");
185   BMessage *data;
186 
187   if ( clipA.Lock() )
188   {
189     clipA.Clear();
190     if ( (data = clipA.Data()) )
191     {
192       data->AddData("text/plain",B_MIME_TYPE,"LocalCount6",12);
193       clipA.Commit();
194     }
195     clipA.Unlock();
196   }
197   if ( clipB.Lock() )
198   {
199     clipB.Unlock();
200   }
201 
202   CHK(clipA.LocalCount() == 1);
203   CHK(clipB.LocalCount() == 0);
204 }
205 
206 /*
207 	SystemCount()
208 	@case 1
209 	@results		count == 0
210  */
211 void CountTester::SystemCount1()
212 {
213   BApplication app("application/x-vnd.clipboardtest");
214   BClipboard clip("SystemCount1");
215 
216   CHK(clip.SystemCount() == 0);
217 }
218 
219 /*
220 	SystemCount()
221 	@case 2
222 	@results		clipA.SystemCount() == 1
223 				clipB.SystemCount() == 1
224  */
225 void CountTester::SystemCount2()
226 {
227   BApplication app("application/x-vnd.clipboardtest");
228   BClipboard clipA("SystemCount2");
229   BClipboard clipB("SystemCount2");
230   BMessage *data;
231 
232   if ( clipA.Lock() )
233   {
234     clipA.Clear();
235     if ( (data = clipA.Data()) )
236     {
237       data->AddData("text/plain",B_MIME_TYPE,"SystemCount2",12);
238       clipA.Commit();
239     }
240     clipA.Unlock();
241   }
242 
243   CHK(clipA.SystemCount() == 1);
244   CHK(clipB.SystemCount() == 1);
245 }
246 
247 /*
248 	SystemCount()
249 	@case 3
250 	@results		clipA.SystemCount() == 1
251 				clipB.SystemCount() == 0
252  */
253 void CountTester::SystemCount3()
254 {
255   BApplication app("application/x-vnd.clipboardtest");
256   BClipboard clipA("SystemCount3A");
257   BClipboard clipB("SystemCount3B");
258   BMessage *data;
259 
260   if ( clipA.Lock() )
261   {
262     clipA.Clear();
263     if ( (data = clipA.Data()) )
264     {
265       data->AddData("text/plain",B_MIME_TYPE,"SystemCount3",12);
266       clipA.Commit();
267     }
268     clipA.Unlock();
269   }
270 
271   CHK(clipA.SystemCount() == 1);
272   CHK(clipB.SystemCount() == 0);
273 }
274 
275 Test* CountTester::Suite()
276 {
277 	TestSuite* SuiteOfTests = new TestSuite;
278 
279 	ADD_TEST4(BClipboard, SuiteOfTests, CountTester, LocalCount1);
280 	ADD_TEST4(BClipboard, SuiteOfTests, CountTester, LocalCount2);
281 	ADD_TEST4(BClipboard, SuiteOfTests, CountTester, LocalCount3);
282 	ADD_TEST4(BClipboard, SuiteOfTests, CountTester, LocalCount4);
283 	ADD_TEST4(BClipboard, SuiteOfTests, CountTester, LocalCount5);
284 	ADD_TEST4(BClipboard, SuiteOfTests, CountTester, LocalCount6);
285 	ADD_TEST4(BClipboard, SuiteOfTests, CountTester, SystemCount1);
286 	ADD_TEST4(BClipboard, SuiteOfTests, CountTester, SystemCount2);
287 	ADD_TEST4(BClipboard, SuiteOfTests, CountTester, SystemCount3);
288 
289 	return SuiteOfTests;
290 }
291 
292 
293 
294