1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371
|
#import "ObjectTesting.h"
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSOrderedSet.h>
static NSString *stringData = @"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
@"<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">"
@"<plist version=\"1.0\">"
@"<dict>"
@" <key>$archiver</key>"
@" <string>NSKeyedArchiver</string>"
@" <key>$objects</key>"
@" <array>"
@" <string>$null</string>"
@" <dict>"
@" <key>$class</key>"
@" <dict>"
@" <key>CF$UID</key>"
@" <integer>14</integer>"
@" </dict>"
@" <key>NS.object.0</key>"
@" <dict>"
@" <key>CF$UID</key>"
@" <integer>2</integer>"
@" </dict>"
@" <key>NS.object.1</key>"
@" <dict>"
@" <key>CF$UID</key>"
@" <integer>3</integer>"
@" </dict>"
@" <key>NS.object.10</key>"
@" <dict>"
@" <key>CF$UID</key>"
@" <integer>12</integer>"
@" </dict>"
@" <key>NS.object.11</key>"
@" <dict>"
@" <key>CF$UID</key>"
@" <integer>13</integer>"
@" </dict>"
@" <key>NS.object.2</key>"
@" <dict>"
@" <key>CF$UID</key>"
@" <integer>4</integer>"
@" </dict>"
@" <key>NS.object.3</key>"
@" <dict>"
@" <key>CF$UID</key>"
@" <integer>5</integer>"
@" </dict>"
@" <key>NS.object.4</key>"
@" <dict>"
@" <key>CF$UID</key>"
@" <integer>6</integer>"
@" </dict>"
@" <key>NS.object.5</key>"
@" <dict>"
@" <key>CF$UID</key>"
@" <integer>7</integer>"
@" </dict>"
@" <key>NS.object.6</key>"
@" <dict>"
@" <key>CF$UID</key>"
@" <integer>8</integer>"
@" </dict>"
@" <key>NS.object.7</key>"
@" <dict>"
@" <key>CF$UID</key>"
@" <integer>9</integer>"
@" </dict>"
@" <key>NS.object.8</key>"
@" <dict>"
@" <key>CF$UID</key>"
@" <integer>10</integer>"
@" </dict>"
@" <key>NS.object.9</key>"
@" <dict>"
@" <key>CF$UID</key>"
@" <integer>11</integer>"
@" </dict>"
@" </dict>"
@" <string>Now</string>"
@" <string>is</string>"
@" <string>the</string>"
@" <string>time</string>"
@" <string>for</string>"
@" <string>all</string>"
@" <string>Horrible</string>"
@" <string>men</string>"
@" <string>to</string>"
@" <string>Flee From</string>"
@" <string>the aid</string>"
@" <string>of their country</string>"
@" <dict>"
@" <key>$classes</key>"
@" <array>"
@" <string>NSMutableOrderedSet</string>"
@" <string>NSOrderedSet</string>"
@" <string>NSObject</string>"
@" </array>"
@" <key>$classname</key>"
@" <string>NSMutableOrderedSet</string>"
@" </dict>"
@" </array>"
@" <key>$top</key>"
@" <dict>"
@" <key>root</key>"
@" <dict>"
@" <key>CF$UID</key>"
@" <integer>1</integer>"
@" </dict>"
@" </dict>"
@" <key>$version</key>"
@" <integer>100000</integer>"
@"</dict>"
@"</plist>";
int main()
{
START_SET("NSOrderedSet base")
NSOrderedSet *testObj, *testObj2;
NSMutableOrderedSet *mutableTest1, *mutableTest2;
NSMutableArray *testObjs = [NSMutableArray array];
NSData *data = [stringData dataUsingEncoding: NSUTF8StringEncoding];
NSMutableSet *testSet;
testObj = AUTORELEASE([NSOrderedSet new]);
[testObjs addObject: testObj];
PASS(testObj != nil && [testObj count] == 0,
"can create an empty ordered set");
testObj = [NSOrderedSet orderedSetWithObject: @"Hello"];
[testObjs addObject: testObj];
PASS(testObj != nil && [testObj count] == 1,
"can create an ordered set with one element");
id objs[] = {@"Hello", @"Hello1"};
testObj = [NSOrderedSet orderedSetWithObjects: objs count: 2];
[testObjs addObject: testObj];
PASS(testObj != nil && [testObj count] == 2,
"can create an ordered set with multi element");
id objs1[] = {@"Hello", @"Hello"};
testObj = [NSOrderedSet orderedSetWithObjects: objs1 count: 2];
[testObjs addObject: testObj];
PASS(testObj != nil && [testObj count] == 1,
"cannot create an ordered set with multiple like elements");
NSMutableArray *arr = [NSMutableArray array];
[arr addObject: @"Hello"];
[arr addObject: @"World"];
testObj = [NSOrderedSet orderedSetWithArray: arr];
[testObjs addObject: testObj];
PASS(testObj != nil && [testObj count] == 2,
"Is able to initialize with array");
id objs3[] = {@"Hello"};
id objc4[] = {@"World"};
testObj = [NSOrderedSet orderedSetWithObjects: objs3 count: 1];
[testObjs addObject: testObj];
testObj2 = [NSOrderedSet orderedSetWithObjects: objc4 count: 1];
[testObjs addObject: testObj2];
BOOL result = [testObj intersectsOrderedSet: testObj2];
PASS(result == NO,
"Sets do not intersect!");
id objs5[] = {@"Hello"};
id objc6[] = {@"Hello"};
testObj = [NSOrderedSet orderedSetWithObjects: objs5 count: 1];
[testObjs addObject: testObj];
testObj2 = [NSOrderedSet orderedSetWithObjects: objc6 count: 1];
[testObjs addObject: testObj2];
BOOL result1 = [testObj intersectsOrderedSet: testObj2];
PASS(result1 == YES,
"Sets do intersect!");
id o1 = @"Hello";
id o2 = @"World";
mutableTest1 = [NSMutableOrderedSet orderedSet];
[mutableTest1 addObject: o1];
[testObjs addObject: mutableTest1];
mutableTest2 = [NSMutableOrderedSet orderedSet];
[mutableTest2 addObject: o2];
[testObjs addObject: mutableTest2];
[mutableTest1 unionOrderedSet: mutableTest2];
PASS(mutableTest1 != nil && mutableTest2 != nil && [mutableTest1 count] == 2,
"mutableSets union properly");
id o3 = @"Hello";
id o4 = @"World";
mutableTest1 = [NSMutableOrderedSet orderedSet];
[mutableTest1 addObject: o3];
[testObjs addObject: mutableTest1];
mutableTest2 = [NSMutableOrderedSet orderedSet];
[mutableTest2 addObject: o4];
[testObjs addObject: mutableTest2];
[mutableTest1 intersectOrderedSet: mutableTest2];
PASS(mutableTest1 != nil && mutableTest2 != nil && [mutableTest1 count] == 0,
"mutableSets do not intersect");
id o5 = @"Hello";
id o6 = @"Hello";
mutableTest1 = [NSMutableOrderedSet orderedSet];
[mutableTest1 addObject: o5];
[testObjs addObject: mutableTest1];
mutableTest2 = [NSMutableOrderedSet orderedSet];
[mutableTest2 addObject: o6];
[testObjs addObject: mutableTest2];
[mutableTest1 intersectOrderedSet: mutableTest2];
PASS(mutableTest1 != nil && mutableTest2 != nil && [mutableTest1 count] == 1,
"mutableSets do intersect");
id o7 = @"Hello";
id o8 = @"World";
mutableTest1 = [NSMutableOrderedSet orderedSet];
[mutableTest1 addObject: o7];
[mutableTest1 addObject: o8];
[testObjs addObject: mutableTest1];
mutableTest2 = [NSMutableOrderedSet orderedSet];
[mutableTest2 addObject: o7];
[testObjs addObject: mutableTest2];
BOOL isSubset = [mutableTest2 isSubsetOfOrderedSet: mutableTest1];
PASS(isSubset,
"mutableTest2 is subset of mutableTest1");
testSet = [NSMutableSet set];
[testSet addObject: o7];
[testSet addObject: o8];
isSubset = [mutableTest2 isSubsetOfSet: testSet];
PASS(isSubset,
"mutableTest2 is subset of testSet");
id o9 = @"Hello";
id o10 = @"World";
id o11 = @"Ready";
mutableTest1 = [NSMutableOrderedSet orderedSet];
[mutableTest1 addObject: o9];
[testObjs addObject: mutableTest1];
mutableTest2 = [NSMutableOrderedSet orderedSet];
[mutableTest2 addObject: o10];
[mutableTest2 addObject: o9];
[testObjs addObject: mutableTest2];
isSubset = [mutableTest2 isSubsetOfOrderedSet: mutableTest1];
PASS(isSubset == NO,
"mutableTest2 is not subset of mutableTest1");
testSet = [NSMutableSet set];
[testSet addObject: o9];
isSubset = [mutableTest2 isSubsetOfSet: testSet];
PASS(isSubset == NO,
"mutableTest2 is not subset of testSet");
o9 = @"Hello";
o10 = @"World";
o11 = @"Ready";
id o12 = @"ToGo";
mutableTest1 = [NSMutableOrderedSet orderedSet];
[mutableTest1 addObject: o9];
[mutableTest1 addObject: o10];
[mutableTest1 addObject: o12];
[mutableTest1 addObject: o11];
[testObjs addObject: mutableTest1];
mutableTest2 = [NSMutableOrderedSet orderedSet];
[mutableTest2 addObject: o9];
[mutableTest2 addObject: o10];
[testObjs addObject: mutableTest2];
isSubset = [mutableTest2 isSubsetOfOrderedSet: mutableTest1];
PASS(isSubset,
"mutableTest2 is subset of mutableTest1");
testSet = [NSMutableSet set];
[testSet addObject: o9];
[testSet addObject: o10];
[testSet addObject: o12];
[testSet addObject: o11];
isSubset = [mutableTest2 isSubsetOfSet: testSet];
PASS(isSubset,
"mutableTest2 is subset of testSet");
o9 = @"Hello";
o10 = @"World";
o11 = @"Ready";
o12 = @"ToGo";
mutableTest1 = [NSMutableOrderedSet orderedSet];
[mutableTest1 addObject: o9];
[mutableTest1 addObject: o10];
[mutableTest1 addObject: o12];
[mutableTest1 addObject: o11];
[testObjs addObject: mutableTest1];
PASS([mutableTest1 isEqual: mutableTest1],
"mutableTest1 is equal to itself");
o9 = @"Hello";
o10 = @"World";
o11 = @"Ready";
o12 = @"ToGo";
NSMutableOrderedSet *mutableTest3 = [NSMutableOrderedSet orderedSet];
[mutableTest3 addObject: o9];
[mutableTest3 addObject: o10];
[mutableTest3 addObject: o12];
[mutableTest3 addObject: o11];
[mutableTest3 insertObject: @"Hello" atIndex: 2];
[testObjs addObject: mutableTest3];
PASS([mutableTest3 isEqual: mutableTest1] == YES,
"Insert at index does not replace existing object");
NSMutableOrderedSet *mutableTest4 = [NSMutableOrderedSet orderedSet];
[mutableTest4 addObject: @"Now"];
[mutableTest4 addObject: @"is"];
[mutableTest4 addObject: @"the"];
[mutableTest4 addObject: @"time"];
[mutableTest4 addObject: @"for"];
[mutableTest4 addObject: @"all"];
[mutableTest4 addObject: @"Good"];
[mutableTest4 addObject: @"men"];
[mutableTest4 addObject: @"to"];
[mutableTest4 addObject: @"come"];
[mutableTest4 addObject: @"to the aid"];
[mutableTest4 addObject: @"of their country"];
[mutableTest4 moveObjectsAtIndexes: [NSIndexSet indexSetWithIndex: 3] toIndex: 10];
[testObjs addObject: mutableTest4];
PASS([[mutableTest4 objectAtIndex: 10] isEqual: @"time"] == YES,
"Move to index moves to correct index");
NSMutableOrderedSet *mutableTest5 = [NSMutableOrderedSet orderedSet];
[mutableTest5 addObject: @"Now"];
[mutableTest5 addObject: @"is"];
[mutableTest5 addObject: @"the"];
[mutableTest5 exchangeObjectAtIndex: 0 withObjectAtIndex: 2];
[testObjs addObject: mutableTest5];
PASS([[mutableTest5 objectAtIndex: 0] isEqual: @"the"] == YES &&
[[mutableTest5 objectAtIndex: 2] isEqual: @"Now"] == YES,
"Exchanges indexes properly");
//NSLog(@"RESULT: %@",mutableTest4);
mutableTest4 = [NSMutableOrderedSet orderedSet];
[mutableTest4 addObject: @"Now"];
[mutableTest4 addObject: @"is"];
[mutableTest4 addObject: @"the"];
[mutableTest4 addObject: @"time"];
[mutableTest4 addObject: @"for"];
[mutableTest4 addObject: @"all"];
[mutableTest4 addObject: @"Good"];
[mutableTest4 addObject: @"men"];
[mutableTest4 addObject: @"to"];
[mutableTest4 addObject: @"come to"];
[mutableTest4 addObject: @"the aid"];
[mutableTest4 addObject: @"of their country"];
NSMutableIndexSet *is = [NSMutableIndexSet indexSetWithIndex: 6];
[is addIndex: 9];
NSMutableArray *array = [NSMutableArray arrayWithObjects: @"Horrible", @"Flee From", nil];
[mutableTest4 replaceObjectsAtIndexes: is
withObjects: array];
[testObjs addObject: mutableTest4];
PASS([[mutableTest4 objectAtIndex: 9] isEqual: @"Flee From"] == YES,
"replaceObjectsAtIndexes: adds to correct indexes");
id uobj = [NSKeyedUnarchiver unarchiveObjectWithData: data];
PASS((uobj != nil &&
[uobj isKindOfClass: [NSMutableOrderedSet class]] &&
[uobj containsObject: @"Now"]),
"Object unarchives correctly from macOS archive")
test_NSObject(@"NSOrderedSet", testObjs);
test_NSCoding(testObjs);
test_NSCopying(@"NSOrderedSet", @"NSMutableOrderedSet", testObjs, YES, NO);
test_NSMutableCopying(@"NSOrderedSet", @"NSMutableOrderedSet", testObjs);
END_SET("NSOrderedSet base")
return 0;
}
|