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>2021-10-19 16:22:40 +0300
committerSybren A. Stüvel <sybren@blender.org>2021-10-19 16:53:11 +0300
commit9a1d75e0b9580819dba188afdab72295cbf47302 (patch)
treed8f4b6d299ef8531b6c205b8aa6c52454b9ce23c /source/blender/blenkernel/intern/asset_library_service_test.cc
parenta7075a30e2611b41af672d5987af662ce5934492 (diff)
Asset Library Service: make insensitive to trailing slashes
Make `AssetLibraryService::get_asset_library_on_disk(path)` insensitive to trailing slashes; i.e. `get_asset_library_on_disk("/path")` and `get_asset_library_on_disk("/path/¨)` will now return the same `AssetLibrary*`.
Diffstat (limited to 'source/blender/blenkernel/intern/asset_library_service_test.cc')
-rw-r--r--source/blender/blenkernel/intern/asset_library_service_test.cc26
1 files changed, 26 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/asset_library_service_test.cc b/source/blender/blenkernel/intern/asset_library_service_test.cc
index b4bb1dc0895..ed299028c41 100644
--- a/source/blender/blenkernel/intern/asset_library_service_test.cc
+++ b/source/blender/blenkernel/intern/asset_library_service_test.cc
@@ -19,6 +19,8 @@
#include "asset_library_service.hh"
+#include "BLI_path_util.h"
+
#include "CLG_log.h"
#include "testing/testing.h"
@@ -84,6 +86,30 @@ TEST_F(AssetLibraryServiceTest, library_pointers)
* cannot be reliably tested by just pointer comparison, though. */
}
+TEST_F(AssetLibraryServiceTest, library_path_trailing_slashes)
+{
+ AssetLibraryService *service = AssetLibraryService::get();
+
+ char asset_lib_no_slash[PATH_MAX];
+ char asset_lib_with_slash[PATH_MAX];
+ STRNCPY(asset_lib_no_slash, asset_library_root_.c_str());
+ STRNCPY(asset_lib_with_slash, asset_library_root_.c_str());
+
+ /* Ensure #asset_lib_no_slash has no trailing slash, regardless of what was passed on the CLI to
+ * the unit test. */
+ while (strlen(asset_lib_no_slash) &&
+ ELEM(asset_lib_no_slash[strlen(asset_lib_no_slash) - 1], SEP, ALTSEP)) {
+ asset_lib_no_slash[strlen(asset_lib_no_slash) - 1] = '\0';
+ }
+
+ BLI_path_slash_ensure(asset_lib_with_slash);
+
+ AssetLibrary *const lib_no_slash = service->get_asset_library_on_disk(asset_lib_no_slash);
+
+ EXPECT_EQ(lib_no_slash, service->get_asset_library_on_disk(asset_lib_with_slash))
+ << "With or without trailing slash shouldn't matter.";
+}
+
TEST_F(AssetLibraryServiceTest, catalogs_loaded)
{
AssetLibraryService *const service = AssetLibraryService::get();