Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Follow up cleanup #trivial #1203

Merged
merged 4 commits into from
Nov 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Source/ASDisplayNode+Yoga.mm
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ @implementation ASDisplayNode (Yoga)
- (ASDisplayNode *)yogaRoot
{
ASDisplayNode *yogaRoot = self;
ASDisplayNode *yogaParent = nil;
ASDisplayNode *yogaParent = nil;
while ((yogaParent = yogaRoot.yogaParent)) {
yogaRoot = yogaParent;
}
Expand Down
4 changes: 3 additions & 1 deletion Source/ASDisplayNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -3280,11 +3280,13 @@ - (void)didEnterVisibleState
// subclass override
ASDisplayNodeAssertMainThread();

#if ASDISPLAYNODE_ASSERTIONS_ENABLED
// Rasterized node's loading state is merged with root node of rasterized tree.
if (!(self.hierarchyState & ASHierarchyStateRasterized)) {
ASDisplayNodeAssert(self.isNodeLoaded, @"Node should be loaded before entering visible state.");
}

#endif

ASAssertUnlocked(__instanceLock__);
[self enumerateInterfaceStateDelegates:^(id<ASInterfaceStateDelegate> del) {
[del didEnterVisibleState];
Expand Down
3 changes: 1 addition & 2 deletions Tests/ASButtonNodeTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ - (void)testAccessibility

// Disable the button and verify that accessibility traits has been updated correctly.
buttonNode.enabled = NO;
UIAccessibilityTraits disabledButtonTrait =
UIAccessibilityTraitButton | UIAccessibilityTraitNotEnabled;
UIAccessibilityTraits disabledButtonTrait = UIAccessibilityTraitButton | UIAccessibilityTraitNotEnabled;
XCTAssertTrue(buttonNode.accessibilityTraits == disabledButtonTrait,
@"Should have disabled button accessibility trait, instead has %llu",
buttonNode.accessibilityTraits);
Expand Down
57 changes: 57 additions & 0 deletions Tests/ASTextNodeTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ @interface ASTextNodeTests : XCTestCase

@property (nonatomic) ASTextNode *textNode;
@property (nonatomic, copy) NSAttributedString *attributedText;
@property (nonatomic) NSMutableArray *textNodeBucket;

@end

Expand All @@ -59,6 +60,7 @@ - (void)setUp
{
[super setUp];
_textNode = [[ASTextNode alloc] init];
_textNodeBucket = [[NSMutableArray alloc] init];

UIFontDescriptor *desc =
[UIFontDescriptor fontDescriptorWithName:@"Didot" size:18];
Expand Down Expand Up @@ -247,6 +249,61 @@ - (void)testThatTheExperimentWorksCorrectly
XCTAssertEqualObjects(sc2.superclass, [ASTextNodeSubclass class]);
}

- (void)testTextNodeSwitchWorksInMultiThreadEnvironment
{
ASConfiguration *config = [ASConfiguration new];
config.experimentalFeatures = ASExperimentalTextNode;
[ASConfigurationManager test_resetWithConfiguration:config];
XCTestExpectation *exp = [self expectationWithDescription:@"wait for full bucket"];

dispatch_queue_t queue = dispatch_queue_create("com.texture.AsyncDisplayKit.ASTextNodeTestsQueue", DISPATCH_QUEUE_CONCURRENT);
dispatch_group_t g = dispatch_group_create();
for (int i = 0; i < 20; i++) {
dispatch_group_async(g, queue, ^{
ASTextNode *textNode = [[ASTextNodeSecondSubclass alloc] init];
XCTAssert([textNode isKindOfClass:[ASTextNode2 class]]);
@synchronized(self.textNodeBucket) {
[self.textNodeBucket addObject:textNode];
if (self.textNodeBucket.count == 20) {
[exp fulfill];
}
}
});
}
[self waitForExpectations:@[exp] timeout:3];
exp = nil;
[self.textNodeBucket removeAllObjects];
}

- (void)testTextNodeSwitchWorksInMultiThreadEnvironment2
{
ASConfiguration *config = [ASConfiguration new];
config.experimentalFeatures = ASExperimentalTextNode;
[ASConfigurationManager test_resetWithConfiguration:config];
XCTestExpectation *exp = [self expectationWithDescription:@"wait for full bucket"];

NSLock *lock = [[NSLock alloc] init];
NSMutableArray *textNodeBucket = [[NSMutableArray alloc] init];

dispatch_queue_t queue = dispatch_queue_create("com.texture.AsyncDisplayKit.ASTextNodeTestsQueue", DISPATCH_QUEUE_CONCURRENT);
dispatch_group_t g = dispatch_group_create();
for (int i = 0; i < 20; i++) {
dispatch_group_async(g, queue, ^{
ASTextNode *textNode = [[ASTextNodeSecondSubclass alloc] init];
XCTAssert([textNode isKindOfClass:[ASTextNode2 class]]);
[lock lock];
[textNodeBucket addObject:textNode];
if (textNodeBucket.count == 20) {
[exp fulfill];
}
[lock unlock];
});
}
[self waitForExpectations:@[exp] timeout:3];
exp = nil;
[textNodeBucket removeAllObjects];
}

@end

@implementation ASTextNodeSubclass
Expand Down