This repository has been archived by the owner on Nov 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 416
/
Copy pathFBTweakInlineTestsMRR.m
122 lines (93 loc) · 6.09 KB
/
FBTweakInlineTestsMRR.m
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
/**
Copyright (c) 2014-present, Facebook, Inc.
All rights reserved.
This source code is licensed under the BSD-style license found in the
LICENSE file in the root directory of this source tree. An additional grant
of patent rights can be found in the PATENTS file in the same directory.
*/
#import <XCTest/XCTest.h>
#import <UIKit/UIKit.h>
#import "FBTweakInline.h"
#if __has_feature(objc_arc)
#error ARC is disallowed.
#endif
@interface FBTweakInlineTestsMRR : XCTestCase
@end
@implementation FBTweakInlineTestsMRR
- (void)setUp
{
[[FBTweakStore sharedInstance] reset];
}
- (void)testValueTypes
{
__attribute__((unused)) short testShort = FBTweakValue(@"Short", @"Short", @"Short", -1);
XCTAssertEqual(testShort, (short)-1, @"Short %d", testShort);
__attribute__((unused)) unsigned short testUnsignedShort = FBTweakValue(@"Unsigned Short", @"Unsigned Short", @"Unsigned Short", 1);
XCTAssertEqual(testUnsignedShort, (unsigned short)1, @"Unsigned Short %d", testUnsignedShort);
__attribute__((unused)) int testInt = FBTweakValue(@"Int", @"Int", @"Int", -1);
XCTAssertEqual(testInt, (int)-1, @"Int %d", testInt);
__attribute__((unused)) unsigned int testUnsignedInt = FBTweakValue(@"Unsigned Int", @"Unsigned Int", @"Unsigned Int", 1);
XCTAssertEqual(testUnsignedInt, (unsigned int)1, @"Unsigned Int %d", testUnsignedInt);
__attribute__((unused)) long long testLongLong = FBTweakValue(@"Long Long", @"Long Long", @"Long Long", -1);
XCTAssertEqual(testLongLong, (long long)-1, @"Long Long %lld", testLongLong);
__attribute__((unused)) unsigned long long testUnsignedLongLong = FBTweakValue(@"Unsigned Long Long", @"Unsigned Long Long", @"Unsigned Long Long", 1);
XCTAssertEqual(testUnsignedLongLong, (unsigned long long)1, @"Unsigned Long Long %llu", testUnsignedLongLong);
__attribute__((unused)) float testFloat = FBTweakValue(@"Float", @"Float", @"Float", 1.0);
XCTAssertEqual(testFloat, (float)1.0, @"Float %f", testFloat);
__attribute__((unused)) BOOL testBool = FBTweakValue(@"BOOL", @"BOOL", @"BOOL", YES);
XCTAssertEqual(testBool, (BOOL)YES, @"Bool %d", testBool);
__attribute__((unused)) const char *testString = FBTweakValue(@"String", @"String", @"String", "one");
XCTAssertEqual(strcmp(testString, "one"), 0, @"String %s", testString);
__attribute__((unused)) NSString *testNSString = FBTweakValue(@"NSString", @"NSString", @"NSString", @"one");
XCTAssertEqualObjects(testNSString, @"one", @"NSString %@", testNSString);
__attribute__((unused)) UIColor *testUIColor = FBTweakValue(@"UIColor", @"UIColor", @"UIColor", [UIColor redColor]);
XCTAssertEqualObjects([UIColor redColor], [UIColor redColor], @"UIColor %@", testUIColor);
__attribute__((unused)) NSString *testNSArray = FBTweakValue(@"NSArray", @"NSArray", @"NSArray", @"two", (@[@"one", @"two", @"three"]));
XCTAssertEqualObjects(testNSArray, @"two", @"NSArray %@", testNSArray);
__attribute__((unused)) NSString *testNSDictionary = FBTweakValue(@"NSDictionary", @"NSDictionary", @"NSDictionary", @"key2", (@{@"key1":@"value1", @"key2":@"value2"}));
XCTAssertEqualObjects(testNSDictionary, @"key2", @"NSString %@", testNSDictionary);
}
- (void)testConstantValues
{
static const double staticConstInput = 1.0;
double staticConstValue = FBTweakValue(@"Static", @"Static", @"Static", staticConstInput);
XCTAssertEqual(staticConstValue, staticConstInput, @"Static %f %f", staticConstInput, staticConstValue);
}
// All values should be converted to the same type as the default.
- (void)testMixedRangeTypes
{
FBTweak *mixedFloatTweak = FBTweakInline(@"Mixed Float", @"Mixed Float", @"Mixed Float", (float)1.0, (double)1.0, (long)1.0);
XCTAssertEqualObjects([NSString stringWithUTF8String:[mixedFloatTweak.defaultValue objCType]], @"f", @"Mixed Float Default %s", [mixedFloatTweak.defaultValue objCType]);
XCTAssertEqual([mixedFloatTweak.defaultValue floatValue], (float)1.0, @"Mixed Float Default %@", mixedFloatTweak.defaultValue);
XCTAssertEqualObjects([NSString stringWithUTF8String:[mixedFloatTweak.minimumValue objCType]], @"f", @"Mixed Float Minimum %s", [mixedFloatTweak.minimumValue objCType]);
XCTAssertEqual([mixedFloatTweak.minimumValue floatValue], (float)1.0, @"Mixed Float Minimum %@", mixedFloatTweak.minimumValue);
XCTAssertEqualObjects([NSString stringWithUTF8String:[mixedFloatTweak.maximumValue objCType]], @"f", @"Mixed Float Maximum %s", [mixedFloatTweak.maximumValue objCType]);
XCTAssertEqual([mixedFloatTweak.maximumValue floatValue], (float)1.0, @"Mixed Float Maximum %@", mixedFloatTweak.maximumValue);
FBTweak *mixedIntTweak = FBTweakInline(@"Mixed Int", @"Mixed Int", @"Mixed Int", (int)1, (char)1, (double)1);
XCTAssertEqualObjects([NSString stringWithUTF8String:[mixedIntTweak.defaultValue objCType]], @"i", @"Mixed Int Default %@", mixedIntTweak.defaultValue);
XCTAssertEqual([mixedIntTweak.defaultValue floatValue], (int)1, @"Mixed Int Default %@", mixedIntTweak.defaultValue);
XCTAssertEqualObjects([NSString stringWithUTF8String:[mixedIntTweak.minimumValue objCType]], @"i", @"Mixed Int Minimum %@", mixedIntTweak.minimumValue);
XCTAssertEqual([mixedIntTweak.minimumValue floatValue], (int)1, @"Mixed Int Minimum %@", mixedIntTweak.minimumValue);
XCTAssertEqualObjects([NSString stringWithUTF8String:[mixedIntTweak.maximumValue objCType]], @"i", @"Mixed Int Maximum %@", mixedIntTweak.maximumValue);
XCTAssertEqual([mixedIntTweak.maximumValue floatValue], (int)1, @"Mixed Int Maximum %@", mixedIntTweak.maximumValue);
}
// Actions use variables so they can work in the global scope, test for name conflicts.
- (void)testMultipleActions
{
FBTweakAction(@"Action", @"Action", @"One", ^{
NSLog(@"Action One");
});
FBTweakAction(@"Action", @"Action", @"Two", ^{
NSLog(@"Action Two");
});
}
- (void)testBind
{
NSMutableURLRequest *v = [[NSMutableURLRequest alloc] init];
FBTweakBind(v, timeoutInterval, @"URL", @"Request", @"Bind", 5.0);
XCTAssertEqual(v.timeoutInterval, (NSTimeInterval)5.0, @"request %@", v);
FBTweak *m = FBTweakInline(@"URL", @"Request", @"Bind", 5.0);
m.currentValue = @(20.0);
XCTAssertEqual(v.timeoutInterval, (NSTimeInterval)20.0, @"request %@ %@", v, m);
}
@end