Files
yoga/tests/CSSLayoutMeasureTest.cpp
Emil Sjolander 46823878a5 BREAKING - Make first parameter of measure and print functions CSSNodeRef instead of just context
Summary: To perform some JNI optimizations for java we need a reference to the node in the measure function. This updates the API to provide the whole node as input instead of just the context.

Reviewed By: javache

Differential Revision: D4081544

fbshipit-source-id: d49679025cea027cf7b8482898de0a01fe0f9d40
2016-10-27 10:52:57 -07:00

45 lines
1.4 KiB
C++

/**
* 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(CSSNodeRef node,
float width,
CSSMeasureMode widthMode,
float height,
CSSMeasureMode heightMode) {
int *measureCount = (int *)CSSNodeGetContext(node);
*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);
}