forked from PureLayout/PureLayout
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPureLayoutTestBase.m
More file actions
95 lines (83 loc) · 3.29 KB
/
Copy pathPureLayoutTestBase.m
File metadata and controls
95 lines (83 loc) · 3.29 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
//
// PureLayoutTestBase.m
// PureLayout Tests
//
// Copyright (c) 2014 Tyler Fox
// https://github.com/smileyborg/PureLayout
//
#import "PureLayoutTestBase.h"
@implementation PureLayoutTestBase
- (NSArray *)viewArray
{
return @[self.viewA, self.viewB, self.viewC, self.viewD];
}
- (void)setUp
{
[super setUp];
self.containerView = [[ALView alloc] initWithFrame:CGRectMake(0.0, 0.0, kContainerViewWidth, kContainerViewHeight)];
self.viewA = [ALView newAutoLayoutView];
self.viewA_A = [ALView newAutoLayoutView];
self.viewA_A_A = [ALView newAutoLayoutView];
self.viewA_A_B = [ALView newAutoLayoutView];
self.viewA_B = [ALView newAutoLayoutView];
self.viewA_B_A = [ALView newAutoLayoutView];
self.viewB = [ALView newAutoLayoutView];
self.viewB_A = [ALView newAutoLayoutView];
self.viewC = [ALView newAutoLayoutView];
self.viewD = [ALView newAutoLayoutView];
[self.containerView addSubview:self.viewA];
[self.viewA addSubview:self.viewA_A];
[self.viewA_A addSubview:self.viewA_A_A];
[self.viewA_A addSubview:self.viewA_A_B];
[self.viewA addSubview:self.viewA_B];
[self.viewA_B addSubview:self.viewA_B_A];
[self.containerView addSubview:self.viewB];
[self.viewB addSubview:self.viewB_A];
[self.containerView addSubview:self.viewC];
[self.containerView addSubview:self.viewD];
}
- (void)tearDown
{
[super tearDown];
}
/**
Forces the container view to immediately do a layout pass, which will evaluate the constraints and set the frames for the container view and subviews.
*/
- (void)evaluateConstraints
{
[self evaluateConstraintsForView:self.containerView];
}
/**
Recursively forces the given view and its subviews to immediately do a layout pass (evaluate the constraints and update frames).
*/
- (void)evaluateConstraintsForView:(ALView *)view
{
for (ALView *subview in view.subviews) {
[self evaluateConstraintsForView:subview];
}
#if TARGET_OS_IPHONE
[view setNeedsLayout];
[view layoutIfNeeded];
#else
[view setNeedsLayout:YES];
[view layoutSubtreeIfNeeded];
#endif /* TARGET_OS_IPHONE */
}
/**
Test the view hierarchy to make sure it is correctly established.
*/
- (void)testViewHierarchy
{
XCTAssertNotNil(self.containerView, @"View hierarchy is not setup as expected.");
XCTAssert(self.viewA.superview == self.containerView, @"View hierarchy is not setup as expected.");
XCTAssert(self.viewA_A.superview == self.viewA, @"View hierarchy is not setup as expected.");
XCTAssert(self.viewA_A_A.superview == self.viewA_A, @"View hierarchy is not setup as expected.");
XCTAssert(self.viewA_A_B.superview == self.viewA_A, @"View hierarchy is not setup as expected.");
XCTAssert(self.viewA_B.superview == self.viewA, @"View hierarchy is not setup as expected.");
XCTAssert(self.viewA_B_A.superview == self.viewA_B, @"View hierarchy is not setup as expected.");
XCTAssert(self.viewB.superview == self.containerView, @"View hierarchy is not setup as expected.");
XCTAssert(self.viewB_A.superview == self.viewB, @"View hierarchy is not setup as expected.");
XCTAssert(self.viewC.superview == self.containerView, @"View hierarchy is not setup as expected.");
XCTAssert(self.viewD.superview == self.containerView, @"View hierarchy is not setup as expected.");
}
@end