Compare commits
60 Commits
1.14.0
...
carlhuting
Author | SHA1 | Date | |
---|---|---|---|
|
19035c90e9 | ||
|
19fd066507 | ||
|
204e849218 | ||
|
8ff13c922a | ||
|
af219f8836 | ||
|
e33123f955 | ||
|
755fa07b39 | ||
|
2701d80078 | ||
|
c393ed1381 | ||
|
a4bdd9cd9b | ||
|
4a4325afb6 | ||
|
586eb6102a | ||
|
b1e6793460 | ||
|
8b17459254 | ||
|
195c166efe | ||
|
0908d3a173 | ||
|
f304990656 | ||
|
cea3865c74 | ||
|
b74c0d4766 | ||
|
54e863cef2 | ||
|
1938792517 | ||
|
aa71dbb5bd | ||
|
8dc46c0a87 | ||
|
1180afed9c | ||
|
1562bce9b4 | ||
|
a9514513a7 | ||
|
cf809b8e8b | ||
|
d7ff5c0689 | ||
|
e3156279fc | ||
|
0ce42d83e0 | ||
|
afc1108659 | ||
|
a15bf6e701 | ||
|
74fc37efc8 | ||
|
5824dbda66 | ||
|
e96a09e5ff | ||
|
9e20dfeea1 | ||
|
6e04631862 | ||
|
88b23ebb3d | ||
|
018916403e | ||
|
af38fd31f8 | ||
|
1e0ebdae2f | ||
|
1adbafe950 | ||
|
e51ca95713 | ||
|
a803421739 | ||
|
011c1964a0 | ||
|
05d205cf89 | ||
|
0a4f7bd558 | ||
|
cea862a6bf | ||
|
cc02a20c9e | ||
|
98fda9c587 | ||
|
2eed95f3e4 | ||
|
e5d3baca81 | ||
|
dee93017f7 | ||
|
e167642672 | ||
|
e9bb1efb03 | ||
|
3f7d03b443 | ||
|
ffce716557 | ||
|
fcfb19e9cf | ||
|
c5f105a7b6 | ||
|
b062d23947 |
@@ -9,7 +9,7 @@ AlignTrailingComments: false
|
|||||||
AllowAllParametersOfDeclarationOnNextLine: false
|
AllowAllParametersOfDeclarationOnNextLine: false
|
||||||
AllowShortBlocksOnASingleLine: false
|
AllowShortBlocksOnASingleLine: false
|
||||||
AllowShortCaseLabelsOnASingleLine: false
|
AllowShortCaseLabelsOnASingleLine: false
|
||||||
AllowShortFunctionsOnASingleLine: Empty
|
AllowShortFunctionsOnASingleLine: Inline
|
||||||
AllowShortIfStatementsOnASingleLine: false
|
AllowShortIfStatementsOnASingleLine: false
|
||||||
AllowShortLoopsOnASingleLine: true
|
AllowShortLoopsOnASingleLine: true
|
||||||
AlwaysBreakAfterReturnType: None
|
AlwaysBreakAfterReturnType: None
|
||||||
|
17
BUCK
17
BUCK
@@ -9,21 +9,17 @@ GMOCK_OVERRIDE_FLAGS = [
|
|||||||
"-Wno-inconsistent-missing-override",
|
"-Wno-inconsistent-missing-override",
|
||||||
]
|
]
|
||||||
|
|
||||||
COMPILER_FLAGS = LIBRARY_COMPILER_FLAGS + [
|
|
||||||
"-std=c++1y",
|
|
||||||
]
|
|
||||||
|
|
||||||
TEST_COMPILER_FLAGS = BASE_COMPILER_FLAGS + GMOCK_OVERRIDE_FLAGS + [
|
TEST_COMPILER_FLAGS = BASE_COMPILER_FLAGS + GMOCK_OVERRIDE_FLAGS + [
|
||||||
"-std=c++1y",
|
|
||||||
"-DDEBUG",
|
"-DDEBUG",
|
||||||
|
"-DYG_ENABLE_EVENTS",
|
||||||
]
|
]
|
||||||
|
|
||||||
yoga_cxx_library(
|
yoga_cxx_library(
|
||||||
name = "yoga",
|
name = "yoga",
|
||||||
srcs = glob(["yoga/*.cpp"]),
|
srcs = glob(["yoga/**/*.cpp"]),
|
||||||
header_namespace = "",
|
header_namespace = "",
|
||||||
exported_headers = subdir_glob([("", "yoga/*.h")]),
|
exported_headers = subdir_glob([("", "yoga/**/*.h")]),
|
||||||
compiler_flags = COMPILER_FLAGS,
|
compiler_flags = LIBRARY_COMPILER_FLAGS,
|
||||||
soname = "libyogacore.$(ext)",
|
soname = "libyogacore.$(ext)",
|
||||||
tests = [":YogaTests"],
|
tests = [":YogaTests"],
|
||||||
visibility = ["PUBLIC"],
|
visibility = ["PUBLIC"],
|
||||||
@@ -34,9 +30,9 @@ yoga_cxx_library(
|
|||||||
|
|
||||||
yoga_cxx_library(
|
yoga_cxx_library(
|
||||||
name = "yogaForDebug",
|
name = "yogaForDebug",
|
||||||
srcs = glob(["yoga/*.cpp"]),
|
srcs = glob(["yoga/**/*.cpp"]),
|
||||||
header_namespace = "",
|
header_namespace = "",
|
||||||
exported_headers = subdir_glob([("", "yoga/*.h")]),
|
exported_headers = subdir_glob([("", "yoga/**/*.h")]),
|
||||||
compiler_flags = TEST_COMPILER_FLAGS,
|
compiler_flags = TEST_COMPILER_FLAGS,
|
||||||
soname = "libyogacore.$(ext)",
|
soname = "libyogacore.$(ext)",
|
||||||
tests = [":YogaTests"],
|
tests = [":YogaTests"],
|
||||||
@@ -55,6 +51,7 @@ yoga_cxx_test(
|
|||||||
visibility = ["PUBLIC"],
|
visibility = ["PUBLIC"],
|
||||||
deps = [
|
deps = [
|
||||||
":yogaForDebug",
|
":yogaForDebug",
|
||||||
|
yoga_dep("testutil:testutil"),
|
||||||
GTEST_TARGET,
|
GTEST_TARGET,
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
@@ -13,3 +13,4 @@ file(GLOB yogacore_SRC yoga/*.cpp)
|
|||||||
add_library(yogacore STATIC ${yogacore_SRC})
|
add_library(yogacore STATIC ${yogacore_SRC})
|
||||||
|
|
||||||
target_link_libraries(yogacore android log)
|
target_link_libraries(yogacore android log)
|
||||||
|
set_target_properties(yogacore PROPERTIES CXX_STANDARD 11)
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -12,7 +12,7 @@ load(
|
|||||||
"yoga_dep",
|
"yoga_dep",
|
||||||
)
|
)
|
||||||
|
|
||||||
COMPILER_FLAGS = BASE_COMPILER_FLAGS + ["-std=c++14"]
|
COMPILER_FLAGS = BASE_COMPILER_FLAGS + ["-std=c++11"]
|
||||||
|
|
||||||
fb_native.csharp_library(
|
fb_native.csharp_library(
|
||||||
name = "yogalibnet46",
|
name = "yogalibnet46",
|
||||||
|
@@ -43,9 +43,6 @@ namespace Facebook.Yoga
|
|||||||
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
|
||||||
public static extern void YGConfigFree(IntPtr node);
|
public static extern void YGConfigFree(IntPtr node);
|
||||||
|
|
||||||
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
|
|
||||||
public static extern int YGNodeGetInstanceCount();
|
|
||||||
|
|
||||||
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
|
||||||
public static extern int YGConfigGetInstanceCount();
|
public static extern int YGConfigGetInstanceCount();
|
||||||
|
|
||||||
|
@@ -673,10 +673,5 @@ namespace Facebook.Yoga
|
|||||||
return _children != null ? ((IEnumerable<YogaNode>)_children).GetEnumerator() :
|
return _children != null ? ((IEnumerable<YogaNode>)_children).GetEnumerator() :
|
||||||
System.Linq.Enumerable.Empty<YogaNode>().GetEnumerator();
|
System.Linq.Enumerable.Empty<YogaNode>().GetEnumerator();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int GetInstanceCount()
|
|
||||||
{
|
|
||||||
return Native.YGNodeGetInstanceCount();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,3 +1,9 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
* file in the root directory of this source tree.
|
||||||
|
*/
|
||||||
//{{NO_DEPENDENCIES}}
|
//{{NO_DEPENDENCIES}}
|
||||||
// Microsoft Visual C++ generated include file.
|
// Microsoft Visual C++ generated include file.
|
||||||
// Used by Yoga.rc
|
// Used by Yoga.rc
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
286
enums.py
286
enums.py
@@ -3,107 +3,57 @@
|
|||||||
# This source code is licensed under the MIT license found in the
|
# This source code is licensed under the MIT license found in the
|
||||||
# LICENSE file in the root directory of this source tree.
|
# LICENSE file in the root directory of this source tree.
|
||||||
|
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||||
from __future__ import division
|
|
||||||
from __future__ import print_function
|
|
||||||
from __future__ import unicode_literals
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
||||||
ENUMS = {
|
ENUMS = {
|
||||||
'Direction': [
|
"Direction": ["Inherit", "LTR", "RTL"],
|
||||||
'Inherit',
|
"Unit": ["Undefined", "Point", "Percent", "Auto"],
|
||||||
'LTR',
|
"FlexDirection": ["Column", "ColumnReverse", "Row", "RowReverse"],
|
||||||
'RTL',
|
"Justify": [
|
||||||
|
"FlexStart",
|
||||||
|
"Center",
|
||||||
|
"FlexEnd",
|
||||||
|
"SpaceBetween",
|
||||||
|
"SpaceAround",
|
||||||
|
"SpaceEvenly",
|
||||||
],
|
],
|
||||||
'Unit': [
|
"Overflow": ["Visible", "Hidden", "Scroll"],
|
||||||
'Undefined',
|
"Align": [
|
||||||
'Point',
|
"Auto",
|
||||||
'Percent',
|
"FlexStart",
|
||||||
'Auto',
|
"Center",
|
||||||
|
"FlexEnd",
|
||||||
|
"Stretch",
|
||||||
|
"Baseline",
|
||||||
|
"SpaceBetween",
|
||||||
|
"SpaceAround",
|
||||||
],
|
],
|
||||||
'FlexDirection': [
|
"PositionType": ["Relative", "Absolute"],
|
||||||
'Column',
|
"Display": ["Flex", "None"],
|
||||||
'ColumnReverse',
|
"Wrap": ["NoWrap", "Wrap", "WrapReverse"],
|
||||||
'Row',
|
"MeasureMode": ["Undefined", "Exactly", "AtMost"],
|
||||||
'RowReverse',
|
"Dimension": ["Width", "Height"],
|
||||||
|
"Edge": [
|
||||||
|
"Left",
|
||||||
|
"Top",
|
||||||
|
"Right",
|
||||||
|
"Bottom",
|
||||||
|
"Start",
|
||||||
|
"End",
|
||||||
|
"Horizontal",
|
||||||
|
"Vertical",
|
||||||
|
"All",
|
||||||
],
|
],
|
||||||
'Justify': [
|
"NodeType": ["Default", "Text"],
|
||||||
'FlexStart',
|
"LogLevel": ["Error", "Warn", "Info", "Debug", "Verbose", "Fatal"],
|
||||||
'Center',
|
"ExperimentalFeature": [
|
||||||
'FlexEnd',
|
|
||||||
'SpaceBetween',
|
|
||||||
'SpaceAround',
|
|
||||||
'SpaceEvenly',
|
|
||||||
],
|
|
||||||
'Overflow': [
|
|
||||||
'Visible',
|
|
||||||
'Hidden',
|
|
||||||
'Scroll',
|
|
||||||
],
|
|
||||||
'Align': [
|
|
||||||
'Auto',
|
|
||||||
'FlexStart',
|
|
||||||
'Center',
|
|
||||||
'FlexEnd',
|
|
||||||
'Stretch',
|
|
||||||
'Baseline',
|
|
||||||
'SpaceBetween',
|
|
||||||
'SpaceAround',
|
|
||||||
],
|
|
||||||
'PositionType': [
|
|
||||||
'Relative',
|
|
||||||
'Absolute',
|
|
||||||
],
|
|
||||||
'Display': [
|
|
||||||
'Flex',
|
|
||||||
'None',
|
|
||||||
],
|
|
||||||
'Wrap': [
|
|
||||||
'NoWrap',
|
|
||||||
'Wrap',
|
|
||||||
'WrapReverse',
|
|
||||||
],
|
|
||||||
'MeasureMode': [
|
|
||||||
'Undefined',
|
|
||||||
'Exactly',
|
|
||||||
'AtMost',
|
|
||||||
],
|
|
||||||
'Dimension': [
|
|
||||||
'Width',
|
|
||||||
'Height',
|
|
||||||
],
|
|
||||||
'Edge': [
|
|
||||||
'Left',
|
|
||||||
'Top',
|
|
||||||
'Right',
|
|
||||||
'Bottom',
|
|
||||||
'Start',
|
|
||||||
'End',
|
|
||||||
'Horizontal',
|
|
||||||
'Vertical',
|
|
||||||
'All',
|
|
||||||
],
|
|
||||||
'NodeType': [
|
|
||||||
'Default',
|
|
||||||
'Text',
|
|
||||||
],
|
|
||||||
'LogLevel': [
|
|
||||||
'Error',
|
|
||||||
'Warn',
|
|
||||||
'Info',
|
|
||||||
'Debug',
|
|
||||||
'Verbose',
|
|
||||||
'Fatal',
|
|
||||||
],
|
|
||||||
'ExperimentalFeature': [
|
|
||||||
# Mimic web flex-basis behavior.
|
# Mimic web flex-basis behavior.
|
||||||
'WebFlexBasis',
|
"WebFlexBasis"
|
||||||
],
|
|
||||||
'PrintOptions': [
|
|
||||||
('Layout', 1),
|
|
||||||
('Style', 2),
|
|
||||||
('Children', 4),
|
|
||||||
],
|
],
|
||||||
|
"PrintOptions": [("Layout", 1), ("Style", 2), ("Children", 4)],
|
||||||
}
|
}
|
||||||
|
|
||||||
LICENSE = """/**
|
LICENSE = """/**
|
||||||
@@ -115,23 +65,25 @@ LICENSE = """/**
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
def to_java_upper(symbol):
|
def to_java_upper(symbol):
|
||||||
symbol = str(symbol)
|
symbol = str(symbol)
|
||||||
out = ''
|
out = ""
|
||||||
for i in range(0, len(symbol)):
|
for i in range(0, len(symbol)):
|
||||||
c = symbol[i]
|
c = symbol[i]
|
||||||
if str.istitle(c) and i is not 0 and not str.istitle(symbol[i - 1]):
|
if str.istitle(c) and i is not 0 and not str.istitle(symbol[i - 1]):
|
||||||
out += '_'
|
out += "_"
|
||||||
out += c.upper()
|
out += c.upper()
|
||||||
return out
|
return out
|
||||||
|
|
||||||
|
|
||||||
def to_log_lower(symbol):
|
def to_log_lower(symbol):
|
||||||
symbol = str(symbol)
|
symbol = str(symbol)
|
||||||
out = ''
|
out = ""
|
||||||
for i in range(0, len(symbol)):
|
for i in range(0, len(symbol)):
|
||||||
c = symbol[i]
|
c = symbol[i]
|
||||||
if str.istitle(c) and i is not 0 and not str.istitle(symbol[i - 1]):
|
if str.istitle(c) and i is not 0 and not str.istitle(symbol[i - 1]):
|
||||||
out += '-'
|
out += "-"
|
||||||
out += c.lower()
|
out += c.lower()
|
||||||
return out
|
return out
|
||||||
|
|
||||||
@@ -139,114 +91,128 @@ def to_log_lower(symbol):
|
|||||||
root = os.path.dirname(os.path.abspath(__file__))
|
root = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
|
||||||
# write out C & Objective-C headers
|
# write out C & Objective-C headers
|
||||||
with open(root + '/yoga/YGEnums.h', 'w') as f:
|
with open(root + "/yoga/YGEnums.h", "w") as f:
|
||||||
f.write(LICENSE)
|
f.write(LICENSE)
|
||||||
f.write('#pragma once\n\n')
|
f.write("#pragma once\n\n")
|
||||||
f.write('#include "YGMacros.h"\n\n')
|
f.write('#include "YGMacros.h"\n\n')
|
||||||
f.write('YG_EXTERN_C_BEGIN\n\n')
|
f.write("YG_EXTERN_C_BEGIN\n\n")
|
||||||
for name, values in sorted(ENUMS.items()):
|
for name, values in sorted(ENUMS.items()):
|
||||||
f.write('#define YG%sCount %s\n' % (name, len(values)))
|
f.write("#define YG%sCount %s\n" % (name, len(values)))
|
||||||
f.write('typedef YG_ENUM_BEGIN(YG%s) {\n' % name)
|
f.write("typedef YG_ENUM_BEGIN(YG%s) {\n" % name)
|
||||||
for value in values:
|
for value in values:
|
||||||
if isinstance(value, tuple):
|
if isinstance(value, tuple):
|
||||||
f.write(' YG%s%s = %d,\n' % (name, value[0], value[1]))
|
f.write(" YG%s%s = %d,\n" % (name, value[0], value[1]))
|
||||||
else:
|
else:
|
||||||
f.write(' YG%s%s,\n' % (name, value))
|
f.write(" YG%s%s,\n" % (name, value))
|
||||||
f.write('} YG_ENUM_END(YG%s);\n' % name)
|
f.write("} YG_ENUM_END(YG%s);\n" % name)
|
||||||
f.write('WIN_EXPORT const char *YG%sToString(const YG%s value);\n' % (name, name))
|
f.write(
|
||||||
f.write('\n')
|
"WIN_EXPORT const char *YG%sToString(const YG%s value);\n" % (name, name)
|
||||||
f.write('YG_EXTERN_C_END\n')
|
)
|
||||||
|
f.write("\n")
|
||||||
|
f.write("YG_EXTERN_C_END\n")
|
||||||
|
|
||||||
# write out C body for printing
|
# write out C body for printing
|
||||||
with open(root + '/yoga/YGEnums.cpp', 'w') as f:
|
with open(root + "/yoga/YGEnums.cpp", "w") as f:
|
||||||
f.write(LICENSE)
|
f.write(LICENSE)
|
||||||
f.write('#include "YGEnums.h"\n\n')
|
f.write('#include "YGEnums.h"\n\n')
|
||||||
for name, values in sorted(ENUMS.items()):
|
for name, values in sorted(ENUMS.items()):
|
||||||
f.write('const char *YG%sToString(const YG%s value){\n' % (name, name))
|
f.write("const char *YG%sToString(const YG%s value){\n" % (name, name))
|
||||||
f.write(' switch(value){\n')
|
f.write(" switch(value){\n")
|
||||||
for value in values:
|
for value in values:
|
||||||
if isinstance(value, tuple):
|
if isinstance(value, tuple):
|
||||||
f.write(' case YG%s%s:\n' % (name, value[0]))
|
f.write(" case YG%s%s:\n" % (name, value[0]))
|
||||||
f.write(' return "%s";\n' % to_log_lower(value[0]))
|
f.write(' return "%s";\n' % to_log_lower(value[0]))
|
||||||
else:
|
else:
|
||||||
f.write(' case YG%s%s:\n' % (name, value))
|
f.write(" case YG%s%s:\n" % (name, value))
|
||||||
f.write(' return "%s";\n' % to_log_lower(value))
|
f.write(' return "%s";\n' % to_log_lower(value))
|
||||||
f.write(' }\n')
|
f.write(" }\n")
|
||||||
f.write(' return "unknown";\n')
|
f.write(' return "unknown";\n')
|
||||||
f.write('}\n\n')
|
f.write("}\n\n")
|
||||||
|
|
||||||
# write out java files
|
# write out java files
|
||||||
for name, values in sorted(ENUMS.items()):
|
for name, values in sorted(ENUMS.items()):
|
||||||
with open(root + '/java/com/facebook/yoga/Yoga%s.java' % name, 'w') as f:
|
with open(root + "/java/com/facebook/yoga/Yoga%s.java" % name, "w") as f:
|
||||||
f.write(LICENSE.replace('/**', '/*', 1))
|
f.write(LICENSE.replace("/**", "/*", 1))
|
||||||
f.write('package com.facebook.yoga;\n\n')
|
f.write("package com.facebook.yoga;\n\n")
|
||||||
f.write('import com.facebook.proguard.annotations.DoNotStrip;\n\n')
|
f.write("import com.facebook.proguard.annotations.DoNotStrip;\n\n")
|
||||||
f.write('@DoNotStrip\n')
|
f.write("@DoNotStrip\n")
|
||||||
f.write('public enum Yoga%s {\n' % name)
|
f.write("public enum Yoga%s {\n" % name)
|
||||||
if len(values) > 0:
|
if len(values) > 0:
|
||||||
for value in values:
|
for value in values:
|
||||||
if isinstance(value, tuple):
|
if isinstance(value, tuple):
|
||||||
f.write(' %s(%d)' % (to_java_upper(value[0]), value[1]))
|
f.write(" %s(%d)" % (to_java_upper(value[0]), value[1]))
|
||||||
else:
|
else:
|
||||||
f.write(' %s(%d)' % (to_java_upper(value), values.index(value)))
|
f.write(" %s(%d)" % (to_java_upper(value), values.index(value)))
|
||||||
if values.index(value) is len(values) - 1:
|
if values.index(value) is len(values) - 1:
|
||||||
f.write(';\n')
|
f.write(";\n")
|
||||||
else:
|
else:
|
||||||
f.write(',\n')
|
f.write(",\n")
|
||||||
else:
|
else:
|
||||||
f.write('__EMPTY(-1);')
|
f.write("__EMPTY(-1);")
|
||||||
f.write('\n')
|
f.write("\n")
|
||||||
f.write(' private int mIntValue;\n')
|
f.write(" private int mIntValue;\n")
|
||||||
f.write('\n')
|
f.write("\n")
|
||||||
f.write(' Yoga%s(int intValue) {\n' % name)
|
f.write(" Yoga%s(int intValue) {\n" % name)
|
||||||
f.write(' mIntValue = intValue;\n')
|
f.write(" mIntValue = intValue;\n")
|
||||||
f.write(' }\n')
|
f.write(" }\n")
|
||||||
f.write('\n')
|
f.write("\n")
|
||||||
f.write(' public int intValue() {\n')
|
f.write(" public int intValue() {\n")
|
||||||
f.write(' return mIntValue;\n')
|
f.write(" return mIntValue;\n")
|
||||||
f.write(' }\n')
|
f.write(" }\n")
|
||||||
f.write('\n')
|
f.write("\n")
|
||||||
f.write(' public static Yoga%s fromInt(int value) {\n' % name)
|
f.write(" public static Yoga%s fromInt(int value) {\n" % name)
|
||||||
f.write(' switch (value) {\n')
|
f.write(" switch (value) {\n")
|
||||||
for value in values:
|
for value in values:
|
||||||
if isinstance(value, tuple):
|
if isinstance(value, tuple):
|
||||||
f.write(' case %d: return %s;\n' % (value[1], to_java_upper(value[0])))
|
f.write(
|
||||||
|
" case %d: return %s;\n" % (value[1], to_java_upper(value[0]))
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
f.write(' case %d: return %s;\n' % (values.index(value), to_java_upper(value)))
|
f.write(
|
||||||
f.write(' default: throw new IllegalArgumentException("Unknown enum value: " + value);\n')
|
" case %d: return %s;\n"
|
||||||
f.write(' }\n')
|
% (values.index(value), to_java_upper(value))
|
||||||
f.write(' }\n')
|
)
|
||||||
f.write('}\n')
|
f.write(
|
||||||
|
' default: throw new IllegalArgumentException("Unknown enum value: " + value);\n'
|
||||||
|
)
|
||||||
|
f.write(" }\n")
|
||||||
|
f.write(" }\n")
|
||||||
|
f.write("}\n")
|
||||||
|
|
||||||
# write out csharp files
|
# write out csharp files
|
||||||
for name, values in sorted(ENUMS.items()):
|
for name, values in sorted(ENUMS.items()):
|
||||||
with open(root + '/csharp/Facebook.Yoga/Yoga%s.cs' % name, 'w') as f:
|
with open(root + "/csharp/Facebook.Yoga/Yoga%s.cs" % name, "w") as f:
|
||||||
f.write(LICENSE)
|
f.write(LICENSE)
|
||||||
f.write('namespace Facebook.Yoga\n{\n')
|
f.write("namespace Facebook.Yoga\n{\n")
|
||||||
if isinstance(next(iter(values or []), None), tuple):
|
if isinstance(next(iter(values or []), None), tuple):
|
||||||
f.write(' [System.Flags]\n')
|
f.write(" [System.Flags]\n")
|
||||||
f.write(' public enum Yoga%s\n {\n' % name)
|
f.write(" public enum Yoga%s\n {\n" % name)
|
||||||
for value in values:
|
for value in values:
|
||||||
if isinstance(value, tuple):
|
if isinstance(value, tuple):
|
||||||
f.write(' %s = %d,\n' % (value[0], value[1]))
|
f.write(" %s = %d,\n" % (value[0], value[1]))
|
||||||
else:
|
else:
|
||||||
f.write(' %s,\n' % value)
|
f.write(" %s,\n" % value)
|
||||||
f.write(' }\n')
|
f.write(" }\n")
|
||||||
f.write('}\n')
|
f.write("}\n")
|
||||||
|
|
||||||
# write out javascript file
|
# write out javascript file
|
||||||
with open(root + '/javascript/sources/YGEnums.js', 'w') as f:
|
with open(root + "/javascript/sources/YGEnums.js", "w") as f:
|
||||||
f.write(LICENSE)
|
f.write(LICENSE)
|
||||||
f.write('module.exports = {\n\n')
|
f.write("module.exports = {\n\n")
|
||||||
for name, values in sorted(ENUMS.items()):
|
for name, values in sorted(ENUMS.items()):
|
||||||
f.write(' %s_COUNT: %s,\n' % (to_java_upper(name), len(values)))
|
f.write(" %s_COUNT: %s,\n" % (to_java_upper(name), len(values)))
|
||||||
base = 0
|
base = 0
|
||||||
for value in values:
|
for value in values:
|
||||||
if isinstance(value, tuple):
|
if isinstance(value, tuple):
|
||||||
f.write(' %s_%s: %d,\n' % (to_java_upper(name), to_java_upper(value[0]), value[1]))
|
f.write(
|
||||||
|
" %s_%s: %d,\n"
|
||||||
|
% (to_java_upper(name), to_java_upper(value[0]), value[1])
|
||||||
|
)
|
||||||
base = value[1] + 1
|
base = value[1] + 1
|
||||||
else:
|
else:
|
||||||
f.write(' %s_%s: %d,\n' % (to_java_upper(name), to_java_upper(value), base))
|
f.write(
|
||||||
|
" %s_%s: %d,\n" % (to_java_upper(name), to_java_upper(value), base)
|
||||||
|
)
|
||||||
base += 1
|
base += 1
|
||||||
f.write('\n')
|
f.write("\n")
|
||||||
f.write('};\n')
|
f.write("};\n")
|
||||||
|
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
org.gradle.jvmargs=-Xmx1536M
|
org.gradle.jvmargs=-Xmx1536M
|
||||||
|
|
||||||
VERSION_NAME=1.14.0
|
VERSION_NAME=1.14.0-SNAPSHOT
|
||||||
POM_URL=https://github.com/facebook/yoga
|
POM_URL=https://github.com/facebook/yoga
|
||||||
POM_SCM_URL=https://github.com/facebook/yoga.git
|
POM_SCM_URL=https://github.com/facebook/yoga.git
|
||||||
POM_SCM_CONNECTION=scm:git:https://github.com/facebook/yoga.git
|
POM_SCM_CONNECTION=scm:git:https://github.com/facebook/yoga.git
|
||||||
|
84
gradlew.bat
vendored
Normal file
84
gradlew.bat
vendored
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
@if "%DEBUG%" == "" @echo off
|
||||||
|
@rem ##########################################################################
|
||||||
|
@rem
|
||||||
|
@rem Gradle startup script for Windows
|
||||||
|
@rem
|
||||||
|
@rem ##########################################################################
|
||||||
|
|
||||||
|
@rem Set local scope for the variables with windows NT shell
|
||||||
|
if "%OS%"=="Windows_NT" setlocal
|
||||||
|
|
||||||
|
set DIRNAME=%~dp0
|
||||||
|
if "%DIRNAME%" == "" set DIRNAME=.
|
||||||
|
set APP_BASE_NAME=%~n0
|
||||||
|
set APP_HOME=%DIRNAME%
|
||||||
|
|
||||||
|
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
|
set DEFAULT_JVM_OPTS=
|
||||||
|
|
||||||
|
@rem Find java.exe
|
||||||
|
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||||
|
|
||||||
|
set JAVA_EXE=java.exe
|
||||||
|
%JAVA_EXE% -version >NUL 2>&1
|
||||||
|
if "%ERRORLEVEL%" == "0" goto init
|
||||||
|
|
||||||
|
echo.
|
||||||
|
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
|
echo.
|
||||||
|
echo Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
echo location of your Java installation.
|
||||||
|
|
||||||
|
goto fail
|
||||||
|
|
||||||
|
:findJavaFromJavaHome
|
||||||
|
set JAVA_HOME=%JAVA_HOME:"=%
|
||||||
|
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||||
|
|
||||||
|
if exist "%JAVA_EXE%" goto init
|
||||||
|
|
||||||
|
echo.
|
||||||
|
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||||
|
echo.
|
||||||
|
echo Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
echo location of your Java installation.
|
||||||
|
|
||||||
|
goto fail
|
||||||
|
|
||||||
|
:init
|
||||||
|
@rem Get command-line arguments, handling Windows variants
|
||||||
|
|
||||||
|
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||||
|
|
||||||
|
:win9xME_args
|
||||||
|
@rem Slurp the command line arguments.
|
||||||
|
set CMD_LINE_ARGS=
|
||||||
|
set _SKIP=2
|
||||||
|
|
||||||
|
:win9xME_args_slurp
|
||||||
|
if "x%~1" == "x" goto execute
|
||||||
|
|
||||||
|
set CMD_LINE_ARGS=%*
|
||||||
|
|
||||||
|
:execute
|
||||||
|
@rem Setup the command line
|
||||||
|
|
||||||
|
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||||
|
|
||||||
|
@rem Execute Gradle
|
||||||
|
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||||
|
|
||||||
|
:end
|
||||||
|
@rem End local scope for the variables with windows NT shell
|
||||||
|
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||||
|
|
||||||
|
:fail
|
||||||
|
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||||
|
rem the _cmd.exe /c_ return code!
|
||||||
|
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||||
|
exit /b 1
|
||||||
|
|
||||||
|
:mainEnd
|
||||||
|
if "%OS%"=="Windows_NT" endlocal
|
||||||
|
|
||||||
|
:omega
|
16
java/BUCK
16
java/BUCK
@@ -3,13 +3,18 @@
|
|||||||
# This source code is licensed under the MIT license found in the
|
# This source code is licensed under the MIT license found in the
|
||||||
# LICENSE file in the root directory of this source tree.
|
# LICENSE file in the root directory of this source tree.
|
||||||
|
|
||||||
load("//tools/build_defs/oss:yoga_defs.bzl", "ANDROID", "CXX_LIBRARY_WHITELIST", "FBJNI_JAVA_TARGET", "FBJNI_TARGET", "INFER_ANNOTATIONS_TARGET", "JNI_TARGET", "JSR_305_TARGET", "JUNIT_TARGET", "PROGRUARD_ANNOTATIONS_TARGET", "SOLOADER_TARGET", "yoga_cxx_library", "yoga_dep", "yoga_java_binary", "yoga_java_library", "yoga_java_test")
|
load("//tools/build_defs/oss:yoga_defs.bzl", "ANDROID", "CXX_LIBRARY_WHITELIST", "FBJNI_JAVA_TARGET", "FBJNI_TARGET", "INFER_ANNOTATIONS_TARGET", "JNI_TARGET", "JSR_305_TARGET", "JUNIT_TARGET", "PROGRUARD_ANNOTATIONS_TARGET", "SOLOADER_TARGET", "yoga_cxx_lib", "yoga_cxx_library", "yoga_dep", "yoga_java_binary", "yoga_java_library", "yoga_java_test")
|
||||||
|
|
||||||
|
CXX_LIBRARY_WHITELIST_FOR_TESTS = CXX_LIBRARY_WHITELIST + [
|
||||||
|
yoga_cxx_lib("testutil:jni"),
|
||||||
|
yoga_cxx_lib("testutil:testutil"),
|
||||||
|
]
|
||||||
|
|
||||||
yoga_cxx_library(
|
yoga_cxx_library(
|
||||||
name = "jni",
|
name = "jni",
|
||||||
srcs = glob(["jni/*.cpp"]),
|
srcs = glob(["jni/*.cpp"]),
|
||||||
headers = glob(["jni/*.h"]),
|
header_namespace = "yoga/java",
|
||||||
header_namespace = "",
|
exported_headers = glob(["jni/*.h"]),
|
||||||
allow_jni_merging = True,
|
allow_jni_merging = True,
|
||||||
compiler_flags = [
|
compiler_flags = [
|
||||||
"-fno-omit-frame-pointer",
|
"-fno-omit-frame-pointer",
|
||||||
@@ -18,7 +23,7 @@ yoga_cxx_library(
|
|||||||
"-Wall",
|
"-Wall",
|
||||||
"-Werror",
|
"-Werror",
|
||||||
"-Os",
|
"-Os",
|
||||||
"-std=c++14",
|
"-std=c++11",
|
||||||
],
|
],
|
||||||
platforms = ANDROID,
|
platforms = ANDROID,
|
||||||
preprocessor_flags = [
|
preprocessor_flags = [
|
||||||
@@ -55,11 +60,12 @@ yoga_java_library(
|
|||||||
yoga_java_test(
|
yoga_java_test(
|
||||||
name = "tests",
|
name = "tests",
|
||||||
srcs = glob(["tests/**/*.java"]),
|
srcs = glob(["tests/**/*.java"]),
|
||||||
cxx_library_whitelist = CXX_LIBRARY_WHITELIST,
|
cxx_library_whitelist = CXX_LIBRARY_WHITELIST_FOR_TESTS,
|
||||||
use_cxx_libraries = True,
|
use_cxx_libraries = True,
|
||||||
visibility = ["PUBLIC"],
|
visibility = ["PUBLIC"],
|
||||||
deps = [
|
deps = [
|
||||||
":java",
|
":java",
|
||||||
|
yoga_dep("testutil:java"),
|
||||||
JUNIT_TARGET,
|
JUNIT_TARGET,
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
@@ -28,7 +28,6 @@ public class YogaNative {
|
|||||||
|
|
||||||
|
|
||||||
// YGNode related
|
// YGNode related
|
||||||
static native int jni_YGNodeGetInstanceCount();
|
|
||||||
static native long jni_YGNodeNew(boolean useBatchingForLayoutOutputs);
|
static native long jni_YGNodeNew(boolean useBatchingForLayoutOutputs);
|
||||||
static native long jni_YGNodeNewWithConfig(long configPointer, boolean useBatchingForLayoutOutputs);
|
static native long jni_YGNodeNewWithConfig(long configPointer, boolean useBatchingForLayoutOutputs);
|
||||||
static native void jni_YGNodeFree(long nativePointer);
|
static native void jni_YGNodeFree(long nativePointer);
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
@@ -75,34 +75,6 @@ const short int LAYOUT_BORDER_START_INDEX = 14;
|
|||||||
|
|
||||||
bool useBatchingForLayoutOutputs;
|
bool useBatchingForLayoutOutputs;
|
||||||
|
|
||||||
class PtrJNodeMap {
|
|
||||||
using JNodeArray = JArrayClass<JYogaNode::javaobject>;
|
|
||||||
std::map<YGNodeRef, size_t> ptrsToIdxs_;
|
|
||||||
alias_ref<JNodeArray> javaNodes_;
|
|
||||||
|
|
||||||
public:
|
|
||||||
PtrJNodeMap() : ptrsToIdxs_{}, javaNodes_{} {}
|
|
||||||
PtrJNodeMap(
|
|
||||||
alias_ref<JArrayLong> nativePointers,
|
|
||||||
alias_ref<JNodeArray> javaNodes)
|
|
||||||
: javaNodes_{javaNodes} {
|
|
||||||
auto pin = nativePointers->pinCritical();
|
|
||||||
auto ptrs = pin.get();
|
|
||||||
for (size_t i = 0, n = pin.size(); i < n; ++i) {
|
|
||||||
ptrsToIdxs_[(YGNodeRef) ptrs[i]] = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
local_ref<JYogaNode> ref(YGNodeRef node) {
|
|
||||||
auto idx = ptrsToIdxs_.find(node);
|
|
||||||
if (idx == ptrsToIdxs_.end()) {
|
|
||||||
return local_ref<JYogaNode>{};
|
|
||||||
} else {
|
|
||||||
return javaNodes_->getElement(idx->second);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
union YGNodeContext {
|
union YGNodeContext {
|
||||||
@@ -135,18 +107,14 @@ public:
|
|||||||
node->setContext(context.asVoidPtr);
|
node->setContext(context.asVoidPtr);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool has(Edge edge) {
|
bool has(Edge edge) { return (edges_ & edge) == edge; }
|
||||||
return (edges_ & edge) == edge;
|
|
||||||
}
|
|
||||||
|
|
||||||
YGNodeEdges& add(Edge edge) {
|
YGNodeEdges& add(Edge edge) {
|
||||||
edges_ |= edge;
|
edges_ |= edge;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
int get() {
|
int get() { return edges_; }
|
||||||
return edges_;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct YogaValue {
|
struct YogaValue {
|
||||||
@@ -942,10 +910,6 @@ void jni_YGNodeSetStyleInputs(
|
|||||||
YGNodeSetStyleInputs(_jlong2YGNodeRef(nativePointer), result, size);
|
YGNodeSetStyleInputs(_jlong2YGNodeRef(nativePointer), result, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
jint jni_YGNodeGetInstanceCount() {
|
|
||||||
return YGNodeGetInstanceCount();
|
|
||||||
}
|
|
||||||
|
|
||||||
jlong jni_YGNodeStyleGetMargin(jlong nativePointer, jint edge) {
|
jlong jni_YGNodeStyleGetMargin(jlong nativePointer, jint edge) {
|
||||||
YGNodeRef yogaNodeRef = _jlong2YGNodeRef(nativePointer);
|
YGNodeRef yogaNodeRef = _jlong2YGNodeRef(nativePointer);
|
||||||
if (!YGNodeEdges{yogaNodeRef}.has(YGNodeEdges::MARGIN)) {
|
if (!YGNodeEdges{yogaNodeRef}.has(YGNodeEdges::MARGIN)) {
|
||||||
@@ -1109,7 +1073,6 @@ jint JNI_OnLoad(JavaVM* vm, void*) {
|
|||||||
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetMaxHeightPercent),
|
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetMaxHeightPercent),
|
||||||
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetAspectRatio),
|
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetAspectRatio),
|
||||||
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetAspectRatio),
|
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetAspectRatio),
|
||||||
YGMakeCriticalNativeMethod(jni_YGNodeGetInstanceCount),
|
|
||||||
YGMakeCriticalNativeMethod(jni_YGNodePrint),
|
YGMakeCriticalNativeMethod(jni_YGNodePrint),
|
||||||
YGMakeNativeMethod(jni_YGNodeClone),
|
YGMakeNativeMethod(jni_YGNodeClone),
|
||||||
YGMakeNativeMethod(jni_YGNodeSetStyleInputs),
|
YGMakeNativeMethod(jni_YGNodeSetStyleInputs),
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
@@ -6,6 +6,11 @@
|
|||||||
*/
|
*/
|
||||||
#include <fb/fbjni.h>
|
#include <fb/fbjni.h>
|
||||||
#include <yoga/YGValue.h>
|
#include <yoga/YGValue.h>
|
||||||
|
#include <yoga/Yoga.h>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
using namespace facebook::jni;
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
struct JYogaNode : public facebook::jni::JavaClass<JYogaNode> {
|
struct JYogaNode : public facebook::jni::JavaClass<JYogaNode> {
|
||||||
static constexpr auto kJavaDescriptor = "Lcom/facebook/yoga/YogaNodeJNIBase;";
|
static constexpr auto kJavaDescriptor = "Lcom/facebook/yoga/YogaNodeJNIBase;";
|
||||||
@@ -28,3 +33,31 @@ struct JYogaLogger : public facebook::jni::JavaClass<JYogaLogger> {
|
|||||||
facebook::jni::alias_ref<JYogaLogLevel>,
|
facebook::jni::alias_ref<JYogaLogLevel>,
|
||||||
jstring);
|
jstring);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class PtrJNodeMap {
|
||||||
|
using JNodeArray = JArrayClass<JYogaNode::javaobject>;
|
||||||
|
std::map<YGNodeRef, size_t> ptrsToIdxs_;
|
||||||
|
alias_ref<JNodeArray> javaNodes_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
PtrJNodeMap() : ptrsToIdxs_{}, javaNodes_{} {}
|
||||||
|
PtrJNodeMap(
|
||||||
|
alias_ref<JArrayLong> nativePointers,
|
||||||
|
alias_ref<JNodeArray> javaNodes)
|
||||||
|
: javaNodes_{javaNodes} {
|
||||||
|
auto pin = nativePointers->pinCritical();
|
||||||
|
auto ptrs = pin.get();
|
||||||
|
for (size_t i = 0, n = pin.size(); i < n; ++i) {
|
||||||
|
ptrsToIdxs_[(YGNodeRef) ptrs[i]] = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
local_ref<JYogaNode> ref(YGNodeRef node) {
|
||||||
|
auto idx = ptrsToIdxs_.find(node);
|
||||||
|
if (idx == ptrsToIdxs_.end()) {
|
||||||
|
return local_ref<JYogaNode>{};
|
||||||
|
} else {
|
||||||
|
return javaNodes_->getElement(idx->second);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
@@ -31,9 +31,9 @@ public class YogaNodeTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInit() {
|
public void testInit() {
|
||||||
final int refCount = YogaNative.jni_YGNodeGetInstanceCount();
|
TestUtil.startCountingNodes();
|
||||||
final YogaNode node = createNode();
|
final YogaNode node = createNode();
|
||||||
assertEquals(refCount + 1, YogaNative.jni_YGNodeGetInstanceCount());
|
assertEquals(1, TestUtil.stopCountingNodes());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -254,7 +254,7 @@ public class YogaNodeTest {
|
|||||||
root_child0_child0_child0.setFlexShrink(1);
|
root_child0_child0_child0.setFlexShrink(1);
|
||||||
root_child0_child0.addChildAt(root_child0_child0_child0, 0);
|
root_child0_child0.addChildAt(root_child0_child0_child0, 0);
|
||||||
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
||||||
assertFalse(((YogaNodeJNIBase) root).getDoesLegacyStretchFlagAffectsLayout());
|
assertTrue(((YogaNodeJNIBase) root).getDoesLegacyStretchFlagAffectsLayout());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,13 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
||||||
*
|
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
|
||||||
* file in the root directory of this source tree.
|
|
||||||
*/
|
|
||||||
#include <yoga/Yoga.h>
|
|
||||||
|
|
||||||
#include "./global.hh"
|
|
||||||
|
|
||||||
unsigned getInstanceCount(void) {
|
|
||||||
return YGNodeGetInstanceCount();
|
|
||||||
}
|
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -32,7 +32,7 @@ yoga_cxx_library(
|
|||||||
"-Wall",
|
"-Wall",
|
||||||
"-Werror",
|
"-Werror",
|
||||||
"-Wno-unused-parameter",
|
"-Wno-unused-parameter",
|
||||||
"-std=c++14",
|
"-std=c++11",
|
||||||
],
|
],
|
||||||
platforms = (ANDROID,),
|
platforms = (ANDROID,),
|
||||||
visibility = ["PUBLIC"],
|
visibility = ["PUBLIC"],
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
147
tests/EventsTest.cpp
Normal file
147
tests/EventsTest.cpp
Normal file
@@ -0,0 +1,147 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
* file in the root directory of this source tree.
|
||||||
|
*/
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
#include <yoga/Yoga.h>
|
||||||
|
#include <yoga/event/event.h>
|
||||||
|
#include <yoga/YGNode.h>
|
||||||
|
#include <yoga/testutil/testutil.h>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <functional>
|
||||||
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace facebook {
|
||||||
|
namespace yoga {
|
||||||
|
namespace test {
|
||||||
|
|
||||||
|
struct EventArgs {
|
||||||
|
const YGNode* node;
|
||||||
|
Event::Type type;
|
||||||
|
std::unique_ptr<void, std::function<void(void*)>> dataPtr;
|
||||||
|
|
||||||
|
template <Event::Type E>
|
||||||
|
const Event::TypedData<E>& data() {
|
||||||
|
return *static_cast<Event::TypedData<E>*>(dataPtr.get());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class EventTest : public ::testing::Test {
|
||||||
|
ScopedEventSubscription subscription = {&EventTest::listen};
|
||||||
|
static void listen(const YGNode&, Event::Type, Event::Data);
|
||||||
|
|
||||||
|
public:
|
||||||
|
static std::vector<EventArgs> events;
|
||||||
|
static EventArgs& lastEvent() { return events.back(); }
|
||||||
|
void TearDown() override;
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST_F(EventTest, new_node_has_event) {
|
||||||
|
auto c = YGConfigGetDefault();
|
||||||
|
auto n = YGNodeNew();
|
||||||
|
|
||||||
|
ASSERT_EQ(lastEvent().node, n);
|
||||||
|
ASSERT_EQ(lastEvent().type, Event::NodeAllocation);
|
||||||
|
ASSERT_EQ(lastEvent().data<Event::NodeAllocation>().config, c);
|
||||||
|
|
||||||
|
YGNodeFree(n);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(EventTest, new_node_with_config_event) {
|
||||||
|
auto c = YGConfigNew();
|
||||||
|
auto n = YGNodeNewWithConfig(c);
|
||||||
|
|
||||||
|
ASSERT_EQ(lastEvent().node, n);
|
||||||
|
ASSERT_EQ(lastEvent().type, Event::NodeAllocation);
|
||||||
|
ASSERT_EQ(lastEvent().data<Event::NodeAllocation>().config, c);
|
||||||
|
|
||||||
|
YGNodeFree(n);
|
||||||
|
YGConfigFree(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(EventTest, clone_node_event) {
|
||||||
|
auto c = YGConfigNew();
|
||||||
|
auto n = YGNodeNewWithConfig(c);
|
||||||
|
auto clone = YGNodeClone(n);
|
||||||
|
|
||||||
|
ASSERT_EQ(lastEvent().node, clone);
|
||||||
|
ASSERT_EQ(lastEvent().type, Event::NodeAllocation);
|
||||||
|
ASSERT_EQ(lastEvent().data<Event::NodeAllocation>().config, c);
|
||||||
|
|
||||||
|
YGNodeFree(n);
|
||||||
|
YGNodeFree(clone);
|
||||||
|
YGConfigFree(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(EventTest, free_node_event) {
|
||||||
|
auto c = YGConfigNew();
|
||||||
|
auto n = YGNodeNewWithConfig(c);
|
||||||
|
YGNodeFree(n);
|
||||||
|
|
||||||
|
ASSERT_EQ(lastEvent().node, n);
|
||||||
|
ASSERT_EQ(lastEvent().type, Event::NodeDeallocation);
|
||||||
|
ASSERT_EQ(lastEvent().data<Event::NodeDeallocation>().config, c);
|
||||||
|
|
||||||
|
YGConfigFree(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(EventTest, layout_events) {
|
||||||
|
auto root = YGNodeNew();
|
||||||
|
auto child = YGNodeNew();
|
||||||
|
YGNodeInsertChild(root, child, 0);
|
||||||
|
|
||||||
|
YGNodeCalculateLayout(root, 123, 456, YGDirectionLTR);
|
||||||
|
|
||||||
|
ASSERT_EQ(events[2].node, root);
|
||||||
|
ASSERT_EQ(events[2].type, Event::NodeLayout);
|
||||||
|
|
||||||
|
ASSERT_EQ(events[3].node, child);
|
||||||
|
ASSERT_EQ(events[3].type, Event::NodeLayout);
|
||||||
|
|
||||||
|
YGNodeFreeRecursive(root);
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
template <Event::Type E>
|
||||||
|
EventArgs createArgs(const YGNode& node, const Event::Data& data) {
|
||||||
|
using Data = Event::TypedData<E>;
|
||||||
|
auto deleteData = [](void* x) { delete static_cast<Data*>(x); };
|
||||||
|
return {&node, E, {new Data{data.get<E>()}, deleteData}};
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
void EventTest::listen(const YGNode& node, Event::Type type, Event::Data data) {
|
||||||
|
switch (type) {
|
||||||
|
case Event::NodeAllocation:
|
||||||
|
events.push_back(createArgs<Event::NodeAllocation>(node, data));
|
||||||
|
break;
|
||||||
|
case Event::NodeDeallocation:
|
||||||
|
events.push_back(createArgs<Event::NodeDeallocation>(node, data));
|
||||||
|
break;
|
||||||
|
case Event::NodeLayout:
|
||||||
|
events.push_back(createArgs<Event::NodeLayout>(node, data));
|
||||||
|
break;
|
||||||
|
case Event::LayoutPassStart:
|
||||||
|
break;
|
||||||
|
case Event::LayoutPassEnd:
|
||||||
|
break;
|
||||||
|
case Event::NodeMeasure:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EventTest::TearDown() {
|
||||||
|
events.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<EventArgs> EventTest::events{};
|
||||||
|
|
||||||
|
} // namespace test
|
||||||
|
} // namespace yoga
|
||||||
|
} // namespace facebook
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
@@ -20,12 +20,8 @@ struct ConfigCloningTest : public ::testing::Test {
|
|||||||
void TearDown() override;
|
void TearDown() override;
|
||||||
|
|
||||||
static YGNode clonedNode;
|
static YGNode clonedNode;
|
||||||
static YGNodeRef cloneNode(YGNodeRef, YGNodeRef, int) {
|
static YGNodeRef cloneNode(YGNodeRef, YGNodeRef, int) { return &clonedNode; }
|
||||||
return &clonedNode;
|
static YGNodeRef doNotClone(YGNodeRef, YGNodeRef, int) { return nullptr; }
|
||||||
}
|
|
||||||
static YGNodeRef doNotClone(YGNodeRef, YGNodeRef, int) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(ConfigCloningTest, uses_values_provided_by_cloning_callback) {
|
TEST_F(ConfigCloningTest, uses_values_provided_by_cloning_callback) {
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,14 +1,19 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
* file in the root directory of this source tree.
|
* file in the root directory of this source tree.
|
||||||
*/
|
*/
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
#include <yoga/testutil/testutil.h>
|
||||||
#include <yoga/YGNode.h>
|
#include <yoga/YGNode.h>
|
||||||
#include <yoga/Yoga.h>
|
#include <yoga/Yoga.h>
|
||||||
|
|
||||||
|
using facebook::yoga::test::TestUtil;
|
||||||
|
|
||||||
TEST(YogaTest, assert_layout_trees_are_same) {
|
TEST(YogaTest, assert_layout_trees_are_same) {
|
||||||
|
TestUtil::startCountingNodes();
|
||||||
|
|
||||||
YGConfig* config = YGConfigNew();
|
YGConfig* config = YGConfigNew();
|
||||||
YGConfigSetUseLegacyStretchBehaviour(config, true);
|
YGConfigSetUseLegacyStretchBehaviour(config, true);
|
||||||
const YGNodeRef root1 = YGNodeNewWithConfig(config);
|
const YGNodeRef root1 = YGNodeNewWithConfig(config);
|
||||||
@@ -30,12 +35,12 @@ TEST(YogaTest, assert_layout_trees_are_same) {
|
|||||||
YGNodeInsertChild(root1_child0_child0, root1_child0_child0_child0, 0);
|
YGNodeInsertChild(root1_child0_child0, root1_child0_child0_child0, 0);
|
||||||
|
|
||||||
const int32_t cal1_configInstanceCount = YGConfigGetInstanceCount();
|
const int32_t cal1_configInstanceCount = YGConfigGetInstanceCount();
|
||||||
const int32_t cal1_nodeInstanceCount = YGNodeGetInstanceCount();
|
const int32_t cal1_nodeInstanceCount = TestUtil::nodeCount();
|
||||||
|
|
||||||
YGNodeCalculateLayout(root1, YGUndefined, YGUndefined, YGDirectionLTR);
|
YGNodeCalculateLayout(root1, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||||
|
|
||||||
ASSERT_EQ(YGConfigGetInstanceCount(), cal1_configInstanceCount);
|
ASSERT_EQ(YGConfigGetInstanceCount(), cal1_configInstanceCount);
|
||||||
ASSERT_EQ(YGNodeGetInstanceCount(), cal1_nodeInstanceCount);
|
ASSERT_EQ(TestUtil::nodeCount(), cal1_nodeInstanceCount);
|
||||||
|
|
||||||
const YGNodeRef root2 = YGNodeNewWithConfig(config);
|
const YGNodeRef root2 = YGNodeNewWithConfig(config);
|
||||||
YGNodeStyleSetWidth(root2, 500);
|
YGNodeStyleSetWidth(root2, 500);
|
||||||
@@ -56,12 +61,12 @@ TEST(YogaTest, assert_layout_trees_are_same) {
|
|||||||
YGNodeInsertChild(root2_child0_child0, root2_child0_child0_child0, 0);
|
YGNodeInsertChild(root2_child0_child0, root2_child0_child0_child0, 0);
|
||||||
|
|
||||||
const int32_t cal2_configInstanceCount = YGConfigGetInstanceCount();
|
const int32_t cal2_configInstanceCount = YGConfigGetInstanceCount();
|
||||||
const int32_t cal2_nodeInstanceCount = YGNodeGetInstanceCount();
|
const int32_t cal2_nodeInstanceCount = TestUtil::nodeCount();
|
||||||
|
|
||||||
YGNodeCalculateLayout(root2, YGUndefined, YGUndefined, YGDirectionLTR);
|
YGNodeCalculateLayout(root2, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||||
|
|
||||||
ASSERT_EQ(YGConfigGetInstanceCount(), cal2_configInstanceCount);
|
ASSERT_EQ(YGConfigGetInstanceCount(), cal2_configInstanceCount);
|
||||||
ASSERT_EQ(YGNodeGetInstanceCount(), cal2_nodeInstanceCount);
|
ASSERT_EQ(TestUtil::nodeCount(), cal2_nodeInstanceCount);
|
||||||
|
|
||||||
ASSERT_TRUE(YGNodeLayoutGetDidUseLegacyFlag(root1));
|
ASSERT_TRUE(YGNodeLayoutGetDidUseLegacyFlag(root1));
|
||||||
ASSERT_TRUE(YGNodeLayoutGetDidUseLegacyFlag(root2));
|
ASSERT_TRUE(YGNodeLayoutGetDidUseLegacyFlag(root2));
|
||||||
@@ -70,12 +75,12 @@ TEST(YogaTest, assert_layout_trees_are_same) {
|
|||||||
YGNodeStyleSetAlignItems(root2, YGAlignFlexEnd);
|
YGNodeStyleSetAlignItems(root2, YGAlignFlexEnd);
|
||||||
|
|
||||||
const int32_t cal3_configInstanceCount = YGConfigGetInstanceCount();
|
const int32_t cal3_configInstanceCount = YGConfigGetInstanceCount();
|
||||||
const int32_t cal3_nodeInstanceCount = YGNodeGetInstanceCount();
|
const int32_t cal3_nodeInstanceCount = TestUtil::nodeCount();
|
||||||
|
|
||||||
YGNodeCalculateLayout(root2, YGUndefined, YGUndefined, YGDirectionLTR);
|
YGNodeCalculateLayout(root2, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||||
|
|
||||||
ASSERT_EQ(YGConfigGetInstanceCount(), cal3_configInstanceCount);
|
ASSERT_EQ(YGConfigGetInstanceCount(), cal3_configInstanceCount);
|
||||||
ASSERT_EQ(YGNodeGetInstanceCount(), cal3_nodeInstanceCount);
|
ASSERT_EQ(TestUtil::stopCountingNodes(), cal3_nodeInstanceCount);
|
||||||
|
|
||||||
ASSERT_FALSE(root1->isLayoutTreeEqualToNode(*root2));
|
ASSERT_FALSE(root1->isLayoutTreeEqualToNode(*root2));
|
||||||
|
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,13 +1,16 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
* file in the root directory of this source tree.
|
* file in the root directory of this source tree.
|
||||||
*/
|
*/
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
#include <yoga/testutil/testutil.h>
|
||||||
#include <yoga/Yoga.h>
|
#include <yoga/Yoga.h>
|
||||||
#include <yoga/YGNode.h>
|
#include <yoga/YGNode.h>
|
||||||
|
|
||||||
|
using facebook::yoga::test::TestUtil;
|
||||||
|
|
||||||
TEST(YogaTest, cloning_shared_root) {
|
TEST(YogaTest, cloning_shared_root) {
|
||||||
const YGConfigRef config = YGConfigNew();
|
const YGConfigRef config = YGConfigNew();
|
||||||
|
|
||||||
@@ -220,7 +223,7 @@ TEST(YogaTest, cloning_two_levels) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(YogaTest, cloning_and_freeing) {
|
TEST(YogaTest, cloning_and_freeing) {
|
||||||
const int32_t initialInstanceCount = YGNodeGetInstanceCount();
|
TestUtil::startCountingNodes();
|
||||||
|
|
||||||
const YGConfigRef config = YGConfigNew();
|
const YGConfigRef config = YGConfigNew();
|
||||||
|
|
||||||
@@ -249,7 +252,7 @@ TEST(YogaTest, cloning_and_freeing) {
|
|||||||
|
|
||||||
YGConfigFree(config);
|
YGConfigFree(config);
|
||||||
|
|
||||||
ASSERT_EQ(initialInstanceCount, YGNodeGetInstanceCount());
|
ASSERT_EQ(0, TestUtil::stopCountingNodes());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(YogaTest, mixed_shared_and_owned_children) {
|
TEST(YogaTest, mixed_shared_and_owned_children) {
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
391
tests/YGStyleAccessorsTest.cpp
Normal file
391
tests/YGStyleAccessorsTest.cpp
Normal file
@@ -0,0 +1,391 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
* file in the root directory of this source tree.
|
||||||
|
*/
|
||||||
|
#include <cstdint>
|
||||||
|
#include <type_traits>
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
#include <yoga/YGEnums.h>
|
||||||
|
#include <yoga/YGStyle.h>
|
||||||
|
#include <yoga/YGValue.h>
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
using AssignedProps =
|
||||||
|
std::remove_reference<decltype(YGStyle{}.assignedProps())>::type;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
constexpr AssignedProps setBits(int from, int n) {
|
||||||
|
return n > 0 ? (setBits(from, n - 1) | AssignedProps{1ull << (from + n - 1)})
|
||||||
|
: 0;
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
#define ACCESSOR_TESTS_1(NAME, X) \
|
||||||
|
style.NAME() = X; \
|
||||||
|
ASSERT_EQ(style.NAME(), X); \
|
||||||
|
ASSERT_EQ(style.assignedProps(), AssignedProps{1ull << YGStyle::NAME##Bit});
|
||||||
|
#define ACCESSOR_TESTS_2(NAME, X, ...) \
|
||||||
|
ACCESSOR_TESTS_1(NAME, X); \
|
||||||
|
ACCESSOR_TESTS_1(NAME, __VA_ARGS__);
|
||||||
|
#define ACCESSOR_TESTS_3(NAME, X, ...) \
|
||||||
|
ACCESSOR_TESTS_1(NAME, X); \
|
||||||
|
ACCESSOR_TESTS_2(NAME, __VA_ARGS__);
|
||||||
|
#define ACCESSOR_TESTS_4(NAME, X, ...) \
|
||||||
|
ACCESSOR_TESTS_1(NAME, X); \
|
||||||
|
ACCESSOR_TESTS_3(NAME, __VA_ARGS__);
|
||||||
|
#define ACCESSOR_TESTS_5(NAME, X, ...) \
|
||||||
|
ACCESSOR_TESTS_1(NAME, X); \
|
||||||
|
ACCESSOR_TESTS_4(NAME, __VA_ARGS__)
|
||||||
|
|
||||||
|
#define ACCESSOR_TESTS_N(a, b, c, d, e, COUNT, ...) ACCESSOR_TESTS_##COUNT
|
||||||
|
#define ACCESSOR_TESTS(...) ACCESSOR_TESTS_N(__VA_ARGS__, 5, 4, 3, 2, 1)
|
||||||
|
|
||||||
|
#define INDEX_ACCESSOR_TESTS_1(NAME, IDX, X) \
|
||||||
|
{ \
|
||||||
|
auto style = YGStyle{}; \
|
||||||
|
style.NAME()[IDX] = X; \
|
||||||
|
ASSERT_EQ(style.NAME()[IDX], X); \
|
||||||
|
ASSERT_EQ( \
|
||||||
|
style.assignedProps(), \
|
||||||
|
AssignedProps{1ull << (YGStyle::NAME##Bit + IDX)}); \
|
||||||
|
auto asArray = decltype(std::declval<const YGStyle&>().NAME()){X}; \
|
||||||
|
style.NAME() = asArray; \
|
||||||
|
ASSERT_EQ(static_cast<decltype(asArray)>(style.NAME()), asArray); \
|
||||||
|
ASSERT_EQ( \
|
||||||
|
style.assignedProps(), \
|
||||||
|
AssignedProps{setBits( \
|
||||||
|
YGStyle::NAME##Bit, \
|
||||||
|
facebook::yoga::enums::count<decltype(IDX)>())}); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define INDEX_ACCESSOR_TESTS_2(NAME, IDX, X, Y) \
|
||||||
|
INDEX_ACCESSOR_TESTS_1(NAME, IDX, X) \
|
||||||
|
INDEX_ACCESSOR_TESTS_1(NAME, IDX, Y)
|
||||||
|
|
||||||
|
#define INDEX_ACCESSOR_TESTS_3(NAME, IDX, X, ...) \
|
||||||
|
INDEX_ACCESSOR_TESTS_1(NAME, IDX, X) \
|
||||||
|
INDEX_ACCESSOR_TESTS_2(NAME, IDX, __VA_ARGS__)
|
||||||
|
|
||||||
|
#define INDEX_ACCESSOR_TESTS_4(NAME, IDX, X, ...) \
|
||||||
|
INDEX_ACCESSOR_TESTS_1(NAME, IDX, X) \
|
||||||
|
INDEX_ACCESSOR_TESTS_3(NAME, IDX, __VA_ARGS__)
|
||||||
|
|
||||||
|
#define INDEX_ACCESSOR_TESTS_5(NAME, IDX, X, ...) \
|
||||||
|
INDEX_ACCESSOR_TESTS_1(NAME, IDX, X) \
|
||||||
|
INDEX_ACCESSOR_TESTS_4(NAME, IDX, __VA_ARGS__)
|
||||||
|
|
||||||
|
#define INDEX_ACCESSOR_TESTS_N(a, b, c, d, e, COUNT, ...) \
|
||||||
|
INDEX_ACCESSOR_TESTS_##COUNT
|
||||||
|
#define INDEX_ACCESSOR_TESTS(...) \
|
||||||
|
INDEX_ACCESSOR_TESTS_N(__VA_ARGS__, 5, 4, 3, 2, 1)
|
||||||
|
|
||||||
|
// test macro for up to 5 values. If more are needed, extend the macros above.
|
||||||
|
#define ACCESSOR_TEST(NAME, DEFAULT_VAL, ...) \
|
||||||
|
TEST(YGStyle, style_##NAME##_access) { \
|
||||||
|
auto style = YGStyle{}; \
|
||||||
|
ASSERT_EQ(style.NAME(), DEFAULT_VAL); \
|
||||||
|
ACCESSOR_TESTS(__VA_ARGS__)(NAME, __VA_ARGS__) \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define INDEX_ACCESSOR_TEST(NAME, DEFAULT_VAL, IDX, ...) \
|
||||||
|
TEST(YGStyle, style_##NAME##_access) { \
|
||||||
|
ASSERT_EQ(YGStyle{}.NAME()[IDX], DEFAULT_VAL); \
|
||||||
|
ASSERT_EQ(YGStyle{}.assignedProps(), 0); \
|
||||||
|
INDEX_ACCESSOR_TESTS(__VA_ARGS__)(NAME, IDX, __VA_ARGS__) \
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace facebook {
|
||||||
|
namespace yoga {
|
||||||
|
|
||||||
|
using CompactValue = detail::CompactValue;
|
||||||
|
|
||||||
|
ACCESSOR_TEST(
|
||||||
|
direction,
|
||||||
|
YGDirectionInherit,
|
||||||
|
YGDirectionLTR,
|
||||||
|
YGDirectionRTL,
|
||||||
|
YGDirectionInherit);
|
||||||
|
|
||||||
|
ACCESSOR_TEST(
|
||||||
|
flexDirection,
|
||||||
|
YGFlexDirectionColumn,
|
||||||
|
YGFlexDirectionColumnReverse,
|
||||||
|
YGFlexDirectionRowReverse,
|
||||||
|
YGFlexDirectionRow)
|
||||||
|
|
||||||
|
ACCESSOR_TEST(
|
||||||
|
justifyContent,
|
||||||
|
YGJustifyFlexStart,
|
||||||
|
YGJustifyFlexEnd,
|
||||||
|
YGJustifySpaceAround,
|
||||||
|
YGJustifyFlexStart,
|
||||||
|
YGJustifySpaceEvenly)
|
||||||
|
|
||||||
|
ACCESSOR_TEST(
|
||||||
|
alignContent,
|
||||||
|
YGAlignFlexStart,
|
||||||
|
YGAlignAuto,
|
||||||
|
YGAlignFlexStart,
|
||||||
|
YGAlignCenter,
|
||||||
|
YGAlignFlexEnd,
|
||||||
|
YGAlignStretch)
|
||||||
|
|
||||||
|
ACCESSOR_TEST(
|
||||||
|
alignItems,
|
||||||
|
YGAlignStretch,
|
||||||
|
YGAlignFlexStart,
|
||||||
|
YGAlignFlexEnd,
|
||||||
|
YGAlignBaseline,
|
||||||
|
YGAlignSpaceBetween,
|
||||||
|
YGAlignSpaceAround)
|
||||||
|
|
||||||
|
ACCESSOR_TEST(
|
||||||
|
alignSelf,
|
||||||
|
YGAlignAuto,
|
||||||
|
YGAlignFlexStart,
|
||||||
|
YGAlignCenter,
|
||||||
|
YGAlignAuto,
|
||||||
|
YGAlignFlexEnd,
|
||||||
|
YGAlignStretch)
|
||||||
|
|
||||||
|
ACCESSOR_TEST(
|
||||||
|
positionType,
|
||||||
|
YGPositionTypeRelative,
|
||||||
|
YGPositionTypeAbsolute,
|
||||||
|
YGPositionTypeRelative)
|
||||||
|
|
||||||
|
ACCESSOR_TEST(
|
||||||
|
flexWrap,
|
||||||
|
YGWrapNoWrap,
|
||||||
|
YGWrapWrap,
|
||||||
|
YGWrapWrapReverse,
|
||||||
|
YGWrapNoWrap)
|
||||||
|
|
||||||
|
ACCESSOR_TEST(
|
||||||
|
overflow,
|
||||||
|
YGOverflowVisible,
|
||||||
|
YGOverflowHidden,
|
||||||
|
YGOverflowScroll,
|
||||||
|
YGOverflowVisible)
|
||||||
|
|
||||||
|
ACCESSOR_TEST(display, YGDisplayFlex, YGDisplayNone, YGDisplayFlex)
|
||||||
|
|
||||||
|
ACCESSOR_TEST(
|
||||||
|
flex,
|
||||||
|
YGFloatOptional{},
|
||||||
|
YGFloatOptional{123.45f},
|
||||||
|
YGFloatOptional{-9.87f},
|
||||||
|
YGFloatOptional{})
|
||||||
|
|
||||||
|
ACCESSOR_TEST(
|
||||||
|
flexGrow,
|
||||||
|
YGFloatOptional{},
|
||||||
|
YGFloatOptional{123.45f},
|
||||||
|
YGFloatOptional{-9.87f},
|
||||||
|
YGFloatOptional{})
|
||||||
|
|
||||||
|
ACCESSOR_TEST(
|
||||||
|
flexShrink,
|
||||||
|
YGFloatOptional{},
|
||||||
|
YGFloatOptional{123.45f},
|
||||||
|
YGFloatOptional{-9.87f},
|
||||||
|
YGFloatOptional{})
|
||||||
|
|
||||||
|
ACCESSOR_TEST(
|
||||||
|
flexBasis,
|
||||||
|
CompactValue::ofAuto(),
|
||||||
|
CompactValue::ofUndefined(),
|
||||||
|
CompactValue::ofAuto(),
|
||||||
|
CompactValue::of<YGUnitPoint>(7777.77f),
|
||||||
|
CompactValue::of<YGUnitPercent>(-100.0f))
|
||||||
|
|
||||||
|
INDEX_ACCESSOR_TEST(
|
||||||
|
position,
|
||||||
|
CompactValue::ofUndefined(),
|
||||||
|
YGEdgeBottom,
|
||||||
|
CompactValue::ofAuto(),
|
||||||
|
CompactValue::ofUndefined(),
|
||||||
|
CompactValue::of<YGUnitPoint>(7777.77f),
|
||||||
|
CompactValue::of<YGUnitPercent>(-100.0f))
|
||||||
|
|
||||||
|
INDEX_ACCESSOR_TEST(
|
||||||
|
margin,
|
||||||
|
CompactValue::ofUndefined(),
|
||||||
|
YGEdgeTop,
|
||||||
|
CompactValue::ofAuto(),
|
||||||
|
CompactValue::ofUndefined(),
|
||||||
|
CompactValue::of<YGUnitPoint>(7777.77f),
|
||||||
|
CompactValue::of<YGUnitPercent>(-100.0f))
|
||||||
|
|
||||||
|
INDEX_ACCESSOR_TEST(
|
||||||
|
padding,
|
||||||
|
CompactValue::ofUndefined(),
|
||||||
|
YGEdgeAll,
|
||||||
|
CompactValue::of<YGUnitPoint>(7777.77f),
|
||||||
|
CompactValue::ofUndefined(),
|
||||||
|
CompactValue::of<YGUnitPercent>(-100.0f))
|
||||||
|
|
||||||
|
INDEX_ACCESSOR_TEST(
|
||||||
|
border,
|
||||||
|
CompactValue::ofUndefined(),
|
||||||
|
YGEdgeHorizontal,
|
||||||
|
CompactValue::of<YGUnitPoint>(-7777.77f),
|
||||||
|
CompactValue::ofUndefined())
|
||||||
|
|
||||||
|
INDEX_ACCESSOR_TEST(
|
||||||
|
dimensions,
|
||||||
|
CompactValue::ofAuto(),
|
||||||
|
YGDimensionWidth,
|
||||||
|
CompactValue::ofUndefined(),
|
||||||
|
CompactValue::ofAuto(),
|
||||||
|
CompactValue::of<YGUnitPoint>(7777.77f),
|
||||||
|
CompactValue::of<YGUnitPercent>(-100.0f))
|
||||||
|
|
||||||
|
INDEX_ACCESSOR_TEST(
|
||||||
|
minDimensions,
|
||||||
|
CompactValue::ofUndefined(),
|
||||||
|
YGDimensionHeight,
|
||||||
|
CompactValue::ofAuto(),
|
||||||
|
CompactValue::ofUndefined(),
|
||||||
|
CompactValue::of<YGUnitPoint>(7777.77f),
|
||||||
|
CompactValue::of<YGUnitPercent>(-100.0f))
|
||||||
|
|
||||||
|
INDEX_ACCESSOR_TEST(
|
||||||
|
maxDimensions,
|
||||||
|
CompactValue::ofUndefined(),
|
||||||
|
YGDimensionHeight,
|
||||||
|
CompactValue::ofAuto(),
|
||||||
|
CompactValue::ofUndefined(),
|
||||||
|
CompactValue::of<YGUnitPoint>(7777.77f),
|
||||||
|
CompactValue::of<YGUnitPercent>(-100.0f))
|
||||||
|
|
||||||
|
ACCESSOR_TEST(
|
||||||
|
aspectRatio,
|
||||||
|
YGFloatOptional{},
|
||||||
|
YGFloatOptional{-123.45f},
|
||||||
|
YGFloatOptional{9876.5f},
|
||||||
|
YGFloatOptional{0.0f},
|
||||||
|
YGFloatOptional{});
|
||||||
|
|
||||||
|
TEST(YGStyle, set_properties_default_to_0) {
|
||||||
|
ASSERT_EQ(YGStyle{}.assignedProps(), AssignedProps{0});
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(YGStyle, set_properties_reflects_all_set_properties) {
|
||||||
|
auto style = YGStyle{};
|
||||||
|
|
||||||
|
style.direction() = YGDirectionRTL;
|
||||||
|
style.justifyContent() = YGJustifySpaceAround;
|
||||||
|
style.flexWrap() = YGWrapWrap;
|
||||||
|
style.padding()[YGEdgeVertical] = YGValue{1, YGUnitPoint};
|
||||||
|
style.minDimensions()[YGDimensionHeight] = YGValue{1, YGUnitPercent};
|
||||||
|
style.aspectRatio() = YGFloatOptional{1.23};
|
||||||
|
|
||||||
|
ASSERT_EQ(
|
||||||
|
style.assignedProps(),
|
||||||
|
AssignedProps{1ull << YGStyle::directionBit |
|
||||||
|
1ull << YGStyle::justifyContentBit |
|
||||||
|
1ull << YGStyle::flexWrapBit |
|
||||||
|
1ull << (YGStyle::paddingBit + YGEdgeVertical) |
|
||||||
|
1ull << (YGStyle::minDimensionsBit + YGDimensionHeight) |
|
||||||
|
1ull << YGStyle::aspectRatioBit});
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(YGStyle, directionBit) {
|
||||||
|
constexpr auto directionBit = YGStyle::directionBit;
|
||||||
|
ASSERT_EQ(directionBit, 0);
|
||||||
|
}
|
||||||
|
TEST(YGStyle, flexDirectionBit) {
|
||||||
|
constexpr auto flexDirectionBit = YGStyle::flexDirectionBit;
|
||||||
|
ASSERT_EQ(flexDirectionBit, 1);
|
||||||
|
}
|
||||||
|
TEST(YGStyle, justifyContentBit) {
|
||||||
|
constexpr auto justifyContentBit = YGStyle::justifyContentBit;
|
||||||
|
ASSERT_EQ(justifyContentBit, 2);
|
||||||
|
}
|
||||||
|
TEST(YGStyle, alignContentBit) {
|
||||||
|
constexpr auto alignContentBit = YGStyle::alignContentBit;
|
||||||
|
ASSERT_EQ(alignContentBit, 3);
|
||||||
|
}
|
||||||
|
TEST(YGStyle, alignItemsBit) {
|
||||||
|
constexpr auto alignItemsBit = YGStyle::alignItemsBit;
|
||||||
|
ASSERT_EQ(alignItemsBit, 4);
|
||||||
|
}
|
||||||
|
TEST(YGStyle, alignSelfBit) {
|
||||||
|
constexpr auto alignSelfBit = YGStyle::alignSelfBit;
|
||||||
|
ASSERT_EQ(alignSelfBit, 5);
|
||||||
|
}
|
||||||
|
TEST(YGStyle, positionTypeBit) {
|
||||||
|
constexpr auto positionTypeBit = YGStyle::positionTypeBit;
|
||||||
|
ASSERT_EQ(positionTypeBit, 6);
|
||||||
|
}
|
||||||
|
TEST(YGStyle, flexWrapBit) {
|
||||||
|
constexpr auto flexWrapBit = YGStyle::flexWrapBit;
|
||||||
|
ASSERT_EQ(flexWrapBit, 7);
|
||||||
|
}
|
||||||
|
TEST(YGStyle, overflowBit) {
|
||||||
|
constexpr auto overflowBit = YGStyle::overflowBit;
|
||||||
|
ASSERT_EQ(overflowBit, 8);
|
||||||
|
}
|
||||||
|
TEST(YGStyle, displayBit) {
|
||||||
|
constexpr auto displayBit = YGStyle::displayBit;
|
||||||
|
ASSERT_EQ(displayBit, 9);
|
||||||
|
}
|
||||||
|
TEST(YGStyle, flexBit) {
|
||||||
|
constexpr auto flexBit = YGStyle::flexBit;
|
||||||
|
ASSERT_EQ(flexBit, 10);
|
||||||
|
}
|
||||||
|
TEST(YGStyle, flexGrowBit) {
|
||||||
|
constexpr auto flexGrowBit = YGStyle::flexGrowBit;
|
||||||
|
ASSERT_EQ(flexGrowBit, 11);
|
||||||
|
}
|
||||||
|
TEST(YGStyle, flexShrinkBit) {
|
||||||
|
constexpr auto flexShrinkBit = YGStyle::flexShrinkBit;
|
||||||
|
ASSERT_EQ(flexShrinkBit, 12);
|
||||||
|
}
|
||||||
|
TEST(YGStyle, flexBasisBit) {
|
||||||
|
constexpr auto flexBasisBit = YGStyle::flexBasisBit;
|
||||||
|
ASSERT_EQ(flexBasisBit, 13);
|
||||||
|
}
|
||||||
|
TEST(YGStyle, marginBit) {
|
||||||
|
constexpr auto marginBit = YGStyle::marginBit;
|
||||||
|
ASSERT_EQ(marginBit, 14);
|
||||||
|
}
|
||||||
|
TEST(YGStyle, positionBit) {
|
||||||
|
constexpr auto positionBit = YGStyle::positionBit;
|
||||||
|
ASSERT_EQ(positionBit, 23);
|
||||||
|
}
|
||||||
|
TEST(YGStyle, paddingBit) {
|
||||||
|
constexpr auto paddingBit = YGStyle::paddingBit;
|
||||||
|
ASSERT_EQ(paddingBit, 32);
|
||||||
|
}
|
||||||
|
TEST(YGStyle, borderBit) {
|
||||||
|
constexpr auto borderBit = YGStyle::borderBit;
|
||||||
|
ASSERT_EQ(borderBit, 41);
|
||||||
|
}
|
||||||
|
TEST(YGStyle, dimensionsBit) {
|
||||||
|
constexpr auto dimensionsBit = YGStyle::dimensionsBit;
|
||||||
|
ASSERT_EQ(dimensionsBit, 50);
|
||||||
|
}
|
||||||
|
TEST(YGStyle, maxDimensionsBit) {
|
||||||
|
constexpr auto maxDimensionsBit = YGStyle::maxDimensionsBit;
|
||||||
|
ASSERT_EQ(maxDimensionsBit, 52);
|
||||||
|
}
|
||||||
|
TEST(YGStyle, minDimensionsBit) {
|
||||||
|
constexpr auto minDimensionsBit = YGStyle::minDimensionsBit;
|
||||||
|
ASSERT_EQ(minDimensionsBit, 54);
|
||||||
|
}
|
||||||
|
TEST(YGStyle, aspectRatioBit) {
|
||||||
|
constexpr auto aspectRatioBit = YGStyle::aspectRatioBit;
|
||||||
|
ASSERT_EQ(aspectRatioBit, 56);
|
||||||
|
}
|
||||||
|
TEST(YGStyle, numStyles) {
|
||||||
|
constexpr auto numStyles = YGStyle::numStyles;
|
||||||
|
ASSERT_EQ(numStyles, 57);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace yoga
|
||||||
|
} // namespace facebook
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
37
testutil/BUCK
Normal file
37
testutil/BUCK
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
load("//tools/build_defs/oss:yoga_defs.bzl", "ANDROID", "FBJNI_TARGET", "LIBRARY_COMPILER_FLAGS", "SOLOADER_TARGET", "yoga_cxx_library", "yoga_dep", "yoga_java_library")
|
||||||
|
|
||||||
|
yoga_cxx_library(
|
||||||
|
name = "testutil",
|
||||||
|
srcs = ["testutil.cpp"],
|
||||||
|
header_namespace = "yoga/testutil",
|
||||||
|
exported_headers = ["testutil.h"],
|
||||||
|
compiler_flags = LIBRARY_COMPILER_FLAGS,
|
||||||
|
soname = "libyoga_testutil.$(ext)",
|
||||||
|
visibility = ["PUBLIC"],
|
||||||
|
deps = [yoga_dep(":yoga")],
|
||||||
|
)
|
||||||
|
|
||||||
|
yoga_java_library(
|
||||||
|
name = "java",
|
||||||
|
srcs = ["TestUtil.java"],
|
||||||
|
source = "1.7",
|
||||||
|
target = "1.7",
|
||||||
|
visibility = ["PUBLIC"],
|
||||||
|
deps = [
|
||||||
|
":jni",
|
||||||
|
SOLOADER_TARGET,
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
yoga_cxx_library(
|
||||||
|
name = "jni",
|
||||||
|
srcs = ["jni.cpp"],
|
||||||
|
compiler_flags = LIBRARY_COMPILER_FLAGS,
|
||||||
|
platforms = ANDROID,
|
||||||
|
soname = "libyoga_testutil_jni.$(ext)",
|
||||||
|
visibility = ["PUBLIC"],
|
||||||
|
deps = [
|
||||||
|
":testutil",
|
||||||
|
FBJNI_TARGET,
|
||||||
|
],
|
||||||
|
)
|
19
testutil/TestUtil.java
Normal file
19
testutil/TestUtil.java
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
* file in the root directory of this source tree.
|
||||||
|
*/
|
||||||
|
package com.facebook.yoga;
|
||||||
|
|
||||||
|
import com.facebook.soloader.SoLoader;
|
||||||
|
|
||||||
|
class TestUtil {
|
||||||
|
static {
|
||||||
|
SoLoader.loadLibrary("yoga_testutil_jni");
|
||||||
|
}
|
||||||
|
|
||||||
|
static native void startCountingNodes();
|
||||||
|
static native int nodeCount();
|
||||||
|
static native int stopCountingNodes();
|
||||||
|
}
|
38
testutil/jni.cpp
Normal file
38
testutil/jni.cpp
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
* file in the root directory of this source tree.
|
||||||
|
*/
|
||||||
|
#include <fb/fbjni.h>
|
||||||
|
#include <yoga/testutil/testutil.h>
|
||||||
|
|
||||||
|
using namespace facebook;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
void startCountingNodes(jni::alias_ref<jclass>) {
|
||||||
|
yoga::test::TestUtil::startCountingNodes();
|
||||||
|
}
|
||||||
|
|
||||||
|
jint nodeCount(jni::alias_ref<jclass>) {
|
||||||
|
return yoga::test::TestUtil::nodeCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
jint stopCountingNodes(jni::alias_ref<jclass>) {
|
||||||
|
return yoga::test::TestUtil::stopCountingNodes();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
jint JNI_OnLoad(JavaVM* vm, void*) {
|
||||||
|
return jni::initialize(vm, [] {
|
||||||
|
jni::registerNatives(
|
||||||
|
"com/facebook/yoga/TestUtil",
|
||||||
|
{
|
||||||
|
makeNativeMethod("startCountingNodes", startCountingNodes),
|
||||||
|
makeNativeMethod("nodeCount", nodeCount),
|
||||||
|
makeNativeMethod("stopCountingNodes", stopCountingNodes),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
65
testutil/testutil.cpp
Normal file
65
testutil/testutil.cpp
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
* file in the root directory of this source tree.
|
||||||
|
*/
|
||||||
|
#include "testutil.h"
|
||||||
|
|
||||||
|
#include <yoga/YGNode.h>
|
||||||
|
#include <yoga/event/event.h>
|
||||||
|
|
||||||
|
namespace facebook {
|
||||||
|
namespace yoga {
|
||||||
|
namespace test {
|
||||||
|
|
||||||
|
int nodeInstanceCount = 0;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
void yogaEventSubscriber(
|
||||||
|
const YGNode& node,
|
||||||
|
Event::Type eventType,
|
||||||
|
const Event::Data& eventData) {
|
||||||
|
|
||||||
|
switch (eventType) {
|
||||||
|
case Event::NodeAllocation:
|
||||||
|
nodeInstanceCount++;
|
||||||
|
break;
|
||||||
|
case Event::NodeDeallocation:
|
||||||
|
nodeInstanceCount--;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
void TestUtil::startCountingNodes() {
|
||||||
|
nodeInstanceCount = 0;
|
||||||
|
Event::subscribe(yogaEventSubscriber);
|
||||||
|
}
|
||||||
|
|
||||||
|
int TestUtil::nodeCount() {
|
||||||
|
return nodeInstanceCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
int TestUtil::stopCountingNodes() {
|
||||||
|
Event::reset();
|
||||||
|
auto prev = nodeInstanceCount;
|
||||||
|
nodeInstanceCount = 0;
|
||||||
|
return prev;
|
||||||
|
}
|
||||||
|
|
||||||
|
ScopedEventSubscription::ScopedEventSubscription(
|
||||||
|
std::function<Event::Subscriber>&& s) {
|
||||||
|
Event::subscribe(std::move(s));
|
||||||
|
}
|
||||||
|
|
||||||
|
ScopedEventSubscription::~ScopedEventSubscription() {
|
||||||
|
Event::reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace test
|
||||||
|
} // namespace yoga
|
||||||
|
} // namespace facebook
|
30
testutil/testutil.h
Normal file
30
testutil/testutil.h
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
* file in the root directory of this source tree.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <yoga/event/event.h>
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
|
namespace facebook {
|
||||||
|
namespace yoga {
|
||||||
|
namespace test {
|
||||||
|
|
||||||
|
struct TestUtil {
|
||||||
|
static void startCountingNodes();
|
||||||
|
static int nodeCount();
|
||||||
|
static int stopCountingNodes();
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ScopedEventSubscription {
|
||||||
|
ScopedEventSubscription(std::function<Event::Subscriber>&&);
|
||||||
|
~ScopedEventSubscription();
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace test
|
||||||
|
} // namespace yoga
|
||||||
|
} // namespace facebook
|
@@ -58,6 +58,7 @@ BASE_COMPILER_FLAGS = [
|
|||||||
"-Wall",
|
"-Wall",
|
||||||
"-Werror",
|
"-Werror",
|
||||||
"-O2",
|
"-O2",
|
||||||
|
"-std=c++11",
|
||||||
]
|
]
|
||||||
|
|
||||||
LIBRARY_COMPILER_FLAGS = BASE_COMPILER_FLAGS + [
|
LIBRARY_COMPILER_FLAGS = BASE_COMPILER_FLAGS + [
|
||||||
@@ -148,6 +149,9 @@ def _single_subdir_glob(dirpath, glob_pattern, exclude = None, prefix = None):
|
|||||||
def yoga_dep(dep):
|
def yoga_dep(dep):
|
||||||
return "//" + dep
|
return "//" + dep
|
||||||
|
|
||||||
|
def yoga_cxx_lib(lib):
|
||||||
|
return yoga_dep(lib)
|
||||||
|
|
||||||
def yoga_android_aar(*args, **kwargs):
|
def yoga_android_aar(*args, **kwargs):
|
||||||
native.android_aar(*args, **kwargs)
|
native.android_aar(*args, **kwargs)
|
||||||
|
|
||||||
|
30
util/BUCK
Normal file
30
util/BUCK
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
# Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
|
#
|
||||||
|
# This source code is licensed under the MIT license found in the
|
||||||
|
# LICENSE file in the root directory of this source tree.
|
||||||
|
load("//tools/build_defs/oss:yoga_defs.bzl", "GTEST_TARGET", "LIBRARY_COMPILER_FLAGS", "yoga_cxx_library", "yoga_cxx_test")
|
||||||
|
|
||||||
|
_TESTS = glob(["*Test.cpp"])
|
||||||
|
|
||||||
|
yoga_cxx_library(
|
||||||
|
name = "util",
|
||||||
|
srcs = glob(
|
||||||
|
["*.cpp"],
|
||||||
|
exclude = _TESTS,
|
||||||
|
),
|
||||||
|
header_namespace = "yoga/util",
|
||||||
|
exported_headers = glob(["*.h"]),
|
||||||
|
compiler_flags = LIBRARY_COMPILER_FLAGS,
|
||||||
|
tests = [":test"],
|
||||||
|
visibility = ["PUBLIC"],
|
||||||
|
)
|
||||||
|
|
||||||
|
yoga_cxx_test(
|
||||||
|
name = "test",
|
||||||
|
srcs = _TESTS,
|
||||||
|
compiler_flags = LIBRARY_COMPILER_FLAGS,
|
||||||
|
deps = [
|
||||||
|
":util",
|
||||||
|
GTEST_TARGET,
|
||||||
|
],
|
||||||
|
)
|
32
util/SingleWriterValueList.cpp
Normal file
32
util/SingleWriterValueList.cpp
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
* file in the root directory of this source tree.
|
||||||
|
*/
|
||||||
|
#include "SingleWriterValueList.h"
|
||||||
|
|
||||||
|
namespace facebook {
|
||||||
|
namespace yoga {
|
||||||
|
namespace detail {
|
||||||
|
|
||||||
|
void* FreeList::getRaw() {
|
||||||
|
if (free_.size() == 0)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
auto ptr = free_.top();
|
||||||
|
free_.pop();
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FreeList::put(std::mutex& mutex, void* ptr) {
|
||||||
|
std::lock_guard<std::mutex> lock{mutex};
|
||||||
|
free_.push(ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
FreeList::FreeList() = default;
|
||||||
|
FreeList::~FreeList() = default;
|
||||||
|
|
||||||
|
} // namespace detail
|
||||||
|
} // namespace yoga
|
||||||
|
} // namespace facebook
|
136
util/SingleWriterValueList.h
Normal file
136
util/SingleWriterValueList.h
Normal file
@@ -0,0 +1,136 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
* file in the root directory of this source tree.
|
||||||
|
*/
|
||||||
|
#include <forward_list>
|
||||||
|
#include <memory>
|
||||||
|
#include <mutex>
|
||||||
|
#include <stack>
|
||||||
|
#include <type_traits>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
namespace facebook {
|
||||||
|
namespace yoga {
|
||||||
|
|
||||||
|
namespace detail {
|
||||||
|
|
||||||
|
class FreeList {
|
||||||
|
std::stack<void*> free_;
|
||||||
|
void* getRaw();
|
||||||
|
|
||||||
|
public:
|
||||||
|
FreeList();
|
||||||
|
~FreeList();
|
||||||
|
|
||||||
|
void put(std::mutex&, void*);
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
T* get() {
|
||||||
|
return static_cast<T*>(getRaw());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace detail
|
||||||
|
|
||||||
|
/// SingleWriterValueList is a data structure that holds a list of values. Each
|
||||||
|
/// value can be borrowed for exclusive writing, and will not be exposed to
|
||||||
|
/// another borrower until returned.
|
||||||
|
/// Additionaly, the whole list of values can be accessed for reading via const
|
||||||
|
/// iterators. Read consistency depends on CPU internals, i.e. whether values
|
||||||
|
/// are written to memory atomically.
|
||||||
|
///
|
||||||
|
/// A typical usage scenario would be a set of threads, where each thread
|
||||||
|
/// borrows a value for lock free writing, e.g. as a thread local variable. This
|
||||||
|
/// avoids the usage of atomics, or locking of shared memory, which both can
|
||||||
|
/// lead to increased latency due to CPU cache flushes and waits.
|
||||||
|
///
|
||||||
|
/// Values are heap allocated (via forward_list), which typically will avoid
|
||||||
|
/// multiple values being allocated in the same CPU cache line, which would also
|
||||||
|
/// lead to cache flushing.
|
||||||
|
///
|
||||||
|
/// SingleWriterValueList never deallocates, to guarantee the validity of
|
||||||
|
/// references and iterators. However, memory returned by a borrower can be
|
||||||
|
/// borrowed again.
|
||||||
|
///
|
||||||
|
/// SingleWriterValueList supports return policies as second template parameter,
|
||||||
|
/// i.e. an optional mutation of values after a borrower returns them. The
|
||||||
|
/// default policy is to do nothing. SingleWriterValueList::resetPolicy is a
|
||||||
|
/// convenience method that will move assign the default value of a type.
|
||||||
|
///
|
||||||
|
/// Example:
|
||||||
|
///
|
||||||
|
/// static SingleWriterValueList<int> counters;
|
||||||
|
/// thread_local auto localCounter = counters.borrow();
|
||||||
|
///
|
||||||
|
/// /* per thread */
|
||||||
|
/// localCounter =+ n;
|
||||||
|
///
|
||||||
|
/// /* anywhere */
|
||||||
|
/// std::accumulate(counters.begin(), counters.end(), 0);
|
||||||
|
///
|
||||||
|
template <typename T, void (*ReturnPolicy)(T&) = nullptr>
|
||||||
|
class SingleWriterValueList {
|
||||||
|
std::forward_list<T> values_{};
|
||||||
|
std::mutex acquireMutex_{};
|
||||||
|
detail::FreeList freeValuesList_{};
|
||||||
|
|
||||||
|
T* allocValue() {
|
||||||
|
values_.emplace_front();
|
||||||
|
return &values_.front();
|
||||||
|
}
|
||||||
|
|
||||||
|
void returnRef(T* value) {
|
||||||
|
if (ReturnPolicy != nullptr) {
|
||||||
|
ReturnPolicy(*value);
|
||||||
|
}
|
||||||
|
freeValuesList_.put(acquireMutex_, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
using const_iterator = decltype(values_.cbegin());
|
||||||
|
|
||||||
|
/// RAII representation of a single value, borrowed for exclusive writing.
|
||||||
|
/// Instances cannot be copied, and will return the borrowed value to the
|
||||||
|
/// owner upon destruction.
|
||||||
|
class Borrowed {
|
||||||
|
T* value_;
|
||||||
|
SingleWriterValueList* owner_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Borrowed(T* value, SingleWriterValueList* owner)
|
||||||
|
: value_{value}, owner_{owner} {}
|
||||||
|
~Borrowed() {
|
||||||
|
if (owner_ != nullptr && value_ != nullptr) {
|
||||||
|
owner_->returnRef(value_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Borrowed(Borrowed&& other) = default;
|
||||||
|
Borrowed& operator=(Borrowed&& other) = default;
|
||||||
|
|
||||||
|
// no copies allowed
|
||||||
|
Borrowed(const Borrowed&) = delete;
|
||||||
|
Borrowed& operator=(const Borrowed&) = delete;
|
||||||
|
|
||||||
|
T& get() { return *value_; }
|
||||||
|
T& operator*() { return get(); }
|
||||||
|
};
|
||||||
|
|
||||||
|
Borrowed borrow() {
|
||||||
|
std::lock_guard<std::mutex> lock{acquireMutex_};
|
||||||
|
T* value = freeValuesList_.get<T>();
|
||||||
|
return {value != nullptr ? value : allocValue(), this};
|
||||||
|
}
|
||||||
|
|
||||||
|
const_iterator cbegin() const { return values_.cbegin(); };
|
||||||
|
const_iterator cend() const { return values_.cend(); };
|
||||||
|
const_iterator begin() const { return cbegin(); };
|
||||||
|
const_iterator end() const { return cend(); };
|
||||||
|
|
||||||
|
static void resetPolicy(T& value) { value = std::move(T{}); }
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace yoga
|
||||||
|
} // namespace facebook
|
163
util/SingleWriterValueListTest.cpp
Normal file
163
util/SingleWriterValueListTest.cpp
Normal file
@@ -0,0 +1,163 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
* file in the root directory of this source tree.
|
||||||
|
*/
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
#include <yoga/util/SingleWriterValueList.h>
|
||||||
|
|
||||||
|
#include <numeric>
|
||||||
|
#include <type_traits>
|
||||||
|
#include <unordered_set>
|
||||||
|
|
||||||
|
namespace facebook {
|
||||||
|
namespace yoga {
|
||||||
|
|
||||||
|
static_assert(
|
||||||
|
!std::is_copy_constructible<SingleWriterValueList<int>>::value,
|
||||||
|
"SingleWriterValueList must not be copyable");
|
||||||
|
static_assert(
|
||||||
|
!std::is_copy_assignable<SingleWriterValueList<int>>::value,
|
||||||
|
"SingleWriterValueList must not be copyable");
|
||||||
|
static_assert(
|
||||||
|
!std::is_copy_constructible<SingleWriterValueList<int>::Borrowed>::value,
|
||||||
|
"SingleWriterValueList::Borrowed must not be copyable");
|
||||||
|
static_assert(
|
||||||
|
!std::is_copy_assignable<SingleWriterValueList<int>::Borrowed>::value,
|
||||||
|
"SingleWriterValueList::Borrowed must not be copyable");
|
||||||
|
static_assert(
|
||||||
|
std::is_move_constructible<SingleWriterValueList<int>::Borrowed>::value,
|
||||||
|
"SingleWriterValueList::Borrowed must be movable");
|
||||||
|
static_assert(
|
||||||
|
std::is_move_assignable<SingleWriterValueList<int>::Borrowed>::value,
|
||||||
|
"SingleWriterValueList::Borrowed must be movable");
|
||||||
|
|
||||||
|
TEST(SingleWriterValueList, borrowsAreExclusive) {
|
||||||
|
SingleWriterValueList<int> x{};
|
||||||
|
|
||||||
|
auto a = x.borrow();
|
||||||
|
auto b = x.borrow();
|
||||||
|
|
||||||
|
ASSERT_NE(&a.get(), &b.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(SingleWriterValueList, borrowsSupportDereference) {
|
||||||
|
SingleWriterValueList<int> x{};
|
||||||
|
|
||||||
|
auto a = x.borrow();
|
||||||
|
*a = 123;
|
||||||
|
|
||||||
|
ASSERT_EQ(*a, 123);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(SingleWriterValueList, borrowsHaveGetMethod) {
|
||||||
|
SingleWriterValueList<int> x{};
|
||||||
|
|
||||||
|
auto a = x.borrow();
|
||||||
|
a.get() = 123;
|
||||||
|
|
||||||
|
ASSERT_EQ(a.get(), 123);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(SingleWriterValueList, exposesBorrowsViaIterator) {
|
||||||
|
SingleWriterValueList<int> x{};
|
||||||
|
|
||||||
|
auto a = x.borrow();
|
||||||
|
auto b = x.borrow();
|
||||||
|
|
||||||
|
*a = 12;
|
||||||
|
*b = 34;
|
||||||
|
|
||||||
|
int sum = 0;
|
||||||
|
for (auto& i : x) {
|
||||||
|
sum += i;
|
||||||
|
}
|
||||||
|
ASSERT_EQ(sum, 12 + 34);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(SingleWriterValueList, exposesBorrowsViaConstIterator) {
|
||||||
|
SingleWriterValueList<int> x{};
|
||||||
|
|
||||||
|
auto a = x.borrow();
|
||||||
|
auto b = x.borrow();
|
||||||
|
|
||||||
|
*a = 12;
|
||||||
|
*b = 34;
|
||||||
|
|
||||||
|
ASSERT_EQ(std::accumulate(x.cbegin(), x.cend(), 0), 12 + 34);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(SingleWriterValueList, doesNotDeallocateReturnedBorrows) {
|
||||||
|
SingleWriterValueList<int> x{};
|
||||||
|
|
||||||
|
std::unordered_set<const int*> values;
|
||||||
|
{
|
||||||
|
auto a = x.borrow();
|
||||||
|
auto b = x.borrow();
|
||||||
|
values.insert(&a.get());
|
||||||
|
values.insert(&b.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
auto it = x.begin();
|
||||||
|
|
||||||
|
ASSERT_NE(it, x.end());
|
||||||
|
ASSERT_NE(values.find(&*it), values.end());
|
||||||
|
|
||||||
|
ASSERT_NE(++it, x.end());
|
||||||
|
ASSERT_NE(values.find(&*it), values.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(SingleWriterValueList, reusesReturnedBorrows) {
|
||||||
|
SingleWriterValueList<int> x{};
|
||||||
|
|
||||||
|
int* firstBorrow;
|
||||||
|
{
|
||||||
|
auto a = x.borrow();
|
||||||
|
firstBorrow = &a.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
auto b = x.borrow();
|
||||||
|
|
||||||
|
ASSERT_EQ(&b.get(), firstBorrow);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(SingleWriterValueList, keepsValuesAfterReturning) {
|
||||||
|
SingleWriterValueList<int> x{};
|
||||||
|
|
||||||
|
{
|
||||||
|
auto a = x.borrow();
|
||||||
|
*a = 123;
|
||||||
|
}
|
||||||
|
|
||||||
|
ASSERT_EQ(*x.begin(), 123);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void addOne(int& v) {
|
||||||
|
v += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(SingleWriterValueList, allowsCustomReturnPolicy) {
|
||||||
|
SingleWriterValueList<int, addOne> x{};
|
||||||
|
|
||||||
|
{
|
||||||
|
auto a = x.borrow();
|
||||||
|
*a = 123;
|
||||||
|
}
|
||||||
|
|
||||||
|
ASSERT_EQ(*x.begin(), 124);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(SingleWriterValueList, hasConvenienceResetPolicy) {
|
||||||
|
SingleWriterValueList<int, SingleWriterValueList<int>::resetPolicy> x{};
|
||||||
|
|
||||||
|
{
|
||||||
|
auto a = x.borrow();
|
||||||
|
*a = 123;
|
||||||
|
}
|
||||||
|
|
||||||
|
ASSERT_EQ(*x.begin(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace yoga
|
||||||
|
} // namespace facebook
|
@@ -32,6 +32,6 @@
|
|||||||
"develop": "gatsby develop"
|
"develop": "gatsby develop"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"prettier": "1.16.4"
|
"prettier": "1.17.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -6978,10 +6978,10 @@ preserve@^0.2.0:
|
|||||||
version "0.2.0"
|
version "0.2.0"
|
||||||
resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b"
|
resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b"
|
||||||
|
|
||||||
prettier@1.16.4:
|
prettier@1.17.0:
|
||||||
version "1.16.4"
|
version "1.17.0"
|
||||||
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.16.4.tgz#73e37e73e018ad2db9c76742e2647e21790c9717"
|
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.17.0.tgz#53b303676eed22cc14a9f0cec09b477b3026c008"
|
||||||
integrity sha512-ZzWuos7TI5CKUeQAtFd6Zhm2s6EpAD/ZLApIhsF9pRvRtM1RFo61dM/4MSRUA0SuLugA/zgrZD8m0BaY46Og7g==
|
integrity sha512-sXe5lSt2WQlCbydGETgfm1YBShgOX4HxQkFPvbxkcwgDvGDeqVau8h+12+lmSVlP3rHPz0oavfddSZg/q+Szjw==
|
||||||
|
|
||||||
pretty-bytes@^4.0.2:
|
pretty-bytes@^4.0.2:
|
||||||
version "4.0.2"
|
version "4.0.2"
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user