Blender V4.3
asset_catalog_tree_test.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2020 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "AS_asset_catalog.hh"
9
10#include "BLI_path_utils.hh"
11
12#include "testing/testing.h"
13
15
17
19
20TEST_F(AssetCatalogTreeTest, insert_item_into_tree)
21{
22 {
24 std::unique_ptr<AssetCatalog> catalog_empty_path = AssetCatalog::from_path("");
25 tree.insert_item(*catalog_empty_path);
26
27 expect_tree_items(tree, {});
28 }
29
30 {
32
33 std::unique_ptr<AssetCatalog> catalog = AssetCatalog::from_path("item");
34 tree.insert_item(*catalog);
35 expect_tree_items(tree, {"item"});
36
37 /* Insert child after parent already exists. */
38 std::unique_ptr<AssetCatalog> child_catalog = AssetCatalog::from_path("item/child");
39 tree.insert_item(*catalog);
40 expect_tree_items(tree, {"item", "item/child"});
41
42 std::vector<AssetCatalogPath> expected_paths;
43
44 /* Test inserting multi-component sub-path. */
45 std::unique_ptr<AssetCatalog> grandgrandchild_catalog = AssetCatalog::from_path(
46 "item/child/grandchild/grandgrandchild");
47 tree.insert_item(*catalog);
48 expected_paths = {
49 "item", "item/child", "item/child/grandchild", "item/child/grandchild/grandgrandchild"};
50 expect_tree_items(tree, expected_paths);
51
52 std::unique_ptr<AssetCatalog> root_level_catalog = AssetCatalog::from_path("root level");
53 tree.insert_item(*catalog);
54 expected_paths = {"item",
55 "item/child",
56 "item/child/grandchild",
57 "item/child/grandchild/grandgrandchild",
58 "root level"};
59 expect_tree_items(tree, expected_paths);
60 }
61
62 {
64
65 std::unique_ptr<AssetCatalog> catalog = AssetCatalog::from_path("item/child");
66 tree.insert_item(*catalog);
67 expect_tree_items(tree, {"item", "item/child"});
68 }
69
70 {
72
73 std::unique_ptr<AssetCatalog> catalog = AssetCatalog::from_path("white space");
74 tree.insert_item(*catalog);
75 expect_tree_items(tree, {"white space"});
76 }
77
78 {
80
81 std::unique_ptr<AssetCatalog> catalog = AssetCatalog::from_path("/item/white space");
82 tree.insert_item(*catalog);
83 expect_tree_items(tree, {"item", "item/white space"});
84 }
85
86 {
88
89 std::unique_ptr<AssetCatalog> catalog_unicode_path = AssetCatalog::from_path("Ružena");
90 tree.insert_item(*catalog_unicode_path);
91 expect_tree_items(tree, {"Ružena"});
92
93 catalog_unicode_path = AssetCatalog::from_path("Ružena/Ružena");
94 tree.insert_item(*catalog_unicode_path);
95 expect_tree_items(tree, {"Ružena", "Ružena/Ružena"});
96 }
97}
98
99TEST_F(AssetCatalogTreeTest, load_single_file_into_tree)
100{
101 AssetCatalogService service(asset_library_root_);
102 service.load_from_disk(asset_library_root_ + SEP_STR + "blender_assets.cats.txt");
103
104 /* Contains not only paths from the CDF but also the missing parents (implicitly defined
105 * catalogs). */
106 std::vector<AssetCatalogPath> expected_paths{
107 "character",
108 "character/Ellie",
109 "character/Ellie/backslashes",
110 "character/Ellie/poselib",
111 "character/Ellie/poselib/tailslash",
112 "character/Ellie/poselib/white space",
113 "character/Ružena",
114 "character/Ružena/poselib",
115 "character/Ružena/poselib/face",
116 "character/Ružena/poselib/hand",
117 "path", /* Implicit. */
118 "path/without", /* Implicit. */
119 "path/without/simplename", /* From CDF. */
120 };
121
122 const AssetCatalogTree &tree = service.catalog_tree();
123 expect_tree_items(tree, expected_paths);
124}
125
127{
128 {
130 const std::vector<AssetCatalogPath> no_catalogs{};
131
132 expect_tree_items(tree, no_catalogs);
133 expect_tree_root_items(tree, no_catalogs);
134 /* Need a root item to check child items. */
135 std::unique_ptr<AssetCatalog> catalog = AssetCatalog::from_path("something");
136 tree.insert_item(*catalog);
137 tree.foreach_root_item([&no_catalogs](const AssetCatalogTreeItem &item) {
138 expect_tree_item_child_items(item, no_catalogs);
139 });
140 }
141
142 AssetCatalogService service(asset_library_root_);
143 service.load_from_disk(asset_library_root_ + SEP_STR + "blender_assets.cats.txt");
144
145 std::vector<AssetCatalogPath> expected_root_items{{"character", "path"}};
146 const AssetCatalogTree &tree = service.catalog_tree();
147 expect_tree_root_items(tree, expected_root_items);
148
149 /* Test if the direct children of the root item are what's expected. */
150 std::vector<std::vector<AssetCatalogPath>> expected_root_child_items = {
151 /* Children of the "character" root item. */
152 {"character/Ellie", "character/Ružena"},
153 /* Children of the "path" root item. */
154 {"path/without"},
155 };
156 int i = 0;
157 tree.foreach_root_item([&expected_root_child_items, &i](const AssetCatalogTreeItem &item) {
158 expect_tree_item_child_items(item, expected_root_child_items[i]);
159 i++;
160 });
161}
162
163} // namespace blender::asset_system::tests
static std::unique_ptr< AssetCatalog > from_path(const AssetCatalogPath &path)
KDTree_3d * tree
TEST_F(AssetCatalogTest, load_single_file)
#define SEP_STR
Definition unit.cc:39