From b7541e8eea1c5a6f4676e79fa3cd2f40a78a49d0 Mon Sep 17 00:00:00 2001 From: David Garcia Quintas Date: Tue, 7 Jul 2015 15:41:52 -0700 Subject: Added convenience method gpr_strjoin_sep --- test/core/support/string_test.c | 42 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'test/core/support') 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; } -- cgit v1.2.3