From b8602d107343ecbe47fade7f222ef67f9f5516a1 Mon Sep 17 00:00:00 2001 From: Scott Goodson Date: Sun, 20 Dec 2015 15:42:57 -0800 Subject: [PATCH] Fix ASBasicImageDownloader tests - prevent use of init / new instead of +sharedImageDownloader. --- AsyncDisplayKit/ASDisplayNode.mm | 19 +++++++++++++------ .../Details/ASBasicImageDownloader.h | 3 +++ .../Details/ASBasicImageDownloader.mm | 4 ++-- .../Private/ASDisplayNodeInternal.h | 1 + .../ASBasicImageDownloaderTests.m | 5 +++-- .../ASDisplayNodeAppearanceTests.m | 4 ++++ 6 files changed, 26 insertions(+), 10 deletions(-) diff --git a/AsyncDisplayKit/ASDisplayNode.mm b/AsyncDisplayKit/ASDisplayNode.mm index 0326273e9d..84ba2956b1 100644 --- a/AsyncDisplayKit/ASDisplayNode.mm +++ b/AsyncDisplayKit/ASDisplayNode.mm @@ -1251,6 +1251,19 @@ static NSInteger incrementIfFound(NSInteger i) { } } +- (BOOL)__visibilityNotificationsDisabled +{ + // Currently, this method is only used by the testing infrastructure to verify this internal feature. + ASDN::MutexLocker l(_propertyLock); + return _flags.visibilityNotificationsDisabled > 0; +} + +- (BOOL)__selfOrParentHasVisibilityNotificationsDisabled +{ + ASDN::MutexLocker l(_propertyLock); + return (_hierarchyState & ASHierarchyStateTransitioningSupernodes); +} + - (void)__incrementVisibilityNotificationsDisabled { ASDN::MutexLocker l(_propertyLock); @@ -1282,12 +1295,6 @@ static NSInteger incrementIfFound(NSInteger i) { } } -- (BOOL)__selfOrParentHasVisibilityNotificationsDisabled -{ - ASDN::MutexLocker l(_propertyLock); - return (_hierarchyState & ASHierarchyStateTransitioningSupernodes); -} - - (void)__enterHierarchy { ASDisplayNodeAssertMainThread(); diff --git a/AsyncDisplayKit/Details/ASBasicImageDownloader.h b/AsyncDisplayKit/Details/ASBasicImageDownloader.h index ecb4861911..7f7a86c907 100644 --- a/AsyncDisplayKit/Details/ASBasicImageDownloader.h +++ b/AsyncDisplayKit/Details/ASBasicImageDownloader.h @@ -16,4 +16,7 @@ + (instancetype)sharedImageDownloader; ++ (instancetype)new __attribute__((unavailable("+[ASBasicImageDownloader sharedImageDownloader] must be used."))); +- (instancetype)init __attribute__((unavailable("+[ASBasicImageDownloader sharedImageDownloader] must be used."))); + @end diff --git a/AsyncDisplayKit/Details/ASBasicImageDownloader.mm b/AsyncDisplayKit/Details/ASBasicImageDownloader.mm index ad1026d013..73301919cc 100644 --- a/AsyncDisplayKit/Details/ASBasicImageDownloader.mm +++ b/AsyncDisplayKit/Details/ASBasicImageDownloader.mm @@ -205,14 +205,14 @@ static const char *kContextKey = NSStringFromClass(ASBasicImageDownloaderContext static ASBasicImageDownloader *sharedImageDownloader = nil; static dispatch_once_t once = 0; dispatch_once(&once, ^{ - sharedImageDownloader = [[ASBasicImageDownloader alloc] init]; + sharedImageDownloader = [[ASBasicImageDownloader alloc] _init]; }); return sharedImageDownloader; } #pragma mark Lifecycle. -- (instancetype)init +- (instancetype)_init { if (!(self = [super init])) return nil; diff --git a/AsyncDisplayKit/Private/ASDisplayNodeInternal.h b/AsyncDisplayKit/Private/ASDisplayNodeInternal.h index d907d964ae..e16eb99092 100644 --- a/AsyncDisplayKit/Private/ASDisplayNodeInternal.h +++ b/AsyncDisplayKit/Private/ASDisplayNodeInternal.h @@ -135,6 +135,7 @@ typedef NS_OPTIONS(NSUInteger, ASDisplayNodeMethodOverrides) // Private API for helper functions / unit tests. Use ASDisplayNodeDisableHierarchyNotifications() to control this. - (BOOL)__visibilityNotificationsDisabled; +- (BOOL)__selfOrParentHasVisibilityNotificationsDisabled; - (void)__incrementVisibilityNotificationsDisabled; - (void)__decrementVisibilityNotificationsDisabled; diff --git a/AsyncDisplayKitTests/ASBasicImageDownloaderTests.m b/AsyncDisplayKitTests/ASBasicImageDownloaderTests.m index b174722341..e0d7e3c9fc 100644 --- a/AsyncDisplayKitTests/ASBasicImageDownloaderTests.m +++ b/AsyncDisplayKitTests/ASBasicImageDownloaderTests.m @@ -16,8 +16,9 @@ @implementation ASBasicImageDownloaderTests -- (void)testAsynchronouslyDownloadTheSameURLTwice { - ASBasicImageDownloader *downloader = [ASBasicImageDownloader new]; +- (void)testAsynchronouslyDownloadTheSameURLTwice +{ + ASBasicImageDownloader *downloader = [ASBasicImageDownloader sharedImageDownloader]; NSURL *URL = [NSURL URLWithString:@"http://wrongPath/wrongResource.png"]; diff --git a/AsyncDisplayKitTests/ASDisplayNodeAppearanceTests.m b/AsyncDisplayKitTests/ASDisplayNodeAppearanceTests.m index e08f50d15f..5b0a0a753f 100644 --- a/AsyncDisplayKitTests/ASDisplayNodeAppearanceTests.m +++ b/AsyncDisplayKitTests/ASDisplayNodeAppearanceTests.m @@ -49,6 +49,7 @@ static dispatch_block_t modifyMethodByAddingPrologueBlockAndReturnCleanupBlock(C @interface ASDisplayNode (PrivateStuffSoWeDontPullInCPPInternalH) - (BOOL)__visibilityNotificationsDisabled; +- (BOOL)__selfOrParentHasVisibilityNotificationsDisabled; - (id)initWithViewClass:(Class)viewClass; - (id)initWithLayerClass:(Class)layerClass; @end @@ -360,6 +361,7 @@ static UIView *viewWithName(NSString *name) { } if (useManualDisable) { XCTAssertTrue([child __visibilityNotificationsDisabled], @"Should not have re-enabled yet"); + XCTAssertTrue([child __selfOrParentHasVisibilityNotificationsDisabled], @"Should not have re-enabled yet"); ASDisplayNodeEnableHierarchyNotifications(child); } @@ -377,6 +379,7 @@ static UIView *viewWithName(NSString *name) { } if (useManualDisable) { XCTAssertTrue([child __visibilityNotificationsDisabled], @"Should not have re-enabled yet"); + XCTAssertTrue([child __selfOrParentHasVisibilityNotificationsDisabled], @"Should not have re-enabled yet"); ASDisplayNodeEnableHierarchyNotifications(child); } @@ -390,6 +393,7 @@ static UIView *viewWithName(NSString *name) { // Make sure that we don't leave these unbalanced XCTAssertFalse([child __visibilityNotificationsDisabled], @"Unbalanced visibility notifications calls"); + XCTAssertFalse([child __selfOrParentHasVisibilityNotificationsDisabled], @"Should not have re-enabled yet"); [window release]; }