Add Test to make sure associated objects live/die with lifetime of UIView.
Summary: Wrote some tests to make sure the associated objects we use for layout live and die with the objects. This was worthwhile because it made me realize UIView+CSSLayout wasn't enabled to ARC. As a result, my tests were failing because they weren't explicitly deallocing nodes. Reviewed By: rnystrom Differential Revision: D4023324 fbshipit-source-id: 5356cf4f0522582d75f83b5eb2193d9bc8d63aee
This commit is contained in:
committed by
Facebook Github Bot
parent
0254e3e97f
commit
eedee80f25
@@ -7,8 +7,11 @@
|
||||
|
||||
include_defs('//CSSLAYOUT_DEFS')
|
||||
|
||||
UIKIT_CSSLAYOUT_COMPILER_FLAGS = ['-fobjc-arc']
|
||||
|
||||
apple_library(
|
||||
name = 'CSSLayout',
|
||||
compiler_flags = UIKIT_CSSLAYOUT_COMPILER_FLAGS,
|
||||
tests = [':CSSLayoutTests'],
|
||||
srcs = glob(['*.m']),
|
||||
exported_headers = glob(['*.h']),
|
||||
@@ -24,6 +27,7 @@ apple_library(
|
||||
|
||||
apple_test(
|
||||
name = 'CSSLayoutTests',
|
||||
compiler_flags = UIKIT_CSSLAYOUT_COMPILER_FLAGS,
|
||||
info_plist = 'Tests/Info.plist',
|
||||
srcs = glob(['Tests/**/*.m']),
|
||||
frameworks = [
|
||||
|
@@ -16,6 +16,36 @@
|
||||
|
||||
@implementation CSSLayoutTests
|
||||
|
||||
- (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());
|
||||
}
|
||||
|
||||
- (void)testHiddenViewsAreNotMeasured
|
||||
{
|
||||
const CGSize firstSize = CGSizeMake(100, 100);
|
||||
|
@@ -30,7 +30,6 @@ static void _updateFrameRecursive(UIView *view);
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[super dealloc];
|
||||
CSSNodeFree(_cnode);
|
||||
}
|
||||
@end
|
||||
|
Reference in New Issue
Block a user