diff options
author | David Garcia Quintas <dgq@google.com> | 2015-07-07 15:41:52 -0700 |
---|---|---|
committer | David Garcia Quintas <dgq@google.com> | 2015-07-07 16:06:57 -0700 |
commit | b7541e8eea1c5a6f4676e79fa3cd2f40a78a49d0 (patch) | |
tree | a4a56198989e08ffea34e0d1eff2c60ddaa4812c /test/core/support | |
parent | 772187cdf0ff9dfafd2e693474c51eeddfe4c800 (diff) |
Added convenience method gpr_strjoin_sep
Diffstat (limited to 'test/core/support')
-rw-r--r-- | test/core/support/string_test.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/test/core/support/string_test.c b/test/core/support/string_test.c index b59082eecf..24e28d68dd 100644 --- a/test/core/support/string_test.c +++ b/test/core/support/string_test.c @@ -145,11 +145,53 @@ static void test_asprintf(void) { } } +static void test_strjoin(void) { + const char *parts[4] = {"one", "two", "three", "four"}; + size_t joined_len; + char *joined; + + LOG_TEST_NAME("test_strjoin"); + + joined = gpr_strjoin(parts, 4, &joined_len); + GPR_ASSERT(0 == strcmp("onetwothreefour", joined)); + gpr_free(joined); + + joined = gpr_strjoin(parts, 0, &joined_len); + GPR_ASSERT(0 == strcmp("", joined)); + gpr_free(joined); + + joined = gpr_strjoin(parts, 1, &joined_len); + GPR_ASSERT(0 == strcmp("one", joined)); + gpr_free(joined); +} + +static void test_strjoin_sep(void) { + const char *parts[4] = {"one", "two", "three", "four"}; + size_t joined_len; + char *joined; + + LOG_TEST_NAME("test_strjoin_sep"); + + joined = gpr_strjoin_sep(parts, 4, ", ", &joined_len); + GPR_ASSERT(0 == strcmp("one, two, three, four", joined)); + gpr_free(joined); + + joined = gpr_strjoin_sep(parts, 0, ", ", &joined_len); + GPR_ASSERT(0 == strcmp("", joined)); + gpr_free(joined); + + joined = gpr_strjoin_sep(parts, 1, ", ", &joined_len); + GPR_ASSERT(0 == strcmp("one", joined)); + gpr_free(joined); +} + int main(int argc, char **argv) { grpc_test_init(argc, argv); test_strdup(); test_hexdump(); test_parse_uint32(); test_asprintf(); + test_strjoin(); + test_strjoin_sep(); return 0; } |