2016-10-14 13:25:24 -07:00
|
|
|
/**
|
|
|
|
* 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 "UIView+CSSLayout.h"
|
|
|
|
|
|
|
|
@interface CSSLayoutTests : XCTestCase
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation CSSLayoutTests
|
|
|
|
|
2016-10-14 14:52:22 -07:00
|
|
|
- (void)testNodesAreDeallocedWithSingleView
|
|
|
|
{
|
|
|
|
XCTAssertEqual(0, CSSNodeGetInstanceCount());
|
|
|
|
|
|
|
|
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
|
|
|
|
[view css_setFlex:1];
|
|
|
|
XCTAssertEqual(1, CSSNodeGetInstanceCount());
|
|
|
|
view = nil;
|
|
|
|
|
|
|
|
XCTAssertEqual(0, CSSNodeGetInstanceCount());
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)testNodesAreDeallocedCascade
|
|
|
|
{
|
|
|
|
XCTAssertEqual(0, CSSNodeGetInstanceCount());
|
|
|
|
|
|
|
|
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
|
|
|
|
[view css_setFlex:1];
|
|
|
|
|
|
|
|
for (int i=0; i<10; i++) {
|
|
|
|
UIView *subview = [[UIView alloc] initWithFrame:CGRectZero];
|
|
|
|
[subview css_setFlex:1];
|
|
|
|
[view addSubview:subview];
|
|
|
|
}
|
|
|
|
XCTAssertEqual(11, CSSNodeGetInstanceCount());
|
|
|
|
view = nil;
|
|
|
|
|
|
|
|
XCTAssertEqual(0, CSSNodeGetInstanceCount());
|
|
|
|
}
|
|
|
|
|
2016-10-14 14:22:49 -07:00
|
|
|
- (void)testHiddenViewsAreNotMeasured
|
2016-10-14 13:25:24 -07:00
|
|
|
{
|
2016-10-14 14:22:49 -07:00
|
|
|
const CGSize firstSize = CGSizeMake(100, 100);
|
2016-10-14 13:25:24 -07:00
|
|
|
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
|
|
|
|
[view css_setUsesFlexbox:YES];
|
2016-10-14 14:22:49 -07:00
|
|
|
[view css_setWidth:firstSize.width];
|
|
|
|
[view css_setHeight:firstSize.height];
|
|
|
|
|
|
|
|
[view css_applyLayout];
|
|
|
|
XCTAssertTrue(CGSizeEqualToSize(firstSize, view.frame.size));
|
|
|
|
|
|
|
|
const CGSize newSize = CGSizeMake(200, 200);
|
|
|
|
[view css_setWidth:newSize.width];
|
|
|
|
[view css_setHeight:newSize.height];
|
|
|
|
view.hidden = YES;
|
|
|
|
|
|
|
|
[view css_applyLayout];
|
|
|
|
XCTAssertFalse(CGSizeEqualToSize(newSize, view.frame.size));
|
2016-10-14 13:25:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|