Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSybren A. Stüvel <sybren@blender.org>2020-07-16 17:10:53 +0300
committerSybren A. Stüvel <sybren@blender.org>2020-07-16 18:38:29 +0300
commita138bf57c994509c9dbd1ea79a6886c24cd5d0d9 (patch)
tree3f081fd8e1ad35dbeb910d4316f5e65263eae77c /tests/gtests
parent09a483a3aac34f0f4226de0bd23d7ec7e6eb3c4e (diff)
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
Diffstat (limited to 'tests/gtests')
-rw-r--r--tests/gtests/CMakeLists.txt3
-rw-r--r--tests/gtests/blenloader/blendfile_loading_base_test.cc11
-rw-r--r--tests/gtests/runner/CMakeLists.txt7
-rw-r--r--tests/gtests/testing/testing.h9
-rw-r--r--tests/gtests/testing/testing_main.cc25
-rw-r--r--tests/gtests/usd/CMakeLists.txt109
-rw-r--r--tests/gtests/usd/abstract_hierarchy_iterator_test.cc327
-rw-r--r--tests/gtests/usd/hierarchy_context_order_test.cc123
-rw-r--r--tests/gtests/usd/object_identifier_test.cc236
-rw-r--r--tests/gtests/usd/usd_stage_creation_test.cc62
10 files changed, 44 insertions, 868 deletions
diff --git a/tests/gtests/CMakeLists.txt b/tests/gtests/CMakeLists.txt
index 4ce68a6f4c0..282eb9080f5 100644
--- a/tests/gtests/CMakeLists.txt
+++ b/tests/gtests/CMakeLists.txt
@@ -19,7 +19,4 @@ if(WITH_GTESTS)
if(WITH_ALEMBIC)
add_subdirectory(alembic)
endif()
- if(WITH_USD)
- add_subdirectory(usd)
- endif()
endif()
diff --git a/tests/gtests/blenloader/blendfile_loading_base_test.cc b/tests/gtests/blenloader/blendfile_loading_base_test.cc
index 62befae90cd..f15ae615e8a 100644
--- a/tests/gtests/blenloader/blendfile_loading_base_test.cc
+++ b/tests/gtests/blenloader/blendfile_loading_base_test.cc
@@ -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;
diff --git a/tests/gtests/runner/CMakeLists.txt b/tests/gtests/runner/CMakeLists.txt
index e7cbabfe7c6..7f28ede9ae9 100644
--- a/tests/gtests/runner/CMakeLists.txt
+++ b/tests/gtests/runner/CMakeLists.txt
@@ -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}"
+)
diff --git a/tests/gtests/testing/testing.h b/tests/gtests/testing/testing.h
index 32cb6e7f18a..34928035b7d 100644
--- a/tests/gtests/testing/testing.h
+++ b/tests/gtests/testing/testing.h
@@ -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); \
diff --git a/tests/gtests/testing/testing_main.cc b/tests/gtests/testing/testing_main.cc
index 6b3a8e5515d..0acdcf3a8a5 100644
--- a/tests/gtests/testing/testing_main.cc
+++ b/tests/gtests/testing/testing_main.cc
@@ -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);
diff --git a/tests/gtests/usd/CMakeLists.txt b/tests/gtests/usd/CMakeLists.txt
deleted file mode 100644
index 0caa2fac155..00000000000
--- a/tests/gtests/usd/CMakeLists.txt
+++ /dev/null
@@ -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)
diff --git a/tests/gtests/usd/abstract_hierarchy_iterator_test.cc b/tests/gtests/usd/abstract_hierarchy_iterator_test.cc
deleted file mode 100644
index d9148a7b289..00000000000
--- a/tests/gtests/usd/abstract_hierarchy_iterator_test.cc
+++ /dev/null
@@ -1,327 +0,0 @@
-/*
- * 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.
- */
-#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>
-
-/* 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;
- used_writers &writers_map;
-
- TestHierarchyWriter(const std::string &writer_type, used_writers &writers_map)
- : writer_type(writer_type), writers_map(writers_map)
- {
- }
-
- void write(HierarchyContext &context) override
- {
- const char *id_name = context.object->id.name;
- used_writers::mapped_type &writers = writers_map[id_name];
-
- if (writers.find(context.export_path) != writers.end()) {
- ADD_FAILURE() << "Unexpectedly found another " << writer_type << " writer for " << id_name
- << " to export to " << context.export_path;
- }
- writers.insert(context.export_path);
- }
-};
-
-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());
- }
- }
-}
-
-class TestingHierarchyIterator : public AbstractHierarchyIterator {
- public: /* Public so that the test cases can directly inspect the created writers. */
- used_writers transform_writers;
- used_writers data_writers;
- used_writers hair_writers;
- used_writers particle_writers;
-
- public:
- explicit TestingHierarchyIterator(Depsgraph *depsgraph) : AbstractHierarchyIterator(depsgraph)
- {
- }
- virtual ~TestingHierarchyIterator()
- {
- }
-
- protected:
- AbstractHierarchyWriter *create_transform_writer(const HierarchyContext *context) override
- {
- return new TestHierarchyWriter("transform", transform_writers);
- }
- AbstractHierarchyWriter *create_data_writer(const HierarchyContext *context) override
- {
- return new TestHierarchyWriter("data", data_writers);
- }
- AbstractHierarchyWriter *create_hair_writer(const HierarchyContext *context) override
- {
- return new TestHierarchyWriter("hair", hair_writers);
- }
- AbstractHierarchyWriter *create_particle_writer(const HierarchyContext *context) override
- {
- return new TestHierarchyWriter("particle", particle_writers);
- }
-
- void delete_object_writer(AbstractHierarchyWriter *writer) override
- {
- delete writer;
- }
-};
-
-class USDHierarchyIteratorTest : public BlendfileLoadingBaseTest {
- protected:
- TestingHierarchyIterator *iterator;
-
- virtual void SetUp()
- {
- BlendfileLoadingBaseTest::SetUp();
- iterator = nullptr;
- }
-
- virtual void TearDown()
- {
- iterator_free();
- BlendfileLoadingBaseTest::TearDown();
- }
-
- /* Create a test iterator. */
- void iterator_create()
- {
- iterator = new TestingHierarchyIterator(depsgraph);
- }
- /* Free the test iterator if it is not nullptr. */
- void iterator_free()
- {
- if (iterator == nullptr) {
- return;
- }
- delete iterator;
- iterator = nullptr;
- }
-};
-
-TEST_F(USDHierarchyIteratorTest, ExportHierarchyTest)
-{
- /* Load the test blend file. */
- if (!blendfile_load("usd/usd_hierarchy_export_test.blend")) {
- return;
- }
- depsgraph_create(DAG_EVAL_RENDER);
- iterator_create();
-
- iterator->iterate_and_write();
-
- // Mapping from object name to set of export paths.
- used_writers expected_transforms = {
- {"OBCamera", {"/Camera"}},
- {"OBDupli1", {"/Dupli1"}},
- {"OBDupli2", {"/ParentOfDupli2/Dupli2"}},
- {"OBGEO_Ear_L",
- {"/Dupli1/GEO_Head-0/GEO_Ear_L-1",
- "/Ground plane/OutsideDupliGrandParent/OutsideDupliParent/GEO_Head/GEO_Ear_L",
- "/ParentOfDupli2/Dupli2/GEO_Head-0/GEO_Ear_L-1"}},
- {"OBGEO_Ear_R",
- {"/Dupli1/GEO_Head-0/GEO_Ear_R-2",
- "/Ground plane/OutsideDupliGrandParent/OutsideDupliParent/GEO_Head/GEO_Ear_R",
- "/ParentOfDupli2/Dupli2/GEO_Head-0/GEO_Ear_R-2"}},
- {"OBGEO_Head",
- {"/Dupli1/GEO_Head-0",
- "/Ground plane/OutsideDupliGrandParent/OutsideDupliParent/GEO_Head",
- "/ParentOfDupli2/Dupli2/GEO_Head-0"}},
- {"OBGEO_Nose",
- {"/Dupli1/GEO_Head-0/GEO_Nose-3",
- "/Ground plane/OutsideDupliGrandParent/OutsideDupliParent/GEO_Head/GEO_Nose",
- "/ParentOfDupli2/Dupli2/GEO_Head-0/GEO_Nose-3"}},
- {"OBGround plane", {"/Ground plane"}},
- {"OBOutsideDupliGrandParent", {"/Ground plane/OutsideDupliGrandParent"}},
- {"OBOutsideDupliParent", {"/Ground plane/OutsideDupliGrandParent/OutsideDupliParent"}},
- {"OBParentOfDupli2", {"/ParentOfDupli2"}}};
- EXPECT_EQ(expected_transforms, iterator->transform_writers);
-
- used_writers expected_data = {
- {"OBCamera", {"/Camera/Camera"}},
- {"OBGEO_Ear_L",
- {"/Dupli1/GEO_Head-0/GEO_Ear_L-1/Ear",
- "/Ground plane/OutsideDupliGrandParent/OutsideDupliParent/GEO_Head/GEO_Ear_L/Ear",
- "/ParentOfDupli2/Dupli2/GEO_Head-0/GEO_Ear_L-1/Ear"}},
- {"OBGEO_Ear_R",
- {"/Dupli1/GEO_Head-0/GEO_Ear_R-2/Ear",
- "/Ground plane/OutsideDupliGrandParent/OutsideDupliParent/GEO_Head/GEO_Ear_R/Ear",
- "/ParentOfDupli2/Dupli2/GEO_Head-0/GEO_Ear_R-2/Ear"}},
- {"OBGEO_Head",
- {"/Dupli1/GEO_Head-0/Face",
- "/Ground plane/OutsideDupliGrandParent/OutsideDupliParent/GEO_Head/Face",
- "/ParentOfDupli2/Dupli2/GEO_Head-0/Face"}},
- {"OBGEO_Nose",
- {"/Dupli1/GEO_Head-0/GEO_Nose-3/Nose",
- "/Ground plane/OutsideDupliGrandParent/OutsideDupliParent/GEO_Head/GEO_Nose/Nose",
- "/ParentOfDupli2/Dupli2/GEO_Head-0/GEO_Nose-3/Nose"}},
- {"OBGround plane", {"/Ground plane/Plane"}},
- {"OBParentOfDupli2", {"/ParentOfDupli2/Icosphere"}},
- };
-
- EXPECT_EQ(expected_data, iterator->data_writers);
-
- // The scene has no hair or particle systems.
- EXPECT_EQ(0, iterator->hair_writers.size());
- EXPECT_EQ(0, iterator->particle_writers.size());
-
- // On the second iteration, everything should be written as well.
- // This tests the default value of iterator->export_subset_.
- iterator->transform_writers.clear();
- iterator->data_writers.clear();
- iterator->iterate_and_write();
- EXPECT_EQ(expected_transforms, iterator->transform_writers);
- EXPECT_EQ(expected_data, iterator->data_writers);
-}
-
-TEST_F(USDHierarchyIteratorTest, ExportSubsetTest)
-{
- // The scene has no hair or particle systems, and this is already covered by ExportHierarchyTest,
- // so not included here. Update this test when hair & particle systems are included.
-
- /* Load the test blend file. */
- if (!blendfile_load("usd/usd_hierarchy_export_test.blend")) {
- return;
- }
- depsgraph_create(DAG_EVAL_RENDER);
- iterator_create();
-
- // Mapping from object name to set of export paths.
- used_writers expected_transforms = {
- {"OBCamera", {"/Camera"}},
- {"OBDupli1", {"/Dupli1"}},
- {"OBDupli2", {"/ParentOfDupli2/Dupli2"}},
- {"OBGEO_Ear_L",
- {"/Dupli1/GEO_Head-0/GEO_Ear_L-1",
- "/Ground plane/OutsideDupliGrandParent/OutsideDupliParent/GEO_Head/GEO_Ear_L",
- "/ParentOfDupli2/Dupli2/GEO_Head-0/GEO_Ear_L-1"}},
- {"OBGEO_Ear_R",
- {"/Dupli1/GEO_Head-0/GEO_Ear_R-2",
- "/Ground plane/OutsideDupliGrandParent/OutsideDupliParent/GEO_Head/GEO_Ear_R",
- "/ParentOfDupli2/Dupli2/GEO_Head-0/GEO_Ear_R-2"}},
- {"OBGEO_Head",
- {"/Dupli1/GEO_Head-0",
- "/Ground plane/OutsideDupliGrandParent/OutsideDupliParent/GEO_Head",
- "/ParentOfDupli2/Dupli2/GEO_Head-0"}},
- {"OBGEO_Nose",
- {"/Dupli1/GEO_Head-0/GEO_Nose-3",
- "/Ground plane/OutsideDupliGrandParent/OutsideDupliParent/GEO_Head/GEO_Nose",
- "/ParentOfDupli2/Dupli2/GEO_Head-0/GEO_Nose-3"}},
- {"OBGround plane", {"/Ground plane"}},
- {"OBOutsideDupliGrandParent", {"/Ground plane/OutsideDupliGrandParent"}},
- {"OBOutsideDupliParent", {"/Ground plane/OutsideDupliGrandParent/OutsideDupliParent"}},
- {"OBParentOfDupli2", {"/ParentOfDupli2"}}};
-
- used_writers expected_data = {
- {"OBCamera", {"/Camera/Camera"}},
- {"OBGEO_Ear_L",
- {"/Dupli1/GEO_Head-0/GEO_Ear_L-1/Ear",
- "/Ground plane/OutsideDupliGrandParent/OutsideDupliParent/GEO_Head/GEO_Ear_L/Ear",
- "/ParentOfDupli2/Dupli2/GEO_Head-0/GEO_Ear_L-1/Ear"}},
- {"OBGEO_Ear_R",
- {"/Dupli1/GEO_Head-0/GEO_Ear_R-2/Ear",
- "/Ground plane/OutsideDupliGrandParent/OutsideDupliParent/GEO_Head/GEO_Ear_R/Ear",
- "/ParentOfDupli2/Dupli2/GEO_Head-0/GEO_Ear_R-2/Ear"}},
- {"OBGEO_Head",
- {"/Dupli1/GEO_Head-0/Face",
- "/Ground plane/OutsideDupliGrandParent/OutsideDupliParent/GEO_Head/Face",
- "/ParentOfDupli2/Dupli2/GEO_Head-0/Face"}},
- {"OBGEO_Nose",
- {"/Dupli1/GEO_Head-0/GEO_Nose-3/Nose",
- "/Ground plane/OutsideDupliGrandParent/OutsideDupliParent/GEO_Head/GEO_Nose/Nose",
- "/ParentOfDupli2/Dupli2/GEO_Head-0/GEO_Nose-3/Nose"}},
- {"OBGround plane", {"/Ground plane/Plane"}},
- {"OBParentOfDupli2", {"/ParentOfDupli2/Icosphere"}},
- };
-
- // Even when only asking an export of transforms, on the first frame everything should be
- // exported.
- {
- ExportSubset export_subset = {0};
- export_subset.transforms = true;
- export_subset.shapes = false;
- iterator->set_export_subset(export_subset);
- }
- iterator->iterate_and_write();
- EXPECT_EQ(expected_transforms, iterator->transform_writers);
- EXPECT_EQ(expected_data, iterator->data_writers);
-
- // Clear data to prepare for the next iteration.
- iterator->transform_writers.clear();
- iterator->data_writers.clear();
-
- // Second iteration, should only write transforms now.
- iterator->iterate_and_write();
- EXPECT_EQ(expected_transforms, iterator->transform_writers);
- EXPECT_EQ(0, iterator->data_writers.size());
-
- // Clear data to prepare for the next iteration.
- iterator->transform_writers.clear();
- iterator->data_writers.clear();
-
- // Third iteration, should only write data now.
- {
- ExportSubset export_subset = {0};
- export_subset.transforms = false;
- export_subset.shapes = true;
- iterator->set_export_subset(export_subset);
- }
- iterator->iterate_and_write();
- EXPECT_EQ(0, iterator->transform_writers.size());
- EXPECT_EQ(expected_data, iterator->data_writers);
-
- // Clear data to prepare for the next iteration.
- iterator->transform_writers.clear();
- iterator->data_writers.clear();
-
- // Fourth iteration, should export everything now.
- {
- ExportSubset export_subset = {0};
- export_subset.transforms = true;
- export_subset.shapes = true;
- iterator->set_export_subset(export_subset);
- }
- iterator->iterate_and_write();
- EXPECT_EQ(expected_transforms, iterator->transform_writers);
- EXPECT_EQ(expected_data, iterator->data_writers);
-}
diff --git a/tests/gtests/usd/hierarchy_context_order_test.cc b/tests/gtests/usd/hierarchy_context_order_test.cc
deleted file mode 100644
index 25cda6d8670..00000000000
--- a/tests/gtests/usd/hierarchy_context_order_test.cc
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * 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.
- */
-#include "IO_abstract_hierarchy_iterator.h"
-
-#include "testing/testing.h"
-
-extern "C" {
-#include "BLI_utildefines.h"
-}
-
-using namespace blender::io;
-
-class HierarchyContextOrderTest : public testing::Test {
-};
-
-static Object *fake_pointer(int value)
-{
- return static_cast<Object *>(POINTER_FROM_INT(value));
-}
-
-TEST_F(HierarchyContextOrderTest, ObjectPointerTest)
-{
- HierarchyContext ctx_a = {0};
- ctx_a.object = fake_pointer(1);
- ctx_a.duplicator = nullptr;
-
- HierarchyContext ctx_b = {0};
- ctx_b.object = fake_pointer(2);
- ctx_b.duplicator = nullptr;
-
- EXPECT_LT(ctx_a, ctx_b);
- EXPECT_FALSE(ctx_b < ctx_a);
- EXPECT_FALSE(ctx_a < ctx_a);
-}
-
-TEST_F(HierarchyContextOrderTest, DuplicatorPointerTest)
-{
- HierarchyContext ctx_a = {0};
- ctx_a.object = fake_pointer(1);
- ctx_a.duplicator = fake_pointer(1);
- ctx_a.export_name = "A";
-
- HierarchyContext ctx_b = {0};
- ctx_b.object = fake_pointer(1);
- ctx_b.duplicator = fake_pointer(1);
- ctx_b.export_name = "B";
-
- EXPECT_LT(ctx_a, ctx_b);
- EXPECT_FALSE(ctx_b < ctx_a);
- EXPECT_FALSE(ctx_a < ctx_a);
-}
-
-TEST_F(HierarchyContextOrderTest, ExportParentTest)
-{
- HierarchyContext ctx_a = {0};
- ctx_a.object = fake_pointer(1);
- ctx_a.export_parent = fake_pointer(1);
-
- HierarchyContext ctx_b = {0};
- ctx_b.object = fake_pointer(1);
- ctx_b.export_parent = fake_pointer(2);
-
- EXPECT_LT(ctx_a, ctx_b);
- EXPECT_FALSE(ctx_b < ctx_a);
- EXPECT_FALSE(ctx_a < ctx_a);
-}
-
-TEST_F(HierarchyContextOrderTest, TransitiveTest)
-{
- HierarchyContext ctx_a = {0};
- ctx_a.object = fake_pointer(1);
- ctx_a.export_parent = fake_pointer(1);
- ctx_a.duplicator = nullptr;
- ctx_a.export_name = "A";
-
- HierarchyContext ctx_b = {0};
- ctx_b.object = fake_pointer(2);
- ctx_b.export_parent = nullptr;
- ctx_b.duplicator = fake_pointer(1);
- ctx_b.export_name = "B";
-
- HierarchyContext ctx_c = {0};
- ctx_c.object = fake_pointer(2);
- ctx_c.export_parent = fake_pointer(2);
- ctx_c.duplicator = fake_pointer(1);
- ctx_c.export_name = "C";
-
- HierarchyContext ctx_d = {0};
- ctx_d.object = fake_pointer(2);
- ctx_d.export_parent = fake_pointer(3);
- ctx_d.duplicator = nullptr;
- ctx_d.export_name = "D";
-
- EXPECT_LT(ctx_a, ctx_b);
- EXPECT_LT(ctx_a, ctx_c);
- EXPECT_LT(ctx_a, ctx_d);
- EXPECT_LT(ctx_b, ctx_c);
- EXPECT_LT(ctx_b, ctx_d);
- EXPECT_LT(ctx_c, ctx_d);
-
- EXPECT_FALSE(ctx_b < ctx_a);
- EXPECT_FALSE(ctx_c < ctx_a);
- EXPECT_FALSE(ctx_d < ctx_a);
- EXPECT_FALSE(ctx_c < ctx_b);
- EXPECT_FALSE(ctx_d < ctx_b);
- EXPECT_FALSE(ctx_d < ctx_c);
-}
diff --git a/tests/gtests/usd/object_identifier_test.cc b/tests/gtests/usd/object_identifier_test.cc
deleted file mode 100644
index 810d4470260..00000000000
--- a/tests/gtests/usd/object_identifier_test.cc
+++ /dev/null
@@ -1,236 +0,0 @@
-/*
- * 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.
- */
-#include "IO_abstract_hierarchy_iterator.h"
-
-#include "testing/testing.h"
-
-#include "BLI_utildefines.h"
-
-#include <climits>
-
-namespace blender {
-namespace io {
-
-namespace {
-
-/* Return object pointer for use in tests. This makes it possible to reliably test for
- * order/equality functions while using hard-coded values for simplicity. */
-Object *fake_pointer(int value)
-{
- return static_cast<Object *>(POINTER_FROM_INT(value));
-}
-
-/* PersistentID subclass for use in tests, making it easier to construct test values. */
-class TestPersistentID : public PersistentID {
- public:
- TestPersistentID(int value0,
- int value1,
- int value2,
- int value3,
- int value4,
- int value5,
- int value6,
- int value7)
- {
- persistent_id_[0] = value0;
- persistent_id_[1] = value1;
- persistent_id_[2] = value2;
- persistent_id_[3] = value3;
- persistent_id_[4] = value4;
- persistent_id_[5] = value5;
- persistent_id_[6] = value6;
- persistent_id_[7] = value7;
- }
- TestPersistentID(int value0, int value1, int value2)
- : TestPersistentID(value0, value1, value2, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX)
- {
- }
- TestPersistentID(int value0, int value1) : TestPersistentID(value0, value1, INT_MAX)
- {
- }
- explicit TestPersistentID(int value0) : TestPersistentID(value0, INT_MAX)
- {
- }
-};
-
-/* ObjectIdentifier subclass for use in tests, making it easier to construct test values. */
-class TestObjectIdentifier : public ObjectIdentifier {
- public:
- TestObjectIdentifier(Object *object, Object *duplicated_by, const PersistentID &persistent_id)
- : ObjectIdentifier(object, duplicated_by, persistent_id)
- {
- }
-};
-
-} // namespace
-
-class ObjectIdentifierOrderTest : public testing::Test {
-};
-
-TEST_F(ObjectIdentifierOrderTest, graph_root)
-{
- ObjectIdentifier id_root_1 = ObjectIdentifier::for_graph_root();
- ObjectIdentifier id_root_2 = ObjectIdentifier::for_graph_root();
- EXPECT_TRUE(id_root_1 == id_root_2);
- EXPECT_FALSE(id_root_1 < id_root_2);
- EXPECT_FALSE(id_root_2 < id_root_1);
-
- ObjectIdentifier id_a = ObjectIdentifier::for_real_object(fake_pointer(1));
- EXPECT_FALSE(id_root_1 == id_a);
- EXPECT_TRUE(id_root_1 < id_a);
- EXPECT_FALSE(id_a < id_root_1);
-
- ObjectIdentifier id_accidental_root = ObjectIdentifier::for_real_object(nullptr);
- EXPECT_TRUE(id_root_1 == id_accidental_root);
- EXPECT_FALSE(id_root_1 < id_accidental_root);
- EXPECT_FALSE(id_accidental_root < id_root_1);
-}
-
-TEST_F(ObjectIdentifierOrderTest, real_objects)
-{
- ObjectIdentifier id_a = ObjectIdentifier::for_real_object(fake_pointer(1));
- ObjectIdentifier id_b = ObjectIdentifier::for_real_object(fake_pointer(2));
- EXPECT_FALSE(id_a == id_b);
- EXPECT_TRUE(id_a < id_b);
-}
-
-TEST_F(ObjectIdentifierOrderTest, duplicated_objects)
-{
- ObjectIdentifier id_real_a = ObjectIdentifier::for_real_object(fake_pointer(1));
- TestObjectIdentifier id_dupli_a(fake_pointer(1), fake_pointer(2), TestPersistentID(0));
- TestObjectIdentifier id_dupli_b(fake_pointer(1), fake_pointer(3), TestPersistentID(0));
- TestObjectIdentifier id_different_dupli_b(fake_pointer(1), fake_pointer(3), TestPersistentID(1));
-
- EXPECT_FALSE(id_real_a == id_dupli_a);
- EXPECT_FALSE(id_dupli_a == id_dupli_b);
- EXPECT_TRUE(id_real_a < id_dupli_a);
- EXPECT_TRUE(id_real_a < id_dupli_b);
- EXPECT_TRUE(id_dupli_a < id_dupli_b);
- EXPECT_TRUE(id_dupli_a < id_different_dupli_b);
-
- EXPECT_FALSE(id_dupli_b == id_different_dupli_b);
- EXPECT_FALSE(id_dupli_a == id_different_dupli_b);
- EXPECT_TRUE(id_dupli_b < id_different_dupli_b);
- EXPECT_FALSE(id_different_dupli_b < id_dupli_b);
-}
-
-TEST_F(ObjectIdentifierOrderTest, behaviour_as_map_keys)
-{
- ObjectIdentifier id_root = ObjectIdentifier::for_graph_root();
- ObjectIdentifier id_another_root = ObjectIdentifier::for_graph_root();
- ObjectIdentifier id_real_a = ObjectIdentifier::for_real_object(fake_pointer(1));
- TestObjectIdentifier id_dupli_a(fake_pointer(1), fake_pointer(2), TestPersistentID(0));
- TestObjectIdentifier id_dupli_b(fake_pointer(1), fake_pointer(3), TestPersistentID(0));
- AbstractHierarchyIterator::ExportGraph graph;
-
- /* This inserts the keys with default values. */
- graph[id_root];
- graph[id_real_a];
- graph[id_dupli_a];
- graph[id_dupli_b];
- graph[id_another_root];
-
- EXPECT_EQ(4, graph.size());
-
- graph.erase(id_another_root);
- EXPECT_EQ(3, graph.size());
-
- TestObjectIdentifier id_another_dupli_b(fake_pointer(1), fake_pointer(3), TestPersistentID(0));
- graph.erase(id_another_dupli_b);
- EXPECT_EQ(2, graph.size());
-}
-
-TEST_F(ObjectIdentifierOrderTest, map_copy_and_update)
-{
- ObjectIdentifier id_root = ObjectIdentifier::for_graph_root();
- ObjectIdentifier id_real_a = ObjectIdentifier::for_real_object(fake_pointer(1));
- TestObjectIdentifier id_dupli_a(fake_pointer(1), fake_pointer(2), TestPersistentID(0));
- TestObjectIdentifier id_dupli_b(fake_pointer(1), fake_pointer(3), TestPersistentID(0));
- TestObjectIdentifier id_dupli_c(fake_pointer(1), fake_pointer(3), TestPersistentID(1));
- AbstractHierarchyIterator::ExportGraph graph;
-
- /* This inserts the keys with default values. */
- graph[id_root];
- graph[id_real_a];
- graph[id_dupli_a];
- graph[id_dupli_b];
- graph[id_dupli_c];
- EXPECT_EQ(5, graph.size());
-
- AbstractHierarchyIterator::ExportGraph graph_copy = graph;
- EXPECT_EQ(5, graph_copy.size());
-
- // Updating a value in a copy should not update the original.
- HierarchyContext ctx1;
- HierarchyContext ctx2;
- ctx1.object = fake_pointer(1);
- ctx2.object = fake_pointer(2);
-
- graph_copy[id_root].insert(&ctx1);
- EXPECT_EQ(0, graph[id_root].size());
-
- // Deleting a key in the copy should not update the original.
- graph_copy.erase(id_dupli_c);
- EXPECT_EQ(4, graph_copy.size());
- EXPECT_EQ(5, graph.size());
-}
-
-class PersistentIDTest : public testing::Test {
-};
-
-TEST_F(PersistentIDTest, is_from_same_instancer)
-{
- PersistentID child_id_a = TestPersistentID(42, 327);
- PersistentID child_id_b = TestPersistentID(17, 327);
- PersistentID child_id_c = TestPersistentID(17);
-
- EXPECT_TRUE(child_id_a.is_from_same_instancer_as(child_id_b));
- EXPECT_FALSE(child_id_a.is_from_same_instancer_as(child_id_c));
-}
-
-TEST_F(PersistentIDTest, instancer_id)
-{
- PersistentID child_id = TestPersistentID(42, 327);
-
- PersistentID expect_instancer_id = TestPersistentID(327);
- EXPECT_EQ(expect_instancer_id, child_id.instancer_pid());
-
- PersistentID empty_id;
- EXPECT_EQ(empty_id, child_id.instancer_pid().instancer_pid());
-
- EXPECT_LT(child_id, expect_instancer_id);
- EXPECT_LT(expect_instancer_id, empty_id);
-}
-
-TEST_F(PersistentIDTest, as_object_name_suffix)
-{
- EXPECT_EQ("", PersistentID().as_object_name_suffix());
- EXPECT_EQ("47", TestPersistentID(47).as_object_name_suffix());
- EXPECT_EQ("327-47", TestPersistentID(47, 327).as_object_name_suffix());
- EXPECT_EQ("42-327-47", TestPersistentID(47, 327, 42).as_object_name_suffix());
-
- EXPECT_EQ("7-6-5-4-3-2-1-0", TestPersistentID(0, 1, 2, 3, 4, 5, 6, 7).as_object_name_suffix());
-
- EXPECT_EQ("0-0-0", TestPersistentID(0, 0, 0).as_object_name_suffix());
- EXPECT_EQ("0-0", TestPersistentID(0, 0).as_object_name_suffix());
- EXPECT_EQ("-3--2--1", TestPersistentID(-1, -2, -3).as_object_name_suffix());
-}
-
-} // namespace io
-} // namespace blender
diff --git a/tests/gtests/usd/usd_stage_creation_test.cc b/tests/gtests/usd/usd_stage_creation_test.cc
deleted file mode 100644
index b262e21f053..00000000000
--- a/tests/gtests/usd/usd_stage_creation_test.cc
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * 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.
- */
-#include "testing/testing.h"
-#include <pxr/usd/usd/stage.h>
-
-#include <string>
-
-extern "C" {
-#include "BLI_path_util.h"
-#include "BLI_utildefines.h"
-
-#include "BKE_appdir.h"
-
-/* 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.");
-
-class USDStageCreationTest : public testing::Test {
-};
-
-TEST_F(USDStageCreationTest, JSONFileLoadingTest)
-{
- if (FLAGS_test_usd_datafiles_dir.empty()) {
- FAIL() << "Pass the --test-usd-datafiles-dir flag";
- }
-
- usd_initialise_plugin_path(FLAGS_test_usd_datafiles_dir.c_str());
-
- /* 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
- * files. Practically, this is a test to see whether the USD JSON files can be found and
- * loaded. */
- std::string filename = "usd-stage-creation-test.usdc";
- pxr::UsdStageRefPtr usd_stage = pxr::UsdStage::CreateNew(filename);
- if (usd_stage != nullptr) {
- /* Even though we don't call usd_stage->SaveFile(), a file is still created on the filesystem
- * when we call CreateNew(). It's immediately closed, though, so we can safely call unlink()
- * here. */
- unlink(filename.c_str());
- }
- else {
- FAIL() << "unable to find suitable USD plugin to write " << filename;
- }
-}