Introduce CSSNodeCopyStyle
Summary: - Add a convenience function to copy all style from one node to another. - CSSNodeIsDirty will return true after this function if any style was changed in the destination node. Reviewed By: emilsjolander Differential Revision: D4188514 fbshipit-source-id: af8d7fb5e8688c64aea05ce7ad23fff9233fb441
This commit is contained in:
committed by
Facebook Github Bot
parent
32c175ac55
commit
191ac98b89
60
tests/CSSLayoutStyleTest.cpp
Normal file
60
tests/CSSLayoutStyleTest.cpp
Normal file
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* 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>
|
||||
|
||||
TEST(CSSLayoutTest, copy_style_same) {
|
||||
const CSSNodeRef node0 = CSSNodeNew();
|
||||
const CSSNodeRef node1 = CSSNodeNew();
|
||||
ASSERT_FALSE(CSSNodeIsDirty(node0));
|
||||
|
||||
CSSNodeCopyStyle(node0, node1);
|
||||
ASSERT_FALSE(CSSNodeIsDirty(node0));
|
||||
|
||||
CSSNodeFree(node0);
|
||||
CSSNodeFree(node1);
|
||||
}
|
||||
|
||||
TEST(CSSLayoutTest, copy_style_modified) {
|
||||
const CSSNodeRef node0 = CSSNodeNew();
|
||||
ASSERT_FALSE(CSSNodeIsDirty(node0));
|
||||
ASSERT_EQ(CSSFlexDirectionColumn, CSSNodeStyleGetFlexDirection(node0));
|
||||
ASSERT_TRUE(CSSValueIsUndefined(CSSNodeStyleGetMaxHeight(node0)));
|
||||
|
||||
const CSSNodeRef node1 = CSSNodeNew();
|
||||
CSSNodeStyleSetFlexDirection(node1, CSSFlexDirectionRow);
|
||||
CSSNodeStyleSetMaxHeight(node1, 10);
|
||||
|
||||
CSSNodeCopyStyle(node0, node1);
|
||||
ASSERT_TRUE(CSSNodeIsDirty(node0));
|
||||
ASSERT_EQ(CSSFlexDirectionRow, CSSNodeStyleGetFlexDirection(node0));
|
||||
ASSERT_EQ(10, CSSNodeStyleGetMaxHeight(node0));
|
||||
|
||||
CSSNodeFree(node0);
|
||||
CSSNodeFree(node1);
|
||||
}
|
||||
|
||||
TEST(CSSLayoutTest, copy_style_modified_same) {
|
||||
const CSSNodeRef node0 = CSSNodeNew();
|
||||
CSSNodeStyleSetFlexDirection(node0, CSSFlexDirectionRow);
|
||||
CSSNodeStyleSetMaxHeight(node0, 10);
|
||||
CSSNodeCalculateLayout(node0, CSSUndefined, CSSUndefined, CSSDirectionLTR);
|
||||
ASSERT_FALSE(CSSNodeIsDirty(node0));
|
||||
|
||||
const CSSNodeRef node1 = CSSNodeNew();
|
||||
CSSNodeStyleSetFlexDirection(node1, CSSFlexDirectionRow);
|
||||
CSSNodeStyleSetMaxHeight(node1, 10);
|
||||
|
||||
CSSNodeCopyStyle(node0, node1);
|
||||
ASSERT_FALSE(CSSNodeIsDirty(node0));
|
||||
|
||||
CSSNodeFree(node0);
|
||||
CSSNodeFree(node1);
|
||||
}
|
Reference in New Issue
Block a user