Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/asset_catalog_test.cc
| Show All 21 Lines | |||||
| #include "BKE_preferences.h" | #include "BKE_preferences.h" | ||||
| #include "BLI_fileops.h" | #include "BLI_fileops.h" | ||||
| #include "BLI_path_util.h" | #include "BLI_path_util.h" | ||||
| #include "DNA_asset_types.h" | #include "DNA_asset_types.h" | ||||
| #include "DNA_userdef_types.h" | #include "DNA_userdef_types.h" | ||||
| #include "CLG_log.h" | |||||
| #include "testing/testing.h" | #include "testing/testing.h" | ||||
| namespace blender::bke::tests { | namespace blender::bke::tests { | ||||
| /* UUIDs from lib/tests/asset_library/blender_assets.cats.txt */ | /* UUIDs from lib/tests/asset_library/blender_assets.cats.txt */ | ||||
| const bUUID UUID_ID_WITHOUT_PATH("e34dd2c5-5d2e-4668-9794-1db5de2a4f71"); | const bUUID UUID_ID_WITHOUT_PATH("e34dd2c5-5d2e-4668-9794-1db5de2a4f71"); | ||||
| const bUUID UUID_POSES_ELLIE("df60e1f6-2259-475b-93d9-69a1b4a8db78"); | const bUUID UUID_POSES_ELLIE("df60e1f6-2259-475b-93d9-69a1b4a8db78"); | ||||
| const bUUID UUID_POSES_ELLIE_WHITESPACE("b06132f6-5687-4751-a6dd-392740eb3c46"); | const bUUID UUID_POSES_ELLIE_WHITESPACE("b06132f6-5687-4751-a6dd-392740eb3c46"); | ||||
| ▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | public: | ||||
| } | } | ||||
| }; | }; | ||||
| class AssetCatalogTest : public testing::Test { | class AssetCatalogTest : public testing::Test { | ||||
| protected: | protected: | ||||
| CatalogFilePath asset_library_root_; | CatalogFilePath asset_library_root_; | ||||
| CatalogFilePath temp_library_path_; | CatalogFilePath temp_library_path_; | ||||
| static void SetUpTestSuite() | |||||
| { | |||||
| testing::Test::SetUpTestSuite(); | |||||
| CLG_init(); | |||||
| } | |||||
| static void TearDownTestSuite() | |||||
| { | |||||
| CLG_exit(); | |||||
| testing::Test::TearDownTestSuite(); | |||||
| } | |||||
| void SetUp() override | void SetUp() override | ||||
| { | { | ||||
| 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(); | ||||
| } | } | ||||
| asset_library_root_ = test_files_dir + "/" + "asset_library"; | asset_library_root_ = test_files_dir + "/" + "asset_library"; | ||||
| ▲ Show 20 Lines • Show All 440 Lines • ▼ Show 20 Lines | TEST_F(AssetCatalogTest, write_single_file) | ||||
| EXPECT_NE(nullptr, loaded_service.find_catalog(UUID_POSES_RUZENA_FACE)); | EXPECT_NE(nullptr, loaded_service.find_catalog(UUID_POSES_RUZENA_FACE)); | ||||
| /* Test that the invalid catalog definition wasn't copied. */ | /* Test that the invalid catalog definition wasn't copied. */ | ||||
| EXPECT_EQ(nullptr, loaded_service.find_catalog(UUID_ID_WITHOUT_PATH)); | EXPECT_EQ(nullptr, loaded_service.find_catalog(UUID_ID_WITHOUT_PATH)); | ||||
| /* TODO(@sybren): test ordering of catalogs in the file. */ | /* TODO(@sybren): test ordering of catalogs in the file. */ | ||||
| } | } | ||||
| TEST_F(AssetCatalogTest, read_write_unicode_filepath) | |||||
| { | |||||
| TestableAssetCatalogService service(asset_library_root_); | |||||
| const CatalogFilePath load_from_path = asset_library_root_ + "/новый/" + | |||||
| AssetCatalogService::DEFAULT_CATALOG_FILENAME; | |||||
| service.load_from_disk(load_from_path); | |||||
| const CatalogFilePath save_to_path = use_temp_path() + "новый.cats.txt"; | |||||
| AssetCatalogDefinitionFile *cdf = service.get_catalog_definition_file(); | |||||
| ASSERT_NE(nullptr, cdf) << "unable to load " << load_from_path; | |||||
| EXPECT_TRUE(cdf->write_to_disk(save_to_path)); | |||||
| AssetCatalogService loaded_service(save_to_path); | |||||
| loaded_service.load_from_disk(); | |||||
| /* Test that the file was loaded correctly. */ | |||||
| const bUUID materials_uuid("a2151dff-dead-4f29-b6bc-b2c7d6cccdb4"); | |||||
| const AssetCatalog *cat = loaded_service.find_catalog(materials_uuid); | |||||
| ASSERT_NE(nullptr, cat); | |||||
| EXPECT_EQ(materials_uuid, cat->catalog_id); | |||||
| EXPECT_EQ(AssetCatalogPath("Материалы"), cat->path); | |||||
| EXPECT_EQ("Russian Materials", cat->simple_name); | |||||
| } | |||||
| TEST_F(AssetCatalogTest, no_writing_empty_files) | TEST_F(AssetCatalogTest, no_writing_empty_files) | ||||
| { | { | ||||
| const CatalogFilePath temp_lib_root = create_temp_path(); | const CatalogFilePath temp_lib_root = create_temp_path(); | ||||
| AssetCatalogService service(temp_lib_root); | AssetCatalogService service(temp_lib_root); | ||||
| service.write_to_disk(temp_lib_root + "phony.blend"); | service.write_to_disk(temp_lib_root + "phony.blend"); | ||||
| const CatalogFilePath default_cdf_path = temp_lib_root + | const CatalogFilePath default_cdf_path = temp_lib_root + | ||||
| AssetCatalogService::DEFAULT_CATALOG_FILENAME; | AssetCatalogService::DEFAULT_CATALOG_FILENAME; | ||||
| ▲ Show 20 Lines • Show All 952 Lines • Show Last 20 Lines | |||||