Move YGLogger into YGConfig and associate YGNodeRef with log events
Summary: Moves the `YGLogger` into `YGConfig` and pass the `YGNodeRef` into the logger to be able to associate the log messages and assertions with the specific node. Tackles facebook/yoga#530 and facebook/yoga#446 Closes https://github.com/facebook/yoga/pull/531 Reviewed By: astreet Differential Revision: D4970149 Pulled By: emilsjolander fbshipit-source-id: b7fcdaa273143ea2fa35861620b2e4d79f04f0af
This commit is contained in:
committed by
Facebook Github Bot
parent
40eba60cf5
commit
91230ae177
@@ -92,7 +92,7 @@ TEST(YogaTest, assert_default_values) {
|
||||
}
|
||||
|
||||
TEST(YogaTest, assert_webdefault_values) {
|
||||
YGConfig * config = YGConfigNew();
|
||||
YGConfig *config = YGConfigNew();
|
||||
YGConfigSetUseWebDefaults(config, true);
|
||||
const YGNodeRef root = YGNodeNewWithConfig(config);
|
||||
|
||||
@@ -105,7 +105,7 @@ TEST(YogaTest, assert_webdefault_values) {
|
||||
}
|
||||
|
||||
TEST(YogaTest, assert_webdefault_values_reset) {
|
||||
YGConfig * config = YGConfigNew();
|
||||
YGConfig *config = YGConfigNew();
|
||||
YGConfigSetUseWebDefaults(config, true);
|
||||
const YGNodeRef root = YGNodeNewWithConfig(config);
|
||||
YGNodeReset(root);
|
||||
|
@@ -70,27 +70,27 @@ TEST(YogaTest, dirty_propagation_only_if_prop_changed) {
|
||||
YGNodeFreeRecursive(root);
|
||||
}
|
||||
|
||||
TEST(YogaTest, dirty_mark_all_children_as_dirty_when_display_changes){
|
||||
TEST(YogaTest, dirty_mark_all_children_as_dirty_when_display_changes) {
|
||||
const YGNodeRef root = YGNodeNew();
|
||||
YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
|
||||
YGNodeStyleSetHeight(root, 100);
|
||||
|
||||
|
||||
const YGNodeRef child0 = YGNodeNew();
|
||||
YGNodeStyleSetFlexGrow(child0, 1);
|
||||
const YGNodeRef child1 = YGNodeNew();
|
||||
YGNodeStyleSetFlexGrow(child1, 1);
|
||||
|
||||
|
||||
const YGNodeRef child1_child0 = YGNodeNew();
|
||||
const YGNodeRef child1_child0_child0 = YGNodeNew();
|
||||
YGNodeStyleSetWidth(child1_child0_child0, 8);
|
||||
YGNodeStyleSetHeight(child1_child0_child0, 16);
|
||||
|
||||
|
||||
YGNodeInsertChild(child1_child0, child1_child0_child0, 0);
|
||||
|
||||
|
||||
YGNodeInsertChild(child1, child1_child0, 0);
|
||||
YGNodeInsertChild(root, child0, 0);
|
||||
YGNodeInsertChild(root, child1, 0);
|
||||
|
||||
|
||||
YGNodeStyleSetDisplay(child0, YGDisplayFlex);
|
||||
YGNodeStyleSetDisplay(child1, YGDisplayNone);
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
@@ -114,7 +114,7 @@ TEST(YogaTest, dirty_mark_all_children_as_dirty_when_display_changes){
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
ASSERT_FLOAT_EQ(8, YGNodeLayoutGetWidth(child1_child0_child0));
|
||||
ASSERT_FLOAT_EQ(16, YGNodeLayoutGetHeight(child1_child0_child0));
|
||||
|
||||
|
||||
YGNodeFreeRecursive(root);
|
||||
}
|
||||
|
||||
|
@@ -8,33 +8,44 @@
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <yoga/Yoga.h>
|
||||
#include <stdarg.h>
|
||||
#include <yoga/Yoga.h>
|
||||
|
||||
namespace {
|
||||
char writeBuffer[4096];
|
||||
int _unmanagedLogger(YGLogLevel level, const char *format, va_list args) {
|
||||
return vsnprintf(writeBuffer + strlen(writeBuffer), sizeof(writeBuffer) - strlen(writeBuffer), format, args);
|
||||
}
|
||||
char writeBuffer[4096];
|
||||
int _unmanagedLogger(const YGConfigRef config,
|
||||
const YGNodeRef node,
|
||||
YGLogLevel level,
|
||||
const char *format,
|
||||
va_list args) {
|
||||
return vsnprintf(writeBuffer + strlen(writeBuffer),
|
||||
sizeof(writeBuffer) - strlen(writeBuffer),
|
||||
format,
|
||||
args);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(YogaTest, logger_default_node_should_print_no_style_info) {
|
||||
writeBuffer[0] = '\0';
|
||||
YGSetLogger(_unmanagedLogger);
|
||||
const YGNodeRef root = YGNodeNew();
|
||||
const YGConfigRef config = YGConfigNew();
|
||||
YGConfigSetLogger(config, _unmanagedLogger);
|
||||
const YGNodeRef root = YGNodeNewWithConfig(config);
|
||||
YGNodeCalculateLayout(root, YGUnitUndefined, YGUnitUndefined, YGDirectionLTR);
|
||||
YGNodePrint(root, (YGPrintOptions)(YGPrintOptionsLayout | YGPrintOptionsChildren | YGPrintOptionsStyle));
|
||||
YGSetLogger(NULL);
|
||||
YGNodePrint(root,
|
||||
(YGPrintOptions)(YGPrintOptionsLayout | YGPrintOptionsChildren |
|
||||
YGPrintOptionsStyle));
|
||||
YGConfigSetLogger(config, NULL);
|
||||
YGNodeFree(root);
|
||||
|
||||
const char * expected = "<div layout=\"width: 0; height: 0; top: 0; left: 0;\" style=\"\" ></div>";
|
||||
|
||||
const char *expected = "<div layout=\"width: 0; height: 0; top: 0; left: 0;\" style=\"\" ></div>";
|
||||
ASSERT_STREQ(expected, writeBuffer);
|
||||
}
|
||||
|
||||
TEST(YogaTest, logger_node_with_percentage_absolute_position_and_margin) {
|
||||
writeBuffer[0] = '\0';
|
||||
YGSetLogger(_unmanagedLogger);
|
||||
const YGNodeRef root = YGNodeNew();
|
||||
const YGConfigRef config = YGConfigNew();
|
||||
YGConfigSetLogger(config, _unmanagedLogger);
|
||||
const YGNodeRef root = YGNodeNewWithConfig(config);
|
||||
YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute);
|
||||
YGNodeStyleSetWidthPercent(root, 50);
|
||||
YGNodeStyleSetHeightPercent(root, 75);
|
||||
@@ -42,27 +53,37 @@ TEST(YogaTest, logger_node_with_percentage_absolute_position_and_margin) {
|
||||
YGNodeStyleSetMargin(root, YGEdgeRight, 10);
|
||||
YGNodeStyleSetMarginAuto(root, YGEdgeLeft);
|
||||
YGNodeCalculateLayout(root, YGUnitUndefined, YGUnitUndefined, YGDirectionLTR);
|
||||
YGNodePrint(root, (YGPrintOptions)(YGPrintOptionsLayout | YGPrintOptionsChildren | YGPrintOptionsStyle));
|
||||
YGSetLogger(NULL);
|
||||
YGNodePrint(root,
|
||||
(YGPrintOptions)(YGPrintOptionsLayout | YGPrintOptionsChildren |
|
||||
YGPrintOptionsStyle));
|
||||
YGConfigSetLogger(config, NULL);
|
||||
YGNodeFree(root);
|
||||
|
||||
const char * expected = "<div layout=\"width: 0; height: 0; top: 0; left: 0;\" style=\"flex: 1; margin-left: auto; margin-right: 10px; width: 50%; height: 75%; position: absolute; \" ></div>";
|
||||
|
||||
const char *expected = "<div layout=\"width: 0; height: 0; top: 0; left: 0;\" style=\"flex: 1; "
|
||||
"margin-left: auto; margin-right: 10px; width: 50%; height: 75%; "
|
||||
"position: absolute; \" ></div>";
|
||||
ASSERT_STREQ(expected, writeBuffer);
|
||||
}
|
||||
|
||||
TEST(YogaTest, logger_node_with_children_should_print_indented) {
|
||||
writeBuffer[0] = '\0';
|
||||
YGSetLogger(_unmanagedLogger);
|
||||
const YGNodeRef root = YGNodeNew();
|
||||
const YGNodeRef child0 = YGNodeNew();
|
||||
const YGNodeRef child1 = YGNodeNew();
|
||||
const YGConfigRef config = YGConfigNew();
|
||||
YGConfigSetLogger(config, _unmanagedLogger);
|
||||
const YGNodeRef root = YGNodeNewWithConfig(config);
|
||||
const YGNodeRef child0 = YGNodeNewWithConfig(config);
|
||||
const YGNodeRef child1 = YGNodeNewWithConfig(config);
|
||||
YGNodeInsertChild(root, child0, 0);
|
||||
YGNodeInsertChild(root, child1, 1);
|
||||
YGNodeCalculateLayout(root, YGUnitUndefined, YGUnitUndefined, YGDirectionLTR);
|
||||
YGNodePrint(root, (YGPrintOptions)(YGPrintOptionsLayout | YGPrintOptionsChildren | YGPrintOptionsStyle));
|
||||
YGSetLogger(NULL);
|
||||
YGNodePrint(root,
|
||||
(YGPrintOptions)(YGPrintOptionsLayout | YGPrintOptionsChildren |
|
||||
YGPrintOptionsStyle));
|
||||
YGConfigSetLogger(config, NULL);
|
||||
YGNodeFreeRecursive(root);
|
||||
|
||||
const char * expected = "<div layout=\"width: 0; height: 0; top: 0; left: 0;\" style=\"\" >\n <div layout=\"width: 0; height: 0; top: 0; left: 0;\" style=\"\" ></div>\n <div layout=\"width: 0; height: 0; top: 0; left: 0;\" style=\"\" ></div>\n</div>";
|
||||
|
||||
const char *expected = "<div layout=\"width: 0; height: 0; top: 0; left: 0;\" style=\"\" >\n "
|
||||
"<div layout=\"width: 0; height: 0; top: 0; left: 0;\" style=\"\" "
|
||||
"></div>\n <div layout=\"width: 0; height: 0; top: 0; left: 0;\" "
|
||||
"style=\"\" ></div>\n</div>";
|
||||
ASSERT_STREQ(expected, writeBuffer);
|
||||
}
|
||||
|
@@ -26,15 +26,12 @@ static YGSize _measure(YGNodeRef node,
|
||||
}
|
||||
|
||||
static YGSize _simulate_wrapping_text(YGNodeRef node,
|
||||
float width,
|
||||
YGMeasureMode widthMode,
|
||||
float height,
|
||||
YGMeasureMode heightMode) {
|
||||
if(widthMode == YGMeasureModeUndefined || width >= 68)
|
||||
{
|
||||
return YGSize{
|
||||
.width = 68, .height = 16
|
||||
};
|
||||
float width,
|
||||
YGMeasureMode widthMode,
|
||||
float height,
|
||||
YGMeasureMode heightMode) {
|
||||
if (widthMode == YGMeasureModeUndefined || width >= 68) {
|
||||
return YGSize{.width = 68, .height = 16};
|
||||
}
|
||||
|
||||
return YGSize{
|
||||
@@ -196,8 +193,7 @@ TEST(YogaTest, dont_measure_when_min_equals_max_mixed_height_percent) {
|
||||
YGNodeFreeRecursive(root);
|
||||
}
|
||||
|
||||
TEST(YogaTest, measure_enough_size_should_be_in_single_line)
|
||||
{
|
||||
TEST(YogaTest, measure_enough_size_should_be_in_single_line) {
|
||||
const YGNodeRef root = YGNodeNew();
|
||||
YGNodeStyleSetWidth(root, 100);
|
||||
|
||||
@@ -215,8 +211,7 @@ TEST(YogaTest, measure_enough_size_should_be_in_single_line)
|
||||
YGNodeFreeRecursive(root);
|
||||
}
|
||||
|
||||
TEST(YogaTest, measure_not_enough_size_should_wrap)
|
||||
{
|
||||
TEST(YogaTest, measure_not_enough_size_should_wrap) {
|
||||
const YGNodeRef root = YGNodeNew();
|
||||
YGNodeStyleSetWidth(root, 55);
|
||||
|
||||
@@ -234,8 +229,7 @@ TEST(YogaTest, measure_not_enough_size_should_wrap)
|
||||
YGNodeFreeRecursive(root);
|
||||
}
|
||||
|
||||
TEST(YogaTest, measure_zero_space_should_grow)
|
||||
{
|
||||
TEST(YogaTest, measure_zero_space_should_grow) {
|
||||
const YGNodeRef root = YGNodeNew();
|
||||
YGNodeStyleSetHeight(root, 200);
|
||||
YGNodeStyleSetFlexDirection(root, YGFlexDirectionColumn);
|
||||
@@ -539,7 +533,6 @@ TEST(YogaTest, measure_no_padding) {
|
||||
YGConfigFree(config);
|
||||
}
|
||||
|
||||
|
||||
#if GTEST_HAS_DEATH_TEST
|
||||
TEST(YogaDeathTest, cannot_add_child_to_node_with_measure_func) {
|
||||
const YGNodeRef root = YGNodeNew();
|
||||
@@ -570,4 +563,3 @@ TEST(YogaTest, can_nullify_measure_func_on_any_node) {
|
||||
ASSERT_TRUE(YGNodeGetMeasureFunc(root) == NULL);
|
||||
YGNodeFreeRecursive(root);
|
||||
}
|
||||
|
||||
|
@@ -11,6 +11,7 @@
|
||||
#include <yoga/Yoga.h>
|
||||
|
||||
extern int32_t gNodeInstanceCount;
|
||||
extern int32_t gConfigInstanceCount;
|
||||
|
||||
static int testMallocCount;
|
||||
static int testCallocCount;
|
||||
@@ -38,7 +39,8 @@ static void testFree(void *ptr) {
|
||||
}
|
||||
|
||||
TEST(YogaTest, memory_func_default) {
|
||||
gNodeInstanceCount = 0; // Reset YGNode instance count for memory func test
|
||||
gNodeInstanceCount = 0; // Reset YGNode instance count for memory func test
|
||||
gConfigInstanceCount = 0; // Reset YGConfig instance count for memory func test
|
||||
YGSetMemoryFuncs(NULL, NULL, NULL, NULL);
|
||||
const YGNodeRef root = YGNodeNew();
|
||||
const YGNodeRef root_child0 = YGNodeNew();
|
||||
@@ -47,7 +49,8 @@ TEST(YogaTest, memory_func_default) {
|
||||
}
|
||||
|
||||
TEST(YogaTest, memory_func_test_funcs) {
|
||||
gNodeInstanceCount = 0; // Reset YGNode instance count for memory func test
|
||||
gNodeInstanceCount = 0; // Reset YGNode instance count for memory func test
|
||||
gConfigInstanceCount = 0; // Reset YGConfig instance count for memory func test
|
||||
YGSetMemoryFuncs(&testMalloc, &testCalloc, &testRealloc, &testFree);
|
||||
const YGNodeRef root = YGNodeNew();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
@@ -64,7 +67,8 @@ TEST(YogaTest, memory_func_test_funcs) {
|
||||
|
||||
#if GTEST_HAS_DEATH_TEST
|
||||
TEST(YogaDeathTest, memory_func_assert_zero_nodes) {
|
||||
gNodeInstanceCount = 0; // Reset YGNode instance count for memory func test
|
||||
gNodeInstanceCount = 0; // Reset YGNode instance count for memory func test
|
||||
gConfigInstanceCount = 0; // Reset YGConfig instance count for memory func test
|
||||
const YGNodeRef root = YGNodeNew();
|
||||
ASSERT_DEATH(YGSetMemoryFuncs(&testMalloc, &testCalloc, &testRealloc, &testFree),
|
||||
"Cannot set memory functions: all node must be freed first");
|
||||
@@ -72,7 +76,8 @@ TEST(YogaDeathTest, memory_func_assert_zero_nodes) {
|
||||
}
|
||||
|
||||
TEST(YogaDeathTest, memory_func_assert_all_non_null) {
|
||||
gNodeInstanceCount = 0; // Reset YGNode instance count for memory func test
|
||||
gNodeInstanceCount = 0; // Reset YGNode instance count for memory func test
|
||||
gConfigInstanceCount = 0; // Reset YGConfig instance count for memory func test
|
||||
ASSERT_DEATH(YGSetMemoryFuncs(NULL, &testCalloc, &testRealloc, &testFree),
|
||||
"Cannot set memory functions: functions must be all NULL or Non-NULL");
|
||||
}
|
||||
|
Reference in New Issue
Block a user