Merge "Add new layouting support for TextLabel and ImageView." into devel/master
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit-third-party / yoga / YGLoggerTest.cpp
1 /**
2  * Copyright (c) 2014-present, Facebook, Inc.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7
8 #include <gtest/gtest.h>
9 #include <stdarg.h>
10 #include <yoga/Yoga.h>
11
12 namespace {
13 char writeBuffer[4096];
14 int _unmanagedLogger(const YGConfigRef config,
15                      const YGNodeRef node,
16                      YGLogLevel level,
17                      const char *format,
18                      va_list args) {
19   return vsnprintf(writeBuffer + strlen(writeBuffer),
20                    sizeof(writeBuffer) - strlen(writeBuffer),
21                    format,
22                    args);
23 }
24 }
25
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);
32   YGNodePrint(root,
33               (YGPrintOptions)(YGPrintOptionsLayout | YGPrintOptionsChildren |
34                                YGPrintOptionsStyle));
35   YGConfigSetLogger(config, NULL);
36   YGNodeFree(root);
37
38   const char *expected = "<div layout=\"width: 0; height: 0; top: 0; left: 0;\" style=\"\" ></div>";
39   ASSERT_STREQ(expected, writeBuffer);
40 }
41
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);
54   YGNodePrint(root,
55               (YGPrintOptions)(YGPrintOptionsLayout | YGPrintOptionsChildren |
56                                YGPrintOptionsStyle));
57   YGConfigSetLogger(config, NULL);
58   YGNodeFree(root);
59
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);
64 }
65
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);
76   YGNodePrint(root,
77               (YGPrintOptions)(YGPrintOptionsLayout | YGPrintOptionsChildren |
78                                YGPrintOptionsStyle));
79   YGConfigSetLogger(config, NULL);
80   YGNodeFreeRecursive(root);
81
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);
87 }