-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathASConfigurationTests.mm
140 lines (120 loc) · 4.09 KB
/
ASConfigurationTests.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
//
// ASConfigurationTests.m
// 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/ASAvailability.h>
#import <AsyncDisplayKit/ASConfiguration.h>
#import <AsyncDisplayKit/ASConfigurationDelegate.h>
#import <AsyncDisplayKit/ASConfigurationInternal.h>
#import "ASTestCase.h"
static ASExperimentalFeatures features[] = {
#if AS_ENABLE_TEXTNODE
ASExperimentalTextNode,
#endif
ASExperimentalInterfaceStateCoalescing,
ASExperimentalLayerDefaults,
ASExperimentalCollectionTeardown,
ASExperimentalFramesetterCache,
ASExperimentalSkipClearData,
ASExperimentalDidEnterPreloadSkipASMLayout,
ASExperimentalDispatchApply,
ASExperimentalDrawingGlobal,
ASExperimentalOptimizeDataControllerPipeline,
ASExperimentalDisableGlobalTextkitLock,
ASExperimentalMainThreadOnlyDataController,
ASExperimentalRangeUpdateOnChangesetUpdate,
};
@interface ASConfigurationTests : ASTestCase <ASConfigurationDelegate>
@end
@implementation ASConfigurationTests {
void (^onActivate)(ASConfigurationTests *self, ASExperimentalFeatures feature);
}
+ (NSArray *)names {
return @[
@"exp_text_node",
@"exp_interface_state_coalesce",
@"exp_infer_layer_defaults",
@"exp_collection_teardown",
@"exp_framesetter_cache",
@"exp_skip_clear_data",
@"exp_did_enter_preload_skip_asm_layout",
@"exp_dispatch_apply",
@"exp_drawing_global",
@"exp_optimize_data_controller_pipeline",
@"exp_disable_global_textkit_lock",
@"exp_main_thread_only_data_controller",
@"exp_range_update_on_changeset_update"
];
}
- (ASExperimentalFeatures)allFeatures
{
ASExperimentalFeatures allFeatures = 0;
for (int i = 0; i < sizeof(features)/sizeof(ASExperimentalFeatures); i++) {
allFeatures |= features[i];
}
return allFeatures;
}
#if AS_ENABLE_TEXTNODE
- (void)testExperimentalFeatureConfig
{
// Set the config
ASConfiguration *config = [[ASConfiguration alloc] initWithDictionary:nil];
config.experimentalFeatures = ASExperimentalLayerDefaults;
config.delegate = self;
[ASConfigurationManager test_resetWithConfiguration:config];
// Set an expectation for a callback, and assert we only get one.
XCTestExpectation *e = [self expectationWithDescription:@"Callbacks done."];
e.expectedFulfillmentCount = 2;
e.assertForOverFulfill = YES;
onActivate = ^(ASConfigurationTests *self, ASExperimentalFeatures feature) {
[e fulfill];
};
// Now activate the graphics experiment and expect it works.
XCTAssertTrue(ASActivateExperimentalFeature(ASExperimentalLayerDefaults));
// We should get a callback here
// Now activate text node and expect it fails.
XCTAssertFalse(ASActivateExperimentalFeature(ASExperimentalTextNode));
// But we should get another callback.
[self waitForExpectationsWithTimeout:3 handler:nil];
}
#endif
- (void)textureDidActivateExperimentalFeatures:(ASExperimentalFeatures)feature
{
if (onActivate) {
onActivate(self, feature);
}
}
- (void)testMappingNamesToFlags
{
// Throw in a bad bit.
ASExperimentalFeatures allFeatures = [self allFeatures];
ASExperimentalFeatures featuresWithBadBit = allFeatures | (1 << 22);
NSArray *expectedNames = [ASConfigurationTests names];
XCTAssertEqualObjects(expectedNames, ASExperimentalFeaturesGetNames(featuresWithBadBit));
}
- (void)testMappingFlagsFromNames
{
// Throw in a bad name.
NSMutableArray *allNames = [[NSMutableArray alloc] initWithArray:[ASConfigurationTests names]];
[allNames addObject:@"__invalid_name"];
ASExperimentalFeatures expected = [self allFeatures];
XCTAssertEqual(expected, ASExperimentalFeaturesFromArray(allNames));
}
- (void)testFlagMatchName
{
NSArray *names = [ASConfigurationTests names];
for (NSInteger i = 0; i < names.count; i++) {
XCTAssertEqual(features[i], ASExperimentalFeaturesFromArray(@[names[i]]));
}
}
- (void)testNameMatchFlag {
NSArray *names = [ASConfigurationTests names];
for (NSInteger i = 0; i < names.count; i++) {
XCTAssertEqualObjects(@[names[i]], ASExperimentalFeaturesGetNames(features[i]));
}
}
@end