forked from TextureGroup/Texture
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathASGraphicsContextTests.mm
96 lines (76 loc) · 3.2 KB
/
ASGraphicsContextTests.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
85
86
87
88
89
90
91
92
93
94
95
96
//
// ASGraphicsContextTests.mm
// Texture
//
// Copyright (c) Pinterest, Inc. All rights reserved.
// Licensed under Apache 2.0: http://www.apache.org/licenses/LICENSE-2.0
//
#import <XCTest/XCTest.h>
#import <AsyncDisplayKit/ASGraphicsContext.h>
#import <AsyncDisplayKit/ASBaseDefines.h>
#import <AsyncDisplayKit/ASAvailability.h>
#import <AsyncDisplayKit/ASConfigurationInternal.h>
@interface ASGraphicsContextTests : XCTestCase
@end
@implementation ASGraphicsContextTests
- (void)setUp
{
[super setUp];
ASConfiguration *config = [ASConfiguration new];
config.experimentalFeatures = ASExperimentalDrawingGlobal;
[ASConfigurationManager test_resetWithConfiguration:config];
}
#if AS_AT_LEAST_IOS13
- (void)testCanceled
{
if (AS_AVAILABLE_IOS_TVOS(13, 13)) {
CGSize size = CGSize{.width=100, .height=100};
XCTestExpectation *expectationCancelled = [self expectationWithDescription:@"canceled"];
asdisplaynode_iscancelled_block_t isCancelledBlock =^BOOL{
[expectationCancelled fulfill];
return true;
};
ASPrimitiveTraitCollection traitCollection = ASPrimitiveTraitCollectionMakeDefault();
UIImage *canceledImage = ASGraphicsCreateImage(traitCollection, size, false, 0, nil, isCancelledBlock, ^{});
XCTAssertNil(canceledImage);
[self waitForExpectations:@[expectationCancelled] timeout:1];
}
}
- (void)testCanceledNil
{
if (AS_AVAILABLE_IOS_TVOS(13, 13)) {
CGSize size = CGSize{.width=100, .height=100};
ASPrimitiveTraitCollection traitCollection = ASPrimitiveTraitCollectionMakeDefault();
XCTestExpectation *expectation = [self expectationWithDescription:@"normal"];
UIImage *image = ASGraphicsCreateImage(traitCollection, size, false, 0, nil, nil, ^{
[expectation fulfill];
});
XCTAssert(image);
[self waitForExpectations:@[expectation] timeout:1];
}
}
- (void)testTraitCollectionPassedToWork
{
if (AS_AVAILABLE_IOS_TVOS(13, 13)) {
CGSize size = CGSize{.width=100, .height=100};
XCTestExpectation *expectationDark = [self expectationWithDescription:@"trait collection dark"];
ASPrimitiveTraitCollection traitCollectionDark = ASPrimitiveTraitCollectionMakeDefault();
traitCollectionDark.userInterfaceStyle = UIUserInterfaceStyleDark;
ASGraphicsCreateImage(traitCollectionDark, size, false, 0, nil, nil, ^{
UITraitCollection *currentTraitCollection = [UITraitCollection currentTraitCollection];
XCTAssertEqual(currentTraitCollection.userInterfaceStyle, UIUserInterfaceStyleDark);
[expectationDark fulfill];
});
XCTestExpectation *expectationLight = [self expectationWithDescription:@"trait collection light"];
ASPrimitiveTraitCollection traitCollectionLight = ASPrimitiveTraitCollectionMakeDefault();
traitCollectionLight.userInterfaceStyle = UIUserInterfaceStyleLight;
ASGraphicsCreateImage(traitCollectionLight, size, false, 0, nil, nil, ^{
UITraitCollection *currentTraitCollection = [UITraitCollection currentTraitCollection];
XCTAssertEqual(currentTraitCollection.userInterfaceStyle, UIUserInterfaceStyleLight);
[expectationLight fulfill];
});
[self waitForExpectations:@[expectationDark, expectationLight] timeout:1];
}
}
#endif
@end