Changeset View
Changeset View
Standalone View
Standalone View
tests/gtests/blenlib/BLI_path_util_test.cc
| Show First 20 Lines • Show All 612 Lines • ▼ Show 20 Lines | TEST(path_util, PathFrameGet) | ||||
| PATH_FRAME_GET("001.avi", 1, 3, true); | PATH_FRAME_GET("001.avi", 1, 3, true); | ||||
| PATH_FRAME_GET("0000299.ext", 299, 7, true); | PATH_FRAME_GET("0000299.ext", 299, 7, true); | ||||
| PATH_FRAME_GET("path/to/frame_2810.dummy_quite_long_extension", 2810, 4, true); | PATH_FRAME_GET("path/to/frame_2810.dummy_quite_long_extension", 2810, 4, true); | ||||
| PATH_FRAME_GET("notframe_7_frame00018.bla", 18, 5, true); | PATH_FRAME_GET("notframe_7_frame00018.bla", 18, 5, true); | ||||
| PATH_FRAME_GET("", -1, -1, false); | PATH_FRAME_GET("", -1, -1, false); | ||||
| } | } | ||||
| #undef PATH_FRAME_GET | #undef PATH_FRAME_GET | ||||
| #define PATH_IS_REL(input_path, expect_rel) \ | |||||
| { \ | |||||
| const bool ret = BLI_path_is_rel(input_path); \ | |||||
| ASSERT_EQ(expect_rel, ret); \ | |||||
| } | |||||
| /* BLI_path_is_rel */ | |||||
| TEST(path_util, IsRel) | |||||
| { | |||||
| PATH_IS_REL("", false); | |||||
| PATH_IS_REL("&", false); | |||||
| PATH_IS_REL("/\\", false); | |||||
| PATH_IS_REL("this_is_not_rel/", false); | |||||
| PATH_IS_REL("a/..//dirty\\not/rel.png", false); | |||||
| PATH_IS_REL("/abs/path/but/not/rel/../to/Blendfile.blend", false); | |||||
| PATH_IS_REL("//rel_to_blend_file.h", true); | |||||
| PATH_IS_REL("//rel/../../../but/above/../file.png", true); | |||||
| PATH_IS_REL("//", true); | |||||
| PATH_IS_REL("//\\", true); | |||||
| PATH_IS_REL("//../notso/&/CLEAN\\../PAAAAATH//", true); | |||||
| } | |||||
| #undef PATH_IS_REL | |||||
| #define PATH_IS_UNC(input_path, expect_unc) \ | |||||
| { \ | |||||
| const bool ret = BLI_path_is_unc(input_path); \ | |||||
| ASSERT_EQ(ret, expect_unc); \ | |||||
| } | |||||
| /* BLI_path_is_unc */ | |||||
| TEST(path_util, IsUNC) | |||||
| { | |||||
| PATH_IS_UNC("this_is_not_unc/", false); | |||||
| PATH_IS_UNC("////not_unc/path/file.h", false); | |||||
| PATH_IS_UNC("\\//no-no-no", false); | |||||
| PATH_IS_UNC("", false); | |||||
| PATH_IS_UNC("\\\\host-name\\share-name\\file_path", true); | |||||
| PATH_IS_UNC("\\\\host\\", true); | |||||
| PATH_IS_UNC("\\\\\\\\\\\\", true); | |||||
| PATH_IS_UNC("\\\\n", true); | |||||
| } | |||||
| #undef PATH_IS_UNC | |||||
| #define PATH_SUFFIX(input_path, maxlen, suffix, sep, expect_path) \ | |||||
| { \ | |||||
| char path[FILE_MAX]; \ | |||||
| BLI_strncpy(path, input_path, FILE_MAX); \ | |||||
| const bool ret = BLI_path_suffix(path, maxlen, suffix, sep); \ | |||||
| if (expect_path != NULL) { \ | |||||
| ASSERT_TRUE(ret); \ | |||||
| ASSERT_STREQ(path, expect_path); \ | |||||
| } \ | |||||
| else { \ | |||||
| ASSERT_FALSE(ret); \ | |||||
| } \ | |||||
| } | |||||
| /* BLI_path_suffix */ | |||||
| TEST(path_util, PathSuffix) | |||||
| { | |||||
| PATH_SUFFIX("path/to/file.png", 1, "abc", "__", NULL); | |||||
| PATH_SUFFIX("name.ext", 10, "88", "0032", NULL); | |||||
| PATH_SUFFIX("path/to/file.png", FILE_MAX, "abc", "__", "path/to/file__abc.png"); | |||||
| PATH_SUFFIX("_", FILE_MAX, "abc", "", "_abc"); | |||||
| PATH_SUFFIX("file.very_long_extension_at_end_of_filename", | |||||
| FILE_MAX, | |||||
| "also$_a%_v§ery_long_2suffix_with&_∑ird_chars", | |||||
| "----", | |||||
| "file----also$_a%_v§ery_long_2suffix_with&_∑ird_chars.very_long_extension_at_end_of_" | |||||
| "filename"); | |||||
| PATH_SUFFIX("name.ext", 15, "88", "0032", "name003288.ext"); | |||||
| PATH_SUFFIX("\\unc/path\\..//name.ext", 50, "-_-", "99", "\\unc/path\\..//name99-_-.ext"); | |||||
| PATH_SUFFIX("first_ext.second.ext", FILE_MAX, "007", "", "first_ext.second007.ext") | |||||
| } | |||||
| #undef PATH_SUFFIX | |||||