More readable instrumentation test
Summary: @public Evolves setup and helpers in `InstrumentationTest` to avoid repetition across test cases, and allow for more readable test by hiding default values where they don’t matter. Reviewed By: SidharthGuglani Differential Revision: D13839521 fbshipit-source-id: 7f7ad49fec84e0bbb09ad746dd8c28bd34de25b2
This commit is contained in:
committed by
Facebook Github Bot
parent
cbea5d44b8
commit
460370b7d3
@@ -14,6 +14,9 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
|
||||||
|
bool operator==(const YGMarkerLayoutData&, const YGMarkerLayoutData&);
|
||||||
|
void PrintTo(const YGMarkerLayoutData, std::ostream*);
|
||||||
|
|
||||||
namespace facebook {
|
namespace facebook {
|
||||||
namespace yoga {
|
namespace yoga {
|
||||||
namespace marker {
|
namespace marker {
|
||||||
@@ -44,16 +47,19 @@ struct MarkerTest : public ::testing::Test {
|
|||||||
|
|
||||||
static void* startMarker(YGMarker, YGNodeRef, YGMarkerData);
|
static void* startMarker(YGMarker, YGNodeRef, YGMarkerData);
|
||||||
static void endMarker(YGMarker, YGNodeRef, YGMarkerData, void*);
|
static void endMarker(YGMarker, YGNodeRef, YGMarkerData, void*);
|
||||||
static uniquePtr<YGConfig> makeConfig();
|
uniquePtr<YGNode> makeNode();
|
||||||
static uniquePtr<YGNode> makeNode(uniquePtr<YGConfig>&);
|
uniquePtr<YGNode> addChild(uniquePtr<YGNode>& owner);
|
||||||
static uniquePtr<YGNode> makeNode(uniquePtr<YGConfig>&, uniquePtr<YGNode>&);
|
static void calculateLayout(
|
||||||
|
uniquePtr<YGNode>& node,
|
||||||
|
float width = YGUndefined,
|
||||||
|
float height = YGUndefined);
|
||||||
|
|
||||||
void SetUp() override;
|
void SetUp() override;
|
||||||
|
uniquePtr<YGConfig> config;
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(MarkerTest, marker_start_works) {
|
TEST_F(MarkerTest, marker_start_works) {
|
||||||
auto config = makeConfig();
|
auto root = makeNode();
|
||||||
auto root = makeNode(config);
|
|
||||||
|
|
||||||
decltype(MarkerSection<YGMarkerLayout>::data)* dataAddress;
|
decltype(MarkerSection<YGMarkerLayout>::data)* dataAddress;
|
||||||
{
|
{
|
||||||
@@ -70,8 +76,7 @@ TEST_F(MarkerTest, marker_start_works) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MarkerTest, marker_end_works) {
|
TEST_F(MarkerTest, marker_end_works) {
|
||||||
auto config = makeConfig();
|
auto root = makeNode();
|
||||||
auto root = makeNode(config);
|
|
||||||
|
|
||||||
{ MarkerSection<YGMarkerLayout> marker{root.get()}; }
|
{ MarkerSection<YGMarkerLayout> marker{root.get()}; }
|
||||||
|
|
||||||
@@ -90,35 +95,34 @@ TEST_F(MarkerTest, marker_end_works) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MarkerTest, layout_marker) {
|
TEST_F(MarkerTest, layout_marker) {
|
||||||
auto config = makeConfig();
|
auto root = makeNode();
|
||||||
auto root = makeNode(config);
|
|
||||||
|
|
||||||
YGNodeCalculateLayout(root.get(), YGUndefined, YGUndefined, YGDirectionLTR);
|
calculateLayout(root);
|
||||||
|
|
||||||
ASSERT_EQ(markerCookie.start.marker, YGMarkerLayout);
|
ASSERT_EQ(markerCookie.start.marker, YGMarkerLayout);
|
||||||
ASSERT_EQ(markerCookie.start.node, root.get());
|
ASSERT_EQ(markerCookie.start.node, root.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MarkerTest, layout_marker_counts_single_node_layout) {
|
TEST_F(MarkerTest, layout_marker_counts_single_node_layout) {
|
||||||
auto config = makeConfig();
|
auto root = makeNode();
|
||||||
auto root = makeNode(config);
|
|
||||||
|
|
||||||
YGNodeCalculateLayout(root.get(), YGUndefined, YGUndefined, YGDirectionLTR);
|
calculateLayout(root);
|
||||||
|
|
||||||
ASSERT_EQ(markerCookie.end.markerData.layout.layouts, 1);
|
ASSERT_EQ(
|
||||||
ASSERT_EQ(markerCookie.end.markerData.layout.measures, 0);
|
markerCookie.end.markerData.layout,
|
||||||
|
(YGMarkerLayoutData{.layouts = 1, .measures = 0}));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MarkerTest, layout_marker_counts_multi_node_layout) {
|
TEST_F(MarkerTest, layout_marker_counts_multi_node_layout) {
|
||||||
auto config = makeConfig();
|
auto root = makeNode();
|
||||||
auto root = makeNode(config);
|
auto childA = addChild(root);
|
||||||
auto childA = makeNode(config, root);
|
auto childB = addChild(root);
|
||||||
auto childB = makeNode(config, root);
|
|
||||||
|
|
||||||
YGNodeCalculateLayout(root.get(), YGUndefined, YGUndefined, YGDirectionLTR);
|
calculateLayout(root);
|
||||||
|
|
||||||
ASSERT_EQ(markerCookie.end.markerData.layout.layouts, 3);
|
ASSERT_EQ(
|
||||||
ASSERT_EQ(markerCookie.end.markerData.layout.measures, 4);
|
markerCookie.end.markerData.layout,
|
||||||
|
(YGMarkerLayoutData{.layouts = 3, .measures = 4}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void* MarkerTest::startMarker(
|
void* MarkerTest::startMarker(
|
||||||
@@ -142,27 +146,29 @@ void MarkerTest::endMarker(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
uniquePtr<YGConfig> MarkerTest::makeConfig() {
|
uniquePtr<YGNode> MarkerTest::makeNode() {
|
||||||
auto c = uniquePtr<YGConfig>{YGConfigNew(), &YGConfigFree};
|
|
||||||
YGConfigSetMarkerCallbacks(c.get(), {startMarker, endMarker});
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
|
|
||||||
uniquePtr<YGNode> MarkerTest::makeNode(uniquePtr<YGConfig>& config) {
|
|
||||||
auto n = uniquePtr<YGNode>{YGNodeNewWithConfig(config.get()), &YGNodeFree};
|
auto n = uniquePtr<YGNode>{YGNodeNewWithConfig(config.get()), &YGNodeFree};
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
uniquePtr<YGNode> MarkerTest::makeNode(
|
uniquePtr<YGNode> MarkerTest::addChild(uniquePtr<YGNode>& owner) {
|
||||||
uniquePtr<YGConfig>& config,
|
auto n = makeNode();
|
||||||
uniquePtr<YGNode>& owner) {
|
|
||||||
auto n = makeNode(config);
|
|
||||||
YGNodeInsertChild(owner.get(), n.get(), YGNodeGetChildCount(owner.get()));
|
YGNodeInsertChild(owner.get(), n.get(), YGNodeGetChildCount(owner.get()));
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MarkerTest::calculateLayout(
|
||||||
|
uniquePtr<YGNode>& node,
|
||||||
|
float width,
|
||||||
|
float height) {
|
||||||
|
YGNodeCalculateLayout(node.get(), width, height, YGDirectionLTR);
|
||||||
|
}
|
||||||
|
|
||||||
void MarkerTest::SetUp() {
|
void MarkerTest::SetUp() {
|
||||||
markerCookie = {};
|
markerCookie = {};
|
||||||
|
|
||||||
|
config = uniquePtr<YGConfig>{YGConfigNew(), &YGConfigFree};
|
||||||
|
YGConfigSetMarkerCallbacks(config.get(), {startMarker, endMarker});
|
||||||
}
|
}
|
||||||
|
|
||||||
decltype(MarkerTest::markerCookie) MarkerTest::markerCookie = {};
|
decltype(MarkerTest::markerCookie) MarkerTest::markerCookie = {};
|
||||||
@@ -171,3 +177,12 @@ decltype(MarkerTest::markerCookie) MarkerTest::markerCookie = {};
|
|||||||
} // namespace marker
|
} // namespace marker
|
||||||
} // namespace yoga
|
} // namespace yoga
|
||||||
} // namespace facebook
|
} // namespace facebook
|
||||||
|
|
||||||
|
bool operator==(const YGMarkerLayoutData& lhs, const YGMarkerLayoutData& rhs) {
|
||||||
|
return lhs.layouts == rhs.layouts && lhs.measures == rhs.measures;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PrintTo(const YGMarkerLayoutData data, std::ostream* os) {
|
||||||
|
*os << "YGMarkerLayoutData{ layouts = " << data.layouts
|
||||||
|
<< ", measures = " << data.measures << " }";
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user