Skip to content

Commit

Permalink
tests: array: for ref test, use the heap
Browse files Browse the repository at this point in the history
Signed-off-by: Eduardo Silva <[email protected]>
  • Loading branch information
edsiper committed Apr 12, 2024
1 parent e4563f8 commit 5d771a8
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions tests/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,22 @@ static void append_string_s()
static void append_string_s_ref()
{
int ret;
char *buf;
struct cfl_array *arr;

arr = cfl_array_create(1);
TEST_CHECK(arr != NULL);

ret = cfl_array_append_string_s(arr, "test", 4, CFL_TRUE);
buf = malloc(5);
TEST_CHECK(buf != NULL);
memcpy(buf, "test", 4);
buf[4] = '\0';

ret = cfl_array_append_string_s(arr, buf, 4, CFL_TRUE);
TEST_CHECK(ret == 0);

cfl_array_destroy(arr);
free(buf);
}

static void append_bytes()
Expand All @@ -133,17 +140,26 @@ static void append_bytes()
static void append_bytes_ref()
{
int ret;
char *buf;
struct cfl_array *arr;

buf = malloc(5);
TEST_CHECK(buf != NULL);
memcpy(buf, "test", 4);
buf[4] = '\0';

arr = cfl_array_create(1);
TEST_CHECK(arr != NULL);

ret = cfl_array_append_bytes(arr, "test", 4, CFL_TRUE);
ret = cfl_array_append_bytes(arr, buf, 4, CFL_TRUE);
TEST_CHECK(ret == 0);

cfl_array_destroy(arr);

free(buf);
}


static void append_reference()
{
int ret;
Expand Down

0 comments on commit 5d771a8

Please sign in to comment.