From 08eaae72238186c34d3ed4e62173335661e5ffd6 Mon Sep 17 00:00:00 2001 From: Nick Gerleman Date: Wed, 28 Dec 2022 01:21:52 -0800 Subject: [PATCH] Reorgnaize C++ tests Summary: This does some preprataion for the Yoga CMake Build. The main change is removing the dedicated testutil top-level-directory and static library. This contains a method to count nodes using the event functions exposed to C++, along with a Java binding for the test utility (since the events don't have a Java binding). It is only used in a single place in a way that isn't very useful, so it simplifies things to treat is as source in the existing C++ test library. This also separates the hand-written and generated UTs, like we are doing in the JS directory in D42207782. Reviewed By: christophpurrer Differential Revision: D42247762 fbshipit-source-id: f8a270e99d0315ba7fc608f2471333e7a7be9d79 --- gentest/gentest.rb | 2 +- java/build.gradle | 1 - .../tests/com/facebook/yoga/YogaNodeTest.java | 2 - settings.gradle | 3 +- tests/EventsTest.cpp | 7 +-- tests/YGLayoutDiffingTest.cpp | 3 +- tests/YGPersistenceTest.cpp | 3 +- .../YGAbsolutePositionTest.cpp | 0 tests/{ => generated}/YGAlignContentTest.cpp | 0 tests/{ => generated}/YGAlignItemsTest.cpp | 0 tests/{ => generated}/YGAlignSelfTest.cpp | 0 tests/{ => generated}/YGAndroidNewsFeed.cpp | 0 tests/{ => generated}/YGBorderTest.cpp | 0 tests/{ => generated}/YGConfigTest.cpp | 0 tests/{ => generated}/YGDimensionTest.cpp | 0 tests/{ => generated}/YGDisplayTest.cpp | 0 tests/{ => generated}/YGFlexDirectionTest.cpp | 0 tests/{ => generated}/YGFlexTest.cpp | 0 tests/{ => generated}/YGFlexWrapTest.cpp | 0 tests/{ => generated}/YGGapTest.cpp | 0 .../{ => generated}/YGJustifyContentTest.cpp | 0 tests/{ => generated}/YGMarginTest.cpp | 0 .../{ => generated}/YGMinMaxDimensionTest.cpp | 0 tests/{ => generated}/YGPaddingTest.cpp | 0 tests/{ => generated}/YGPercentageTest.cpp | 0 tests/{ => generated}/YGRoundingTest.cpp | 0 tests/{ => generated}/YGSizeOverflowTest.cpp | 0 .../testutil.cpp => tests/util/TestUtil.cpp | 2 +- .../testutil.h => tests/util/TestUtil.h | 0 testutil/build.gradle | 39 ----------------- testutil/src/main/AndroidManifest.xml | 12 ------ testutil/src/main/cpp/CMakeLists.txt | 43 ------------------- testutil/src/main/cpp/jni/jni.cpp | 39 ----------------- .../main/java/com/facebook/yoga/TestUtil.java | 20 --------- 34 files changed, 11 insertions(+), 165 deletions(-) rename tests/{ => generated}/YGAbsolutePositionTest.cpp (100%) rename tests/{ => generated}/YGAlignContentTest.cpp (100%) rename tests/{ => generated}/YGAlignItemsTest.cpp (100%) rename tests/{ => generated}/YGAlignSelfTest.cpp (100%) rename tests/{ => generated}/YGAndroidNewsFeed.cpp (100%) rename tests/{ => generated}/YGBorderTest.cpp (100%) rename tests/{ => generated}/YGConfigTest.cpp (100%) rename tests/{ => generated}/YGDimensionTest.cpp (100%) rename tests/{ => generated}/YGDisplayTest.cpp (100%) rename tests/{ => generated}/YGFlexDirectionTest.cpp (100%) rename tests/{ => generated}/YGFlexTest.cpp (100%) rename tests/{ => generated}/YGFlexWrapTest.cpp (100%) rename tests/{ => generated}/YGGapTest.cpp (100%) rename tests/{ => generated}/YGJustifyContentTest.cpp (100%) rename tests/{ => generated}/YGMarginTest.cpp (100%) rename tests/{ => generated}/YGMinMaxDimensionTest.cpp (100%) rename tests/{ => generated}/YGPaddingTest.cpp (100%) rename tests/{ => generated}/YGPercentageTest.cpp (100%) rename tests/{ => generated}/YGRoundingTest.cpp (100%) rename tests/{ => generated}/YGSizeOverflowTest.cpp (100%) rename testutil/src/main/cpp/testutil/testutil.cpp => tests/util/TestUtil.cpp (97%) rename testutil/src/main/cpp/include/yoga/testutil/testutil.h => tests/util/TestUtil.h (100%) delete mode 100644 testutil/build.gradle delete mode 100644 testutil/src/main/AndroidManifest.xml delete mode 100644 testutil/src/main/cpp/CMakeLists.txt delete mode 100644 testutil/src/main/cpp/jni/jni.cpp delete mode 100644 testutil/src/main/java/com/facebook/yoga/TestUtil.java diff --git a/gentest/gentest.rb b/gentest/gentest.rb index 54481ac3..98b8d77a 100644 --- a/gentest/gentest.rb +++ b/gentest/gentest.rb @@ -42,7 +42,7 @@ Dir['fixtures/*.html'].each do |file| browser.goto('file://' + Dir.pwd + '/test.html') logs = browser.driver.logs.get(:browser) - f = File.open("../tests/#{name}.cpp", 'w') + f = File.open("../tests/generated/#{name}.cpp", 'w') f.write eval(logs[0].message.sub(/^[^"]*/, '')) f.close diff --git a/java/build.gradle b/java/build.gradle index 1672a9ea..0b990b8a 100644 --- a/java/build.gradle +++ b/java/build.gradle @@ -53,7 +53,6 @@ dependencies { implementation project(':yoga:proguard-annotations') implementation 'com.facebook.soloader:soloader:0.10.4' testImplementation 'junit:junit:4.12' - testImplementation project(':testutil') } apply plugin: 'com.vanniktech.maven.publish' diff --git a/java/tests/com/facebook/yoga/YogaNodeTest.java b/java/tests/com/facebook/yoga/YogaNodeTest.java index ffc6fa7f..12c6390a 100644 --- a/java/tests/com/facebook/yoga/YogaNodeTest.java +++ b/java/tests/com/facebook/yoga/YogaNodeTest.java @@ -32,9 +32,7 @@ public class YogaNodeTest { @Test public void testInit() { - TestUtil.startCountingNodes(); final YogaNode node = createNode(); - assertEquals(1, TestUtil.stopCountingNodes()); } @Test diff --git a/settings.gradle b/settings.gradle index a737016a..65579757 100644 --- a/settings.gradle +++ b/settings.gradle @@ -5,9 +5,8 @@ * LICENSE file in the root directory of this source tree. */ -include ':yoga', ':yogacore', ':yoga-layout', ':yoga:proguard-annotations', ':libfb', ':testutil' +include ':yoga', ':yogacore', ':yoga-layout', ':yoga:proguard-annotations', ':libfb' project(':yoga').projectDir = file('java') project(':yoga:proguard-annotations').projectDir = file('java/proguard-annotations') project(':yoga-layout').projectDir = file('android') project(':libfb').projectDir = file('lib/fb') -project(':testutil').projectDir = file('testutil') diff --git a/tests/EventsTest.cpp b/tests/EventsTest.cpp index da7bc107..aa371041 100644 --- a/tests/EventsTest.cpp +++ b/tests/EventsTest.cpp @@ -6,16 +6,17 @@ */ #include -#include #include +#include +#include #include -#include #include #include #include #include -#include + +#include "util/TestUtil.h" namespace facebook { namespace yoga { diff --git a/tests/YGLayoutDiffingTest.cpp b/tests/YGLayoutDiffingTest.cpp index 6f767331..ca76b840 100644 --- a/tests/YGLayoutDiffingTest.cpp +++ b/tests/YGLayoutDiffingTest.cpp @@ -6,10 +6,11 @@ */ #include -#include #include #include +#include "util/TestUtil.h" + using facebook::yoga::test::TestUtil; TEST(YogaTest, assert_layout_trees_are_same) { diff --git a/tests/YGPersistenceTest.cpp b/tests/YGPersistenceTest.cpp index beb39e47..6bf1e7da 100644 --- a/tests/YGPersistenceTest.cpp +++ b/tests/YGPersistenceTest.cpp @@ -6,10 +6,11 @@ */ #include -#include #include #include +#include "util/TestUtil.h" + using facebook::yoga::test::TestUtil; TEST(YogaTest, cloning_shared_root) { diff --git a/tests/YGAbsolutePositionTest.cpp b/tests/generated/YGAbsolutePositionTest.cpp similarity index 100% rename from tests/YGAbsolutePositionTest.cpp rename to tests/generated/YGAbsolutePositionTest.cpp diff --git a/tests/YGAlignContentTest.cpp b/tests/generated/YGAlignContentTest.cpp similarity index 100% rename from tests/YGAlignContentTest.cpp rename to tests/generated/YGAlignContentTest.cpp diff --git a/tests/YGAlignItemsTest.cpp b/tests/generated/YGAlignItemsTest.cpp similarity index 100% rename from tests/YGAlignItemsTest.cpp rename to tests/generated/YGAlignItemsTest.cpp diff --git a/tests/YGAlignSelfTest.cpp b/tests/generated/YGAlignSelfTest.cpp similarity index 100% rename from tests/YGAlignSelfTest.cpp rename to tests/generated/YGAlignSelfTest.cpp diff --git a/tests/YGAndroidNewsFeed.cpp b/tests/generated/YGAndroidNewsFeed.cpp similarity index 100% rename from tests/YGAndroidNewsFeed.cpp rename to tests/generated/YGAndroidNewsFeed.cpp diff --git a/tests/YGBorderTest.cpp b/tests/generated/YGBorderTest.cpp similarity index 100% rename from tests/YGBorderTest.cpp rename to tests/generated/YGBorderTest.cpp diff --git a/tests/YGConfigTest.cpp b/tests/generated/YGConfigTest.cpp similarity index 100% rename from tests/YGConfigTest.cpp rename to tests/generated/YGConfigTest.cpp diff --git a/tests/YGDimensionTest.cpp b/tests/generated/YGDimensionTest.cpp similarity index 100% rename from tests/YGDimensionTest.cpp rename to tests/generated/YGDimensionTest.cpp diff --git a/tests/YGDisplayTest.cpp b/tests/generated/YGDisplayTest.cpp similarity index 100% rename from tests/YGDisplayTest.cpp rename to tests/generated/YGDisplayTest.cpp diff --git a/tests/YGFlexDirectionTest.cpp b/tests/generated/YGFlexDirectionTest.cpp similarity index 100% rename from tests/YGFlexDirectionTest.cpp rename to tests/generated/YGFlexDirectionTest.cpp diff --git a/tests/YGFlexTest.cpp b/tests/generated/YGFlexTest.cpp similarity index 100% rename from tests/YGFlexTest.cpp rename to tests/generated/YGFlexTest.cpp diff --git a/tests/YGFlexWrapTest.cpp b/tests/generated/YGFlexWrapTest.cpp similarity index 100% rename from tests/YGFlexWrapTest.cpp rename to tests/generated/YGFlexWrapTest.cpp diff --git a/tests/YGGapTest.cpp b/tests/generated/YGGapTest.cpp similarity index 100% rename from tests/YGGapTest.cpp rename to tests/generated/YGGapTest.cpp diff --git a/tests/YGJustifyContentTest.cpp b/tests/generated/YGJustifyContentTest.cpp similarity index 100% rename from tests/YGJustifyContentTest.cpp rename to tests/generated/YGJustifyContentTest.cpp diff --git a/tests/YGMarginTest.cpp b/tests/generated/YGMarginTest.cpp similarity index 100% rename from tests/YGMarginTest.cpp rename to tests/generated/YGMarginTest.cpp diff --git a/tests/YGMinMaxDimensionTest.cpp b/tests/generated/YGMinMaxDimensionTest.cpp similarity index 100% rename from tests/YGMinMaxDimensionTest.cpp rename to tests/generated/YGMinMaxDimensionTest.cpp diff --git a/tests/YGPaddingTest.cpp b/tests/generated/YGPaddingTest.cpp similarity index 100% rename from tests/YGPaddingTest.cpp rename to tests/generated/YGPaddingTest.cpp diff --git a/tests/YGPercentageTest.cpp b/tests/generated/YGPercentageTest.cpp similarity index 100% rename from tests/YGPercentageTest.cpp rename to tests/generated/YGPercentageTest.cpp diff --git a/tests/YGRoundingTest.cpp b/tests/generated/YGRoundingTest.cpp similarity index 100% rename from tests/YGRoundingTest.cpp rename to tests/generated/YGRoundingTest.cpp diff --git a/tests/YGSizeOverflowTest.cpp b/tests/generated/YGSizeOverflowTest.cpp similarity index 100% rename from tests/YGSizeOverflowTest.cpp rename to tests/generated/YGSizeOverflowTest.cpp diff --git a/testutil/src/main/cpp/testutil/testutil.cpp b/tests/util/TestUtil.cpp similarity index 97% rename from testutil/src/main/cpp/testutil/testutil.cpp rename to tests/util/TestUtil.cpp index adb88a0d..3b54f07a 100644 --- a/testutil/src/main/cpp/testutil/testutil.cpp +++ b/tests/util/TestUtil.cpp @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -#include +#include "TestUtil.h" #include #include diff --git a/testutil/src/main/cpp/include/yoga/testutil/testutil.h b/tests/util/TestUtil.h similarity index 100% rename from testutil/src/main/cpp/include/yoga/testutil/testutil.h rename to tests/util/TestUtil.h diff --git a/testutil/build.gradle b/testutil/build.gradle deleted file mode 100644 index 40d2ee14..00000000 --- a/testutil/build.gradle +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - - -apply plugin: 'com.android.library' - -android { - compileSdkVersion rootProject.compileSdkVersion - buildToolsVersion rootProject.buildToolsVersion - - defaultConfig { - minSdkVersion rootProject.minSdkVersion - targetSdkVersion rootProject.targetSdkVersion - - ndk { - abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a' - } - - externalNativeBuild { - cmake { - arguments '-DANDROID_TOOLCHAIN=clang', '-DANDROID_STL=c++_static' - } - } - } - - externalNativeBuild { - cmake { - path 'src/main/cpp/CMakeLists.txt' - } - } - - dependencies { - implementation 'com.facebook.soloader:soloader:0.10.4' - } -} diff --git a/testutil/src/main/AndroidManifest.xml b/testutil/src/main/AndroidManifest.xml deleted file mode 100644 index 7d6f3e5c..00000000 --- a/testutil/src/main/AndroidManifest.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - diff --git a/testutil/src/main/cpp/CMakeLists.txt b/testutil/src/main/cpp/CMakeLists.txt deleted file mode 100644 index 37fe6062..00000000 --- a/testutil/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,43 +0,0 @@ -# Copyright (c) Meta Platforms, Inc. and affiliates. -# -# This source code is licensed under the MIT license found in the -# LICENSE file in the root directory of this source tree. - -cmake_minimum_required(VERSION 3.4.1) - -set(CMAKE_VERBOSE_MAKEFILE on) - -set(libfb_DIR ${CMAKE_SOURCE_DIR}/../../../../lib/fb/src/main/cpp) -set(yogacore_DIR ${CMAKE_SOURCE_DIR}/../../../..) -set(build_DIR ${CMAKE_SOURCE_DIR}/build) - -set(libfb_build_DIR ${build_DIR}/libfb/${ANDROID_ABI}) -set(yogacore_build_DIR ${build_DIR}/yogacore/${ANDROID_ABI}) - -file(MAKE_DIRECTORY ${build_DIR}) - -add_subdirectory(${libfb_DIR} ${libfb_build_DIR}) -add_subdirectory(${yogacore_DIR} ${yogacore_build_DIR}) - -add_compile_options( - -fno-omit-frame-pointer - -fexceptions - -Wall - -std=c++11 - -DDISABLE_CPUCAP - -DDISABLE_XPLAT) - -file(GLOB testutil_SRC - jni/*.cpp - testutil/*.cpp) - -add_library(testutil SHARED - ${testutil_SRC}) - -target_include_directories(testutil PRIVATE - include) -target_include_directories(testutil PRIVATE - ${libfb_DIR}/include - ${yogacore_DIR}) - -target_link_libraries(testutil yogacore fb) diff --git a/testutil/src/main/cpp/jni/jni.cpp b/testutil/src/main/cpp/jni/jni.cpp deleted file mode 100644 index ab9b6721..00000000 --- a/testutil/src/main/cpp/jni/jni.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and 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 - -using namespace facebook; - -namespace { - -void startCountingNodes(jni::alias_ref) { - yoga::test::TestUtil::startCountingNodes(); -} - -jint nodeCount(jni::alias_ref) { - return yoga::test::TestUtil::nodeCount(); -} - -jint stopCountingNodes(jni::alias_ref) { - 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), - }); - }); -} diff --git a/testutil/src/main/java/com/facebook/yoga/TestUtil.java b/testutil/src/main/java/com/facebook/yoga/TestUtil.java deleted file mode 100644 index e972c292..00000000 --- a/testutil/src/main/java/com/facebook/yoga/TestUtil.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and 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(); -}