diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/utils/utils_test.c | 28 | ||||
-rw-r--r-- | tests/utils/utils_test.ok | 15 |
2 files changed, 43 insertions, 0 deletions
diff --git a/tests/utils/utils_test.c b/tests/utils/utils_test.c index 711d6e12..211b4d1a 100644 --- a/tests/utils/utils_test.c +++ b/tests/utils/utils_test.c @@ -1014,6 +1014,33 @@ void strbuf_test() printf("(need %d chars, had size=63) %s\n", rc, buf); } +static void startswith_test_str(const char *str, const char *startswith_str, bool expect_rc) +{ + bool rc = osmo_str_startswith(str, startswith_str); + printf("osmo_str_startswith(%s, ", osmo_quote_str(str, -1)); + printf("%s) == %s\n", osmo_quote_str(startswith_str, -1), rc ? "true" : "false"); + if (rc != expect_rc) + printf(" ERROR: EXPECTED %s\n", expect_rc ? "true" : "false"); +} + +static void startswith_test() +{ + printf("\n%s()\n", __func__); + startswith_test_str(NULL, NULL, true); + startswith_test_str("", NULL, true); + startswith_test_str(NULL, "", true); + startswith_test_str("", "", true); + startswith_test_str("abc", NULL, true); + startswith_test_str("abc", "", true); + startswith_test_str(NULL, "abc", false); + startswith_test_str("", "abc", false); + startswith_test_str("abc", "a", true); + startswith_test_str("abc", "ab", true); + startswith_test_str("abc", "abc", true); + startswith_test_str("abc", "abcd", false); + startswith_test_str("abc", "xyz", false); +} + int main(int argc, char **argv) { static const struct log_info log_info = {}; @@ -1032,5 +1059,6 @@ int main(int argc, char **argv) osmo_sockaddr_to_str_and_uint_test(); osmo_str_tolowupper_test(); strbuf_test(); + startswith_test(); return 0; } diff --git a/tests/utils/utils_test.ok b/tests/utils/utils_test.ok index 8fce9f13..5783eb16 100644 --- a/tests/utils/utils_test.ok +++ b/tests/utils/utils_test.ok @@ -340,3 +340,18 @@ cascade: (need 134 chars) T minus 10 9 8 7 6 5 4 3 2 1 ... Lift off! -- T minus 10 9 8 7 6 5 4 3 2 1 ... Lift off! -- T minus 10 9 8 7 6 5 4 3 2 1 ... Lift off! (need 134 chars, had size=63) T minus 10 9 8 7 6 5 4 3 2 1 ... Lift off! -- T minus 10 9 8 7 + +startswith_test() +osmo_str_startswith(NULL, NULL) == true +osmo_str_startswith("", NULL) == true +osmo_str_startswith(NULL, "") == true +osmo_str_startswith("", "") == true +osmo_str_startswith("abc", NULL) == true +osmo_str_startswith("abc", "") == true +osmo_str_startswith(NULL, "abc") == false +osmo_str_startswith("", "abc") == false +osmo_str_startswith("abc", "a") == true +osmo_str_startswith("abc", "ab") == true +osmo_str_startswith("abc", "abc") == true +osmo_str_startswith("abc", "abcd") == false +osmo_str_startswith("abc", "xyz") == false |