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
This commit is contained in:
Nick Gerleman
2022-12-28 01:21:52 -08:00
committed by Facebook GitHub Bot
parent 894142d589
commit 08eaae7223
34 changed files with 11 additions and 165 deletions

View File

@@ -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

View File

@@ -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'

View File

@@ -32,9 +32,7 @@ public class YogaNodeTest {
@Test
public void testInit() {
TestUtil.startCountingNodes();
final YogaNode node = createNode();
assertEquals(1, TestUtil.stopCountingNodes());
}
@Test

View File

@@ -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')

View File

@@ -6,16 +6,17 @@
*/
#include <gtest/gtest.h>
#include <yoga/Yoga.h>
#include <yoga/event/event.h>
#include <yoga/Yoga.h>
#include <yoga/YGEnums.h>
#include <yoga/YGNode.h>
#include <yoga/testutil/testutil.h>
#include <algorithm>
#include <functional>
#include <memory>
#include <vector>
#include <yoga/YGEnums.h>
#include "util/TestUtil.h"
namespace facebook {
namespace yoga {

View File

@@ -6,10 +6,11 @@
*/
#include <gtest/gtest.h>
#include <yoga/testutil/testutil.h>
#include <yoga/YGNode.h>
#include <yoga/Yoga.h>
#include "util/TestUtil.h"
using facebook::yoga::test::TestUtil;
TEST(YogaTest, assert_layout_trees_are_same) {

View File

@@ -6,10 +6,11 @@
*/
#include <gtest/gtest.h>
#include <yoga/testutil/testutil.h>
#include <yoga/Yoga.h>
#include <yoga/YGNode.h>
#include "util/TestUtil.h"
using facebook::yoga::test::TestUtil;
TEST(YogaTest, cloning_shared_root) {

View File

@@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/
#include <yoga/testutil/testutil.h>
#include "TestUtil.h"
#include <yoga/YGNode.h>
#include <yoga/event/event.h>

View File

@@ -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'
}
}

View File

@@ -1,12 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
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.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.facebook.yoga.testutil">
</manifest>

View File

@@ -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)

View File

@@ -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 <fbjni/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),
});
});
}

View File

@@ -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();
}