From 6ae38feb654576054839d7b5b5741069a4e14a2f Mon Sep 17 00:00:00 2001 From: Kevin Gozali Date: Wed, 21 Mar 2018 16:38:43 -0700 Subject: [PATCH] Added sample iOS unit test setup for fabric/debug target Summary: basic setup for unit testing Fabric impl Reviewed By: hramos Differential Revision: D7359239 fbshipit-source-id: ccaf36e775036f2fad4d8c882bce86bbbe06dd28 --- ReactCommon/fabric/debug/BUCK | 33 ++++++-- .../tests/DebugStringConvertibleTest.cpp | 77 +++++++++++++++++++ 2 files changed, 105 insertions(+), 5 deletions(-) create mode 100644 ReactCommon/fabric/debug/tests/DebugStringConvertibleTest.cpp diff --git a/ReactCommon/fabric/debug/BUCK b/ReactCommon/fabric/debug/BUCK index 5a021202e..d17009730 100644 --- a/ReactCommon/fabric/debug/BUCK +++ b/ReactCommon/fabric/debug/BUCK @@ -5,18 +5,18 @@ APPLE_COMPILER_FLAGS = [] if not IS_OSS_BUILD: load("@xplat//configurations/buck/apple:flag_defs.bzl", "get_static_library_ios_flags", "flags") - APPLE_COMPILER_FLAGS = flags.get_flag_value(get_static_library_ios_flags(), 'compiler_flags') + APPLE_COMPILER_FLAGS = flags.get_flag_value(get_static_library_ios_flags(), "compiler_flags") rn_xplat_cxx_library( name = "debug", srcs = glob( [ - "**/*.cpp", + "*.cpp", ], ), headers = glob( [ - "**/*.h", + "*.h", ], ), header_namespace = "", @@ -27,10 +27,10 @@ rn_xplat_cxx_library( prefix = "fabric/debug", ), compiler_flags = [ - "-std=c++14", - "-Wall", "-fexceptions", "-frtti", + "-std=c++14", + "-Wall", ], fbobjc_compiler_flags = APPLE_COMPILER_FLAGS, fbobjc_preprocessor_flags = get_debug_preprocessor_flags() + APPLE_INSPECTOR_FLAGS, @@ -39,8 +39,31 @@ rn_xplat_cxx_library( "-DLOG_TAG=\"ReactNative\"", "-DWITH_FBSYSTRACE=1", ], + tests = [ + ":tests", + ], visibility = ["PUBLIC"], deps = [ "xplat//folly:headers_only", ], ) + +if not IS_OSS_BUILD: + load("@xplat//configurations/buck:default_platform_defs.bzl", "APPLE") + + cxx_test( + name = "tests", + srcs = glob(["tests/**/*.cpp"]), + compiler_flags = [ + "-fexceptions", + "-frtti", + "-std=c++14", + "-Wall", + ], + platforms = APPLE, + deps = [ + "xplat//folly:molly", + "xplat//third-party/gmock:gtest", + ":debug", + ], + ) diff --git a/ReactCommon/fabric/debug/tests/DebugStringConvertibleTest.cpp b/ReactCommon/fabric/debug/tests/DebugStringConvertibleTest.cpp new file mode 100644 index 000000000..272255b39 --- /dev/null +++ b/ReactCommon/fabric/debug/tests/DebugStringConvertibleTest.cpp @@ -0,0 +1,77 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * + * 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 + +using namespace facebook::react; + +TEST(DebugStringConvertibleTest, handleSimpleNode) { + SharedDebugStringConvertibleList empty; + auto item = std::make_shared("View", "hello", empty, empty); + + ASSERT_STREQ(item->getDebugName().c_str(), "View"); + ASSERT_STREQ(item->getDebugValue().c_str(), "hello"); + ASSERT_STREQ(item->getDebugDescription().c_str(), "\n"); +} + +TEST(DebugStringConvertibleTest, handleSimpleNodeWithProps) { + SharedDebugStringConvertibleList empty; + SharedDebugStringConvertibleList props = { + std::make_shared("x", "1", empty, empty) + }; + auto item = std::make_shared("View", "hello", props, empty); + + ASSERT_STREQ(item->getDebugName().c_str(), "View"); + ASSERT_STREQ(item->getDebugValue().c_str(), "hello"); + ASSERT_STREQ(item->getDebugDescription().c_str(), "\n"); +} + +TEST(DebugStringConvertibleTest, handleSimpleNodeWithChildren) { + SharedDebugStringConvertibleList empty; + SharedDebugStringConvertibleList children = { + std::make_shared("Child", "a", empty, empty) + }; + auto item = std::make_shared("View", "hello", empty, children); + + ASSERT_STREQ(item->getDebugName().c_str(), "View"); + ASSERT_STREQ(item->getDebugValue().c_str(), "hello"); + ASSERT_STREQ(item->getDebugDescription().c_str(), "\n \n\n"); +} + +TEST(DebugStringConvertibleTest, handleNestedNode) { + SharedDebugStringConvertibleList empty; + SharedDebugStringConvertibleList props = { + std::make_shared("x", "1", empty, empty) + }; + SharedDebugStringConvertibleList children = { + std::make_shared("Child", "a", props, empty) + }; + auto item = std::make_shared("View", "hello", props, children); + + ASSERT_STREQ(item->getDebugName().c_str(), "View"); + ASSERT_STREQ(item->getDebugValue().c_str(), "hello"); + ASSERT_STREQ(item->getDebugDescription().c_str(), "\n \n\n"); +} + +TEST(DebugStringConvertibleTest, handleNodeWithComplexProps) { + SharedDebugStringConvertibleList empty; + SharedDebugStringConvertibleList subProps = { + std::make_shared("height", "100", empty, empty), + std::make_shared("width", "200", empty, empty) + }; + SharedDebugStringConvertibleList props = { + std::make_shared("x", "1", subProps, empty) + }; + auto item = std::make_shared("View", "hello", props, empty); + + ASSERT_STREQ(item->getDebugName().c_str(), "View"); + ASSERT_STREQ(item->getDebugValue().c_str(), "hello"); + ASSERT_STREQ(item->getDebugDescription().c_str(), "\n"); +}