Tests: move tests from USD test directory into `io/common` and `io/usd`
This commit is a followup of {D7649}, and ports the USD tests to the new testing approach. It moves test code from `tests/gtests/usd` into `source/blender/io/common` and `source/blender/io/usd`, and adjusts the use of namespaces to be consistent with the other tests. I decided to put one test into `io/usd/tests`, instead of `io/usd/intern`. The reason is that this test does not correspond with a single file in that directory; instead, it tests Blender's integration with the USD library itself. There are two new CLI arguments for the Big Test Runner: - `--test-assets-dir`, which points to the `lib/tests` directory in the SVN repository. This allows unit tests to find test assets. - `--test-release-dir`, which points to `bin/{BLENDER_VERSION}` in the build directory. At the moment this is only used by the USD test. The CLI arguments are automatically passed to the Big Test Runner when using `ctest`. When manually running the tests, the arguments are only required when there is a test run that needs them. For more info about splitting some code into 'common', see rB084c5d6c7e2cf8. No functional changes to the tests themselves, only to the way they are built & run. Differential Revision: https://developer.blender.org/D8314 Reviewed by: brecht, mont29
This commit is contained in:
parent
09a483a3aa
commit
a138bf57c9
|
@ -48,3 +48,16 @@ set(LIB
|
|||
blender_add_lib(bf_io_common "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")
|
||||
|
||||
target_link_libraries(bf_io_common INTERFACE)
|
||||
|
||||
if(WITH_GTESTS)
|
||||
set(TEST_SRC
|
||||
intern/abstract_hierarchy_iterator_test.cc
|
||||
intern/hierarchy_context_order_test.cc
|
||||
intern/object_identifier_test.cc
|
||||
)
|
||||
set(TEST_LIB
|
||||
bf_blenloader_test
|
||||
)
|
||||
include(GTestTesting)
|
||||
blender_add_test_lib(bf_io_common_tests "${TEST_SRC}" "${INC};${TEST_INC}" "${INC_SYS}" "${LIB};${TEST_LIB}")
|
||||
endif()
|
||||
|
|
|
@ -19,21 +19,21 @@
|
|||
#include "IO_abstract_hierarchy_iterator.h"
|
||||
#include "blenloader/blendfile_loading_base_test.h"
|
||||
|
||||
extern "C" {
|
||||
#include "BLI_math.h"
|
||||
#include "DEG_depsgraph.h"
|
||||
#include "DNA_object_types.h"
|
||||
}
|
||||
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
namespace blender::io {
|
||||
|
||||
namespace {
|
||||
|
||||
/* Mapping from ID.name to set of export hierarchy path. Duplicated objects can be exported
|
||||
* multiple times with different export paths, hence the set. */
|
||||
typedef std::map<std::string, std::set<std::string>> used_writers;
|
||||
|
||||
using namespace blender::io;
|
||||
|
||||
class TestHierarchyWriter : public AbstractHierarchyWriter {
|
||||
public:
|
||||
std::string writer_type;
|
||||
|
@ -57,16 +57,7 @@ class TestHierarchyWriter : public AbstractHierarchyWriter {
|
|||
}
|
||||
};
|
||||
|
||||
void debug_print_writers(const char *label, const used_writers &writers_map)
|
||||
{
|
||||
printf("%s:\n", label);
|
||||
for (auto idname_writers : writers_map) {
|
||||
printf(" %s:\n", idname_writers.first.c_str());
|
||||
for (const std::string &export_path : idname_writers.second) {
|
||||
printf(" - %s\n", export_path.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
class TestingHierarchyIterator : public AbstractHierarchyIterator {
|
||||
public: /* Public so that the test cases can directly inspect the created writers. */
|
||||
|
@ -84,19 +75,19 @@ class TestingHierarchyIterator : public AbstractHierarchyIterator {
|
|||
}
|
||||
|
||||
protected:
|
||||
AbstractHierarchyWriter *create_transform_writer(const HierarchyContext *context) override
|
||||
AbstractHierarchyWriter *create_transform_writer(const HierarchyContext * /*context*/) override
|
||||
{
|
||||
return new TestHierarchyWriter("transform", transform_writers);
|
||||
}
|
||||
AbstractHierarchyWriter *create_data_writer(const HierarchyContext *context) override
|
||||
AbstractHierarchyWriter *create_data_writer(const HierarchyContext * /*context*/) override
|
||||
{
|
||||
return new TestHierarchyWriter("data", data_writers);
|
||||
}
|
||||
AbstractHierarchyWriter *create_hair_writer(const HierarchyContext *context) override
|
||||
AbstractHierarchyWriter *create_hair_writer(const HierarchyContext * /*context*/) override
|
||||
{
|
||||
return new TestHierarchyWriter("hair", hair_writers);
|
||||
}
|
||||
AbstractHierarchyWriter *create_particle_writer(const HierarchyContext *context) override
|
||||
AbstractHierarchyWriter *create_particle_writer(const HierarchyContext * /*context*/) override
|
||||
{
|
||||
return new TestHierarchyWriter("particle", particle_writers);
|
||||
}
|
||||
|
@ -325,3 +316,4 @@ TEST_F(USDHierarchyIteratorTest, ExportSubsetTest)
|
|||
EXPECT_EQ(expected_transforms, iterator->transform_writers);
|
||||
EXPECT_EQ(expected_data, iterator->data_writers);
|
||||
}
|
||||
} // namespace blender::io
|
|
@ -24,16 +24,20 @@ extern "C" {
|
|||
#include "BLI_utildefines.h"
|
||||
}
|
||||
|
||||
using namespace blender::io;
|
||||
namespace blender::io {
|
||||
|
||||
class HierarchyContextOrderTest : public testing::Test {
|
||||
};
|
||||
namespace {
|
||||
|
||||
static Object *fake_pointer(int value)
|
||||
Object *fake_pointer(int value)
|
||||
{
|
||||
return static_cast<Object *>(POINTER_FROM_INT(value));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
class HierarchyContextOrderTest : public testing::Test {
|
||||
};
|
||||
|
||||
TEST_F(HierarchyContextOrderTest, ObjectPointerTest)
|
||||
{
|
||||
HierarchyContext ctx_a = {0};
|
||||
|
@ -121,3 +125,5 @@ TEST_F(HierarchyContextOrderTest, TransitiveTest)
|
|||
EXPECT_FALSE(ctx_d < ctx_b);
|
||||
EXPECT_FALSE(ctx_d < ctx_c);
|
||||
}
|
||||
|
||||
} // namespace blender::io
|
|
@ -24,8 +24,7 @@
|
|||
|
||||
#include <climits>
|
||||
|
||||
namespace blender {
|
||||
namespace io {
|
||||
namespace blender::io {
|
||||
|
||||
namespace {
|
||||
|
||||
|
@ -232,5 +231,4 @@ TEST_F(PersistentIDTest, as_object_name_suffix)
|
|||
EXPECT_EQ("-3--2--1", TestPersistentID(-1, -2, -3).as_object_name_suffix());
|
||||
}
|
||||
|
||||
} // namespace io
|
||||
} // namespace blender
|
||||
} // namespace blender::io
|
|
@ -109,3 +109,15 @@ else()
|
|||
endif()
|
||||
|
||||
target_link_libraries(bf_usd INTERFACE ${TBB_LIBRARIES})
|
||||
|
||||
if(WITH_GTESTS)
|
||||
set(TEST_SRC
|
||||
tests/usd_stage_creation_test.cc
|
||||
)
|
||||
set(TEST_INC
|
||||
)
|
||||
set(TEST_LIB
|
||||
)
|
||||
include(GTestTesting)
|
||||
blender_add_test_lib(bf_io_usd_tests "${TEST_SRC}" "${INC};${TEST_INC}" "${INC_SYS}" "${LIB};${TEST_LIB}")
|
||||
endif()
|
||||
|
|
|
@ -21,28 +21,32 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
extern "C" {
|
||||
#include "BLI_path_util.h"
|
||||
#include "BLI_utildefines.h"
|
||||
|
||||
#include "BKE_appdir.h"
|
||||
|
||||
extern "C" {
|
||||
/* Workaround to make it possible to pass a path at runtime to USD. See creator.c. */
|
||||
void usd_initialise_plugin_path(const char *datafiles_usd_path);
|
||||
}
|
||||
|
||||
DEFINE_string(test_usd_datafiles_dir, "", "The bin/{BLENDER_VERSION}/datafiles/usd directory.");
|
||||
namespace blender::io::usd {
|
||||
|
||||
class USDStageCreationTest : public testing::Test {
|
||||
};
|
||||
|
||||
TEST_F(USDStageCreationTest, JSONFileLoadingTest)
|
||||
{
|
||||
if (FLAGS_test_usd_datafiles_dir.empty()) {
|
||||
FAIL() << "Pass the --test-usd-datafiles-dir flag";
|
||||
const std::string &release_dir = blender::tests::flags_test_release_dir();
|
||||
if (release_dir.empty()) {
|
||||
FAIL();
|
||||
}
|
||||
|
||||
usd_initialise_plugin_path(FLAGS_test_usd_datafiles_dir.c_str());
|
||||
char usd_datafiles_dir[FILE_MAX];
|
||||
BLI_path_join(usd_datafiles_dir, FILE_MAX, release_dir.c_str(), "datafiles", "usd", nullptr);
|
||||
|
||||
usd_initialise_plugin_path(usd_datafiles_dir);
|
||||
|
||||
/* Simply the ability to create a USD Stage for a specific filename means that the extension
|
||||
* has been recognised by the USD library, and that a USD plugin has been loaded to write such
|
||||
|
@ -60,3 +64,5 @@ TEST_F(USDStageCreationTest, JSONFileLoadingTest)
|
|||
FAIL() << "unable to find suitable USD plugin to write " << filename;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace blender::io::usd
|
|
@ -19,7 +19,4 @@ if(WITH_GTESTS)
|
|||
if(WITH_ALEMBIC)
|
||||
add_subdirectory(alembic)
|
||||
endif()
|
||||
if(WITH_USD)
|
||||
add_subdirectory(usd)
|
||||
endif()
|
||||
endif()
|
||||
|
|
|
@ -50,8 +50,6 @@ extern "C" {
|
|||
#include "wm.h"
|
||||
}
|
||||
|
||||
DEFINE_string(test_assets_dir, "", "lib/tests directory from SVN containing the test assets.");
|
||||
|
||||
BlendfileLoadingBaseTest::~BlendfileLoadingBaseTest()
|
||||
{
|
||||
}
|
||||
|
@ -125,19 +123,18 @@ void BlendfileLoadingBaseTest::TearDown()
|
|||
|
||||
bool BlendfileLoadingBaseTest::blendfile_load(const char *filepath)
|
||||
{
|
||||
if (FLAGS_test_assets_dir.empty()) {
|
||||
ADD_FAILURE()
|
||||
<< "Pass the flag --test-assets-dir and point to the lib/tests directory from SVN.";
|
||||
const std::string &test_assets_dir = blender::tests::flags_test_asset_dir();
|
||||
if (test_assets_dir.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
char abspath[FILENAME_MAX];
|
||||
BLI_path_join(abspath, sizeof(abspath), FLAGS_test_assets_dir.c_str(), filepath, NULL);
|
||||
BLI_path_join(abspath, sizeof(abspath), test_assets_dir.c_str(), filepath, NULL);
|
||||
|
||||
bfile = BLO_read_from_file(abspath, BLO_READ_SKIP_NONE, NULL /* reports */);
|
||||
if (bfile == nullptr) {
|
||||
ADD_FAILURE() << "Unable to load file '" << filepath << "' from test assets dir '"
|
||||
<< FLAGS_test_assets_dir << "'";
|
||||
<< test_assets_dir << "'";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -60,4 +60,9 @@ setup_liblinks(blender_test)
|
|||
# exposes those tests individually to the ctest runner.
|
||||
# See https://cmake.org/cmake/help/v3.18/module/GoogleTest.html
|
||||
include(GoogleTest)
|
||||
gtest_discover_tests(blender_test)
|
||||
gtest_discover_tests(blender_test
|
||||
# So that unit tests know where to find files:
|
||||
EXTRA_ARGS
|
||||
--test-assets-dir "${CMAKE_SOURCE_DIR}/../lib/tests"
|
||||
--test-release-dir "$<TARGET_FILE_DIR:blender>/${BLENDER_VERSION}"
|
||||
)
|
||||
|
|
|
@ -7,6 +7,15 @@
|
|||
#include "glog/logging.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace blender::tests {
|
||||
|
||||
/* These strings are passed on the CLI with the --test-asset-dir and --test-release-dir arguments.
|
||||
* The arguments are added automatically when invoking tests via `ctest`. */
|
||||
const std::string &flags_test_asset_dir(); /* ../lib/tests in the SVN directory. */
|
||||
const std::string &flags_test_release_dir(); /* bin/{blender version} in the build directory. */
|
||||
|
||||
} // namespace blender::tests
|
||||
|
||||
#define EXPECT_V3_NEAR(a, b, eps) \
|
||||
{ \
|
||||
EXPECT_NEAR(a[0], b[0], eps); \
|
||||
|
|
|
@ -19,6 +19,31 @@
|
|||
|
||||
#include "testing/testing.h"
|
||||
|
||||
DEFINE_string(test_assets_dir, "", "lib/tests directory from SVN containing the test assets.");
|
||||
DEFINE_string(test_release_dir, "", "bin/{blender version} directory of the current build.");
|
||||
|
||||
namespace blender::tests {
|
||||
|
||||
const std::string &flags_test_asset_dir()
|
||||
{
|
||||
if (FLAGS_test_assets_dir.empty()) {
|
||||
ADD_FAILURE()
|
||||
<< "Pass the flag --test-assets-dir and point to the lib/tests directory from SVN.";
|
||||
}
|
||||
return FLAGS_test_assets_dir;
|
||||
}
|
||||
|
||||
const std::string &flags_test_release_dir()
|
||||
{
|
||||
if (FLAGS_test_release_dir.empty()) {
|
||||
ADD_FAILURE()
|
||||
<< "Pass the flag --test-release-dir and point to the bin/{blender version} directory.";
|
||||
}
|
||||
return FLAGS_test_release_dir;
|
||||
}
|
||||
|
||||
} // namespace blender::tests
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
|
|
|
@ -1,109 +0,0 @@
|
|||
# ***** BEGIN GPL LICENSE BLOCK *****
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
#
|
||||
# The Original Code is Copyright (C) 2019, Blender Foundation
|
||||
# All rights reserved.
|
||||
# ***** END GPL LICENSE BLOCK *****
|
||||
|
||||
# This suppresses the warning "This file includes at least one deprecated or antiquated
|
||||
# header which may be removed without further notice at a future date", which is caused
|
||||
# by the USD library including <ext/hash_set> on Linux. This has been reported at:
|
||||
# https://github.com/PixarAnimationStudios/USD/issues/1057.
|
||||
if(UNIX AND NOT APPLE)
|
||||
add_definitions(-D_GLIBCXX_PERMIT_BACKWARD_HASH)
|
||||
endif()
|
||||
if(WIN32)
|
||||
add_definitions(-DNOMINMAX)
|
||||
endif()
|
||||
add_definitions(-DPXR_STATIC)
|
||||
|
||||
set(INC
|
||||
.
|
||||
..
|
||||
../../../source/blender/blenlib
|
||||
../../../source/blender/blenkernel
|
||||
../../../source/blender/io/common
|
||||
../../../source/blender/io/usd
|
||||
../../../source/blender/makesdna
|
||||
../../../source/blender/depsgraph
|
||||
${USD_INCLUDE_DIRS}
|
||||
${BOOST_INCLUDE_DIR}
|
||||
${TBB_INCLUDE_DIR}
|
||||
)
|
||||
|
||||
set(LIB
|
||||
bf_blenloader_test
|
||||
bf_blenloader
|
||||
|
||||
# Should not be needed but gives windows linker errors if the ocio libs are linked before this:
|
||||
bf_intern_opencolorio
|
||||
bf_gpu
|
||||
|
||||
bf_usd
|
||||
bf_io_common
|
||||
|
||||
${BOOST_LIBRARIES}
|
||||
${TBB_LIBRARIES}
|
||||
)
|
||||
|
||||
include_directories(${INC})
|
||||
|
||||
setup_libdirs()
|
||||
get_property(BLENDER_SORTED_LIBS GLOBAL PROPERTY BLENDER_SORTED_LIBS_PROP)
|
||||
|
||||
set(SRC
|
||||
abstract_hierarchy_iterator_test.cc
|
||||
hierarchy_context_order_test.cc
|
||||
object_identifier_test.cc
|
||||
)
|
||||
|
||||
# TODO(Sybren): re-enable this unit test.
|
||||
# if(NOT APPLE)
|
||||
# # TODO(Sybren): This unit test has only been tested on Linux, and should possibly be
|
||||
# # restructured to support other platforms as well.
|
||||
# list(APPEND SRC usd_stage_creation_test.cc)
|
||||
# endif()
|
||||
|
||||
|
||||
if(WITH_BUILDINFO)
|
||||
list(APPEND SRC
|
||||
"$<TARGET_OBJECTS:buildinfoobj>"
|
||||
)
|
||||
endif()
|
||||
|
||||
# get_cmake_property(_variableNames VARIABLES)
|
||||
# list(SORT _variableNames)
|
||||
# foreach(_variableName ${_variableNames})
|
||||
# message(STATUS "${_variableName}=${${_variableName}}")
|
||||
# endforeach()
|
||||
|
||||
# Works on Linux, not on Windows:
|
||||
# set(_usd_DATAFILES_DIR "${CMAKE_INSTALL_PREFIX}/${BLENDER_VERSION}/datafiles/usd")
|
||||
set(_usd_DATAFILES_DIR "$<TARGET_FILE_DIR:blender>/${BLENDER_VERSION}/datafiles/usd")
|
||||
|
||||
BLENDER_SRC_GTEST_EX(
|
||||
NAME usd
|
||||
SRC "${SRC}"
|
||||
EXTRA_LIBS "${LIB}"
|
||||
COMMAND_ARGS
|
||||
--test-assets-dir "${CMAKE_SOURCE_DIR}/../lib/tests"
|
||||
)
|
||||
# TODO(Sybren): add the below CLI argument to the test when the usd_stage_creation_test.cc
|
||||
# test is reenabled.
|
||||
# --test-usd-datafiles-dir "${_usd_DATAFILES_DIR}"
|
||||
unset(_usd_DATAFILES_DIR)
|
||||
|
||||
setup_liblinks(usd_test)
|
Loading…
Reference in New Issue