From 7bf2ecb6049a4def75ba6481dd7efc5a332c18d9 Mon Sep 17 00:00:00 2001 From: Lev Brouk Date: Mon, 29 Apr 2024 11:20:29 -0700 Subject: [PATCH] more coverage --- test/test.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/test/test.c b/test/test.c index 85c543a76..c68b149b3 100644 --- a/test/test.c +++ b/test/test.c @@ -5470,25 +5470,29 @@ static void test_natsFormatStringArray(void) { natsStatus s; - char *str = NULL; + char *array[4]; + memset(array, 0, sizeof(array)); test("Check empty: "); - s = nats_formatStringArray(&str, NULL, 0); - testCond((s == NATS_OK) && (str != NULL) && (strcmp(str, "[]") == 0)); - NATS_FREE(str); - str = NULL; + s = nats_formatStringArray(&array[0], NULL, 0); + testCond((s == NATS_OK) && (array[0] != NULL) && (strcmp(array[0], "[]") == 0)); test("Check one: "); const char *oneArray[] = {"one"}; - s = nats_formatStringArray(&str, oneArray, 1); - testCond((s == NATS_OK) && (str != NULL) && (strcmp(str, "[\"one\"]") == 0)); - NATS_FREE(str); + s = nats_formatStringArray(&array[1], oneArray, 1); + testCond((s == NATS_OK) && (array[1] != NULL) && (strcmp(array[1], "[\"one\"]") == 0)); test("Check multiple: "); - const char *threeArray[] = {"one","two","three"}; - s = nats_formatStringArray(&str, threeArray, 3); - testCond((s == NATS_OK) && (str != NULL) && (strcmp(str, "[\"one\",\"two\",\"three\"]") == 0)); - NATS_FREE(str); + const char *threeArray[] = {"one", "two", "three"}; + s = nats_formatStringArray(&array[2], threeArray, 3); + testCond((s == NATS_OK) && (array[2] != NULL) && (strcmp(array[2], "[\"one\",\"two\",\"three\"]") == 0)); + + test("Check NULL: "); + const char *nullArray[] = {NULL}; + s = nats_formatStringArray(&array[3], nullArray, 1); + testCond((s == NATS_OK) && (array[3] != NULL) && (strcmp(array[3], "[\"(null)\"]") == 0)); + + NATS_FREE_STRINGS(array, 3); } static natsStatus