Skip to content

Commit

Permalink
Merge pull request #1322 from jluebbe/gptrarray-test-helper
Browse files Browse the repository at this point in the history
test/common: add helper to build a GPtrArray from a ;-separated string
  • Loading branch information
jluebbe committed Jan 15, 2024
2 parents e3ce0d3 + b154e5b commit ea047d8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
12 changes: 12 additions & 0 deletions test/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,18 @@ void replace_strdup(gchar **dst, const gchar *src)
*dst = g_strdup(src);
}

GPtrArray *test_ptr_array_from_strsplit(const gchar *input)
{
GPtrArray *result = g_ptr_array_new_with_free_func(g_free);
/* The strings will be owned by the returned GPtrArray, so we don't
* want to free them via g_auto(GStrv). */
g_autofree GStrv strv = g_strsplit(input, ";", 0);

r_ptr_array_addv(result, strv, FALSE);

return result;
}

void* dup_test_mem(GPtrArray *ptrs, const void *mem, gsize len)
{
void *result = g_memdup(mem, len);
Expand Down
6 changes: 6 additions & 0 deletions test/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ void flip_bits_fd(int fd, off_t offset, guint8 mask);
void flip_bits_filename(gchar *filename, off_t offset, guint8 mask);
void replace_strdup(gchar **dst, const gchar *src);

/**
* Build a GPtrArray from a ;-separated string. The elements in the array are
* freed with the array itself.
*/
GPtrArray *test_ptr_array_from_strsplit(const gchar *input);

void* dup_test_mem(GPtrArray *ptrs, const void *mem, gsize len);
void* dup_test_printf(GPtrArray *ptrs, const gchar *str, ...)
__attribute__((__format__(__printf__, 2, 3)));
Expand Down

0 comments on commit ea047d8

Please sign in to comment.