forked from facebookarchive/AsyncDisplayKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathASTextNodeShadowerTests.m
More file actions
156 lines (140 loc) · 8.33 KB
/
Copy pathASTextNodeShadowerTests.m
File metadata and controls
156 lines (140 loc) · 8.33 KB
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/* 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 "ASTextNodeShadower.h"
@interface ASTextNodeShadowerTests : XCTestCase
@property (nonatomic, readwrite, strong) ASTextNodeShadower *shadower;
@end
@implementation ASTextNodeShadowerTests
- (void)testInstantiation
{
CGSize shadowOffset = CGSizeMake(3, 5);
CGColorRef shadowColor = CGColorRetain([UIColor blackColor].CGColor);
CGFloat shadowOpacity = 0.3;
CGFloat shadowRadius = 4.2;
_shadower = [[ASTextNodeShadower alloc] initWithShadowOffset:shadowOffset
shadowColor:shadowColor
shadowOpacity:shadowOpacity
shadowRadius:shadowRadius];
XCTAssertNotNil(_shadower, @"Couldn't instantiate shadow drawer");
XCTAssertTrue(CGSizeEqualToSize(_shadower.shadowOffset, shadowOffset), @"Failed to set shadowOffset (%@) to %@", NSStringFromCGSize(_shadower.shadowOffset), NSStringFromCGSize(shadowOffset));
XCTAssertTrue(_shadower.shadowColor == shadowColor, @"Failed to set shadowColor (%@) to %@", _shadower.shadowColor, shadowColor);
XCTAssertTrue(_shadower.shadowOpacity == shadowOpacity, @"Failed to set shadowOpacity (%f) to %f", _shadower.shadowOpacity, shadowOpacity);
XCTAssertTrue(_shadower.shadowRadius == shadowRadius, @"Failed to set shadowRadius (%f) to %f", _shadower.shadowRadius, shadowRadius);
CGColorRelease(shadowColor);
}
- (void)testNoShadowIfNoRadiusAndNoOffset
{
CGSize shadowOffset = CGSizeZero;
CGColorRef shadowColor = CGColorRetain([UIColor blackColor].CGColor);
CGFloat shadowOpacity = 0.3;
CGFloat shadowRadius = 0;
_shadower = [[ASTextNodeShadower alloc] initWithShadowOffset:shadowOffset
shadowColor:shadowColor
shadowOpacity:shadowOpacity
shadowRadius:shadowRadius];
UIEdgeInsets shadowPadding = [_shadower shadowPadding];
XCTAssertTrue(UIEdgeInsetsEqualToEdgeInsets(shadowPadding, UIEdgeInsetsZero), @"There should be no shadow padding if shadow radius is zero");
CGColorRelease(shadowColor);
}
- (void)testShadowIfOffsetButNoRadius
{
CGSize shadowOffset = CGSizeMake(3, 5);
CGColorRef shadowColor = CGColorRetain([UIColor blackColor].CGColor);
CGFloat shadowOpacity = 0.3;
CGFloat shadowRadius = 0;
_shadower = [[ASTextNodeShadower alloc] initWithShadowOffset:shadowOffset
shadowColor:shadowColor
shadowOpacity:shadowOpacity
shadowRadius:shadowRadius];
UIEdgeInsets shadowPadding = [_shadower shadowPadding];
UIEdgeInsets expectedInsets = UIEdgeInsetsMake(0, 0, -5, -3);
XCTAssertTrue(UIEdgeInsetsEqualToEdgeInsets(shadowPadding, expectedInsets), @"Expected insets %@, encountered insets %@", NSStringFromUIEdgeInsets(expectedInsets), NSStringFromUIEdgeInsets(shadowPadding));
CGColorRelease(shadowColor);
}
- (void)testNoShadowIfNoOpacity
{
CGSize shadowOffset = CGSizeMake(3, 5);
CGColorRef shadowColor = CGColorRetain([UIColor blackColor].CGColor);
CGFloat shadowOpacity = 0;
CGFloat shadowRadius = 4;
_shadower = [[ASTextNodeShadower alloc] initWithShadowOffset:shadowOffset
shadowColor:shadowColor
shadowOpacity:shadowOpacity
shadowRadius:shadowRadius];
UIEdgeInsets shadowPadding = [_shadower shadowPadding];
XCTAssertTrue(UIEdgeInsetsEqualToEdgeInsets(shadowPadding, UIEdgeInsetsZero), @"There should be no shadow padding if shadow opacity is zero");
CGColorRelease(shadowColor);
}
- (void)testShadowPaddingForRadiusOf4
{
CGSize shadowOffset = CGSizeZero;
CGColorRef shadowColor = CGColorRetain([UIColor blackColor].CGColor);
CGFloat shadowOpacity = 1;
CGFloat shadowRadius = 4;
_shadower = [[ASTextNodeShadower alloc] initWithShadowOffset:shadowOffset
shadowColor:shadowColor
shadowOpacity:shadowOpacity
shadowRadius:shadowRadius];
UIEdgeInsets shadowPadding = [_shadower shadowPadding];
UIEdgeInsets expectedInsets = UIEdgeInsetsMake(-shadowRadius, -shadowRadius, -shadowRadius, -shadowRadius);
XCTAssertTrue(UIEdgeInsetsEqualToEdgeInsets(shadowPadding, expectedInsets), @"Unexpected edge insets %@ for radius of %f ", NSStringFromUIEdgeInsets(shadowPadding), shadowRadius);
CGColorRelease(shadowColor);
}
- (void)testShadowPaddingForRadiusOf4OffsetOf11
{
CGSize shadowOffset = CGSizeMake(1, 1);
CGColorRef shadowColor = CGColorRetain([UIColor blackColor].CGColor);
CGFloat shadowOpacity = 1;
CGFloat shadowRadius = 4;
_shadower = [[ASTextNodeShadower alloc] initWithShadowOffset:shadowOffset
shadowColor:shadowColor
shadowOpacity:shadowOpacity
shadowRadius:shadowRadius];
UIEdgeInsets shadowPadding = [_shadower shadowPadding];
UIEdgeInsets expectedInsets = UIEdgeInsetsMake(-shadowRadius + shadowOffset.height, // Top: -3
-shadowRadius + shadowOffset.width, // Left: -3
-shadowRadius - shadowOffset.height, // Bottom: -5
-shadowRadius - shadowOffset.width); // Right: -5
XCTAssertTrue(UIEdgeInsetsEqualToEdgeInsets(shadowPadding, expectedInsets), @"Unexpected edge insets %@ for radius of %f ", NSStringFromUIEdgeInsets(shadowPadding), shadowRadius);
CGColorRelease(shadowColor);
}
- (void)testShadowPaddingForRadiusOf4OffsetOfNegative11
{
CGSize shadowOffset = CGSizeMake(-1, -1);
CGColorRef shadowColor = CGColorRetain([UIColor blackColor].CGColor);
CGFloat shadowOpacity = 1;
CGFloat shadowRadius = 4;
_shadower = [[ASTextNodeShadower alloc] initWithShadowOffset:shadowOffset
shadowColor:shadowColor
shadowOpacity:shadowOpacity
shadowRadius:shadowRadius];
UIEdgeInsets shadowPadding = [_shadower shadowPadding];
UIEdgeInsets expectedInsets = UIEdgeInsetsMake(-shadowRadius + shadowOffset.height, // Top: -3
-shadowRadius + shadowOffset.width, // Left: -5
-shadowRadius - shadowOffset.height, // Bottom: -5
-shadowRadius - shadowOffset.width); // Right: -3
XCTAssertTrue(UIEdgeInsetsEqualToEdgeInsets(shadowPadding, expectedInsets), @"Unexpected edge insets %@ for radius of %f ", NSStringFromUIEdgeInsets(shadowPadding), shadowRadius);
CGColorRelease(shadowColor);
}
- (void)testASDNEdgeInsetsInvert
{
UIEdgeInsets insets = UIEdgeInsetsMake(-5, -7, -3, -2);
UIEdgeInsets invertedInsets = ASDNEdgeInsetsInvert(insets);
UIEdgeInsets expectedInsets = UIEdgeInsetsMake(5, 7, 3, 2);
XCTAssertTrue(UIEdgeInsetsEqualToEdgeInsets(invertedInsets, expectedInsets), @"Expected %@, actual result %@", NSStringFromUIEdgeInsets(expectedInsets), NSStringFromUIEdgeInsets(invertedInsets));
}
- (void)testASDNEdgeInsetsInvertDoubleNegation
{
CGRect originalRect = CGRectMake(31, 32, 33, 34);
UIEdgeInsets insets = UIEdgeInsetsMake(-5, -7, -3, -2);
CGRect insettedRect = UIEdgeInsetsInsetRect(originalRect, insets);
CGRect outsettedInsettedRect = UIEdgeInsetsInsetRect(insettedRect, ASDNEdgeInsetsInvert(insets));
XCTAssertTrue(CGRectEqualToRect(originalRect, outsettedInsettedRect), @"Insetting a CGRect, and then outsetting it (insetting with the negated edge insets) should return the original CGRect");
}
@end