Files
yoga/tests/YGDirtyMarkingTest.cpp

97 lines
2.9 KiB
C++
Raw Normal View History

/**
* 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 <yoga/Yoga.h>
#include <gtest/gtest.h>
TEST(YogaTest, dirty_propagation) {
const YGNodeRef root = YGNodeNew();
YGNodeStyleSetAlignItems(root, YGAlignFlexStart);
2016-12-19 19:15:48 +01:00
YGNodeStyleSetWidth(root, YGPx(100));
YGNodeStyleSetHeight(root, YGPx(100));
const YGNodeRef root_child0 = YGNodeNew();
2016-12-19 19:15:48 +01:00
YGNodeStyleSetWidth(root_child0, YGPx(50));
YGNodeStyleSetHeight(root_child0, YGPx(20));
YGNodeInsertChild(root, root_child0, 0);
const YGNodeRef root_child1 = YGNodeNew();
2016-12-19 19:15:48 +01:00
YGNodeStyleSetWidth(root_child1, YGPx(50));
YGNodeStyleSetHeight(root_child1, YGPx(20));
YGNodeInsertChild(root, root_child1, 1);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
2016-12-19 19:15:48 +01:00
YGNodeStyleSetWidth(root_child0, YGPx(20));
EXPECT_TRUE(YGNodeIsDirty(root_child0));
EXPECT_FALSE(YGNodeIsDirty(root_child1));
EXPECT_TRUE(YGNodeIsDirty(root));
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
EXPECT_FALSE(YGNodeIsDirty(root_child0));
EXPECT_FALSE(YGNodeIsDirty(root_child1));
EXPECT_FALSE(YGNodeIsDirty(root));
YGNodeFreeRecursive(root);
}
TEST(YogaTest, dirty_propagation_only_if_prop_changed) {
const YGNodeRef root = YGNodeNew();
YGNodeStyleSetAlignItems(root, YGAlignFlexStart);
2016-12-19 19:15:48 +01:00
YGNodeStyleSetWidth(root, YGPx(100));
YGNodeStyleSetHeight(root, YGPx(100));
const YGNodeRef root_child0 = YGNodeNew();
2016-12-19 19:15:48 +01:00
YGNodeStyleSetWidth(root_child0, YGPx(50));
YGNodeStyleSetHeight(root_child0, YGPx(20));
YGNodeInsertChild(root, root_child0, 0);
const YGNodeRef root_child1 = YGNodeNew();
2016-12-19 19:15:48 +01:00
YGNodeStyleSetWidth(root_child1, YGPx(50));
YGNodeStyleSetHeight(root_child1, YGPx(20));
YGNodeInsertChild(root, root_child1, 1);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
2016-12-19 19:15:48 +01:00
YGNodeStyleSetWidth(root_child0, YGPx(50));
EXPECT_FALSE(YGNodeIsDirty(root_child0));
EXPECT_FALSE(YGNodeIsDirty(root_child1));
EXPECT_FALSE(YGNodeIsDirty(root));
YGNodeFreeRecursive(root);
}
TEST(YogaTest, dirty_node_only_if_children_are_actually_removed) {
const YGNodeRef root = YGNodeNew();
YGNodeStyleSetAlignItems(root, YGAlignFlexStart);
2016-12-19 19:15:48 +01:00
YGNodeStyleSetWidth(root, YGPx(50));
YGNodeStyleSetHeight(root, YGPx(50));
const YGNodeRef child0 = YGNodeNew();
2016-12-19 19:15:48 +01:00
YGNodeStyleSetWidth(child0, YGPx(50));
YGNodeStyleSetHeight(child0, YGPx(25));
YGNodeInsertChild(root, child0, 0);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
const YGNodeRef child1 = YGNodeNew();
YGNodeRemoveChild(root, child1);
EXPECT_FALSE(YGNodeIsDirty(root));
YGNodeFree(child1);
YGNodeRemoveChild(root, child0);
EXPECT_TRUE(YGNodeIsDirty(root));
YGNodeFree(child0);
YGNodeFreeRecursive(root);
}