Rename C api
Summary: This renames the core C api to use the new Yoga branding. Differential Revision: D4259190 fbshipit-source-id: 26c8b356ca464d4304f5f9dc4192bff10cea2dc9
This commit is contained in:
committed by
Facebook Github Bot
parent
f7cc614d67
commit
dda24b1e23
@@ -7,73 +7,73 @@
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
#include <CSSLayout/CSSLayout.h>
|
||||
#include <CSSLayout/Yoga.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
static CSSSize _measure(CSSNodeRef node,
|
||||
static YGSize _measure(YGNodeRef node,
|
||||
float width,
|
||||
YGMeasureMode widthMode,
|
||||
float height,
|
||||
YGMeasureMode heightMode) {
|
||||
int *measureCount = (int*) CSSNodeGetContext(node);
|
||||
int *measureCount = (int*) YGNodeGetContext(node);
|
||||
if (measureCount) {
|
||||
(*measureCount)++;
|
||||
}
|
||||
|
||||
return CSSSize {
|
||||
return YGSize {
|
||||
.width = 10,
|
||||
.height = 10,
|
||||
};
|
||||
}
|
||||
|
||||
TEST(CSSLayoutTest, dont_measure_single_grow_shrink_child) {
|
||||
const CSSNodeRef root = CSSNodeNew();
|
||||
CSSNodeStyleSetWidth(root, 100);
|
||||
CSSNodeStyleSetHeight(root, 100);
|
||||
TEST(YogaTest, dont_measure_single_grow_shrink_child) {
|
||||
const YGNodeRef root = YGNodeNew();
|
||||
YGNodeStyleSetWidth(root, 100);
|
||||
YGNodeStyleSetHeight(root, 100);
|
||||
|
||||
int measureCount = 0;
|
||||
|
||||
const CSSNodeRef root_child0 = CSSNodeNew();
|
||||
CSSNodeSetContext(root_child0, &measureCount);
|
||||
CSSNodeSetMeasureFunc(root_child0, _measure);
|
||||
CSSNodeStyleSetFlexGrow(root_child0, 1);
|
||||
CSSNodeStyleSetFlexShrink(root_child0, 1);
|
||||
CSSNodeInsertChild(root, root_child0, 0);
|
||||
const YGNodeRef root_child0 = YGNodeNew();
|
||||
YGNodeSetContext(root_child0, &measureCount);
|
||||
YGNodeSetMeasureFunc(root_child0, _measure);
|
||||
YGNodeStyleSetFlexGrow(root_child0, 1);
|
||||
YGNodeStyleSetFlexShrink(root_child0, 1);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
CSSNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
|
||||
ASSERT_EQ(0, measureCount);
|
||||
|
||||
CSSNodeFreeRecursive(root);
|
||||
YGNodeFreeRecursive(root);
|
||||
}
|
||||
|
||||
#if GTEST_HAS_DEATH_TEST
|
||||
TEST(CSSLayoutTest, cannot_add_child_to_node_with_measure_func) {
|
||||
const CSSNodeRef root = CSSNodeNew();
|
||||
CSSNodeSetMeasureFunc(root, _measure);
|
||||
TEST(YogaTest, cannot_add_child_to_node_with_measure_func) {
|
||||
const YGNodeRef root = YGNodeNew();
|
||||
YGNodeSetMeasureFunc(root, _measure);
|
||||
|
||||
const CSSNodeRef root_child0 = CSSNodeNew();
|
||||
ASSERT_DEATH(CSSNodeInsertChild(root, root_child0, 0), "Cannot add child.*");
|
||||
CSSNodeFree(root_child0);
|
||||
CSSNodeFreeRecursive(root);
|
||||
const YGNodeRef root_child0 = YGNodeNew();
|
||||
ASSERT_DEATH(YGNodeInsertChild(root, root_child0, 0), "Cannot add child.*");
|
||||
YGNodeFree(root_child0);
|
||||
YGNodeFreeRecursive(root);
|
||||
}
|
||||
|
||||
TEST(CSSLayoutTest, cannot_add_nonnull_measure_func_to_non_leaf_node) {
|
||||
const CSSNodeRef root = CSSNodeNew();
|
||||
const CSSNodeRef root_child0 = CSSNodeNew();
|
||||
CSSNodeInsertChild(root, root_child0, 0);
|
||||
TEST(YogaTest, cannot_add_nonnull_measure_func_to_non_leaf_node) {
|
||||
const YGNodeRef root = YGNodeNew();
|
||||
const YGNodeRef root_child0 = YGNodeNew();
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
|
||||
ASSERT_DEATH(CSSNodeSetMeasureFunc(root, _measure), "Cannot set measure function.*");
|
||||
CSSNodeFreeRecursive(root);
|
||||
ASSERT_DEATH(YGNodeSetMeasureFunc(root, _measure), "Cannot set measure function.*");
|
||||
YGNodeFreeRecursive(root);
|
||||
}
|
||||
|
||||
TEST(CSSLayoutTest, can_nullify_measure_func_on_any_node) {
|
||||
const CSSNodeRef root = CSSNodeNew();
|
||||
CSSNodeInsertChild(root, CSSNodeNew(), 0);
|
||||
TEST(YogaTest, can_nullify_measure_func_on_any_node) {
|
||||
const YGNodeRef root = YGNodeNew();
|
||||
YGNodeInsertChild(root, YGNodeNew(), 0);
|
||||
|
||||
CSSNodeSetMeasureFunc(root, NULL);
|
||||
ASSERT_TRUE(CSSNodeGetMeasureFunc(root) == NULL);
|
||||
CSSNodeFreeRecursive(root);
|
||||
YGNodeSetMeasureFunc(root, NULL);
|
||||
ASSERT_TRUE(YGNodeGetMeasureFunc(root) == NULL);
|
||||
YGNodeFreeRecursive(root);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user