23
23
// / The maximum time to wait for an expectation before failing.
24
24
static const NSTimeInterval kGULTestCaseTimeoutInterval = 10 ;
25
25
26
- @interface GULUserDefaults ()
27
- // Expose for testing.
28
- - (void )clearAllData ;
29
- @end
30
-
31
26
@interface GULUserDefaultsThreadArgs : NSObject
32
27
33
28
// / The new user defaults to be tested on threads.
@@ -152,26 +147,6 @@ - (void)testNewUserDefaultsWithStandardUserDefaults {
152
147
XCTAssertEqualObjects ([newUserDefaults dictionaryForKey: key4], dictionary2);
153
148
XCTAssertEqualObjects ([userDefaults objectForKey: key4], dictionary2);
154
149
155
- // Remove all of the objects from the new user defaults. The values from the NSUserDefaults must
156
- // also be cleared.
157
- [newUserDefaults clearAllData ];
158
- XCTAssertNil ([userDefaults objectForKey: key1]);
159
- XCTAssertNil ([newUserDefaults objectForKey: key1]);
160
- XCTAssertNil ([userDefaults objectForKey: key2]);
161
- XCTAssertNil ([newUserDefaults objectForKey: key2]);
162
- XCTAssertNil ([userDefaults objectForKey: key3]);
163
- XCTAssertNil ([newUserDefaults objectForKey: key3]);
164
- XCTAssertNil ([userDefaults objectForKey: key4]);
165
- XCTAssertNil ([newUserDefaults objectForKey: key4]);
166
- XCTAssertNil ([userDefaults objectForKey: key5]);
167
- XCTAssertNil ([newUserDefaults objectForKey: key5]);
168
- XCTAssertNil ([userDefaults objectForKey: key6]);
169
- XCTAssertNil ([newUserDefaults objectForKey: key6]);
170
- XCTAssertNil ([userDefaults objectForKey: key7]);
171
- XCTAssertNil ([newUserDefaults objectForKey: key7]);
172
- XCTAssertNil ([userDefaults objectForKey: key8]);
173
- XCTAssertNil ([newUserDefaults objectForKey: key8]);
174
-
175
150
[self removePreferenceFileWithSuiteName: suiteName];
176
151
}
177
152
@@ -385,24 +360,6 @@ - (void)testNewSharedUserDefaultsWithStandardUserDefaults {
385
360
XCTAssertEqualObjects ([newUserDefaults objectForKey: key4], dictionary2);
386
361
XCTAssertEqualObjects ([userDefaults objectForKey: key4], dictionary2);
387
362
388
- // Remove all of the objects from the new user defaults. The values from the NSUserDefaults must
389
- // also be cleared.
390
- [newUserDefaults clearAllData ];
391
- XCTAssertNil ([userDefaults objectForKey: key1]);
392
- XCTAssertNil ([newUserDefaults objectForKey: key1]);
393
- XCTAssertNil ([userDefaults objectForKey: key2]);
394
- XCTAssertNil ([newUserDefaults objectForKey: key2]);
395
- XCTAssertNil ([userDefaults objectForKey: key3]);
396
- XCTAssertNil ([newUserDefaults objectForKey: key3]);
397
- XCTAssertNil ([userDefaults objectForKey: key4]);
398
- XCTAssertNil ([newUserDefaults objectForKey: key4]);
399
- XCTAssertNil ([userDefaults objectForKey: key5]);
400
- XCTAssertNil ([newUserDefaults objectForKey: key5]);
401
- XCTAssertNil ([userDefaults objectForKey: key6]);
402
- XCTAssertNil ([newUserDefaults objectForKey: key6]);
403
- XCTAssertNil ([userDefaults objectForKey: key7]);
404
- XCTAssertNil ([newUserDefaults objectForKey: key7]);
405
-
406
363
[[NSUserDefaults standardUserDefaults ] removePersistentDomainForName: appDomain];
407
364
}
408
365
@@ -424,15 +381,14 @@ - (void)testUserDefaultNotifications {
424
381
[newUserDefaults setObject: nil forKey: @" test-another" ];
425
382
XCTAssertNil ([newUserDefaults objectForKey: @" test-another" ]);
426
383
[newUserDefaults synchronize ];
427
- [newUserDefaults clearAllData ];
428
384
[[NSNotificationCenter defaultCenter ] removeObserver: observer];
429
385
430
386
// Remove the underlying reference file.
431
387
[self removePreferenceFileWithSuiteName: suiteName];
432
388
}
433
389
434
390
- (void )testSynchronizeToDisk {
435
- #if TARGET_OS_OSX
391
+ #if TARGET_OS_OSX || TARGET_OS_MACCATALYST
436
392
// `NSFileManager` has trouble reading the files in `~/Library` even though the
437
393
// `removeItemAtPath:` call works. Watching Finder while stepping through this test shows that the
438
394
// file does get created and removed properly. When using LLDB to call `fileExistsAtPath:` the
@@ -458,7 +414,6 @@ - (void)testSynchronizeToDisk {
458
414
459
415
// Now get the file directly from disk.
460
416
XCTAssertTrue ([fileManager fileExistsAtPath: filePath]);
461
- [newUserDefaults clearAllData ];
462
417
[newUserDefaults synchronize ];
463
418
464
419
[self removePreferenceFileWithSuiteName: suiteName];
@@ -500,7 +455,6 @@ - (void)testSetNilObject {
500
455
501
456
[newUserDefaults setObject: nil forKey: @" fine" ];
502
457
XCTAssertNil ([newUserDefaults objectForKey: @" fine" ]);
503
- [newUserDefaults clearAllData ];
504
458
505
459
[self removePreferenceFileWithSuiteName: suiteName];
506
460
}
@@ -513,7 +467,6 @@ - (void)testRemoveObject {
513
467
514
468
[newUserDefaults removeObjectForKey: @" fine" ];
515
469
XCTAssertNil ([newUserDefaults objectForKey: @" fine" ]);
516
- [newUserDefaults clearAllData ];
517
470
518
471
[self removePreferenceFileWithSuiteName: suiteName];
519
472
}
@@ -535,7 +488,6 @@ - (void)testNewUserDefaultsWithNSUserDefaultsFile {
535
488
GULUserDefaults *newUserDefaults = [[GULUserDefaults alloc ] initWithSuiteName: suiteName];
536
489
XCTAssertEqualObjects ([newUserDefaults objectForKey: @" key1" ], @" value1" );
537
490
XCTAssertEqualObjects ([newUserDefaults objectForKey: @" key2" ], @" value2" );
538
- [newUserDefaults clearAllData ];
539
491
540
492
// Clean up.
541
493
[self removePreferenceFileWithSuiteName: suiteName];
@@ -572,7 +524,6 @@ - (void)testNewUserDefaultsThreadSafeAddingObjects {
572
524
XCTAssertEqualObjects ([userDefaults objectForKey: key], @(i));
573
525
}
574
526
575
- [userDefaults clearAllData ];
576
527
[self removePreferenceFileWithSuiteName: suiteName];
577
528
}
578
529
@@ -616,7 +567,6 @@ - (void)testNewUserDefaultsRemovingObjects {
616
567
XCTAssertNil ([userDefaults objectForKey: key]);
617
568
}
618
569
619
- [userDefaults clearAllData ];
620
570
[self removePreferenceFileWithSuiteName: suiteName];
621
571
}
622
572
@@ -661,8 +611,6 @@ - (void)testNewUserDefaultsRemovingSomeObjects {
661
611
XCTAssertEqualObjects ([userDefaults objectForKey: key], @(i));
662
612
}
663
613
}
664
- [userDefaults clearAllData ];
665
-
666
614
[self removePreferenceFileWithSuiteName: suiteName];
667
615
}
668
616
@@ -702,8 +650,6 @@ - (void)testBothUserDefaultsThreadSafeAddingObjects {
702
650
XCTAssertEqualObjects ([userDefaults objectForKey: key], @(i));
703
651
}
704
652
}
705
-
706
- [newUserDefaults clearAllData ];
707
653
[self removePreferenceFileWithSuiteName: suiteName];
708
654
}
709
655
@@ -760,8 +706,6 @@ - (void)testBothUserDefaultsRemovingSomeObjects {
760
706
}
761
707
}
762
708
}
763
- [userDefaults clearAllData ];
764
-
765
709
[self removePreferenceFileWithSuiteName: suiteName];
766
710
}
767
711
@@ -835,6 +779,9 @@ - (NSString *)filePathForPreferencesName:(NSString *)preferencesName {
835
779
}
836
780
837
781
- (void )removePreferenceFileWithSuiteName : (NSString *)suiteName {
782
+ NSUserDefaults *userDefaults = [[NSUserDefaults alloc ] initWithSuiteName: suiteName];
783
+ [userDefaults removePersistentDomainForName: suiteName];
784
+
838
785
NSString *path = [self filePathForPreferencesName: suiteName];
839
786
NSFileManager *fileManager = [NSFileManager defaultManager ];
840
787
if ([fileManager fileExistsAtPath: path]) {
0 commit comments