forked from fachrifaul/Texture
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathASTransactionTests.mm
84 lines (64 loc) · 2.11 KB
/
ASTransactionTests.mm
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
//
// ASTransactionTests.m
// AsyncDisplayKitTests
//
// Copyright (c) Pinterest, Inc. All rights reserved.
// Licensed under Apache 2.0: http://www.apache.org/licenses/LICENSE-2.0
//
#import "ASTestCase.h"
#import <AsyncDisplayKit/AsyncDisplayKit.h>
@interface ASTransactionTests : ASTestCase
@end
@implementation ASTransactionTests
- (void)testWeak
{
__weak _ASAsyncTransaction* weakTransaction = nil;
@autoreleasepool {
CALayer *layer = [[CALayer alloc] init];
_ASAsyncTransaction *transaction = layer.asyncdisplaykit_asyncTransaction;
weakTransaction = transaction;
layer = nil;
}
// held by main transaction group
XCTAssertNotNil(weakTransaction);
// run so that transaction group drains.
static NSTimeInterval delay = 0.1;
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:delay]];
XCTAssertNil(weakTransaction);
}
- (void)testWeakWhenCancelled
{
__weak _ASAsyncTransaction* weakTransaction = nil;
@autoreleasepool {
CALayer *layer = [[CALayer alloc] init];
_ASAsyncTransaction *transaction = layer.asyncdisplaykit_asyncTransaction;
weakTransaction = transaction;
[layer asyncdisplaykit_cancelAsyncTransactions];
layer = nil;
}
XCTAssertNil(weakTransaction);
}
- (void)testWeakWithSingleOperation
{
__weak _ASAsyncTransaction* weakTransaction = nil;
@autoreleasepool {
CALayer *layer = [[CALayer alloc] init];
_ASAsyncTransaction *transaction = layer.asyncdisplaykit_asyncTransaction;
[transaction addOperationWithBlock:^id<NSObject> _Nullable{
return nil;
} priority:1
queue:dispatch_get_main_queue()
completion:^(id _Nullable value, BOOL canceled) {
;
}];
weakTransaction = transaction;
layer = nil;
}
// held by main transaction group
XCTAssertNotNil(weakTransaction);
// run so that transaction group drains.
static NSTimeInterval delay = 0.1;
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:delay]];
XCTAssertNil(weakTransaction);
}
@end