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