Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/asset_library_test.cc
| Show All 15 Lines | |||||
| * The Original Code is Copyright (C) 2020 Blender Foundation | * The Original Code is Copyright (C) 2020 Blender Foundation | ||||
| * All rights reserved. | * All rights reserved. | ||||
| */ | */ | ||||
| #include "BKE_appdir.h" | #include "BKE_appdir.h" | ||||
| #include "BKE_asset_catalog.hh" | #include "BKE_asset_catalog.hh" | ||||
| #include "BKE_asset_library.hh" | #include "BKE_asset_library.hh" | ||||
| #include "asset_library_service.hh" | |||||
| #include "CLG_log.h" | |||||
| #include "testing/testing.h" | #include "testing/testing.h" | ||||
| namespace blender::bke::tests { | namespace blender::bke::tests { | ||||
| TEST(AssetLibraryTest, load_and_free_c_functions) | class AssetLibraryServiceTest : public testing::Test { | ||||
| public: | |||||
| static void SetUpTestSuite() | |||||
| { | |||||
| CLG_init(); | |||||
| } | |||||
| static void TearDownTestSuite() | |||||
| { | |||||
| CLG_exit(); | |||||
| } | |||||
| void TearDown() override | |||||
| { | |||||
| AssetLibraryService::destroy(); | |||||
| } | |||||
| }; | |||||
| TEST_F(AssetLibraryServiceTest, bke_asset_library_load) | |||||
| { | { | ||||
| const std::string test_files_dir = blender::tests::flags_test_asset_dir(); | const std::string test_files_dir = blender::tests::flags_test_asset_dir(); | ||||
| if (test_files_dir.empty()) { | if (test_files_dir.empty()) { | ||||
| FAIL(); | FAIL(); | ||||
| } | } | ||||
| /* Load the asset library. */ | /* Load the asset library. */ | ||||
| const std::string library_path = test_files_dir + "/" + "asset_library"; | const std::string library_path = test_files_dir + "/" + "asset_library"; | ||||
| ::AssetLibrary *library_c_ptr = BKE_asset_library_load(library_path.data()); | ::AssetLibrary *library_c_ptr = BKE_asset_library_load(library_path.data()); | ||||
| ASSERT_NE(nullptr, library_c_ptr); | ASSERT_NE(nullptr, library_c_ptr); | ||||
| /* Check that it can be cast to the C++ type and has a Catalog Service. */ | /* Check that it can be cast to the C++ type and has a Catalog Service. */ | ||||
| blender::bke::AssetLibrary *library_cpp_ptr = reinterpret_cast<blender::bke::AssetLibrary *>( | blender::bke::AssetLibrary *library_cpp_ptr = reinterpret_cast<blender::bke::AssetLibrary *>( | ||||
| library_c_ptr); | library_c_ptr); | ||||
| AssetCatalogService *service = library_cpp_ptr->catalog_service.get(); | AssetCatalogService *service = library_cpp_ptr->catalog_service.get(); | ||||
| ASSERT_NE(nullptr, service); | ASSERT_NE(nullptr, service); | ||||
| /* Check that the catalogs defined in the library are actually loaded. This just tests one single | /* Check that the catalogs defined in the library are actually loaded. This just tests one single | ||||
| * catalog, as that indicates the file has been loaded. Testing that that loading went OK is for | * catalog, as that indicates the file has been loaded. Testing that that loading went OK is for | ||||
| * the asset catalog service tests. */ | * the asset catalog service tests. */ | ||||
| const bUUID uuid_poses_ellie("df60e1f6-2259-475b-93d9-69a1b4a8db78"); | const bUUID uuid_poses_ellie("df60e1f6-2259-475b-93d9-69a1b4a8db78"); | ||||
| AssetCatalog *poses_ellie = service->find_catalog(uuid_poses_ellie); | AssetCatalog *poses_ellie = service->find_catalog(uuid_poses_ellie); | ||||
| ASSERT_NE(nullptr, poses_ellie) << "unable to find POSES_ELLIE catalog"; | ASSERT_NE(nullptr, poses_ellie) << "unable to find POSES_ELLIE catalog"; | ||||
| EXPECT_EQ("character/Ellie/poselib", poses_ellie->path.str()); | EXPECT_EQ("character/Ellie/poselib", poses_ellie->path.str()); | ||||
| BKE_asset_library_free(library_c_ptr); | |||||
| } | } | ||||
| TEST(AssetLibraryTest, load_nonexistent_directory) | TEST_F(AssetLibraryServiceTest, load_nonexistent_directory) | ||||
| { | { | ||||
| const std::string test_files_dir = blender::tests::flags_test_asset_dir(); | const std::string test_files_dir = blender::tests::flags_test_asset_dir(); | ||||
| if (test_files_dir.empty()) { | if (test_files_dir.empty()) { | ||||
| FAIL(); | FAIL(); | ||||
| } | } | ||||
| /* Load the asset library. */ | /* Load the asset library. */ | ||||
| const std::string library_path = test_files_dir + "/" + | const std::string library_path = test_files_dir + "/" + | ||||
| "asset_library/this/subdir/does/not/exist"; | "asset_library/this/subdir/does/not/exist"; | ||||
| ::AssetLibrary *library_c_ptr = BKE_asset_library_load(library_path.data()); | ::AssetLibrary *library_c_ptr = BKE_asset_library_load(library_path.data()); | ||||
| ASSERT_NE(nullptr, library_c_ptr); | ASSERT_NE(nullptr, library_c_ptr); | ||||
| /* Check that it can be cast to the C++ type and has a Catalog Service. */ | /* Check that it can be cast to the C++ type and has a Catalog Service. */ | ||||
| blender::bke::AssetLibrary *library_cpp_ptr = reinterpret_cast<blender::bke::AssetLibrary *>( | blender::bke::AssetLibrary *library_cpp_ptr = reinterpret_cast<blender::bke::AssetLibrary *>( | ||||
| library_c_ptr); | library_c_ptr); | ||||
| AssetCatalogService *service = library_cpp_ptr->catalog_service.get(); | AssetCatalogService *service = library_cpp_ptr->catalog_service.get(); | ||||
| ASSERT_NE(nullptr, service); | ASSERT_NE(nullptr, service); | ||||
| /* Check that the catalog service doesn't have any catalogs. */ | /* Check that the catalog service doesn't have any catalogs. */ | ||||
| EXPECT_TRUE(service->is_empty()); | EXPECT_TRUE(service->is_empty()); | ||||
| BKE_asset_library_free(library_c_ptr); | |||||
| } | } | ||||
| } // namespace blender::bke::tests | } // namespace blender::bke::tests | ||||