Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

Commit b8602d1

Browse files
author
Scott Goodson
committed
Fix ASBasicImageDownloader tests - prevent use of init / new instead of +sharedImageDownloader.
1 parent 97bb05d commit b8602d1

6 files changed

Lines changed: 26 additions & 10 deletions

File tree

AsyncDisplayKit/ASDisplayNode.mm

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,6 +1251,19 @@ - (void)removeFromSupernode
12511251
}
12521252
}
12531253

1254+
- (BOOL)__visibilityNotificationsDisabled
1255+
{
1256+
// Currently, this method is only used by the testing infrastructure to verify this internal feature.
1257+
ASDN::MutexLocker l(_propertyLock);
1258+
return _flags.visibilityNotificationsDisabled > 0;
1259+
}
1260+
1261+
- (BOOL)__selfOrParentHasVisibilityNotificationsDisabled
1262+
{
1263+
ASDN::MutexLocker l(_propertyLock);
1264+
return (_hierarchyState & ASHierarchyStateTransitioningSupernodes);
1265+
}
1266+
12541267
- (void)__incrementVisibilityNotificationsDisabled
12551268
{
12561269
ASDN::MutexLocker l(_propertyLock);
@@ -1282,12 +1295,6 @@ - (void)__decrementVisibilityNotificationsDisabled
12821295
}
12831296
}
12841297

1285-
- (BOOL)__selfOrParentHasVisibilityNotificationsDisabled
1286-
{
1287-
ASDN::MutexLocker l(_propertyLock);
1288-
return (_hierarchyState & ASHierarchyStateTransitioningSupernodes);
1289-
}
1290-
12911298
- (void)__enterHierarchy
12921299
{
12931300
ASDisplayNodeAssertMainThread();

AsyncDisplayKit/Details/ASBasicImageDownloader.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,7 @@
1616

1717
+ (instancetype)sharedImageDownloader;
1818

19+
+ (instancetype)new __attribute__((unavailable("+[ASBasicImageDownloader sharedImageDownloader] must be used.")));
20+
- (instancetype)init __attribute__((unavailable("+[ASBasicImageDownloader sharedImageDownloader] must be used.")));
21+
1922
@end

AsyncDisplayKit/Details/ASBasicImageDownloader.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,14 +205,14 @@ + (instancetype)sharedImageDownloader
205205
static ASBasicImageDownloader *sharedImageDownloader = nil;
206206
static dispatch_once_t once = 0;
207207
dispatch_once(&once, ^{
208-
sharedImageDownloader = [[ASBasicImageDownloader alloc] init];
208+
sharedImageDownloader = [[ASBasicImageDownloader alloc] _init];
209209
});
210210
return sharedImageDownloader;
211211
}
212212

213213
#pragma mark Lifecycle.
214214

215-
- (instancetype)init
215+
- (instancetype)_init
216216
{
217217
if (!(self = [super init]))
218218
return nil;

AsyncDisplayKit/Private/ASDisplayNodeInternal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ typedef NS_OPTIONS(NSUInteger, ASDisplayNodeMethodOverrides)
135135

136136
// Private API for helper functions / unit tests. Use ASDisplayNodeDisableHierarchyNotifications() to control this.
137137
- (BOOL)__visibilityNotificationsDisabled;
138+
- (BOOL)__selfOrParentHasVisibilityNotificationsDisabled;
138139
- (void)__incrementVisibilityNotificationsDisabled;
139140
- (void)__decrementVisibilityNotificationsDisabled;
140141

AsyncDisplayKitTests/ASBasicImageDownloaderTests.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ @interface ASBasicImageDownloaderTests : XCTestCase
1616

1717
@implementation ASBasicImageDownloaderTests
1818

19-
- (void)testAsynchronouslyDownloadTheSameURLTwice {
20-
ASBasicImageDownloader *downloader = [ASBasicImageDownloader new];
19+
- (void)testAsynchronouslyDownloadTheSameURLTwice
20+
{
21+
ASBasicImageDownloader *downloader = [ASBasicImageDownloader sharedImageDownloader];
2122

2223
NSURL *URL = [NSURL URLWithString:@"http://wrongPath/wrongResource.png"];
2324

AsyncDisplayKitTests/ASDisplayNodeAppearanceTests.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ static dispatch_block_t modifyMethodByAddingPrologueBlockAndReturnCleanupBlock(C
4949

5050
@interface ASDisplayNode (PrivateStuffSoWeDontPullInCPPInternalH)
5151
- (BOOL)__visibilityNotificationsDisabled;
52+
- (BOOL)__selfOrParentHasVisibilityNotificationsDisabled;
5253
- (id)initWithViewClass:(Class)viewClass;
5354
- (id)initWithLayerClass:(Class)layerClass;
5455
@end
@@ -360,6 +361,7 @@ - (void)checkMoveAcrossHierarchyLayerBacked:(BOOL)isLayerBacked useManualCalls:(
360361
}
361362
if (useManualDisable) {
362363
XCTAssertTrue([child __visibilityNotificationsDisabled], @"Should not have re-enabled yet");
364+
XCTAssertTrue([child __selfOrParentHasVisibilityNotificationsDisabled], @"Should not have re-enabled yet");
363365
ASDisplayNodeEnableHierarchyNotifications(child);
364366
}
365367

@@ -377,6 +379,7 @@ - (void)checkMoveAcrossHierarchyLayerBacked:(BOOL)isLayerBacked useManualCalls:(
377379
}
378380
if (useManualDisable) {
379381
XCTAssertTrue([child __visibilityNotificationsDisabled], @"Should not have re-enabled yet");
382+
XCTAssertTrue([child __selfOrParentHasVisibilityNotificationsDisabled], @"Should not have re-enabled yet");
380383
ASDisplayNodeEnableHierarchyNotifications(child);
381384
}
382385

@@ -390,6 +393,7 @@ - (void)checkMoveAcrossHierarchyLayerBacked:(BOOL)isLayerBacked useManualCalls:(
390393

391394
// Make sure that we don't leave these unbalanced
392395
XCTAssertFalse([child __visibilityNotificationsDisabled], @"Unbalanced visibility notifications calls");
396+
XCTAssertFalse([child __selfOrParentHasVisibilityNotificationsDisabled], @"Should not have re-enabled yet");
393397

394398
[window release];
395399
}

0 commit comments

Comments
 (0)