[Bf-blender-cvs] [e6c40bc9e1f] master: USD: Simplified unit test and made it work on Windows as well

Sybren A. Stüvel noreply at git.blender.org
Fri Dec 13 18:59:39 CET 2019


Commit: e6c40bc9e1f11e306977e5a5090501b8c922fb98
Author: Sybren A. Stüvel
Date:   Fri Dec 13 18:56:55 2019 +0100
Branches: master
https://developer.blender.org/rBe6c40bc9e1f11e306977e5a5090501b8c922fb98

USD: Simplified unit test and made it work on Windows as well

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

M	tests/gtests/usd/CMakeLists.txt
M	tests/gtests/usd/usd_stage_creation_test.cc

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

diff --git a/tests/gtests/usd/CMakeLists.txt b/tests/gtests/usd/CMakeLists.txt
index e2768509ec4..8dbfb93f0f1 100644
--- a/tests/gtests/usd/CMakeLists.txt
+++ b/tests/gtests/usd/CMakeLists.txt
@@ -64,7 +64,7 @@ set(SRC
   hierarchy_context_order_test.cc
 )
 
-if(UNIX AND NOT APPLE)
+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)
@@ -75,13 +75,24 @@ 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"
-    --test-blender-executable-dir "${EXECUTABLE_OUTPUT_PATH}"
+    --test-usd-datafiles-dir "${_usd_DATAFILES_DIR}"
 )
+unset(_usd_DATAFILES_DIR)
 
 setup_liblinks(usd_test)
diff --git a/tests/gtests/usd/usd_stage_creation_test.cc b/tests/gtests/usd/usd_stage_creation_test.cc
index 9d76b42371d..b262e21f053 100644
--- a/tests/gtests/usd/usd_stage_creation_test.cc
+++ b/tests/gtests/usd/usd_stage_creation_test.cc
@@ -31,43 +31,24 @@ extern "C" {
 void usd_initialise_plugin_path(const char *datafiles_usd_path);
 }
 
-DEFINE_string(test_blender_executable_dir, "", "Blender's installation directory.");
+DEFINE_string(test_usd_datafiles_dir, "", "The bin/{BLENDER_VERSION}/datafiles/usd directory.");
 
 class USDStageCreationTest : public testing::Test {
 };
 
 TEST_F(USDStageCreationTest, JSONFileLoadingTest)
 {
-  std::string filename = "usd-stage-creation-test.usdc";
-
-  if (FLAGS_test_blender_executable_dir.empty()) {
-    FAIL() << "Pass the --test-blender-executable-dir flag";
-  }
-
-  /* Required on Linux to make BKE_appdir_folder_id() find the datafiles.
-   * Without going to this directory, Blender looks for the datafiles in
-   * .../bin/tests instead of .../bin */
-  const char *blender_executable_dir = FLAGS_test_blender_executable_dir.c_str();
-  if (chdir(blender_executable_dir) < 0) {
-    FAIL() << "unable to change directory to " << FLAGS_test_blender_executable_dir;
+  if (FLAGS_test_usd_datafiles_dir.empty()) {
+    FAIL() << "Pass the --test-usd-datafiles-dir flag";
   }
 
-  const char *usd_datafiles_relpath = BKE_appdir_folder_id(BLENDER_DATAFILES, "usd");
-  EXPECT_NE(usd_datafiles_relpath, nullptr) << "Unable to find datafiles/usd";
-
-  char usd_datafiles_abspath[FILE_MAX];
-  BLI_path_join(usd_datafiles_abspath,
-                sizeof(usd_datafiles_abspath),
-                blender_executable_dir,
-                usd_datafiles_relpath,
-                NULL);
-
-  usd_initialise_plugin_path(usd_datafiles_abspath);
+  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



More information about the Bf-blender-cvs mailing list