Changeset View
Changeset View
Standalone View
Standalone View
tests/gtests/blenlib/BLI_string_test.cc
| /* Apache License, Version 2.0 */ | /* Apache License, Version 2.0 */ | ||||
| #include "testing/testing.h" | #include "testing/testing.h" | ||||
| extern "C" { | extern "C" { | ||||
| #include "BLI_utildefines.h" | #include "BLI_utildefines.h" | ||||
| #include "BLI_string.h" | #include "BLI_string.h" | ||||
| #include "BLI_string_utf8.h" | #include "BLI_string_utf8.h" | ||||
| } | } | ||||
| #define WORD_1 "lorem" | |||||
| #define WORD_2 "lorem ipsum" | |||||
| #define WORD_3 "lorem ipsum dolor" | |||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /* stubs */ | /* stubs */ | ||||
| extern "C" { | extern "C" { | ||||
| int mk_wcwidth(wchar_t ucs); | int mk_wcwidth(wchar_t ucs); | ||||
| int mk_wcswidth(const wchar_t *pwcs, size_t n); | int mk_wcswidth(const wchar_t *pwcs, size_t n); | ||||
| ▲ Show 20 Lines • Show All 339 Lines • ▼ Show 20 Lines | TEST(string, StrFormatIntGrouped) | ||||
| EXPECT_STREQ("-1,000", num_str); | EXPECT_STREQ("-1,000", num_str); | ||||
| BLI_str_format_int_grouped(num_str, num = 999); | BLI_str_format_int_grouped(num_str, num = 999); | ||||
| EXPECT_STREQ("999", num_str); | EXPECT_STREQ("999", num_str); | ||||
| BLI_str_format_int_grouped(num_str, num = -999); | BLI_str_format_int_grouped(num_str, num = -999); | ||||
| EXPECT_STREQ("-999", num_str); | EXPECT_STREQ("-999", num_str); | ||||
| } | } | ||||
campbellbarton: text "lorem" etc... can be define:
#define WORD_1 "lorem"
#define WORD_2 "lorem ipsum"… | |||||
| TEST(string, StrRStripWhitespace) | |||||
| { | |||||
| char clean_str[16]; | |||||
| size_t len; | |||||
| { | |||||
Not Done Inline ActionsDon't join unit tests together. They're testing different aspects of behavior and needs to be done as separate tests. sergey: Don't join unit tests together. They're testing different aspects of behavior and needs to be… | |||||
Not Done Inline ActionsWhat exactly do you mean here? Tried to do things exactly as other tests in BLI_string_test.cc are doing them. Severin: What exactly do you mean here? Tried to do things exactly as other tests in BLI_string_test.cc… | |||||
| const char *str = " " WORD_1 " "; | |||||
| len = BLI_str_rstrip_whitespace(clean_str, str, sizeof(clean_str)); | |||||
| EXPECT_STREQ(" " WORD_1, clean_str); | |||||
| EXPECT_EQ(strlen(WORD_1) + 2, len); | |||||
| } | |||||
| { | |||||
| const char *str = WORD_1; | |||||
| len = BLI_str_rstrip_whitespace(clean_str, str, sizeof(clean_str)); | |||||
| EXPECT_STREQ(WORD_1, clean_str); | |||||
| EXPECT_EQ(strlen(WORD_1), len); | |||||
| } | |||||
| { | |||||
| const char *str = " " WORD_2 " "; | |||||
| len = BLI_str_rstrip_whitespace(clean_str, str, sizeof(clean_str)); | |||||
| EXPECT_STREQ(" " WORD_2, clean_str); | |||||
| EXPECT_EQ(strlen(WORD_2) + 2, len); | |||||
| } | |||||
| { | |||||
| const char *str = " l "; | |||||
| len = BLI_str_rstrip_whitespace(clean_str, str, sizeof(clean_str)); | |||||
| EXPECT_STREQ(" l", clean_str); | |||||
| EXPECT_EQ(3, len); | |||||
| } | |||||
| /* Corner cases. */ | |||||
| /* case strlen > max_len */ | |||||
| { | |||||
| const char *str = " " WORD_3 " "; | |||||
| char *str_exp = NULL; | |||||
| BLI_strncpy(str_exp, str, sizeof(clean_str)); | |||||
| len = BLI_str_rstrip_whitespace(clean_str, str, sizeof(clean_str)); | |||||
| EXPECT_STREQ(str_exp, clean_str); | |||||
| EXPECT_EQ(sizeof(clean_str), len); | |||||
| } | |||||
| { | |||||
| const char *str = " "; | |||||
Not Done Inline Actions0 instead of NULL i think? sergey: 0 instead of NULL i think? | |||||
Not Done Inline ActionsThink both work, but since everywhere else NULL is used, I went with it, too. Severin: Think both work, but since everywhere else NULL is used, I went with it, too. | |||||
| len = BLI_str_rstrip_whitespace(clean_str, str, sizeof(clean_str)); | |||||
| EXPECT_STREQ("", clean_str); | |||||
| EXPECT_EQ(NULL, len); | |||||
| } | |||||
| { | |||||
| const char *str = ""; | |||||
| len = BLI_str_rstrip_whitespace(clean_str, str, sizeof(clean_str)); | |||||
| EXPECT_STREQ("", clean_str); | |||||
| EXPECT_EQ(NULL, len); | |||||
| } | |||||
| } | |||||
| TEST(string, StrLStripWhitespace) | |||||
| { | |||||
| char clean_str[16]; | |||||
Not Done Inline ActionsSame as above. sergey: Same as above. | |||||
| size_t len; | |||||
| { | |||||
| const char *str = " " WORD_1 " "; | |||||
| len = BLI_str_lstrip_whitespace(clean_str, str, sizeof(clean_str)); | |||||
| EXPECT_STREQ(WORD_1 " ", clean_str); | |||||
| EXPECT_EQ(strlen(WORD_1) + 2, len); | |||||
| } | |||||
| { | |||||
| const char *str = WORD_1; | |||||
| len = BLI_str_lstrip_whitespace(clean_str, str, sizeof(clean_str)); | |||||
| EXPECT_STREQ(WORD_1, clean_str); | |||||
| EXPECT_EQ(strlen(WORD_1), len); | |||||
| } | |||||
| { | |||||
| const char *str = " " WORD_2 " "; | |||||
| len = BLI_str_lstrip_whitespace(clean_str, str, sizeof(clean_str)); | |||||
| EXPECT_STREQ(WORD_2 " ", clean_str); | |||||
| EXPECT_EQ(strlen(WORD_2) + 2, len); | |||||
| } | |||||
| { | |||||
| const char *str = " l "; | |||||
| len = BLI_str_lstrip_whitespace(clean_str, str, sizeof(clean_str)); | |||||
| EXPECT_STREQ("l ", clean_str); | |||||
| EXPECT_EQ(3, len); | |||||
| } | |||||
| /* Corner cases. */ | |||||
| /* case strlen > max_len */ | |||||
| { | |||||
| const char *str = " " WORD_3 " "; | |||||
| char *str_exp = NULL; | |||||
| BLI_strncpy(str_exp, str, sizeof(clean_str)); | |||||
| len = BLI_str_lstrip_whitespace(clean_str, str, sizeof(clean_str)); | |||||
| EXPECT_STREQ(str_exp, clean_str); | |||||
| EXPECT_EQ(sizeof(clean_str), len); | |||||
| } | |||||
| { | |||||
| const char *str = " "; | |||||
| len = BLI_str_lstrip_whitespace(clean_str, str, sizeof(clean_str)); | |||||
| EXPECT_STREQ("", clean_str); | |||||
| EXPECT_EQ(NULL, len); | |||||
| } | |||||
| { | |||||
| const char *str = ""; | |||||
| len = BLI_str_lstrip_whitespace(clean_str, str, sizeof(clean_str)); | |||||
| EXPECT_STREQ("", clean_str); | |||||
| EXPECT_EQ(NULL, len); | |||||
| } | |||||
| } | |||||
text "lorem" etc... can be define:
#define WORD_1 "lorem" #define WORD_2 "lorem ipsum" #define WORD_3 "lorem ipsum dolor" .... const char *str = " " WORD_1 " "; EXPECT_EQ(len, strlen(WORD_1));