Don't assume a node with a measure function is a leaf node
Summary: Don't assume a node with a measure function is a leaf node Reviewed By: gkassabli Differential Revision: D4021096 fbshipit-source-id: 7e039239b1697a0ac42dce9f4b7e252a931bad7e
This commit is contained in:
committed by
Facebook Github Bot
parent
14009ec470
commit
b45a7e3737
44
tests/CSSLayoutMeasureTest.cpp
Normal file
44
tests/CSSLayoutMeasureTest.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <CSSLayout/CSSLayout.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
static CSSSize _measure(void *context,
|
||||
float width,
|
||||
CSSMeasureMode widthMode,
|
||||
float height,
|
||||
CSSMeasureMode heightMode) {
|
||||
int *measureCount = (int *)context;
|
||||
*measureCount = *measureCount + 1;
|
||||
return CSSSize {
|
||||
.width = widthMode == CSSMeasureModeUndefined ? 10 : width,
|
||||
.height = heightMode == CSSMeasureModeUndefined ? 10 : width,
|
||||
};
|
||||
}
|
||||
|
||||
TEST(CSSLayoutTest, ignore_measure_on_non_leaf_node) {
|
||||
const CSSNodeRef root = CSSNodeNew();
|
||||
int measureCount = 0;
|
||||
CSSNodeSetContext(root, &measureCount);
|
||||
CSSNodeSetMeasureFunc(root, _measure);
|
||||
|
||||
const CSSNodeRef root_child0 = CSSNodeNew();
|
||||
int childMeasureCount = 0;
|
||||
CSSNodeSetContext(root_child0, &childMeasureCount);
|
||||
CSSNodeSetMeasureFunc(root_child0, _measure);
|
||||
CSSNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR);
|
||||
|
||||
ASSERT_EQ(0, measureCount);
|
||||
ASSERT_EQ(1, childMeasureCount);
|
||||
|
||||
CSSNodeFreeRecursive(root);
|
||||
}
|
Reference in New Issue
Block a user