Files
Swiftgram/Tests/ASConfigurationTests.m
Max Wang 17f24aad3d Mismatch name experimental features (#1159)
* fix SIMULATE_WEB_RESPONSE not imported #449

* Fix to make rangeMode update in right time

* remove uncessary assert

* Fix collection cell editing bug for iOS 9 & 10

* Revert "Fix collection cell editing bug for iOS 9 & 10"

This reverts commit 06e18a10596622ff8a68835c95a23986d7bf61ea.

* fix mismatch of name array and experimental features

* add more tests

* remove nslog

* add change log

* fix tests
2018-10-11 12:01:37 -07:00

123 lines
3.7 KiB
Objective-C

//
// 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 "ASTestCase.h"
#import "ASConfiguration.h"
#import "ASConfigurationDelegate.h"
#import "ASConfigurationInternal.h"
static ASExperimentalFeatures features[] = {
ASExperimentalGraphicsContexts,
ASExperimentalTextNode,
ASExperimentalInterfaceStateCoalescing,
ASExperimentalUnfairLock,
ASExperimentalLayerDefaults,
ASExperimentalNetworkImageQueue,
ASExperimentalCollectionTeardown,
ASExperimentalFramesetterCache,
ASExperimentalClearDataDuringDeallocation
};
@interface ASConfigurationTests : ASTestCase <ASConfigurationDelegate>
@end
@implementation ASConfigurationTests {
void (^onActivate)(ASConfigurationTests *self, ASExperimentalFeatures feature);
}
+ (NSArray *)names {
return @[
@"exp_graphics_contexts",
@"exp_text_node",
@"exp_interface_state_coalesce",
@"exp_unfair_lock",
@"exp_infer_layer_defaults",
@"exp_network_image_queue",
@"exp_collection_teardown",
@"exp_framesetter_cache",
@"exp_clear_data_during_deallocation"
];
}
- (ASExperimentalFeatures)allFeatures {
ASExperimentalFeatures allFeatures = 0;
for (int i = 0; i < sizeof(features)/sizeof(ASExperimentalFeatures); i++) {
allFeatures |= features[i];
}
return allFeatures;
}
- (void)testExperimentalFeatureConfig
{
// Set the config
ASConfiguration *config = [[ASConfiguration alloc] initWithDictionary:nil];
config.experimentalFeatures = ASExperimentalGraphicsContexts;
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(ASExperimentalGraphicsContexts));
// 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];
}
- (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