test: move the array tests to pwtest

Add them to the existing pw_properties test binary and rename that to
pw-utils.

Same functionality as before for the pw_array tests.
This commit is contained in:
Peter Hutterer 2021-06-01 16:28:13 +10:00
parent 3865d8846e
commit 493f0724b5
3 changed files with 47 additions and 37 deletions

View file

@ -1,5 +1,4 @@
test_apps = [ test_apps = [
'test-array',
'test-client', 'test-client',
'test-context', 'test-context',
'test-endpoint', 'test-endpoint',

View file

@ -38,9 +38,10 @@ executable('test-example',
include_directories: pwtest_inc, include_directories: pwtest_inc,
link_with: pwtest_lib) link_with: pwtest_lib)
test('test properties', test('test pipewire utils',
executable('test-properties', executable('test-pw-utils',
'test-properties.c', 'test-properties.c',
'test-array.c',
include_directories: pwtest_inc, include_directories: pwtest_inc,
link_with: pwtest_lib) link_with: pwtest_lib)
) )

View file

@ -22,19 +22,27 @@
* DEALINGS IN THE SOFTWARE. * DEALINGS IN THE SOFTWARE.
*/ */
#include <pipewire/array.h>
static void test_abi(void) #ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "pwtest.h"
#include "pipewire/array.h"
PWTEST(array_test_abi)
{ {
/* array */ /* array */
#if defined(__x86_64__) && defined(__LP64__) #if defined(__x86_64__) && defined(__LP64__)
spa_assert(sizeof(struct pw_array) == 32); pwtest_int_eq(sizeof(struct pw_array), 32U);
return PWTEST_PASS;
#else #else
fprintf(stderr, "%zd\n", sizeof(struct pw_array)); fprintf(stderr, "Unknown arch: pw_array is size %zd\n", sizeof(struct pw_array));
return PWTEST_SKIP;
#endif #endif
} }
static void test_array(void) PWTEST(array_test)
{ {
struct pw_array arr; struct pw_array arr;
uint32_t *ptr; uint32_t *ptr;
@ -42,68 +50,70 @@ static void test_array(void)
size_t i; size_t i;
pw_array_init(&arr, 64); pw_array_init(&arr, 64);
spa_assert(SPA_N_ELEMENTS(vals) == 4); pwtest_int_eq(SPA_N_ELEMENTS(vals), 4U);
spa_assert(pw_array_get_len(&arr, uint32_t) == 0); pwtest_int_eq(pw_array_get_len(&arr, uint32_t), 0U);
spa_assert(pw_array_check_index(&arr, 0, uint32_t) == false); pwtest_bool_false(pw_array_check_index(&arr, 0, uint32_t));
spa_assert(pw_array_first(&arr) == pw_array_end(&arr)); pwtest_ptr_eq(pw_array_first(&arr), pw_array_end(&arr));
pw_array_for_each(ptr, &arr) pw_array_for_each(ptr, &arr)
spa_assert_not_reached(); pwtest_fail_if_reached();
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
ptr = (uint32_t*)pw_array_add(&arr, sizeof(uint32_t)); ptr = (uint32_t*)pw_array_add(&arr, sizeof(uint32_t));
*ptr = vals[i]; *ptr = vals[i];
} }
spa_assert(pw_array_get_len(&arr, uint32_t) == 4); pwtest_int_eq(pw_array_get_len(&arr, uint32_t), 4U);
spa_assert(pw_array_check_index(&arr, 2, uint32_t) == true); pwtest_bool_true(pw_array_check_index(&arr, 2, uint32_t));
spa_assert(pw_array_check_index(&arr, 3, uint32_t) == true); pwtest_bool_true(pw_array_check_index(&arr, 3, uint32_t));
spa_assert(pw_array_check_index(&arr, 4, uint32_t) == false); pwtest_bool_false(pw_array_check_index(&arr, 4, uint32_t));
i = 0; i = 0;
pw_array_for_each(ptr, &arr) { pw_array_for_each(ptr, &arr) {
spa_assert(*ptr == vals[i++]); pwtest_int_eq(*ptr, vals[i++]);
} }
/* remove second */ /* remove second */
ptr = pw_array_get_unchecked(&arr, 2, uint32_t); ptr = pw_array_get_unchecked(&arr, 2, uint32_t);
spa_assert(ptr != NULL); pwtest_ptr_notnull(ptr);
pw_array_remove(&arr, ptr); pw_array_remove(&arr, ptr);
spa_assert(pw_array_get_len(&arr, uint32_t) == 3); pwtest_int_eq(pw_array_get_len(&arr, uint32_t), 3U);
spa_assert(pw_array_check_index(&arr, 3, uint32_t) == false); pwtest_bool_false(pw_array_check_index(&arr, 3, uint32_t));
ptr = pw_array_get_unchecked(&arr, 2, uint32_t); ptr = pw_array_get_unchecked(&arr, 2, uint32_t);
spa_assert(ptr != NULL); pwtest_ptr_notnull(ptr);
spa_assert(*ptr == vals[3]); pwtest_int_eq(*ptr, vals[3]);
/* remove first */ /* remove first */
ptr = pw_array_get_unchecked(&arr, 0, uint32_t); ptr = pw_array_get_unchecked(&arr, 0, uint32_t);
spa_assert(ptr != NULL); pwtest_ptr_notnull(ptr);
pw_array_remove(&arr, ptr); pw_array_remove(&arr, ptr);
spa_assert(pw_array_get_len(&arr, uint32_t) == 2); pwtest_int_eq(pw_array_get_len(&arr, uint32_t), 2U);
ptr = pw_array_get_unchecked(&arr, 0, uint32_t); ptr = pw_array_get_unchecked(&arr, 0, uint32_t);
spa_assert(ptr != NULL); pwtest_ptr_notnull(ptr);
spa_assert(*ptr == vals[1]); pwtest_int_eq(*ptr, vals[1]);
/* iterate */ /* iterate */
ptr = (uint32_t*)pw_array_first(&arr); ptr = (uint32_t*)pw_array_first(&arr);
spa_assert(pw_array_check(&arr, ptr)); pwtest_bool_true(pw_array_check(&arr, ptr));
spa_assert(*ptr == vals[1]); pwtest_int_eq(*ptr, vals[1]);
ptr++; ptr++;
spa_assert(pw_array_check(&arr, ptr)); pwtest_bool_true(pw_array_check(&arr, ptr));
spa_assert(*ptr == vals[3]); pwtest_int_eq(*ptr, vals[3]);
ptr++; ptr++;
spa_assert(pw_array_check(&arr, ptr) == false); pwtest_bool_false(pw_array_check(&arr, ptr));
pw_array_reset(&arr); pw_array_reset(&arr);
spa_assert(pw_array_get_len(&arr, uint32_t) == 0); pwtest_int_eq(pw_array_get_len(&arr, uint32_t), 0U);
pw_array_clear(&arr); pw_array_clear(&arr);
return PWTEST_PASS;
} }
int main(int argc, char *argv[]) PWTEST_SUITE(pw_array)
{ {
test_abi(); pwtest_add(array_test_abi, PWTEST_NOARG);
test_array(); pwtest_add(array_test, PWTEST_NOARG);
return 0; return PWTEST_PASS;
} }