From 13339b764694f73c86c2895c2cf0489ee0c23a22 Mon Sep 17 00:00:00 2001 From: Pawel Szewczyk Date: Wed, 18 Feb 2015 11:51:34 +0100 Subject: [PATCH] libusbgx: tests: Add simulation of configfs for getting bindings Signed-off-by: Pawel Szewczyk Add asserts for gadget, config and bindings. Change-Id: If6ce39332101826888c70790f8518876e03f8a44 Signed-off-by: Krzysztof Opasiak --- tests/usbg-test.c | 34 ++++++++++++++++++++++++++++++++++ tests/usbg-test.h | 12 ++++++++++++ 2 files changed, 46 insertions(+) diff --git a/tests/usbg-test.c b/tests/usbg-test.c index 5359eb9..ae9e133 100644 --- a/tests/usbg-test.c +++ b/tests/usbg-test.c @@ -1082,3 +1082,37 @@ void for_each_test_config(void **state, ConfigTest fun) } } } + +void for_each_binding(void **state, BindingTestFunc fun) +{ + struct test_state *ts; + struct test_gadget *tg; + struct test_config *tc; + struct test_binding *tb; + usbg_state *s = NULL; + usbg_gadget *g = NULL; + usbg_config *c = NULL; + usbg_binding *b = NULL; + + ts = (struct test_state *)(*state); + *state = NULL; + + init_with_state(ts, &s); + *state = s; + + for (tg = ts->gadgets; tg->name; tg++) { + g = usbg_get_gadget(s, tg->name); + assert_non_null(g); + for (tc = tg->configs; tc->label; tc++) { + c = usbg_get_config(g, tc->id, tc->label); + assert_non_null(c); + + b = usbg_get_first_binding(c); + for (tb = tc->bindings; tb->name; ++tb) { + assert_non_null(b); + fun(tb, b); + b = usbg_get_next_binding(b); + } + } + } +} diff --git a/tests/usbg-test.h b/tests/usbg-test.h index 2ddb250..a79fd3e 100644 --- a/tests/usbg-test.h +++ b/tests/usbg-test.h @@ -357,4 +357,16 @@ typedef void (*ConfigTest)(usbg_config *c, struct test_config *tc); */ void for_each_test_config(void **state, ConfigTest fun); +/** + * @brief Function that performs test on given usbg binding + */ +typedef void (*BindingTestFunc)(struct test_binding *tb, usbg_binding *b); + +/** + * @brief Call given function for all usb bindings present in given state + * @param[in] state Properly prepared state to be tested + * @param[in] fun Function to be called on each usb binding in state + */ +void for_each_binding(void **state, BindingTestFunc fun); + #endif /* USBG_TEST_H */ -- 2.7.4