Blender V4.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_callbacks.hh"
9
11
12#include "CLG_log.h"
13
14#include "testing/testing.h"
15
17
18class AssetLibraryTest : public testing::Test {
19 public:
20 static void SetUpTestSuite()
21 {
22 CLG_init();
24 }
25 static void TearDownTestSuite()
26 {
27 CLG_exit();
29 }
30
35};
36
38{
39 const std::string test_files_dir = blender::tests::flags_test_asset_dir();
40 if (test_files_dir.empty()) {
41 FAIL();
42 }
43
44 /* Load the asset library. */
45 const std::string library_dirpath = test_files_dir + "/" + "asset_library";
46 AssetLibrary *library = AS_asset_library_load(__func__, library_dirpath.data());
47 ASSERT_NE(nullptr, library);
48
49 /* Check that it can be cast to the C++ type and has a Catalog Service. */
50 const AssetCatalogService &service = library->catalog_service();
51
52 /* Check that the catalogs defined in the library are actually loaded. This just tests one single
53 * catalog, as that indicates the file has been loaded. Testing that loading went OK is for
54 * the asset catalog service tests. */
55 const bUUID uuid_poses_ellie("df60e1f6-2259-475b-93d9-69a1b4a8db78");
56 AssetCatalog *poses_ellie = service.find_catalog(uuid_poses_ellie);
57 ASSERT_NE(nullptr, poses_ellie) << "unable to find POSES_ELLIE catalog";
58 EXPECT_EQ("character/Ellie/poselib", poses_ellie->path.str());
59}
60
61TEST_F(AssetLibraryTest, load_nonexistent_directory)
62{
63 const std::string test_files_dir = blender::tests::flags_test_asset_dir();
64 if (test_files_dir.empty()) {
65 FAIL();
66 }
67
68 /* Load the asset library. */
69 const std::string library_dirpath = test_files_dir + "/" +
70 "asset_library/this/subdir/does/not/exist";
71 AssetLibrary *library = AS_asset_library_load(__func__, library_dirpath.data());
72 ASSERT_NE(nullptr, library);
73
74 /* Check that it can be cast to the C++ type and has a Catalog Service. */
75 AssetCatalogService &service = library->catalog_service();
76 /* Check that the catalog service doesn't have any catalogs. */
77 EXPECT_TRUE(service.is_empty());
78}
79
80} // namespace blender::asset_system::tests
blender::asset_system::AssetLibrary * AS_asset_library_load(const Main *bmain, const AssetLibraryReference &library_reference)
void BKE_callback_global_finalize()
Definition callbacks.cc:108
void BKE_callback_global_init()
Definition callbacks.cc:103
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
void CLG_exit(void)
Definition clog.c:706
void CLG_init(void)
Definition clog.c:699
AssetCatalog * find_catalog(CatalogID catalog_id) const
AssetCatalogService & catalog_service() const
TEST_F(AssetCatalogTest, load_single_file)
Universally Unique Identifier according to RFC4122.