Blender  V3.3
asset_library_test.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2020 Blender Foundation. All rights reserved. */
3 
4 #include "BKE_appdir.h"
5 #include "BKE_asset_catalog.hh"
6 #include "BKE_asset_library.hh"
7 #include "BKE_callbacks.h"
8 
10 
11 #include "CLG_log.h"
12 
13 #include "testing/testing.h"
14 
15 namespace blender::bke::tests {
16 
17 class AssetLibraryTest : public testing::Test {
18  public:
19  static void SetUpTestSuite()
20  {
21  CLG_init();
23  }
24  static void TearDownTestSuite()
25  {
26  CLG_exit();
28  }
29 
30  void TearDown() override
31  {
33  }
34 };
35 
36 TEST_F(AssetLibraryTest, bke_asset_library_load)
37 {
38  const std::string test_files_dir = blender::tests::flags_test_asset_dir();
39  if (test_files_dir.empty()) {
40  FAIL();
41  }
42 
43  /* Load the asset library. */
44  const std::string library_path = test_files_dir + "/" + "asset_library";
45  ::AssetLibrary *library_c_ptr = BKE_asset_library_load(library_path.data());
46  ASSERT_NE(nullptr, library_c_ptr);
47 
48  /* Check that it can be cast to the C++ type and has a Catalog Service. */
49  blender::bke::AssetLibrary *library_cpp_ptr = reinterpret_cast<blender::bke::AssetLibrary *>(
50  library_c_ptr);
51  AssetCatalogService *service = library_cpp_ptr->catalog_service.get();
52  ASSERT_NE(nullptr, service);
53 
54  /* Check that the catalogs defined in the library are actually loaded. This just tests one single
55  * catalog, as that indicates the file has been loaded. Testing that loading went OK is for
56  * the asset catalog service tests. */
57  const bUUID uuid_poses_ellie("df60e1f6-2259-475b-93d9-69a1b4a8db78");
58  AssetCatalog *poses_ellie = service->find_catalog(uuid_poses_ellie);
59  ASSERT_NE(nullptr, poses_ellie) << "unable to find POSES_ELLIE catalog";
60  EXPECT_EQ("character/Ellie/poselib", poses_ellie->path.str());
61 }
62 
63 TEST_F(AssetLibraryTest, load_nonexistent_directory)
64 {
65  const std::string test_files_dir = blender::tests::flags_test_asset_dir();
66  if (test_files_dir.empty()) {
67  FAIL();
68  }
69 
70  /* Load the asset library. */
71  const std::string library_path = test_files_dir + "/" +
72  "asset_library/this/subdir/does/not/exist";
73  ::AssetLibrary *library_c_ptr = BKE_asset_library_load(library_path.data());
74  ASSERT_NE(nullptr, library_c_ptr);
75 
76  /* Check that it can be cast to the C++ type and has a Catalog Service. */
77  blender::bke::AssetLibrary *library_cpp_ptr = reinterpret_cast<blender::bke::AssetLibrary *>(
78  library_c_ptr);
79  AssetCatalogService *service = library_cpp_ptr->catalog_service.get();
80  ASSERT_NE(nullptr, service);
81 
82  /* Check that the catalog service doesn't have any catalogs. */
83  EXPECT_TRUE(service->is_empty());
84 }
85 
86 } // namespace blender::bke::tests
struct AssetLibrary * BKE_asset_library_load(const char *library_path)
void BKE_callback_global_finalize(void)
Definition: callbacks.c:105
void BKE_callback_global_init(void)
Definition: callbacks.c:100
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
void CLG_exit(void)
Definition: clog.c:703
void CLG_init(void)
Definition: clog.c:696
const std::string & str() const
AssetCatalog * find_catalog(CatalogID catalog_id) const
TEST_F(BKE_armature_find_selected_bones_test, some_bones_selected)
Universally Unique Identifier according to RFC4122.
std::unique_ptr< AssetCatalogService > catalog_service