2 * Copyright (c) 2014-present, Facebook, Inc.
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
8 #include <gtest/gtest.h>
10 #include <yoga/Yoga.h>
13 char writeBuffer[4096];
14 int _unmanagedLogger(const YGConfigRef config,
19 return vsnprintf(writeBuffer + strlen(writeBuffer),
20 sizeof(writeBuffer) - strlen(writeBuffer),
26 TEST(YogaTest, logger_default_node_should_print_no_style_info) {
27 writeBuffer[0] = '\0';
28 const YGConfigRef config = YGConfigNew();
29 YGConfigSetLogger(config, _unmanagedLogger);
30 const YGNodeRef root = YGNodeNewWithConfig(config);
31 YGNodeCalculateLayout(root, YGUnitUndefined, YGUnitUndefined, YGDirectionLTR);
33 (YGPrintOptions)(YGPrintOptionsLayout | YGPrintOptionsChildren |
34 YGPrintOptionsStyle));
35 YGConfigSetLogger(config, NULL);
38 const char *expected = "<div layout=\"width: 0; height: 0; top: 0; left: 0;\" style=\"\" ></div>";
39 ASSERT_STREQ(expected, writeBuffer);
42 TEST(YogaTest, logger_node_with_percentage_absolute_position_and_margin) {
43 writeBuffer[0] = '\0';
44 const YGConfigRef config = YGConfigNew();
45 YGConfigSetLogger(config, _unmanagedLogger);
46 const YGNodeRef root = YGNodeNewWithConfig(config);
47 YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute);
48 YGNodeStyleSetWidthPercent(root, 50);
49 YGNodeStyleSetHeightPercent(root, 75);
50 YGNodeStyleSetFlex(root, 1);
51 YGNodeStyleSetMargin(root, YGEdgeRight, 10);
52 YGNodeStyleSetMarginAuto(root, YGEdgeLeft);
53 YGNodeCalculateLayout(root, YGUnitUndefined, YGUnitUndefined, YGDirectionLTR);
55 (YGPrintOptions)(YGPrintOptionsLayout | YGPrintOptionsChildren |
56 YGPrintOptionsStyle));
57 YGConfigSetLogger(config, NULL);
60 const char *expected = "<div layout=\"width: 0; height: 0; top: 0; left: 0;\" style=\"flex: 1; "
61 "margin-left: auto; margin-right: 10px; width: 50%; height: 75%; "
62 "position: absolute; \" ></div>";
63 ASSERT_STREQ(expected, writeBuffer);
66 TEST(YogaTest, logger_node_with_children_should_print_indented) {
67 writeBuffer[0] = '\0';
68 const YGConfigRef config = YGConfigNew();
69 YGConfigSetLogger(config, _unmanagedLogger);
70 const YGNodeRef root = YGNodeNewWithConfig(config);
71 const YGNodeRef child0 = YGNodeNewWithConfig(config);
72 const YGNodeRef child1 = YGNodeNewWithConfig(config);
73 YGNodeInsertChild(root, child0, 0);
74 YGNodeInsertChild(root, child1, 1);
75 YGNodeCalculateLayout(root, YGUnitUndefined, YGUnitUndefined, YGDirectionLTR);
77 (YGPrintOptions)(YGPrintOptionsLayout | YGPrintOptionsChildren |
78 YGPrintOptionsStyle));
79 YGConfigSetLogger(config, NULL);
80 YGNodeFreeRecursive(root);
82 const char *expected = "<div layout=\"width: 0; height: 0; top: 0; left: 0;\" style=\"\" >\n "
83 "<div layout=\"width: 0; height: 0; top: 0; left: 0;\" style=\"\" "
84 "></div>\n <div layout=\"width: 0; height: 0; top: 0; left: 0;\" "
85 "style=\"\" ></div>\n</div>";
86 ASSERT_STREQ(expected, writeBuffer);