2016-08-31 08:02:40 -07:00
|
|
|
/**
|
|
|
|
* 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, start_overrides) {
|
|
|
|
const CSSNodeRef root = CSSNodeNew();
|
2016-12-02 05:47:43 -08:00
|
|
|
CSSNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
|
2016-08-31 08:02:40 -07:00
|
|
|
CSSNodeStyleSetWidth(root, 100);
|
|
|
|
CSSNodeStyleSetHeight(root, 100);
|
|
|
|
|
|
|
|
const CSSNodeRef root_child0 = CSSNodeNew();
|
|
|
|
CSSNodeStyleSetFlexGrow(root_child0, 1);
|
2016-12-02 05:47:43 -08:00
|
|
|
CSSNodeStyleSetMargin(root_child0, YGEdgeStart, 10);
|
|
|
|
CSSNodeStyleSetMargin(root_child0, YGEdgeLeft, 20);
|
|
|
|
CSSNodeStyleSetMargin(root_child0, YGEdgeRight, 20);
|
2016-08-31 08:02:40 -07:00
|
|
|
CSSNodeInsertChild(root, root_child0, 0);
|
|
|
|
|
2016-12-02 05:47:43 -08:00
|
|
|
CSSNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
2016-11-22 02:46:00 -08:00
|
|
|
ASSERT_FLOAT_EQ(10, CSSNodeLayoutGetLeft(root_child0));
|
|
|
|
ASSERT_FLOAT_EQ(20, CSSNodeLayoutGetRight(root_child0));
|
2016-08-31 08:02:40 -07:00
|
|
|
|
2016-12-02 05:47:43 -08:00
|
|
|
CSSNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
|
2016-11-22 02:46:00 -08:00
|
|
|
ASSERT_FLOAT_EQ(20, CSSNodeLayoutGetLeft(root_child0));
|
|
|
|
ASSERT_FLOAT_EQ(10, CSSNodeLayoutGetRight(root_child0));
|
2016-09-29 04:09:56 -07:00
|
|
|
|
|
|
|
CSSNodeFreeRecursive(root);
|
2016-08-31 08:02:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(CSSLayoutTest, end_overrides) {
|
|
|
|
const CSSNodeRef root = CSSNodeNew();
|
2016-12-02 05:47:43 -08:00
|
|
|
CSSNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
|
2016-08-31 08:02:40 -07:00
|
|
|
CSSNodeStyleSetWidth(root, 100);
|
|
|
|
CSSNodeStyleSetHeight(root, 100);
|
|
|
|
|
|
|
|
const CSSNodeRef root_child0 = CSSNodeNew();
|
|
|
|
CSSNodeStyleSetFlexGrow(root_child0, 1);
|
2016-12-02 05:47:43 -08:00
|
|
|
CSSNodeStyleSetMargin(root_child0, YGEdgeEnd, 10);
|
|
|
|
CSSNodeStyleSetMargin(root_child0, YGEdgeLeft, 20);
|
|
|
|
CSSNodeStyleSetMargin(root_child0, YGEdgeRight, 20);
|
2016-08-31 08:02:40 -07:00
|
|
|
CSSNodeInsertChild(root, root_child0, 0);
|
|
|
|
|
2016-12-02 05:47:43 -08:00
|
|
|
CSSNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
2016-11-22 02:46:00 -08:00
|
|
|
ASSERT_FLOAT_EQ(20, CSSNodeLayoutGetLeft(root_child0));
|
|
|
|
ASSERT_FLOAT_EQ(10, CSSNodeLayoutGetRight(root_child0));
|
2016-08-31 08:02:40 -07:00
|
|
|
|
2016-12-02 05:47:43 -08:00
|
|
|
CSSNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
|
2016-11-22 02:46:00 -08:00
|
|
|
ASSERT_FLOAT_EQ(10, CSSNodeLayoutGetLeft(root_child0));
|
|
|
|
ASSERT_FLOAT_EQ(20, CSSNodeLayoutGetRight(root_child0));
|
2016-09-29 04:09:56 -07:00
|
|
|
|
|
|
|
CSSNodeFreeRecursive(root);
|
2016-08-31 08:02:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(CSSLayoutTest, horizontal_overridden) {
|
|
|
|
const CSSNodeRef root = CSSNodeNew();
|
2016-12-02 05:47:43 -08:00
|
|
|
CSSNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
|
2016-08-31 08:02:40 -07:00
|
|
|
CSSNodeStyleSetWidth(root, 100);
|
|
|
|
CSSNodeStyleSetHeight(root, 100);
|
|
|
|
|
|
|
|
const CSSNodeRef root_child0 = CSSNodeNew();
|
|
|
|
CSSNodeStyleSetFlexGrow(root_child0, 1);
|
2016-12-02 05:47:43 -08:00
|
|
|
CSSNodeStyleSetMargin(root_child0, YGEdgeHorizontal, 10);
|
|
|
|
CSSNodeStyleSetMargin(root_child0, YGEdgeLeft, 20);
|
2016-08-31 08:02:40 -07:00
|
|
|
CSSNodeInsertChild(root, root_child0, 0);
|
|
|
|
|
2016-12-02 05:47:43 -08:00
|
|
|
CSSNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
2016-11-22 02:46:00 -08:00
|
|
|
ASSERT_FLOAT_EQ(20, CSSNodeLayoutGetLeft(root_child0));
|
|
|
|
ASSERT_FLOAT_EQ(10, CSSNodeLayoutGetRight(root_child0));
|
2016-09-29 04:09:56 -07:00
|
|
|
|
|
|
|
CSSNodeFreeRecursive(root);
|
2016-08-31 08:02:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(CSSLayoutTest, vertical_overridden) {
|
|
|
|
const CSSNodeRef root = CSSNodeNew();
|
2016-12-02 05:47:43 -08:00
|
|
|
CSSNodeStyleSetFlexDirection(root, YGFlexDirectionColumn);
|
2016-08-31 08:02:40 -07:00
|
|
|
CSSNodeStyleSetWidth(root, 100);
|
|
|
|
CSSNodeStyleSetHeight(root, 100);
|
|
|
|
|
|
|
|
const CSSNodeRef root_child0 = CSSNodeNew();
|
|
|
|
CSSNodeStyleSetFlexGrow(root_child0, 1);
|
2016-12-02 05:47:43 -08:00
|
|
|
CSSNodeStyleSetMargin(root_child0, YGEdgeVertical, 10);
|
|
|
|
CSSNodeStyleSetMargin(root_child0, YGEdgeTop, 20);
|
2016-08-31 08:02:40 -07:00
|
|
|
CSSNodeInsertChild(root, root_child0, 0);
|
|
|
|
|
2016-12-02 05:47:43 -08:00
|
|
|
CSSNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
2016-11-22 02:46:00 -08:00
|
|
|
ASSERT_FLOAT_EQ(20, CSSNodeLayoutGetTop(root_child0));
|
|
|
|
ASSERT_FLOAT_EQ(10, CSSNodeLayoutGetBottom(root_child0));
|
2016-09-29 04:09:56 -07:00
|
|
|
|
|
|
|
CSSNodeFreeRecursive(root);
|
2016-08-31 08:02:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(CSSLayoutTest, horizontal_overrides_all) {
|
|
|
|
const CSSNodeRef root = CSSNodeNew();
|
2016-12-02 05:47:43 -08:00
|
|
|
CSSNodeStyleSetFlexDirection(root, YGFlexDirectionColumn);
|
2016-08-31 08:02:40 -07:00
|
|
|
CSSNodeStyleSetWidth(root, 100);
|
|
|
|
CSSNodeStyleSetHeight(root, 100);
|
|
|
|
|
|
|
|
const CSSNodeRef root_child0 = CSSNodeNew();
|
|
|
|
CSSNodeStyleSetFlexGrow(root_child0, 1);
|
2016-12-02 05:47:43 -08:00
|
|
|
CSSNodeStyleSetMargin(root_child0, YGEdgeHorizontal, 10);
|
|
|
|
CSSNodeStyleSetMargin(root_child0, YGEdgeAll, 20);
|
2016-08-31 08:02:40 -07:00
|
|
|
CSSNodeInsertChild(root, root_child0, 0);
|
|
|
|
|
2016-12-02 05:47:43 -08:00
|
|
|
CSSNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
2016-11-22 02:46:00 -08:00
|
|
|
ASSERT_FLOAT_EQ(10, CSSNodeLayoutGetLeft(root_child0));
|
|
|
|
ASSERT_FLOAT_EQ(20, CSSNodeLayoutGetTop(root_child0));
|
|
|
|
ASSERT_FLOAT_EQ(10, CSSNodeLayoutGetRight(root_child0));
|
|
|
|
ASSERT_FLOAT_EQ(20, CSSNodeLayoutGetBottom(root_child0));
|
2016-09-29 04:09:56 -07:00
|
|
|
|
|
|
|
CSSNodeFreeRecursive(root);
|
2016-08-31 08:02:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(CSSLayoutTest, vertical_overrides_all) {
|
|
|
|
const CSSNodeRef root = CSSNodeNew();
|
2016-12-02 05:47:43 -08:00
|
|
|
CSSNodeStyleSetFlexDirection(root, YGFlexDirectionColumn);
|
2016-08-31 08:02:40 -07:00
|
|
|
CSSNodeStyleSetWidth(root, 100);
|
|
|
|
CSSNodeStyleSetHeight(root, 100);
|
|
|
|
|
|
|
|
const CSSNodeRef root_child0 = CSSNodeNew();
|
|
|
|
CSSNodeStyleSetFlexGrow(root_child0, 1);
|
2016-12-02 05:47:43 -08:00
|
|
|
CSSNodeStyleSetMargin(root_child0, YGEdgeVertical, 10);
|
|
|
|
CSSNodeStyleSetMargin(root_child0, YGEdgeAll, 20);
|
2016-08-31 08:02:40 -07:00
|
|
|
CSSNodeInsertChild(root, root_child0, 0);
|
|
|
|
|
2016-12-02 05:47:43 -08:00
|
|
|
CSSNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
2016-11-22 02:46:00 -08:00
|
|
|
ASSERT_FLOAT_EQ(20, CSSNodeLayoutGetLeft(root_child0));
|
|
|
|
ASSERT_FLOAT_EQ(10, CSSNodeLayoutGetTop(root_child0));
|
|
|
|
ASSERT_FLOAT_EQ(20, CSSNodeLayoutGetRight(root_child0));
|
|
|
|
ASSERT_FLOAT_EQ(10, CSSNodeLayoutGetBottom(root_child0));
|
2016-09-29 04:09:56 -07:00
|
|
|
|
|
|
|
CSSNodeFreeRecursive(root);
|
2016-08-31 08:02:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(CSSLayoutTest, all_overridden) {
|
|
|
|
const CSSNodeRef root = CSSNodeNew();
|
2016-12-02 05:47:43 -08:00
|
|
|
CSSNodeStyleSetFlexDirection(root, YGFlexDirectionColumn);
|
2016-08-31 08:02:40 -07:00
|
|
|
CSSNodeStyleSetWidth(root, 100);
|
|
|
|
CSSNodeStyleSetHeight(root, 100);
|
|
|
|
|
|
|
|
const CSSNodeRef root_child0 = CSSNodeNew();
|
|
|
|
CSSNodeStyleSetFlexGrow(root_child0, 1);
|
2016-12-02 05:47:43 -08:00
|
|
|
CSSNodeStyleSetMargin(root_child0, YGEdgeLeft, 10);
|
|
|
|
CSSNodeStyleSetMargin(root_child0, YGEdgeTop, 10);
|
|
|
|
CSSNodeStyleSetMargin(root_child0, YGEdgeRight, 10);
|
|
|
|
CSSNodeStyleSetMargin(root_child0, YGEdgeBottom, 10);
|
|
|
|
CSSNodeStyleSetMargin(root_child0, YGEdgeAll, 20);
|
2016-08-31 08:02:40 -07:00
|
|
|
CSSNodeInsertChild(root, root_child0, 0);
|
|
|
|
|
2016-12-02 05:47:43 -08:00
|
|
|
CSSNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
2016-11-22 02:46:00 -08:00
|
|
|
ASSERT_FLOAT_EQ(10, CSSNodeLayoutGetLeft(root_child0));
|
|
|
|
ASSERT_FLOAT_EQ(10, CSSNodeLayoutGetTop(root_child0));
|
|
|
|
ASSERT_FLOAT_EQ(10, CSSNodeLayoutGetRight(root_child0));
|
|
|
|
ASSERT_FLOAT_EQ(10, CSSNodeLayoutGetBottom(root_child0));
|
2016-09-29 04:09:56 -07:00
|
|
|
|
|
|
|
CSSNodeFreeRecursive(root);
|
2016-08-31 08:02:40 -07:00
|
|
|
}
|