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-09-28 17:07:18 +0300
committerSybren A. Stüvel <sybren@blender.org>2021-09-28 17:09:12 +0300
commit52a702468a59f1945ecfcf6dde6bccf648a27d36 (patch)
tree4bd067c0c0435a0f6d155f671119eea1acc142a3 /source/blender/blenkernel/intern/asset_catalog_test.cc
parentd2004326a1f96f85cb1b6f7c57712de8998ecca0 (diff)
Asset Catalog Service: add function to change catalog path
Add `AssetCatalogService::update_catalog_path()` to change the catalog path of the given catalog, and also change the path of all the catalogs contained within the given catalog. Rebuilds the tree structure for the UI, but does not save the new catalog definitions to disk. No user-facing changes, just backend preparation for UI work.
Diffstat (limited to 'source/blender/blenkernel/intern/asset_catalog_test.cc')
-rw-r--r--source/blender/blenkernel/intern/asset_catalog_test.cc48
1 files changed, 48 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/asset_catalog_test.cc b/source/blender/blenkernel/intern/asset_catalog_test.cc
index 5177abd2820..b36c15940b8 100644
--- a/source/blender/blenkernel/intern/asset_catalog_test.cc
+++ b/source/blender/blenkernel/intern/asset_catalog_test.cc
@@ -711,6 +711,37 @@ TEST_F(AssetCatalogTest, delete_catalog_write_to_disk)
EXPECT_NE(nullptr, loaded_service.find_catalog(UUID_POSES_RUZENA_FACE));
}
+TEST_F(AssetCatalogTest, update_catalog_path)
+{
+ AssetCatalogService service(asset_library_root_);
+ service.load_from_disk(asset_library_root_ + "/" +
+ AssetCatalogService::DEFAULT_CATALOG_FILENAME);
+
+ const AssetCatalog *orig_cat = service.find_catalog(UUID_POSES_RUZENA);
+ const CatalogPath orig_path = orig_cat->path;
+
+ service.update_catalog_path(UUID_POSES_RUZENA, "charlib/Ružena");
+
+ EXPECT_EQ(nullptr, service.find_catalog_by_path(orig_path))
+ << "The original (pre-rename) path should not be associated with a catalog any more.";
+
+ const AssetCatalog *renamed_cat = service.find_catalog(UUID_POSES_RUZENA);
+ ASSERT_NE(nullptr, renamed_cat);
+ ASSERT_EQ(orig_cat, renamed_cat) << "Changing the path should not reallocate the catalog.";
+ EXPECT_EQ(orig_cat->simple_name, renamed_cat->simple_name)
+ << "Changing the path should not change the simple name.";
+ EXPECT_EQ(orig_cat->catalog_id, renamed_cat->catalog_id)
+ << "Changing the path should not change the catalog ID.";
+
+ EXPECT_EQ("charlib/Ružena", renamed_cat->path)
+ << "Changing the path should change the path. Surprise.";
+
+ EXPECT_EQ("charlib/Ružena/hand", service.find_catalog(UUID_POSES_RUZENA_HAND)->path)
+ << "Changing the path should update children.";
+ EXPECT_EQ("charlib/Ružena/face", service.find_catalog(UUID_POSES_RUZENA_FACE)->path)
+ << "Changing the path should update children.";
+}
+
TEST_F(AssetCatalogTest, merge_catalog_files)
{
const CatalogFilePath cdf_dir = create_temp_path();
@@ -813,4 +844,21 @@ TEST_F(AssetCatalogTest, order_by_path)
}
}
+TEST_F(AssetCatalogTest, is_contained_in)
+{
+ const AssetCatalog cat(BLI_uuid_generate_random(), "simple/path/child", "");
+
+ EXPECT_FALSE(cat.is_contained_in("unrelated"));
+ EXPECT_FALSE(cat.is_contained_in("sim"));
+ EXPECT_FALSE(cat.is_contained_in("simple/pathx"));
+ EXPECT_FALSE(cat.is_contained_in("simple/path/c"));
+ EXPECT_FALSE(cat.is_contained_in("simple/path/child/grandchild"));
+ EXPECT_FALSE(cat.is_contained_in("simple/path/"))
+ << "Non-normalized paths are not expected to work.";
+
+ EXPECT_TRUE(cat.is_contained_in(""));
+ EXPECT_TRUE(cat.is_contained_in("simple"));
+ EXPECT_TRUE(cat.is_contained_in("simple/path"));
+}
+
} // namespace blender::bke::tests