forked from TextureGroup/Texture
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathASDisplayNodeTests.mm
2786 lines (2297 loc) · 112 KB
/
ASDisplayNodeTests.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//
// ASDisplayNodeTests.mm
// Texture
//
// Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
// Changes after 4/13/2017 are: Copyright (c) Pinterest, Inc. All rights reserved.
// Licensed under Apache 2.0: http://www.apache.org/licenses/LICENSE-2.0
//
#import <QuartzCore/QuartzCore.h>
#import <XCTest/XCTest.h>
#import <OCMock/OCMock.h>
#import <AsyncDisplayKit/_ASDisplayLayer.h>
#import <AsyncDisplayKit/_ASDisplayView.h>
#import <AsyncDisplayKit/ASAvailability.h>
#import <AsyncDisplayKit/ASDisplayNode+Subclasses.h>
#import <AsyncDisplayKit/ASDisplayNode+FrameworkPrivate.h>
#import <AsyncDisplayKit/ASDisplayNodeInternal.h>
#import <AsyncDisplayKit/ASDisplayNodeCornerLayerDelegate.h>
#import <AsyncDisplayKit/UIView+ASConvenience.h>
#import <AsyncDisplayKit/ASCellNode.h>
#import <AsyncDisplayKit/ASEditableTextNode.h>
#import <AsyncDisplayKit/ASImageNode.h>
#import <AsyncDisplayKit/ASOverlayLayoutSpec.h>
#import <AsyncDisplayKit/ASInsetLayoutSpec.h>
#import <AsyncDisplayKit/ASStackLayoutSpec.h>
#import <AsyncDisplayKit/ASCenterLayoutSpec.h>
#import <AsyncDisplayKit/ASBackgroundLayoutSpec.h>
#import <AsyncDisplayKit/ASInternalHelpers.h>
#import <AsyncDisplayKit/ASDisplayNodeExtras.h>
#import <AsyncDisplayKit/ASViewController.h>
#import "ASXCTExtensions.h"
#import "ASDisplayNodeTestsHelper.h"
// Conveniences for making nodes named a certain way
#define DeclareNodeNamed(n) ASDisplayNode *n = [[ASDisplayNode alloc] init]; n.debugName = @#n
#define DeclareViewNamed(v) \
ASDisplayNode *node_##v = [[ASDisplayNode alloc] init]; \
node_##v.debugName = @#v; \
UIView *v = node_##v.view;
#define DeclareLayerNamed(l) \
ASDisplayNode *node_##l = [[ASDisplayNode alloc] init]; \
node_##l.debugName = @#l; \
node_##l.layerBacked = YES; \
CALayer *l = node_##l.layer;
static NSString *orderStringFromSublayers(CALayer *l) {
return [[[l.sublayers valueForKey:@"asyncdisplaykit_node"] valueForKey:@"debugName"] componentsJoinedByString:@","];
}
static NSString *orderStringFromSubviews(UIView *v) {
return [[[v.subviews valueForKey:@"asyncdisplaykit_node"] valueForKey:@"debugName"] componentsJoinedByString:@","];
}
static NSString *orderStringFromSubnodes(ASDisplayNode *n) {
return [[n.subnodes valueForKey:@"debugName"] componentsJoinedByString:@","];
}
// Asserts subnode, subview, sublayer order match what you provide here
#define XCTAssertNodeSubnodeSubviewSublayerOrder(n, loaded, isLayerBacked, order, description) \
XCTAssertEqualObjects(orderStringFromSubnodes(n), order, @"Incorrect node order for " description );\
if (loaded) {\
if (!isLayerBacked) {\
XCTAssertEqualObjects(orderStringFromSubviews(n.view), order, @"Incorrect subviews for " description);\
}\
XCTAssertEqualObjects(orderStringFromSublayers(n.layer), order, @"Incorrect sublayers for " description);\
}
#define XCTAssertNodesHaveParent(parent, nodes ...) \
for (ASDisplayNode *n in @[ nodes ]) {\
XCTAssertEqualObjects(parent, n.supernode, @"%@ has the wrong parent", n.debugName);\
}
#define XCTAssertNodesLoaded(nodes ...) \
for (ASDisplayNode *n in @[ nodes ]) {\
XCTAssertTrue(n.nodeLoaded, @"%@ should be loaded", n.debugName);\
}
#define XCTAssertNodesNotLoaded(nodes ...) \
for (ASDisplayNode *n in @[ nodes ]) {\
XCTAssertFalse(n.nodeLoaded, @"%@ should not be loaded", n.debugName);\
}
@interface UIWindow (Testing)
// UIWindow has this handy method that is not public but great for testing
- (UIResponder *)firstResponder;
@end
@interface ASDisplayNode (HackForTests)
- (id)initWithViewClass:(Class)viewClass;
- (id)initWithLayerClass:(Class)layerClass;
- (void)setInterfaceState:(ASInterfaceState)state;
// FIXME: Importing ASDisplayNodeInternal.h causes a heap of problems.
- (void)enterInterfaceState:(ASInterfaceState)interfaceState;
@end
@interface ASTestDisplayNode : ASDisplayNode
@property (nonatomic) void (^willDeallocBlock)(__unsafe_unretained ASTestDisplayNode *node);
@property (nonatomic) CGSize(^calculateSizeBlock)(ASTestDisplayNode *node, CGSize size);
@property (nonatomic, nullable) UIGestureRecognizer *gestureRecognizer;
@property (nonatomic, nullable) id idGestureRecognizer;
@property (nonatomic, nullable) UIImage *bigImage;
@property (nonatomic, nullable) NSArray *randomProperty;
@property (nonatomic) BOOL displayRangeStateChangedToYES;
@property (nonatomic) BOOL displayRangeStateChangedToNO;
@property (nonatomic) BOOL hasPreloaded;
@property (nonatomic) BOOL preloadStateChangedToYES;
@property (nonatomic) BOOL preloadStateChangedToNO;
@property (nonatomic) NSUInteger displayWillStartCount;
@property (nonatomic) NSUInteger didDisplayCount;
@end
@interface ASTestResponderNode : ASTestDisplayNode
@end
@implementation ASTestDisplayNode
- (void)setInterfaceState:(ASInterfaceState)state
{
[super setInterfaceState:state];
ASCATransactionQueueWait(nil);
}
- (CGSize)calculateSizeThatFits:(CGSize)constrainedSize
{
return _calculateSizeBlock ? _calculateSizeBlock(self, constrainedSize) : CGSizeZero;
}
- (void)didEnterDisplayState
{
[super didEnterDisplayState];
self.displayRangeStateChangedToYES = YES;
}
- (void)didExitDisplayState
{
[super didExitDisplayState];
self.displayRangeStateChangedToNO = YES;
}
- (void)didEnterPreloadState
{
[super didEnterPreloadState];
self.preloadStateChangedToYES = YES;
self.hasPreloaded = YES;
}
- (void)didExitPreloadState
{
[super didExitPreloadState];
self.preloadStateChangedToNO = YES;
}
- (void)dealloc
{
if (_willDeallocBlock) {
_willDeallocBlock(self);
}
}
- (void)displayDidFinish
{
[super displayDidFinish];
_didDisplayCount++;
}
- (void)displayWillStartAsynchronously:(BOOL)asynchronously
{
[super displayWillStartAsynchronously:asynchronously];
_displayWillStartCount++;
}
- (CALayer *__strong (*)[NUM_CLIP_CORNER_LAYERS])clipCornerLayers
{
return &self->_clipCornerLayers;
}
+ (UIImage *)displayWithParameters:(id<NSObject>)parameter isCancelled:(NS_NOESCAPE asdisplaynode_iscancelled_block_t)isCancelled
{
return nil;
}
@end
@interface ASSynchronousTestDisplayNodeViaViewClass : ASDisplayNode
@end
@implementation ASSynchronousTestDisplayNodeViaViewClass
+ (Class)viewClass {
return [UIView class];
}
@end
@interface ASSynchronousTestDisplayNodeViaLayerClass : ASDisplayNode
@end
@implementation ASSynchronousTestDisplayNodeViaLayerClass
+ (Class)layerClass {
return [CALayer class];
}
@end
@interface UIDisplayNodeTestView : UIView
@end
@interface UIResponderNodeTestView : _ASDisplayView
@property(nonatomic) BOOL testIsFirstResponder;
@end
@implementation UIDisplayNodeTestView
@end
@interface ASTestWindow : UIWindow
@end
@implementation ASTestWindow
- (id)firstResponder {
return self.subviews.firstObject;
}
@end
@implementation ASTestResponderNode
+ (Class)viewClass {
return [UIResponderNodeTestView class];
}
- (BOOL)canBecomeFirstResponder {
return YES;
}
@end
@implementation UIResponderNodeTestView
- (BOOL)becomeFirstResponder {
self.testIsFirstResponder = YES;
return YES;
}
- (BOOL)canResignFirstResponder {
return YES;
}
- (BOOL)resignFirstResponder {
[super resignFirstResponder];
if (self.testIsFirstResponder) {
self.testIsFirstResponder = NO;
return YES;
}
return NO;
}
@end
@interface ASTestResponderNodeWithOverride : ASDisplayNode
@end
@implementation ASTestResponderNodeWithOverride
- (BOOL)canBecomeFirstResponder {
return YES;
}
@end
@interface ASTestViewController: ASViewController<ASDisplayNode *>
@end
@implementation ASTestViewController
- (BOOL)prefersStatusBarHidden { return YES; }
@end
@interface UIResponderNodeTestDisplayViewCallingSuper : _ASDisplayView
@end
@implementation UIResponderNodeTestDisplayViewCallingSuper
- (BOOL)canBecomeFirstResponder { return YES; }
- (BOOL)becomeFirstResponder { return [super becomeFirstResponder]; }
@end
@interface UIResponderNodeTestViewCallingSuper : UIView
@end
@implementation UIResponderNodeTestViewCallingSuper
- (BOOL)canBecomeFirstResponder { return YES; }
- (BOOL)becomeFirstResponder { return [super becomeFirstResponder]; }
@end
@interface ASDisplayNodeTests : XCTestCase
@end
@implementation ASDisplayNodeTests
{
dispatch_queue_t queue;
}
- (void)testOverriddenNodeFirstResponderBehavior
{
ASTestDisplayNode *node = [[ASTestResponderNode alloc] init];
XCTAssertTrue([node canBecomeFirstResponder]);
XCTAssertTrue([node becomeFirstResponder]);
}
- (void)testOverriddenDisplayViewFirstResponderBehavior
{
UIWindow *window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
ASDisplayNode *node = [[ASDisplayNode alloc] initWithViewClass:[UIResponderNodeTestDisplayViewCallingSuper class]];
// We have to add the node to a window otherwise the super responder methods call responses are undefined
// This will also create the backing view of the node
[window addSubnode:node];
[window makeKeyAndVisible];
XCTAssertTrue([node canBecomeFirstResponder]);
XCTAssertTrue([node becomeFirstResponder]);
}
- (void)testOverriddenViewFirstResponderBehavior
{
UIWindow *window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
ASDisplayNode *node = [[ASDisplayNode alloc] initWithViewClass:[UIResponderNodeTestViewCallingSuper class]];
// We have to add the node to a window otherwise the super responder methods call responses are undefined
// This will also create the backing view of the node
[window addSubnode:node];
[window makeKeyAndVisible];
XCTAssertTrue([node canBecomeFirstResponder]);
XCTAssertTrue([node becomeFirstResponder]);
}
- (void)testDefaultFirstResponderBehavior
{
ASTestDisplayNode *node = [[ASTestDisplayNode alloc] init];
XCTAssertFalse([node canBecomeFirstResponder]);
XCTAssertFalse([node becomeFirstResponder]);
}
- (void)testResponderMethodsBehavior
{
UIWindow *window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
ASEditableTextNode *textNode = [[ASEditableTextNode alloc] init];
// We have to add the text node to a window otherwise the responder methods responses are undefined
// This will also create the backing view of the node
[window addSubnode:textNode];
[window makeKeyAndVisible];
XCTAssertTrue([textNode canBecomeFirstResponder]);
XCTAssertTrue([textNode becomeFirstResponder]);
XCTAssertTrue([window firstResponder] == textNode.textView);
XCTAssertTrue([textNode resignFirstResponder]);
// If the textNode resigns it's first responder the view should not be the first responder
XCTAssertTrue([window firstResponder] == nil);
XCTAssertFalse([textNode.view isFirstResponder]);
}
- (void)testResponderOverrrideCanBecomeFirstResponder
{
UIWindow *window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
ASTestResponderNodeWithOverride *node = [[ASTestResponderNodeWithOverride alloc] init];
// We have to add the text node to a window otherwise the responder methods responses are undefined
// This will also create the backing view of the node
[window addSubnode:node];
[window makeKeyAndVisible];
XCTAssertTrue([node canBecomeFirstResponder]);
XCTAssertTrue([node becomeFirstResponder]);
XCTAssertTrue([window firstResponder] == node.view);
}
- (void)testUnsupportedResponderSetupWillThrow
{
ASTestResponderNode *node = [[ASTestResponderNode alloc] init];
[node setViewBlock:^UIView * _Nonnull{
return [[UIView alloc] init];
}];
XCTAssertThrows([node view], @"Externally provided views should be synchronous");
}
- (void)setUp
{
[super setUp];
queue = dispatch_queue_create("com.facebook.AsyncDisplayKit.ASDisplayNodeTestsQueue", NULL);
}
- (void)testViewCreatedOffThreadCanBeRealizedOnThread
{
__block ASDisplayNode *node = nil;
[self executeOffThread:^{
node = [[ASDisplayNode alloc] init];
}];
UIView *view = node.view;
XCTAssertNotNil(view, @"Getting node's view on-thread should succeed.");
}
- (void)testNodeCreatedOffThreadWithExistingView
{
UIView *view = [[UIDisplayNodeTestView alloc] init];
__block ASDisplayNode *node = nil;
[self executeOffThread:^{
node = [[ASDisplayNode alloc] initWithViewBlock:^UIView *{
return view;
}];
}];
XCTAssertFalse(node.layerBacked, @"Can't be layer backed");
XCTAssertTrue(node.synchronous, @"Node with plain view should be synchronous");
XCTAssertFalse(node.nodeLoaded, @"Shouldn't have a view yet");
XCTAssertEqual(view, node.view, @"Getting node's view on-thread should succeed.");
}
- (void)testNodeCreatedOffThreadWithLazyView
{
__block UIView *view = nil;
__block ASDisplayNode *node = nil;
[self executeOffThread:^{
node = [[ASDisplayNode alloc] initWithViewBlock:^UIView *{
XCTAssertTrue([NSThread isMainThread], @"View block must run on the main queue");
view = [[UIDisplayNodeTestView alloc] init];
return view;
}];
}];
XCTAssertNil(view, @"View block should not be invoked yet");
[node view];
XCTAssertNotNil(view, @"View block should have been invoked");
XCTAssertEqual(view, node.view, @"Getting node's view on-thread should succeed.");
XCTAssertTrue(node.synchronous, @"Node with plain view should be synchronous");
}
- (void)testNodeCreatedWithLazyAsyncView
{
ASDisplayNode *node = [[ASDisplayNode alloc] initWithViewBlock:^UIView *{
XCTAssertTrue([NSThread isMainThread], @"View block must run on the main queue");
return [[_ASDisplayView alloc] init];
}];
XCTAssertThrows([node view], @"Externally provided views should be synchronous");
XCTAssertTrue(node.synchronous, @"Node with externally provided view should be synchronous");
}
- (void)checkValuesMatchDefaults:(ASDisplayNode *)node isLayerBacked:(BOOL)isLayerBacked
{
NSString *targetName = isLayerBacked ? @"layer" : @"view";
NSString *hasLoadedView = node.nodeLoaded ? @"with view" : [NSString stringWithFormat:@"after loading %@", targetName];
// id rgbBlackCGColorIdPtr = (id)[UIColor blackColor].CGColor;
XCTAssertEqual((id)nil, node.contents, @"default contents broken %@", hasLoadedView);
XCTAssertEqual(NO, node.clipsToBounds, @"default clipsToBounds broken %@", hasLoadedView);
XCTAssertEqual(YES, node.opaque, @"default opaque broken %@", hasLoadedView);
XCTAssertEqual(NO, node.needsDisplayOnBoundsChange, @"default needsDisplayOnBoundsChange broken %@", hasLoadedView);
XCTAssertEqual(YES, node.allowsGroupOpacity, @"default allowsGroupOpacity broken %@", hasLoadedView);
XCTAssertEqual(NO, node.allowsEdgeAntialiasing, @"default allowsEdgeAntialiasing broken %@", hasLoadedView);
XCTAssertEqual((kCALayerLeftEdge | kCALayerRightEdge | kCALayerBottomEdge | kCALayerTopEdge), node.edgeAntialiasingMask, @"default edgeAntialisingMask broken %@", hasLoadedView);
XCTAssertEqual(NO, node.hidden, @"default hidden broken %@", hasLoadedView);
XCTAssertEqual(1.0f, node.alpha, @"default alpha broken %@", hasLoadedView);
XCTAssertTrue(CGRectEqualToRect(CGRectZero, node.bounds), @"default bounds broken %@", hasLoadedView);
XCTAssertTrue(CGRectEqualToRect(CGRectZero, node.frame), @"default frame broken %@", hasLoadedView);
XCTAssertTrue(CGPointEqualToPoint(CGPointZero, node.position), @"default position broken %@", hasLoadedView);
XCTAssertEqual((CGFloat)0.0, node.zPosition, @"default zPosition broken %@", hasLoadedView);
XCTAssertEqual(node.isNodeLoaded && !isLayerBacked ? 2.0f : 1.0f, node.contentsScale, @"default contentsScale broken %@", hasLoadedView);
XCTAssertEqual([UIScreen mainScreen].scale, node.contentsScaleForDisplay, @"default contentsScaleForDisplay broken %@", hasLoadedView);
XCTAssertTrue(CATransform3DEqualToTransform(CATransform3DIdentity, node.transform), @"default transform broken %@", hasLoadedView);
XCTAssertTrue(CATransform3DEqualToTransform(CATransform3DIdentity, node.subnodeTransform), @"default subnodeTransform broken %@", hasLoadedView);
XCTAssertEqual((id)nil, node.backgroundColor, @"default backgroundColor broken %@", hasLoadedView);
XCTAssertEqual(UIViewContentModeScaleToFill, node.contentMode, @"default contentMode broken %@", hasLoadedView);
// XCTAssertEqualObjects(rgbBlackCGColorIdPtr, (id)node.shadowColor, @"default shadowColor broken %@", hasLoadedView);
XCTAssertEqual(0.0f, node.shadowOpacity, @"default shadowOpacity broken %@", hasLoadedView);
XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(0, -3), node.shadowOffset), @"default shadowOffset broken %@", hasLoadedView);
XCTAssertEqual(3.f, node.shadowRadius, @"default shadowRadius broken %@", hasLoadedView);
XCTAssertEqual(0.0f, node.borderWidth, @"default borderWidth broken %@", hasLoadedView);
// XCTAssertEqualObjects(rgbBlackCGColorIdPtr, (id)node.borderColor, @"default borderColor broken %@", hasLoadedView);
XCTAssertEqual(NO, node.displaySuspended, @"default displaySuspended broken %@", hasLoadedView);
XCTAssertEqual(YES, node.displaysAsynchronously, @"default displaysAsynchronously broken %@", hasLoadedView);
XCTAssertEqual(NO, node.asyncdisplaykit_asyncTransactionContainer, @"default asyncdisplaykit_asyncTransactionContainer broken %@", hasLoadedView);
XCTAssertEqualObjects(nil, node.debugName, @"default name broken %@", hasLoadedView);
XCTAssertEqual(NO, node.isAccessibilityElement, @"default isAccessibilityElement is broken %@", hasLoadedView);
XCTAssertEqual((id)nil, node.accessibilityLabel, @"default accessibilityLabel is broken %@", hasLoadedView);
XCTAssertEqual((id)nil, node.accessibilityHint, @"default accessibilityHint is broken %@", hasLoadedView);
XCTAssertEqual((id)nil, node.accessibilityValue, @"default accessibilityValue is broken %@", hasLoadedView);
// if (AS_AT_LEAST_IOS11) {
// XCTAssertEqual((id)nil, node.accessibilityAttributedLabel, @"default accessibilityAttributedLabel is broken %@", hasLoadedView);
// XCTAssertEqual((id)nil, node.accessibilityAttributedHint, @"default accessibilityAttributedHint is broken %@", hasLoadedView);
// XCTAssertEqual((id)nil, node.accessibilityAttributedValue, @"default accessibilityAttributedValue is broken %@", hasLoadedView);
// }
XCTAssertEqual(UIAccessibilityTraitNone, node.accessibilityTraits, @"default accessibilityTraits is broken %@", hasLoadedView);
XCTAssertTrue(CGRectEqualToRect(CGRectZero, node.accessibilityFrame), @"default accessibilityFrame is broken %@", hasLoadedView);
XCTAssertEqual((id)nil, node.accessibilityLanguage, @"default accessibilityLanguage is broken %@", hasLoadedView);
XCTAssertEqual(NO, node.accessibilityElementsHidden, @"default accessibilityElementsHidden is broken %@", hasLoadedView);
XCTAssertEqual(NO, node.accessibilityViewIsModal, @"default accessibilityViewIsModal is broken %@", hasLoadedView);
XCTAssertEqual(NO, node.shouldGroupAccessibilityChildren, @"default shouldGroupAccessibilityChildren is broken %@", hasLoadedView);
XCTAssertEqual((id)nil, node.accessibilityCustomActions, @"default acccessibilityCustomActions is broken %@", hasLoadedView);
if (!isLayerBacked) {
XCTAssertEqual(YES, node.userInteractionEnabled, @"default userInteractionEnabled broken %@", hasLoadedView);
XCTAssertEqual(NO, node.exclusiveTouch, @"default exclusiveTouch broken %@", hasLoadedView);
XCTAssertEqual(YES, node.autoresizesSubviews, @"default autoresizesSubviews broken %@", hasLoadedView);
XCTAssertEqual(UIViewAutoresizingNone, node.autoresizingMask, @"default autoresizingMask broken %@", hasLoadedView);
XCTAssertTrue(UIEdgeInsetsEqualToEdgeInsets(UIEdgeInsetsMake(8, 8, 8, 8), node.layoutMargins), @"default layoutMargins broken %@", hasLoadedView);
XCTAssertEqual(NO, node.preservesSuperviewLayoutMargins, @"default preservesSuperviewLayoutMargins broken %@", hasLoadedView);
XCTAssertTrue(UIEdgeInsetsEqualToEdgeInsets(UIEdgeInsetsZero, node.safeAreaInsets), @"default safeAreaInsets broken %@", hasLoadedView);
XCTAssertEqual(YES, node.insetsLayoutMarginsFromSafeArea, @"default insetsLayoutMarginsFromSafeArea broken %@", hasLoadedView);
if (node.nodeLoaded) {
XCTAssertNotNil(node.tintColor, @"default tintColor broken %@", hasLoadedView); // It has been populated by the UIView.
} else {
XCTAssertNil(node.tintColor, @"default tintColor broken %@", hasLoadedView);
}
} else {
XCTAssertEqual(NO, node.userInteractionEnabled, @"layer-backed nodes do not support userInteractionEnabled %@", hasLoadedView);
XCTAssertEqual(NO, node.exclusiveTouch, @"layer-backed nodes do not support exclusiveTouch %@", hasLoadedView);
XCTAssertNil(node.tintColor, @"default tintColor broken %@", hasLoadedView);
}
}
- (void)checkDefaultPropertyValuesWithLayerBacking:(BOOL)isLayerBacked
{
ASDisplayNode *node = [[ASDisplayNode alloc] init];
XCTAssertEqual(NO, node.isLayerBacked, @"default isLayerBacked broken without view");
node.layerBacked = isLayerBacked;
XCTAssertEqual(isLayerBacked, node.isLayerBacked, @"setIsLayerBacked: broken");
// Assert that the values can be fetched from the node before the view is realized.
[self checkValuesMatchDefaults:node isLayerBacked:isLayerBacked];
[node layer]; // Force either view or layer loading
XCTAssertTrue(node.nodeLoaded, @"Didn't load view");
// Assert that the values can be fetched from the node after the view is realized.
[self checkValuesMatchDefaults:node isLayerBacked:isLayerBacked];
}
- (void)testDefaultPropertyValuesLayer
{
[self checkDefaultPropertyValuesWithLayerBacking:YES];
}
- (void)testDefaultPropertyValuesView
{
[self checkDefaultPropertyValuesWithLayerBacking:NO];
}
- (UIImage *)bogusImage
{
static UIImage *bogusImage;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
UIGraphicsBeginImageContext(CGSizeMake(1, 1));
bogusImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
});
return bogusImage;
}
- (BOOL)dummySelector
{
// no-op; only used for testing of UIAccessibilityCustomAction propagation
return YES;
}
- (void)checkValuesMatchSetValues:(ASDisplayNode *)node isLayerBacked:(BOOL)isLayerBacked
{
NSString *targetName = isLayerBacked ? @"layer" : @"view";
NSString *hasLoadedView = node.nodeLoaded ? @"with view" : [NSString stringWithFormat:@"after loading %@", targetName];
XCTAssertEqual(isLayerBacked, node.isLayerBacked, @"isLayerBacked broken %@", hasLoadedView);
XCTAssertEqualObjects((id)[self bogusImage].CGImage, (id)node.contents, @"contents broken %@", hasLoadedView);
XCTAssertEqual(YES, node.clipsToBounds, @"clipsToBounds broken %@", hasLoadedView);
XCTAssertEqual(NO, node.opaque, @"opaque broken %@", hasLoadedView);
XCTAssertEqual(YES, node.needsDisplayOnBoundsChange, @"needsDisplayOnBoundsChange broken %@", hasLoadedView);
XCTAssertEqual(NO, node.allowsGroupOpacity, @"allowsGroupOpacity broken %@", hasLoadedView);
XCTAssertEqual(YES, node.allowsEdgeAntialiasing, @"allowsEdgeAntialiasing broken %@", hasLoadedView);
XCTAssertTrue((kCALayerLeftEdge | kCALayerTopEdge) == node.edgeAntialiasingMask, @"edgeAntialiasingMask broken: %@", hasLoadedView);
XCTAssertEqual(YES, node.hidden, @"hidden broken %@", hasLoadedView);
XCTAssertEqual(.5f, node.alpha, @"alpha broken %@", hasLoadedView);
XCTAssertTrue(CGRectEqualToRect(CGRectMake(10, 15, 42, 115.2), node.bounds), @"bounds broken %@", hasLoadedView);
XCTAssertTrue(CGPointEqualToPoint(CGPointMake(10, 65), node.position), @"position broken %@", hasLoadedView);
XCTAssertEqual((CGFloat)5.6, node.zPosition, @"zPosition broken %@", hasLoadedView);
XCTAssertEqual(.5f, node.contentsScale, @"contentsScale broken %@", hasLoadedView);
XCTAssertTrue(CATransform3DEqualToTransform(CATransform3DMakeScale(0.5, 0.5, 1.0), node.transform), @"transform broken %@", hasLoadedView);
XCTAssertTrue(CATransform3DEqualToTransform(CATransform3DMakeTranslation(1337, 7357, 7007), node.subnodeTransform), @"subnodeTransform broken %@", hasLoadedView);
XCTAssertEqualObjects([UIColor clearColor], node.backgroundColor, @"backgroundColor broken %@", hasLoadedView);
XCTAssertEqualObjects([UIColor orangeColor], node.tintColor, @"tintColor broken %@", hasLoadedView);
XCTAssertEqual(UIViewContentModeBottom, node.contentMode, @"contentMode broken %@", hasLoadedView);
XCTAssertEqual([[UIColor cyanColor] CGColor], node.shadowColor, @"shadowColor broken %@", hasLoadedView);
XCTAssertEqual(.5f, node.shadowOpacity, @"shadowOpacity broken %@", hasLoadedView);
XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(1.0f, 1.0f), node.shadowOffset), @"shadowOffset broken %@", hasLoadedView);
XCTAssertEqual(.5f, node.shadowRadius, @"shadowRadius broken %@", hasLoadedView);
XCTAssertEqual(.5f, node.borderWidth, @"borderWidth broken %@", hasLoadedView);
XCTAssertEqual([[UIColor orangeColor] CGColor], node.borderColor, @"borderColor broken %@", hasLoadedView);
XCTAssertEqual(YES, node.displaySuspended, @"displaySuspended broken %@", hasLoadedView);
XCTAssertEqual(NO, node.displaysAsynchronously, @"displaySuspended broken %@", hasLoadedView);
XCTAssertEqual(YES, node.asyncdisplaykit_asyncTransactionContainer, @"asyncTransactionContainer broken %@", hasLoadedView);
XCTAssertEqual(NO, node.userInteractionEnabled, @"userInteractionEnabled broken %@", hasLoadedView);
XCTAssertEqual((BOOL)!isLayerBacked, node.exclusiveTouch, @"exclusiveTouch broken %@", hasLoadedView);
XCTAssertEqualObjects(@"quack like a duck", node.debugName, @"debugName broken %@", hasLoadedView);
XCTAssertEqual(YES, node.isAccessibilityElement, @"accessibilityElement broken %@", hasLoadedView);
XCTAssertEqualObjects(@"Ship love", node.accessibilityLabel, @"accessibilityLabel broken %@", hasLoadedView);
XCTAssertEqualObjects(@"Awesome things will happen", node.accessibilityHint, @"accessibilityHint broken %@", hasLoadedView);
XCTAssertEqualObjects(@"1 of 2", node.accessibilityValue, @"accessibilityValue broken %@", hasLoadedView);
// setting the accessibilityLabel, accessibilityHint and accessibilityValue is supposed to be bridged to the attributed versions
// if (AS_AT_LEAST_IOS11) {
// XCTAssertEqualObjects(@"Ship love", node.accessibilityAttributedLabel.string, @"accessibilityAttributedLabel is broken %@", hasLoadedView);
// XCTAssertEqualObjects(@"Awesome things will happen", node.accessibilityAttributedHint.string, @"accessibilityAttributedHint is broken %@", hasLoadedView);
// XCTAssertEqualObjects(@"1 of 2", node.accessibilityAttributedValue.string, @"accessibilityAttributedValue is broken %@", hasLoadedView);
// }
XCTAssertEqual(UIAccessibilityTraitSelected | UIAccessibilityTraitButton, node.accessibilityTraits, @"accessibilityTraits broken %@", hasLoadedView);
XCTAssertTrue(CGRectEqualToRect(CGRectMake(1, 2, 3, 4), node.accessibilityFrame), @"accessibilityFrame broken %@", hasLoadedView);
XCTAssertEqualObjects(@"mas", node.accessibilityLanguage, @"accessibilityLanguage broken %@", hasLoadedView);
XCTAssertEqual(YES, node.accessibilityElementsHidden, @"accessibilityElementsHidden broken %@", hasLoadedView);
XCTAssertEqual(YES, node.accessibilityViewIsModal, @"accessibilityViewIsModal broken %@", hasLoadedView);
XCTAssertEqual(YES, node.shouldGroupAccessibilityChildren, @"shouldGroupAccessibilityChildren broken %@", hasLoadedView);
XCTAssertEqual(UIAccessibilityNavigationStyleSeparate, node.accessibilityNavigationStyle, @"accessibilityNavigationStyle broken %@", hasLoadedView);
if (AS_AVAILABLE_IOS_TVOS(8, 9)) {
XCTAssertNotNil(node.accessibilityCustomActions, @"accessibilityCustomActions broken %@", hasLoadedView);
XCTAssertEqualObjects(@"custom action", ((UIAccessibilityCustomAction *)(node.accessibilityCustomActions.firstObject)).name, @"accessibilityCustomActions broken %@", hasLoadedView);
}
XCTAssertTrue(CGPointEqualToPoint(CGPointMake(1.0, 1.0), node.accessibilityActivationPoint), @"accessibilityActivationPoint broken %@", hasLoadedView);
XCTAssertNotNil(node.accessibilityPath, @"accessibilityPath broken %@", hasLoadedView);
if (!isLayerBacked) {
XCTAssertEqual(UIViewAutoresizingFlexibleLeftMargin, node.autoresizingMask, @"autoresizingMask %@", hasLoadedView);
XCTAssertEqual(NO, node.autoresizesSubviews, @"autoresizesSubviews broken %@", hasLoadedView);
XCTAssertTrue(UIEdgeInsetsEqualToEdgeInsets(UIEdgeInsetsMake(3, 5, 8, 11), node.layoutMargins), @"layoutMargins broken %@", hasLoadedView);
XCTAssertEqual(YES, node.preservesSuperviewLayoutMargins, @"preservesSuperviewLayoutMargins broken %@", hasLoadedView);
XCTAssertEqual(NO, node.insetsLayoutMarginsFromSafeArea, @"insetsLayoutMarginsFromSafeArea broken %@", hasLoadedView);
}
}
- (void)checkSimpleBridgePropertiesSetPropagate:(BOOL)isLayerBacked
{
__block ASDisplayNode *node = nil;
[self executeOffThread:^{
node = [[ASDisplayNode alloc] init];
node.layerBacked = isLayerBacked;
node.contents = (id)[self bogusImage].CGImage;
node.clipsToBounds = YES;
node.opaque = NO;
node.needsDisplayOnBoundsChange = YES;
node.allowsGroupOpacity = NO;
node.allowsEdgeAntialiasing = YES;
node.edgeAntialiasingMask = (kCALayerLeftEdge | kCALayerTopEdge);
node.hidden = YES;
node.alpha = .5f;
node.position = CGPointMake(10, 65);
node.zPosition = 5.6;
node.bounds = CGRectMake(10, 15, 42, 115.2);
node.contentsScale = .5f;
node.transform = CATransform3DMakeScale(0.5, 0.5, 1.0);
node.subnodeTransform = CATransform3DMakeTranslation(1337, 7357, 7007);
node.backgroundColor = [UIColor clearColor];
node.tintColor = [UIColor orangeColor];
node.contentMode = UIViewContentModeBottom;
node.shadowColor = [[UIColor cyanColor] CGColor];
node.shadowOpacity = .5f;
node.shadowOffset = CGSizeMake(1.0f, 1.0f);
node.shadowRadius = .5f;
node.borderWidth = .5f;
node.borderColor = [[UIColor orangeColor] CGColor];
node.displaySuspended = YES;
node.displaysAsynchronously = NO;
node.asyncdisplaykit_asyncTransactionContainer = YES;
node.userInteractionEnabled = NO;
node.debugName = @"quack like a duck";
node.isAccessibilityElement = YES;
for (int i = 0; i < 4; i++) {
if (i % 2 == 0) {
XCTAssertNoThrow(node.accessibilityLabel = nil);
XCTAssertNoThrow(node.accessibilityHint = nil);
XCTAssertNoThrow(node.accessibilityValue = nil);
} else {
node.accessibilityLabel = @"Ship love";
node.accessibilityHint = @"Awesome things will happen";
node.accessibilityValue = @"1 of 2";
}
}
node.accessibilityTraits = UIAccessibilityTraitSelected | UIAccessibilityTraitButton;
node.accessibilityFrame = CGRectMake(1, 2, 3, 4);
node.accessibilityLanguage = @"mas";
node.accessibilityElementsHidden = YES;
node.accessibilityViewIsModal = YES;
node.shouldGroupAccessibilityChildren = YES;
node.accessibilityNavigationStyle = UIAccessibilityNavigationStyleSeparate;
if (AS_AVAILABLE_IOS_TVOS(8, 9)) {
node.accessibilityCustomActions = @[ [[UIAccessibilityCustomAction alloc] initWithName:@"custom action" target:self selector:@selector(dummySelector)] ];
}
node.accessibilityActivationPoint = CGPointMake(1.0, 1.0);
node.accessibilityPath = [UIBezierPath bezierPath];
if (!isLayerBacked) {
node.exclusiveTouch = YES;
node.autoresizesSubviews = NO;
node.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
node.insetsLayoutMarginsFromSafeArea = NO;
node.layoutMargins = UIEdgeInsetsMake(3, 5, 8, 11);
node.preservesSuperviewLayoutMargins = YES;
}
}];
// Assert that the values can be fetched from the node before the view is realized.
[self checkValuesMatchSetValues:node isLayerBacked:isLayerBacked];
// Assert that the realized view/layer have the correct values.
[node layer];
[self checkValuesMatchSetValues:node isLayerBacked:isLayerBacked];
// As a final sanity check, change a value on the realized view and ensure it is fetched through the node.
if (isLayerBacked) {
node.layer.hidden = NO;
} else {
node.view.hidden = NO;
}
XCTAssertEqual(NO, node.hidden, @"After the view is realized, the node should delegate properties to the view.");
}
// Set each of the simple bridged UIView properties to a non-default value off-thread, then
// assert that they are correct on the node and propagated to the UIView realized on-thread.
- (void)testSimpleUIViewBridgePropertiesSetOffThreadPropagate
{
[self checkSimpleBridgePropertiesSetPropagate:NO];
}
- (void)testSimpleCALayerBridgePropertiesSetOffThreadPropagate
{
[self checkSimpleBridgePropertiesSetPropagate:YES];
}
- (void)testPropertiesSetOffThreadBeforeLoadingExternalView
{
UIView *view = [[UIDisplayNodeTestView alloc] init];
__block ASDisplayNode *node = nil;
[self executeOffThread:^{
node = [[ASDisplayNode alloc] initWithViewBlock:^{
return view;
}];
node.backgroundColor = [UIColor blueColor];
node.tintColor = [UIColor orangeColor];
node.frame = CGRectMake(10, 20, 30, 40);
node.autoresizingMask = UIViewAutoresizingFlexibleWidth;
node.userInteractionEnabled = YES;
}];
[self checkExternalViewAppliedPropertiesMatch:node];
}
- (void)testPropertiesSetOnThreadAfterLoadingExternalView
{
UIView *view = [[UIDisplayNodeTestView alloc] init];
ASDisplayNode *node = [[ASDisplayNode alloc] initWithViewBlock:^{
return view;
}];
// Load the backing view first
[node view];
node.backgroundColor = [UIColor blueColor];
node.tintColor = [UIColor orangeColor];
node.frame = CGRectMake(10, 20, 30, 40);
node.autoresizingMask = UIViewAutoresizingFlexibleWidth;
node.userInteractionEnabled = YES;
[self checkExternalViewAppliedPropertiesMatch:node];
}
- (void)checkExternalViewAppliedPropertiesMatch:(ASDisplayNode *)node
{
UIView *view = node.view;
XCTAssertEqualObjects([UIColor blueColor], view.backgroundColor, @"backgroundColor not propagated to view");
XCTAssertEqualObjects([UIColor orangeColor], view.tintColor, @"tintColor not propagated to view");
XCTAssertTrue(CGRectEqualToRect(CGRectMake(10, 20, 30, 40), view.frame), @"frame not propagated to view");
XCTAssertEqual(UIViewAutoresizingFlexibleWidth, view.autoresizingMask, @"autoresizingMask not propagated to view");
XCTAssertEqual(YES, view.userInteractionEnabled, @"userInteractionEnabled not propagated to view");
}
- (void)testPropertiesSetOffThreadBeforeLoadingExternalLayer
{
CALayer *layer = [[CAShapeLayer alloc] init];
__block ASDisplayNode *node = nil;
[self executeOffThread:^{
node = [[ASDisplayNode alloc] initWithLayerBlock:^{
return layer;
}];
node.backgroundColor = [UIColor blueColor];
node.frame = CGRectMake(10, 20, 30, 40);
}];
[self checkExternalLayerAppliedPropertiesMatch:node];
}
- (void)testPropertiesSetOnThreadAfterLoadingExternalLayer
{
CALayer *layer = [[CAShapeLayer alloc] init];
ASDisplayNode *node = [[ASDisplayNode alloc] initWithLayerBlock:^{
return layer;
}];
// Load the backing layer first
[node layer];
node.backgroundColor = [UIColor blueColor];
node.frame = CGRectMake(10, 20, 30, 40);
[self checkExternalLayerAppliedPropertiesMatch:node];
}
- (void)checkExternalLayerAppliedPropertiesMatch:(ASDisplayNode *)node
{
CALayer *layer = node.layer;
XCTAssertTrue(CGColorEqualToColor([UIColor blueColor].CGColor, layer.backgroundColor), @"backgroundColor not propagated to layer");
XCTAssertTrue(CGRectEqualToRect(CGRectMake(10, 20, 30, 40), layer.frame), @"frame not propagated to layer");
}
// Perform parallel updates of a standard UIView/CALayer and an ASDisplayNode and ensure they are equivalent.
- (void)testDeriveFrameFromBoundsPositionAnchorPoint
{
UIView *plainView = [[UIView alloc] initWithFrame:CGRectZero];
plainView.layer.anchorPoint = CGPointMake(0.25f, 0.75f);
plainView.layer.position = CGPointMake(10, 20);
plainView.layer.bounds = CGRectMake(0, 0, 60, 80);
__block ASDisplayNode *node = nil;
[self executeOffThread:^{
node = [[ASDisplayNode alloc] init];
node.anchorPoint = CGPointMake(0.25f, 0.75f);
node.bounds = CGRectMake(0, 0, 60, 80);
node.position = CGPointMake(10, 20);
}];
XCTAssertTrue(CGRectEqualToRect(plainView.frame, node.frame), @"Node frame should match UIView frame before realization.");
XCTAssertTrue(CGRectEqualToRect(plainView.frame, node.view.frame), @"Realized view frame should match UIView frame.");
}
// Perform parallel updates of a standard UIView/CALayer and an ASDisplayNode and ensure they are equivalent.
- (void)testSetFrameSetsBoundsPosition
{
UIView *plainView = [[UIView alloc] initWithFrame:CGRectZero];
plainView.layer.anchorPoint = CGPointMake(0.25f, 0.75f);
plainView.layer.frame = CGRectMake(10, 20, 60, 80);
__block ASDisplayNode *node = nil;
[self executeOffThread:^{
node = [[ASDisplayNode alloc] init];
node.anchorPoint = CGPointMake(0.25f, 0.75f);
node.frame = CGRectMake(10, 20, 60, 80);
}];
XCTAssertTrue(CGPointEqualToPoint(plainView.layer.position, node.position), @"Node position should match UIView position before realization.");
XCTAssertTrue(CGRectEqualToRect(plainView.layer.bounds, node.bounds), @"Node bounds should match UIView bounds before realization.");
XCTAssertTrue(CGPointEqualToPoint(plainView.layer.position, node.view.layer.position), @"Realized view position should match UIView position before realization.");
XCTAssertTrue(CGRectEqualToRect(plainView.layer.bounds, node.view.layer.bounds), @"Realized view bounds should match UIView bounds before realization.");
}
- (void)testDisplayNodePointConversionWithFrames
{
ASDisplayNode *node = nil;
ASDisplayNode *innerNode = nil;
// Setup
CGPoint originalPoint = CGPointZero, convertedPoint = CGPointZero, correctPoint = CGPointZero;
node = [[ASDisplayNode alloc] init];
innerNode = [[ASDisplayNode alloc] init];
[node addSubnode:innerNode];
// Convert point *FROM* outer node's coordinate space to inner node's coordinate space
node.frame = CGRectMake(100, 100, 100, 100);
innerNode.frame = CGRectMake(10, 10, 20, 20);
originalPoint = CGPointMake(105, 105);
correctPoint = CGPointMake(95, 95);
convertedPoint = [self checkConvertPoint:originalPoint fromNode:node selfNode:innerNode];
XCTAssertTrue(CGPointEqualToPoint(convertedPoint, correctPoint), @"Unexpected point conversion result. Point: %@ Expected conversion: %@ Actual conversion: %@", NSStringFromCGPoint(originalPoint), NSStringFromCGPoint(correctPoint), NSStringFromCGPoint(convertedPoint));
// Setup
node = [[ASDisplayNode alloc] init];
innerNode = [[ASDisplayNode alloc] init];
[node addSubnode:innerNode];
// Convert point *FROM* inner node's coordinate space to outer node's coordinate space
node.frame = CGRectMake(100, 100, 100, 100);
innerNode.frame = CGRectMake(10, 10, 20, 20);
originalPoint = CGPointMake(5, 5);
correctPoint = CGPointMake(15, 15);
convertedPoint = [self checkConvertPoint:originalPoint fromNode:innerNode selfNode:node];
XCTAssertTrue(CGPointEqualToPoint(convertedPoint, correctPoint), @"Unexpected point conversion result. Point: %@ Expected conversion: %@ Actual conversion: %@", NSStringFromCGPoint(originalPoint), NSStringFromCGPoint(correctPoint), NSStringFromCGPoint(convertedPoint));
// Setup
node = [[ASDisplayNode alloc] init];
innerNode = [[ASDisplayNode alloc] init];
[node addSubnode:innerNode];
// Convert point in inner node's coordinate space *TO* outer node's coordinate space
node.frame = CGRectMake(100, 100, 100, 100);
innerNode.frame = CGRectMake(10, 10, 20, 20);
originalPoint = CGPointMake(95, 95);
correctPoint = CGPointMake(105, 105);
convertedPoint = [self checkConvertPoint:originalPoint toNode:node selfNode:innerNode];
XCTAssertTrue(CGPointEqualToPoint(convertedPoint, correctPoint), @"Unexpected point conversion result. Point: %@ Expected conversion: %@ Actual conversion: %@", NSStringFromCGPoint(originalPoint), NSStringFromCGPoint(correctPoint), NSStringFromCGPoint(convertedPoint));
// Setup
node = [[ASDisplayNode alloc] init];
innerNode = [[ASDisplayNode alloc] init];
[node addSubnode:innerNode];
// Convert point in outer node's coordinate space *TO* inner node's coordinate space
node.frame = CGRectMake(0, 0, 100, 100);
innerNode.frame = CGRectMake(10, 10, 20, 20);
originalPoint = CGPointMake(5, 5);
correctPoint = CGPointMake(-5, -5);
convertedPoint = [self checkConvertPoint:originalPoint toNode:innerNode selfNode:node];
XCTAssertTrue(CGPointEqualToPoint(convertedPoint, correctPoint), @"Unexpected point conversion result. Point: %@ Expected conversion: %@ Actual conversion: %@", NSStringFromCGPoint(originalPoint), NSStringFromCGPoint(correctPoint), NSStringFromCGPoint(convertedPoint));
}
// Test conversions when bounds is not null.
// NOTE: Esoteric values were picked to facilitate visual inspection by demonstrating the relevance of certain numbers and lack of relevance of others
- (void)testDisplayNodePointConversionWithNonZeroBounds
{
ASDisplayNode *node = nil;
ASDisplayNode *innerNode = nil;
// Setup
CGPoint originalPoint = CGPointZero, convertedPoint = CGPointZero, correctPoint = CGPointZero;
node = [[ASDisplayNode alloc] init];
innerNode = [[ASDisplayNode alloc] init];
[node addSubnode:innerNode];
// Convert point *FROM* outer node's coordinate space to inner node's coordinate space
node.anchorPoint = CGPointZero;
innerNode.anchorPoint = CGPointZero;
node.bounds = CGRectMake(20, 20, 100, 100);
innerNode.position = CGPointMake(23, 23);
innerNode.bounds = CGRectMake(17, 17, 20, 20);
originalPoint = CGPointMake(42, 42);
correctPoint = CGPointMake(36, 36);
convertedPoint = [self checkConvertPoint:originalPoint fromNode:node selfNode:innerNode];
XCTAssertTrue(CGPointEqualToPoint(convertedPoint, correctPoint), @"Unexpected point conversion result. Point: %@ Expected conversion: %@ Actual conversion: %@", NSStringFromCGPoint(originalPoint), NSStringFromCGPoint(correctPoint), NSStringFromCGPoint(convertedPoint));
// Setup
node = [[ASDisplayNode alloc] init];
innerNode = [[ASDisplayNode alloc] init];
[node addSubnode:innerNode];
// Convert point *FROM* inner node's coordinate space to outer node's coordinate space
node.anchorPoint = CGPointZero;
innerNode.anchorPoint = CGPointZero;
node.bounds = CGRectMake(-1000, -1000, 1337, 1337);
innerNode.position = CGPointMake(23, 23);
innerNode.bounds = CGRectMake(17, 17, 200, 200);
originalPoint = CGPointMake(5, 5);
correctPoint = CGPointMake(11, 11);
convertedPoint = [self checkConvertPoint:originalPoint fromNode:innerNode selfNode:node];
XCTAssertTrue(CGPointEqualToPoint(convertedPoint, correctPoint), @"Unexpected point conversion result. Point: %@ Expected conversion: %@ Actual conversion: %@", NSStringFromCGPoint(originalPoint), NSStringFromCGPoint(correctPoint), NSStringFromCGPoint(convertedPoint));
// Setup
node = [[ASDisplayNode alloc] init];
innerNode = [[ASDisplayNode alloc] init];
[node addSubnode:innerNode];
// Convert point in inner node's coordinate space *TO* outer node's coordinate space
node.anchorPoint = CGPointZero;
innerNode.anchorPoint = CGPointZero;
node.bounds = CGRectMake(20, 20, 100, 100);
innerNode.position = CGPointMake(23, 23);
innerNode.bounds = CGRectMake(17, 17, 20, 20);
originalPoint = CGPointMake(36, 36);
correctPoint = CGPointMake(42, 42);
convertedPoint = [self checkConvertPoint:originalPoint toNode:node selfNode:innerNode];
XCTAssertTrue(CGPointEqualToPoint(convertedPoint, correctPoint), @"Unexpected point conversion result. Point: %@ Expected conversion: %@ Actual conversion: %@", NSStringFromCGPoint(originalPoint), NSStringFromCGPoint(correctPoint), NSStringFromCGPoint(convertedPoint));
// Setup
node = [[ASDisplayNode alloc] init];