21#include "testing/testing.h"
35 const std::string test_files_dir = blender::tests::flags_test_asset_dir();
36 if (test_files_dir.empty()) {
85 <<
"Calling twice without destroying in between should return the same instance.";
101 asset_library_root_);
105 <<
"Calling twice without destroying in between should return the same instance.";
107 <<
"Calling twice without destroying in between should return the same instance.";
123 <<
"Getting the local (current file) reference without a main saved on disk should return "
124 "the current file library";
128 std::string dummy_filepath = asset_library_root_ +
SEP +
"dummy.blend";
132 asset_library_root_);
140 <<
"Getting an asset library from a local (current file) library reference should never "
141 "match any custom asset library";
151 char asset_lib_with_slash[
PATH_MAX];
152 STRNCPY(asset_lib_no_slash, asset_library_root_.c_str());
153 STRNCPY(asset_lib_with_slash, asset_library_root_.c_str());
157 while (strlen(asset_lib_no_slash) &&
158 ELEM(asset_lib_no_slash[strlen(asset_lib_no_slash) - 1],
SEP,
ALTSEP))
160 asset_lib_no_slash[strlen(asset_lib_no_slash) - 1] =
'\0';
170 <<
"With or without trailing slash shouldn't matter.";
177 asset_library_root_);
182 <<
"Catalogs should be loaded after getting an asset library from disk.";
189 <<
"Empty AssetLibraryService should have no unsaved catalogs";
192 asset_library_root_);
195 <<
"Unchanged AssetLibrary should have no unsaved catalogs";
200 <<
"Deletion of catalogs via AssetCatalogService should not automatically tag as 'unsaved "
205 ASSERT_NE(
nullptr, cat) <<
"Catalog " <<
UUID_POSES_RUZENA <<
" should be known";
209 <<
"Tagging as having unsaved changes of a single catalog service should result in unsaved "
210 "changes being reported.";
218 "blender_assets.cats.txt";
221 ASSERT_EQ(0,
BLI_copy(original_cdf_file.c_str(), writable_cdf_file.c_str()));
227 <<
"Unchanged AssetLibrary should have no unsaved catalogs";
235 <<
"Tagging as having unsaved changes of a single catalog service should result in unsaved "
236 "changes being reported.";
239 cat_service.
write_to_disk(writable_dir +
"dummy_path.blend");
241 <<
"Written AssetCatalogService should have no unsaved catalogs";
264 <<
"Catalog not expected in the runtime asset library.";
269 std::string dummy_filepath = create_temp_path() +
"dummy.blend";
300 <<
"Catalog not expected in the on disk asset library.";
304 on_disk_catservice.
undo();
306 EXPECT_EQ(
nullptr, ellie_catalog) <<
"This catalog should not be present after undo";
308 <<
"This catalog should still be present after undo";
322 move_runtime_current_file_into_on_disk_library__directory_with_catalogs)
337 <<
"Catalog not expected in the runtime asset library.";
342 std::string dummy_filepath = asset_library_root_ +
SEP +
"dummy.blend";
356 (asset_library_root_ +
SEP).c_str()),
374 <<
"Catalogs should be loaded after getting an asset library from disk.";
380 on_disk_catservice.
undo();
382 EXPECT_EQ(
nullptr, ellie_catalog) <<
"This catalog should not be present after undo";
384 <<
"This catalog should still be present after undo";
File and directory operations.
constexpr const char * c_str() const
AssetCatalog * find_catalog(CatalogID catalog_id) const
bool write_to_disk(const CatalogFilePath &blend_file_path)
AssetCatalog * create_catalog(const AssetCatalogPath &catalog_path)
void prune_catalogs_by_id(CatalogID catalog_id)
void tag_has_unsaved_changes(AssetCatalog *edited_catalog=nullptr)
static const CatalogFilePath DEFAULT_CATALOG_FILENAME
const CatalogID catalog_id
struct blender::asset_system::AssetCatalog::Flags flags
AssetLibrary * get_asset_library(const Main *bmain, const AssetLibraryReference &library_reference)
AssetLibrary * get_asset_library_current_file()
static AssetLibrary * move_runtime_current_file_into_on_disk_library(const Main &bmain)
static AssetLibraryService * get()
AssetLibrary * get_asset_library_on_disk_custom(StringRef name, StringRefNull root_path)
bool has_any_unsaved_catalogs() const
AssetCatalogService & catalog_service() const
StringRefNull root_path() const
CatalogFilePath create_temp_path()
CatalogFilePath use_temp_path()
CatalogFilePath temp_library_path_
CatalogFilePath asset_library_root_
#define EXPECT_FALSE(result)
#define EXPECT_NE(result, expect)
#define EXPECT_TRUE(result)
const UUID UUID_POSES_RUZENA("79a4f887-ab60-4bd4-94da-d572e27d6aed")
TEST_F(AssetCatalogPathTest, construction)
const UUID UUID_POSES_ELLIE("df60e1f6-2259-475b-93d9-69a1b4a8db78")
std::string CatalogFilePath
char * STRNCPY(char(&dst)[N], const char *src)
bool BLI_dir_create_recursive(const char *dirname) ATTR_NONNULL()
void BLI_path_slash_native(char *path) ATTR_NONNULL(1)
const char * BKE_tempdir_session() ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL
int BLI_path_cmp_normalized(const char *p1, const char *p2) ATTR_NONNULL(1
int BLI_delete(const char *path, bool dir, bool recursive) ATTR_NONNULL()
int BLI_path_slash_ensure(char *path, size_t path_maxncpy) ATTR_NONNULL(1)
void BKE_main_free(Main *bmain)
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
int BLI_copy(const char *path_src, const char *path_dst) ATTR_NONNULL()
void BKE_tempdir_init(const char *userdir)