/* * 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 #include #include #include #include #include #include #include using namespace facebook::react; TEST(traitCastTest, testOne) { auto builder = simpleComponentBuilder(); auto viewShadowNode = std::shared_ptr{}; auto scrollViewShadowNode = std::shared_ptr{}; auto paragraphShadowNode = std::shared_ptr{}; auto textShadowNode = std::shared_ptr{}; auto rawTextShadowNode = std::shared_ptr{}; // clang-format off auto element = Element() .reference(scrollViewShadowNode) .children({ Element() .reference(paragraphShadowNode) .children({ Element() .reference(textShadowNode), Element() .reference(rawTextShadowNode) }), Element() .reference(viewShadowNode), }); // clang-format on auto rootShadowNode = builder.build(element); // Casting `nullptr` returns `nullptrs`. EXPECT_FALSE(traitCast(nullptr)); EXPECT_FALSE(traitCast(nullptr)); // `ViewShadowNode` is `LayoutableShadowNode` and `YogaLayoutableShadowNode`. EXPECT_TRUE(traitCast(viewShadowNode.get())); EXPECT_TRUE( traitCast(viewShadowNode.get())); EXPECT_NO_FATAL_FAILURE( traitCast(*viewShadowNode)); EXPECT_NO_FATAL_FAILURE( traitCast(*viewShadowNode)); // `ScrollViewShadowNode` is `LayoutableShadowNode` and // `YogaLayoutableShadowNode`. EXPECT_TRUE( traitCast(scrollViewShadowNode.get())); EXPECT_TRUE( traitCast(scrollViewShadowNode.get())); EXPECT_NO_FATAL_FAILURE( traitCast(*scrollViewShadowNode)); EXPECT_NO_FATAL_FAILURE( traitCast(*scrollViewShadowNode)); // `ParagraphShadowNode` is `LayoutableShadowNode` and // `YogaLayoutableShadowNode`. EXPECT_TRUE( traitCast(paragraphShadowNode.get())); EXPECT_TRUE( traitCast(paragraphShadowNode.get())); EXPECT_NO_FATAL_FAILURE( traitCast(*paragraphShadowNode)); EXPECT_NO_FATAL_FAILURE( traitCast(*paragraphShadowNode)); // `TextShadowNode` is *not* `LayoutableShadowNode` nor // `YogaLayoutableShadowNode`. EXPECT_FALSE(traitCast(textShadowNode.get())); EXPECT_FALSE( traitCast(textShadowNode.get())); EXPECT_DEATH_IF_SUPPORTED( traitCast(*textShadowNode), ""); EXPECT_DEATH_IF_SUPPORTED( traitCast(*textShadowNode), ""); // `RawTextShadowNode` is *not* `LayoutableShadowNode` nor // `YogaLayoutableShadowNode`. EXPECT_FALSE( traitCast(rawTextShadowNode.get())); EXPECT_FALSE( traitCast(rawTextShadowNode.get())); EXPECT_DEATH_IF_SUPPORTED( traitCast(*rawTextShadowNode), ""); EXPECT_DEATH_IF_SUPPORTED( traitCast(*rawTextShadowNode), ""); }