Changeset View
Changeset View
Standalone View
Standalone View
tests/gtests/blenlib/BLI_path_util_test.cc
| Context not available. | |||||
| EXPECT_STREQ("", file); | EXPECT_STREQ("", file); | ||||
| } | } | ||||
| } | } | ||||
| /* BLI_split_name_num */ | |||||
| TEST(path_util, PathUtilSplitNameNum) | |||||
| { | |||||
| { | |||||
| const char *name = "/any/path/file"; | |||||
| char true_name[16], delimiter='.'; | |||||
| int number, len; | |||||
| len = BLI_split_name_num(true_name, &number, name, delimiter); | |||||
| EXPECT_EQ(len, 14); | |||||
| EXPECT_EQ(number, 0); | |||||
| EXPECT_STREQ(true_name, name); | |||||
| } | |||||
| { | |||||
| const char *name = "/any/path/file567"; | |||||
| char true_name[16], delimiter='.'; | |||||
| int number, len; | |||||
| len = BLI_split_name_num(true_name, &number, name, delimiter); | |||||
| EXPECT_EQ(len, 17); | |||||
| EXPECT_EQ(number, 0); | |||||
| EXPECT_STREQ("/any/path/file567", true_name); | |||||
| } | |||||
| { | |||||
| const char *name = "/any/path/file567"; | |||||
| char true_name[16], delimiter='e'; | |||||
| int number, len; | |||||
| len = BLI_split_name_num(true_name, &number, name, delimiter); | |||||
| EXPECT_EQ(len, 13); | |||||
| EXPECT_EQ(number, 567); | |||||
| EXPECT_STREQ(true_name, "/any/path/fil"); | |||||
| } | |||||
| { | |||||
| const char *name = "e567"; | |||||
| char true_name[16], delimiter='e'; | |||||
| int number, len; | |||||
| len = BLI_split_name_num(true_name, &number, name, delimiter); | |||||
| EXPECT_EQ(len, 0); | |||||
| EXPECT_EQ(number, 567); | |||||
| EXPECT_STREQ(true_name, ""); | |||||
| } | |||||
| { | |||||
| const char *name = "567"; | |||||
| char true_name[16], delimiter='e'; | |||||
| int number, len; | |||||
| len = BLI_split_name_num(true_name, &number, name, delimiter); | |||||
| EXPECT_EQ(len, 3); | |||||
| EXPECT_EQ(number, 0); | |||||
| EXPECT_STREQ(true_name, "567"); | |||||
| } | |||||
| } | |||||
| /* BLI_make_file_string */ | |||||
| TEST(path_util, PathUtilMakeFlieString) | |||||
| { | |||||
| { | |||||
| const char *name = "filename"; | |||||
| const char *dir = "mydir/subdir"; | |||||
| const char *relabase = "/any/path/file"; | |||||
| char result_string[30]; | |||||
| BLI_make_file_string(relabase, result_string, dir, name); | |||||
| EXPECT_STREQ("mydir/subdir/filename", result_string); | |||||
| } | |||||
| { | |||||
| const char *name = "filename"; | |||||
| const char *dir = "mydir/subdir/"; | |||||
| const char *relabase = "/any/path/file"; | |||||
| char result_string[30]; | |||||
| BLI_make_file_string(relabase, result_string, dir, name); | |||||
| EXPECT_STREQ("mydir/subdir/filename", result_string); | |||||
| } | |||||
| { | |||||
| const char *name = "filename"; | |||||
| const char *dir = "//mydir/subdir"; | |||||
| const char *relabase = "/any/path/"; | |||||
| char result_string[40]; | |||||
| BLI_make_file_string(relabase, result_string, dir, name); | |||||
| EXPECT_STREQ("/any/path/mydir/subdir/filename", result_string); | |||||
| } | |||||
| { | |||||
| const char *name = "filename"; | |||||
| const char *dir = "//mydir/subdir"; | |||||
| const char *relabase = "/any/path/another_file"; | |||||
| char result_string[40]; | |||||
| BLI_make_file_string(relabase, result_string, dir, name); | |||||
| EXPECT_STREQ("/any/path/mydir/subdir/filename", result_string); | |||||
| } | |||||
| } | |||||
| /* BLI_path_sufix */ | |||||
| TEST(path_util, PathUtilPathSufix) | |||||
| { | |||||
| { | |||||
| char name[20] = "filename"; | |||||
| const char *separator = "_____"; | |||||
| const char *suffix = "SUFFIX"; | |||||
| const int maxlen = 20; | |||||
| bool res = BLI_path_suffix(name, maxlen, suffix, separator); | |||||
| EXPECT_TRUE(res); | |||||
| EXPECT_STREQ("filename_____SUFFIX", name); | |||||
| } | |||||
| { | |||||
| char name[20] = "filename.txt"; | |||||
| const char *separator = "_"; | |||||
| const char *suffix = "SUFFIX"; | |||||
| const int maxlen = 20; | |||||
| bool res = BLI_path_suffix(name, maxlen, suffix, separator); | |||||
| EXPECT_TRUE(res); | |||||
| EXPECT_STREQ("filename_SUFFIX.txt", name); | |||||
| } | |||||
| { | |||||
| char name[20] = "filename"; | |||||
| const char *separator = "_____"; | |||||
| const char *suffix = "SUFFIX1"; | |||||
| const int maxlen = 20; | |||||
| bool res = BLI_path_suffix(name, maxlen, suffix, separator); | |||||
| EXPECT_FALSE(res); | |||||
| } | |||||
| } | |||||
| /* BLI_path_frame_range */ | |||||
| TEST(path_util, PathUtilPathFrameRange) | |||||
| { | |||||
| { | |||||
| char name[20] = "filename__"; | |||||
| const int digits = 3, start = 21, end = 40; | |||||
| bool res = BLI_path_frame_range(name, start, end, digits); | |||||
| EXPECT_TRUE(res); | |||||
| EXPECT_STREQ("filename__021-040", name); | |||||
| } | |||||
| { | |||||
| char name[16] = "filename__#.txt"; | |||||
| const int digits = 3, start = 21, end = 40; | |||||
| bool res = BLI_path_frame_range(name, start, end, digits); | |||||
| EXPECT_TRUE(res); | |||||
| EXPECT_STREQ("filename__21-40.txt", name); | |||||
| } | |||||
| { | |||||
| char name[50] = "filename_###_.txt"; | |||||
| const int digits = 3, start = 21, end = 40; | |||||
| bool res = BLI_path_frame_range(name, start, end, digits); | |||||
| EXPECT_TRUE(res); | |||||
| EXPECT_STREQ("filename_021-040_.txt", name); | |||||
| } | |||||
| } | |||||
| /* BLI_string_dec */ | |||||
| TEST(path_util, PathUtilStringDec) | |||||
| { | |||||
| { | |||||
| const char * name = "/any/path/filename"; | |||||
| char head[20], tail[20]; | |||||
| short unsigned numlen; | |||||
| int res = BLI_stringdec(name, head, tail, &numlen); | |||||
| EXPECT_EQ(res,0); | |||||
| EXPECT_EQ(numlen,0); | |||||
| EXPECT_STREQ(name, head); | |||||
| EXPECT_STREQ("", tail); | |||||
| } | |||||
| { | |||||
| const char * name = "/any/path/filename.ext"; | |||||
| char head[30], tail[20]; | |||||
| short unsigned numlen; | |||||
| int res = BLI_stringdec(name, head, tail, &numlen); | |||||
| EXPECT_EQ(res,0); | |||||
| EXPECT_EQ(numlen,0); | |||||
| EXPECT_STREQ("/any/path/filename", head); | |||||
| EXPECT_STREQ(".ext", tail); | |||||
| } | |||||
| { | |||||
| const char * name = "/any/path/filename72"; | |||||
| char head[30], tail[20]; | |||||
| short unsigned numlen; | |||||
| int res = BLI_stringdec(name, head, tail, &numlen); | |||||
| EXPECT_EQ(res,72); | |||||
| EXPECT_EQ(numlen,2); | |||||
| EXPECT_STREQ("/any/path/filename", head); | |||||
| EXPECT_STREQ("", tail); | |||||
| } | |||||
| { | |||||
| const char * name = "/any/path/filename72.ext64"; | |||||
| char head[30], tail[20]; | |||||
| short unsigned numlen; | |||||
| int res = BLI_stringdec(name, head, tail, &numlen); | |||||
| EXPECT_EQ(res,72); | |||||
| EXPECT_EQ(numlen,2); | |||||
| EXPECT_STREQ("/any/path/filename", head); | |||||
| EXPECT_STREQ(".ext64", tail); | |||||
| } | |||||
| { | |||||
| const char * name = "/any/path/file0072name.ext"; | |||||
| char head[30], tail[20]; | |||||
| short unsigned numlen; | |||||
| int res = BLI_stringdec(name, head, tail, &numlen); | |||||
| EXPECT_EQ(res,72); | |||||
| EXPECT_EQ(numlen,4); | |||||
| EXPECT_STREQ("/any/path/file", head); | |||||
| EXPECT_STREQ("name.ext", tail); | |||||
| } | |||||
| { | |||||
| const char * name = "/any/path/file53name012.ext"; | |||||
| char head[30], tail[20]; | |||||
| short unsigned numlen; | |||||
| int res = BLI_stringdec(name, head, tail, &numlen); | |||||
| EXPECT_EQ(res,12); | |||||
| EXPECT_EQ(numlen,3); | |||||
| EXPECT_STREQ("/any/path/file53name", head); | |||||
| EXPECT_STREQ(".ext", tail); | |||||
| } | |||||
| { | |||||
| const char * name = "/any/path32/filename.ext64"; | |||||
| char head[30], tail[20]; | |||||
| short unsigned numlen; | |||||
| int res = BLI_stringdec(name, head, tail, &numlen); | |||||
| EXPECT_EQ(res,0); | |||||
| EXPECT_EQ(numlen,0); | |||||
| EXPECT_STREQ("/any/path32/filename", head); | |||||
| EXPECT_STREQ(".ext64", tail); | |||||
| } | |||||
| } | |||||
| /* BLI_string_enc */ | |||||
| TEST(path_util, PathUtilStringEnc) | |||||
| { | |||||
| { | |||||
| char result[30]; | |||||
| const char * head = "/any/path/file"; | |||||
| const char * tail = ".ext"; | |||||
| short unsigned numlen = 1; | |||||
| int num = 52; | |||||
| BLI_stringenc(result, head, tail, numlen, num); | |||||
| EXPECT_STREQ("/any/path/file52.ext", result); | |||||
| } | |||||
| { | |||||
| char result[30]; | |||||
| const char * head = "/any/path/file"; | |||||
| const char * tail = ".ext"; | |||||
| short unsigned numlen = 5; | |||||
| int num = 52; | |||||
| BLI_stringenc(result, head, tail, numlen, num); | |||||
| EXPECT_STREQ("/any/path/file00052.ext", result); | |||||
| } | |||||
| } | |||||
| /* BLI_string_dec_AND_enc */ | |||||
| TEST(path_util, PathUtilStringDecANDEnc) | |||||
| { | |||||
| { | |||||
| const char * name = "/any/path/file53name012.ext"; | |||||
| char head[30], tail[20], result[30]; | |||||
| short unsigned numlen; | |||||
| int num = BLI_stringdec(name, head, tail, &numlen); | |||||
| BLI_stringenc(result, head, tail, numlen, num); | |||||
| EXPECT_STREQ("/any/path/file53name012.ext", result); | |||||
| } | |||||
| { | |||||
| const char * name = "/any/path64/filename.ext64"; | |||||
| char head[30], tail[20], result[30]; | |||||
| short unsigned numlen; | |||||
| int num = BLI_stringdec(name, head, tail, &numlen); | |||||
| BLI_stringenc(result, head, tail, numlen, num); | |||||
| EXPECT_STREQ("/any/path64/filename.ext64", result); | |||||
| } | |||||
| } | |||||
| /* BLI_string_enc_AND_dec */ | |||||
| TEST(path_util, PathUtilStringEncANDDec) | |||||
| { | |||||
| { | |||||
| char result[30]; | |||||
| char head[15] = "/any/path/file"; | |||||
| char tail[5] = ".ext"; | |||||
| short unsigned numlen = 1; | |||||
| int num = 52; | |||||
| BLI_stringenc(result, head, tail, numlen, num); | |||||
| int res = BLI_stringdec(result, head, tail, &numlen); | |||||
| EXPECT_EQ(res,52); | |||||
| EXPECT_EQ(numlen,2); | |||||
| EXPECT_STREQ("/any/path/file", head); | |||||
| EXPECT_STREQ(".ext", tail); | |||||
| } | |||||
| { | |||||
| char result[30]; | |||||
| char head[17] = "/any/path32/file"; | |||||
| char tail[7] = ".ext64"; | |||||
| short unsigned numlen = 5; | |||||
| int num = 52; | |||||
| BLI_stringenc(result, head, tail, numlen, num); | |||||
| int res = BLI_stringdec(result, head, tail, &numlen); | |||||
| EXPECT_EQ(res,52); | |||||
| EXPECT_EQ(numlen,5); | |||||
| EXPECT_STREQ("/any/path32/file", head); | |||||
| EXPECT_STREQ(".ext64", tail); | |||||
| } | |||||
| } | |||||
| Context not available. | |||||