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-12 12:28:16 +0300
committerSybren A. Stüvel <sybren@blender.org>2021-10-12 12:28:16 +0300
commitad1735f8ede966b7d49423928ad05cca25119949 (patch)
tree27c351114b6f66ef50418445fb35e16c9edbf6e1 /source/blender/blenkernel/intern/asset_catalog_test.cc
parentac657bee0142f96fcd3fa5d56455658834a19b19 (diff)
Asset Catalogs: recursive deletion of catalogs & children
Recursively delete asset catalogs with `AssetCatalogService:prune_...` functions. This deletes the catalog and all of its children. The old `delete_catalog` function has been renamed to `delete_catalog_by_id()`, and is now a lower-level function (no deletion of children, no rebuilding of the tree). The `prune_catalogs_by_path()` and `prune_catalogs_by_id()` do delete children and do rebuild the catalog tree. Manifest task: T91634
Diffstat (limited to 'source/blender/blenkernel/intern/asset_catalog_test.cc')
-rw-r--r--source/blender/blenkernel/intern/asset_catalog_test.cc58
1 files changed, 55 insertions, 3 deletions
diff --git a/source/blender/blenkernel/intern/asset_catalog_test.cc b/source/blender/blenkernel/intern/asset_catalog_test.cc
index 69efab76b43..cf06638bcdd 100644
--- a/source/blender/blenkernel/intern/asset_catalog_test.cc
+++ b/source/blender/blenkernel/intern/asset_catalog_test.cc
@@ -719,7 +719,7 @@ TEST_F(AssetCatalogTest, delete_catalog_leaf)
/* Delete a leaf catalog, i.e. one that is not a parent of another catalog.
* This keeps this particular test easy. */
- service.delete_catalog(UUID_POSES_RUZENA_HAND);
+ service.prune_catalogs_by_id(UUID_POSES_RUZENA_HAND);
EXPECT_EQ(nullptr, service.find_catalog(UUID_POSES_RUZENA_HAND));
/* Contains not only paths from the CDF but also the missing parents (implicitly defined
@@ -743,13 +743,65 @@ TEST_F(AssetCatalogTest, delete_catalog_leaf)
assert_expected_tree_items(tree, expected_paths);
}
+TEST_F(AssetCatalogTest, delete_catalog_parent_by_id)
+{
+ AssetCatalogService service(asset_library_root_);
+ service.load_from_disk(asset_library_root_ + "/" + "blender_assets.cats.txt");
+
+ /* Delete a parent catalog. */
+ service.delete_catalog_by_id(UUID_POSES_RUZENA);
+
+ /* The catalog should have been deleted, but its children should still be there. */
+ EXPECT_EQ(nullptr, service.find_catalog(UUID_POSES_RUZENA));
+ EXPECT_NE(nullptr, service.find_catalog(UUID_POSES_RUZENA_FACE));
+ EXPECT_NE(nullptr, service.find_catalog(UUID_POSES_RUZENA_HAND));
+}
+
+TEST_F(AssetCatalogTest, delete_catalog_parent_by_path)
+{
+ AssetCatalogService service(asset_library_root_);
+ service.load_from_disk(asset_library_root_ + "/" + "blender_assets.cats.txt");
+
+ /* Create an extra catalog with the to-be-deleted path, and one with a child of that.
+ * This creates some duplicates that are bound to occur in production asset libraries as well. */
+ const bUUID cat1_uuid = service.create_catalog("character/Ružena/poselib")->catalog_id;
+ const bUUID cat2_uuid = service.create_catalog("character/Ružena/poselib/body")->catalog_id;
+
+ /* Delete a parent catalog. */
+ service.prune_catalogs_by_path("character/Ružena/poselib");
+
+ /* The catalogs and their children should have been deleted. */
+ EXPECT_EQ(nullptr, service.find_catalog(UUID_POSES_RUZENA));
+ EXPECT_EQ(nullptr, service.find_catalog(UUID_POSES_RUZENA_FACE));
+ EXPECT_EQ(nullptr, service.find_catalog(UUID_POSES_RUZENA_HAND));
+ EXPECT_EQ(nullptr, service.find_catalog(cat1_uuid));
+ EXPECT_EQ(nullptr, service.find_catalog(cat2_uuid));
+
+ /* Contains not only paths from the CDF but also the missing parents (implicitly defined
+ * catalogs). This is why a leaf catalog was deleted. */
+ std::vector<AssetCatalogPath> expected_paths{
+ "character",
+ "character/Ellie",
+ "character/Ellie/poselib",
+ "character/Ellie/poselib/tailslash",
+ "character/Ellie/poselib/white space",
+ "character/Ružena",
+ "path",
+ "path/without",
+ "path/without/simplename",
+ };
+
+ AssetCatalogTree *tree = service.get_catalog_tree();
+ assert_expected_tree_items(tree, expected_paths);
+}
+
TEST_F(AssetCatalogTest, delete_catalog_write_to_disk)
{
TestableAssetCatalogService service(asset_library_root_);
service.load_from_disk(asset_library_root_ + "/" +
AssetCatalogService::DEFAULT_CATALOG_FILENAME);
- service.delete_catalog(UUID_POSES_ELLIE);
+ service.delete_catalog_by_id(UUID_POSES_ELLIE);
const CatalogFilePath save_to_path = use_temp_path();
AssetCatalogDefinitionFile *cdf = service.get_catalog_definition_file();
@@ -844,7 +896,7 @@ TEST_F(AssetCatalogTest, backups)
/* Read a CDF, modify, and write it. */
AssetCatalogService service(cdf_dir);
service.load_from_disk();
- service.delete_catalog(UUID_POSES_ELLIE);
+ service.delete_catalog_by_id(UUID_POSES_ELLIE);
service.write_to_disk_on_blendfile_save(cdf_dir + "phony.blend");
const CatalogFilePath backup_path = writable_cdf_file + "~";