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-08-02 12:02:47 +0300
committerSybren A. Stüvel <sybren@blender.org>2021-08-02 12:08:02 +0300
commit1f0d6f763573b22772dcdb61320a12e1c11949e0 (patch)
tree03f68b9e777d507b3aeeb21fac35a172f32b95fa /source/blender/blenkernel/intern/asset_catalog_test.cc
parent3fd5c93f9ce805b1a59bb6a03a9d39767697e336 (diff)
Asset Catalogs: loading a catalog definition file
Initial, limited implementation of loading a single asset catalog definition file. These files are structured as follows: CATALOG_ID virtual/path/of/catalog SUBCATALOG_ID virtual/path/of/catalog/child SOMETHING_ELSE some/unrelated/hierarchy These virtual paths will be used to show the catalog in a tree structure; the tree structure itself is not part of this commit. Each asset will have one catalog ID that determines where in that tree the asset shows up. Currently only a single catalog definition file can be read; merging data from multiple such files, and writing them out again after changes are made, is for future commits. This commit only contains the code to load a single file, and unittests to check that this actually works. No UI, no user-facing functionality yet.
Diffstat (limited to 'source/blender/blenkernel/intern/asset_catalog_test.cc')
-rw-r--r--source/blender/blenkernel/intern/asset_catalog_test.cc62
1 files changed, 62 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/asset_catalog_test.cc b/source/blender/blenkernel/intern/asset_catalog_test.cc
new file mode 100644
index 00000000000..d6c00670bd6
--- /dev/null
+++ b/source/blender/blenkernel/intern/asset_catalog_test.cc
@@ -0,0 +1,62 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2020 Blender Foundation
+ * All rights reserved.
+ */
+
+#include "BKE_asset_catalog.hh"
+
+#include "testing/testing.h"
+
+#include <filesystem>
+
+namespace fs = std::filesystem;
+
+namespace blender::bke::tests {
+
+TEST(AssetCatalogTest, load_single_file)
+{
+ const fs::path test_files_dir = blender::tests::flags_test_asset_dir();
+ if (test_files_dir.empty()) {
+ FAIL();
+ }
+
+ AssetCatalogService service;
+ service.load_from_disk(test_files_dir / "asset_library/single_catalog_definition_file.cats.txt");
+
+ // Test getting a non-existant catalog ID.
+ EXPECT_EQ(nullptr, service.find_catalog("NONEXISTANT"));
+
+ // Test getting a 7-bit ASCII catalog ID.
+ AssetCatalog *poses_elly = service.find_catalog("POSES_ELLY");
+ ASSERT_NE(nullptr, poses_elly);
+ EXPECT_EQ("POSES_ELLY", poses_elly->catalog_id);
+ EXPECT_EQ("character/Elly/poselib", poses_elly->path);
+
+ // Test whitespace stripping.
+ AssetCatalog *poses_whitespace = service.find_catalog("POSES_ELLY_WHITESPACE");
+ ASSERT_NE(nullptr, poses_whitespace);
+ EXPECT_EQ("POSES_ELLY_WHITESPACE", poses_whitespace->catalog_id);
+ EXPECT_EQ("character/Elly/poselib/whitespace", poses_whitespace->path);
+
+ // Test getting a UTF-8 catalog ID.
+ AssetCatalog *poses_ruzena = service.find_catalog("POSES_RUŽENA");
+ ASSERT_NE(nullptr, poses_ruzena);
+ EXPECT_EQ("POSES_RUŽENA", poses_ruzena->catalog_id);
+ EXPECT_EQ("character/Ružena/poselib", poses_ruzena->path);
+}
+
+} // namespace blender::bke::tests