[Bf-blender-cvs] [a138bf57c99] master: Tests: move tests from USD test directory into `io/common` and `io/usd`

Sybren A. Stüvel noreply at git.blender.org
Thu Jul 16 17:50:42 CEST 2020


Commit: a138bf57c994509c9dbd1ea79a6886c24cd5d0d9
Author: Sybren A. Stüvel
Date:   Thu Jul 16 16:10:53 2020 +0200
Branches: master
https://developer.blender.org/rBa138bf57c994509c9dbd1ea79a6886c24cd5d0d9

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

===================================================================

M	source/blender/io/common/CMakeLists.txt
R095	tests/gtests/usd/abstract_hierarchy_iterator_test.cc	source/blender/io/common/intern/abstract_hierarchy_iterator_test.cc
R096	tests/gtests/usd/hierarchy_context_order_test.cc	source/blender/io/common/intern/hierarchy_context_order_test.cc
R099	tests/gtests/usd/object_identifier_test.cc	source/blender/io/common/intern/object_identifier_test.cc
M	source/blender/io/usd/CMakeLists.txt
R084	tests/gtests/usd/usd_stage_creation_test.cc	source/blender/io/usd/tests/usd_stage_creation_test.cc
M	tests/gtests/CMakeLists.txt
M	tests/gtests/blenloader/blendfile_loading_base_test.cc
M	tests/gtests/runner/CMakeLists.txt
M	tests/gtests/testing/testing.h
M	tests/gtests/testing/testing_main.cc
D	tests/gtests/usd/CMakeLists.txt

===================================================================

diff --git a/source/blender/io/common/CMakeLists.txt b/source/blender/io/common/CMakeLists.txt
index 708f24ca0e2..a6975863413 100644
--- a/source/blender/io/common/CMakeLists.txt
+++ b/source/blender/io/common/CMakeLists.txt
@@ -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()
diff --git a/tests/gtests/usd/abstract_hierarchy_iterator_test.cc b/source/blender/io/common/intern/abstract_hierarchy_iterator_test.cc
similarity index 95%
rename from tests/gtests/usd/abstract_hierarchy_iterator_test.cc
rename to source/blender/io/common/intern/abstract_hierarchy_iterator_test.cc
index d9148a7b289..04d26422143 100644
--- a/tests/gtests/usd/abstract_hierarchy_iterator_test.cc
+++ b/source/blender/io/common/intern/abstract_hierarchy_iterator_test.cc
@@ -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
diff --git a/tests/gtests/usd/hierarchy_context_order_test.cc b/source/blender/io/common/intern/hierarchy_context_order_test.cc
similarity index 96%
rename from tests/gtests/usd/hierarchy_context_order_test.cc
rename to source/blender/io/common/intern/hierarchy_context_order_test.cc
index 25cda6d8670..7273b92c479 100644
--- a/tests/gtests/usd/hierarchy_context_order_test.cc
+++ b/source/blender/io/common/intern/hierarchy_context_order_test.cc
@@ -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
diff --git a/tests/gtests/usd/object_identifier_test.cc b/source/blender/io/common/intern/object_identifier_test.cc
similarity index 99%
rename from tests/gtests/usd/object_identifier_test.cc
rename to source/blender/io/common/intern/object_identifier_test.cc
index 810d4470260..2b565876f22 100644
--- a/tests/gtests/usd/object_identifier_test.cc
+++ b/source/blender/io/common/intern/object_identifier_test.cc
@@ -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
diff --git a/source/blender/io/usd/CMakeLists.txt b/source/blender/io/usd/CMakeLists.txt
index 19e16a5b328..79b15c60b94 100644
--- a/source/blender/io/usd/CMakeLists.txt
+++ b/source/blender/io/usd/CMakeLists.txt
@@ -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()
diff --git a/tests/gtests/usd/usd_stage_creation_test.cc b/source/blender/io/usd/tests/usd_stage_creation_test.cc
similarity index 84%
rename from tests/gtests/usd/usd_stage_creation_test.cc
rename to source/blender/io/usd/tests/usd_stage_creation_test.cc
index b262e21f053..d41ae6c4f26 100644
--- a/tests/gtests/usd/usd_stage_creation_test.cc
+++ b/source/blender/io/usd/tests/usd_stage_creation_test.cc
@@ -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
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 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list