Blender V5.3
asset_library_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"
6#include "AS_asset_library.hh"
7
8#include "BKE_global.hh"
9#include "BKE_gtest_base.hh"
10#include "BKE_main.hh"
11
13
14#include "testing/testing.h"
15
17
19 protected:
21 void SetUp() override
22 {
23 /* G_MAIN is needed for variable expansion in asset library paths.
24 * IE {project_root}, {blend_name}, {blend_dir} etc.
25 */
27 G_MAIN = bmain;
28 }
29
30 void TearDown() override
31 {
34 G_MAIN = nullptr;
35 }
36};
37
39{
40 const std::string test_files_dir = blender::tests::flags_test_asset_dir();
41 if (test_files_dir.empty()) {
42 FAIL();
43 }
44
45 /* Load the asset library. */
46 const std::string library_dirpath = test_files_dir + "/" + "asset_library";
47 AssetLibrary *library = AS_asset_library_load_from_directory(__func__, library_dirpath.data());
48 ASSERT_NE(nullptr, library);
49
50 /* Check that it can be cast to the C++ type and has a Catalog Service. */
51 const AssetCatalogService &service = library->catalog_service();
52
53 /* Check that the catalogs defined in the library are actually loaded. This just tests one single
54 * catalog, as that indicates the file has been loaded. Testing that loading went OK is for
55 * the asset catalog service tests. */
56 const UUID uuid_poses_ellie("df60e1f6-2259-475b-93d9-69a1b4a8db78");
57 AssetCatalog *poses_ellie = service.find_catalog(uuid_poses_ellie);
58 ASSERT_NE(nullptr, poses_ellie) << "unable to find POSES_ELLIE catalog";
59 EXPECT_EQ("character/Ellie/poselib", poses_ellie->path.str());
60}
61
62TEST_F(AssetLibraryTest, load_nonexistent_directory)
63{
64 const std::string test_files_dir = blender::tests::flags_test_asset_dir();
65 if (test_files_dir.empty()) {
66 FAIL();
67 }
68
69 /* Load the asset library. */
70 const std::string library_dirpath = test_files_dir + "/" +
71 "asset_library/this/subdir/does/not/exist";
72 AssetLibrary *library = AS_asset_library_load_from_directory(__func__, library_dirpath.data());
73 ASSERT_NE(nullptr, library);
74
75 /* Check that it can be cast to the C++ type and has a Catalog Service. */
76 AssetCatalogService &service = library->catalog_service();
77 /* Check that the catalog service doesn't have any catalogs. */
78 EXPECT_TRUE(service.is_empty());
79}
80
81} // namespace blender::asset_system::tests
#define G_MAIN
AssetCatalog * find_catalog(CatalogID catalog_id) const
#define EXPECT_TRUE(result)
TEST_F(AssetCatalogPathTest, construction)
Main * BKE_main_new()
Definition main.cc:93
void BKE_main_free(Main *bmain)
Definition main.cc:202
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
asset_system::AssetLibrary * AS_asset_library_load_from_directory(const char *name, const char *library_dirpath)