Files
Swiftgram/Tests/ASConfigurationTests.m
Adlai Holler 27fac9f586 Create a centralized configuration API (#747)
* Update the dangerfile

* Make a trivial change to test new dangerfile

* Try out the new value with another trivial change

* Add a configuration API to make a unified place for pulling config from clients safely

* Specify properties for delegate

* Finish removing text experiment global enable

* Generate the config file

* Clean up configuration to fix tests

* Work on making it serializable

* Finish it up

* Fix example code

* Update sample project

* Clean up a few things

* Align with new project order

* Make it faster and update license header

* Add an option to specify your config at compile time

* Update another license header

* Add a version field, and bring interface state coalescing into configuration

* Update CA queue code

* Update CATransactionQueue tests

* Turn transaction queue on by default (for now, see comment)

* Update the tests

* Update the tests AGAIN

* Remove unused ordered set
2018-03-25 12:52:57 -07:00

78 lines
2.6 KiB
Objective-C

//
// ASConfigurationTests.m
// Texture
//
// Copyright (c) 2018-present, Pinterest, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
#import <XCTest/XCTest.h>
#import "ASTestCase.h"
#import "ASConfiguration.h"
#import "ASConfigurationDelegate.h"
#import "ASConfigurationInternal.h"
@interface ASConfigurationTests : ASTestCase <ASConfigurationDelegate>
@end
@implementation ASConfigurationTests {
void (^onActivate)(ASConfigurationTests *self, ASExperimentalFeatures feature);
}
- (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:@"Callback 1 done."];
onActivate = ^(ASConfigurationTests *self, ASExperimentalFeatures feature) {
XCTAssertEqual(feature, ASExperimentalGraphicsContexts);
[e fulfill];
// Next time it's a fail.
self->onActivate = ^(ASConfigurationTests *self, ASExperimentalFeatures feature) {
XCTFail(@"Too many callbacks.");
};
};
// 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));
[self waitForExpectationsWithTimeout:3 handler:nil];
}
- (void)textureDidActivateExperimentalFeatures:(ASExperimentalFeatures)feature
{
if (onActivate) {
onActivate(self, feature);
}
}
- (void)testMappingNamesToFlags
{
// Throw in a bad bit.
ASExperimentalFeatures features = ASExperimentalTextNode | ASExperimentalGraphicsContexts | (1 << 22);
NSArray *expectedNames = @[ @"exp_graphics_contexts", @"exp_text_node" ];
XCTAssertEqualObjects(expectedNames, ASExperimentalFeaturesGetNames(features));
}
- (void)testMappingFlagsFromNames
{
// Throw in a bad name.
NSArray *names = @[ @"exp_text_node", @"exp_graphics_contexts", @"__invalid_name" ];
ASExperimentalFeatures expected = ASExperimentalGraphicsContexts | ASExperimentalTextNode;
XCTAssertEqual(expected, ASExperimentalFeaturesFromArray(names));
}
@end