From: Pawel Szewczyk Date: Mon, 25 May 2015 13:11:28 +0000 (+0200) Subject: libusbgx: tests: Add create function test X-Git-Tag: libusbgx-v0.1.0~41 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ca8120c2aacf7e8c0393a44b2af9c5a046c2881a;p=platform%2Fupstream%2Flibusbg.git libusbgx: tests: Add create function test Change-Id: I3a47f0d16b9259f09bb4ea3eeb3734a89af43019 Signed-off-by: Pawel Szewczyk [Update description] Signed-off-by: Krzysztof Opasiak --- diff --git a/tests/test.c b/tests/test.c index aefce06..7b93b1c 100644 --- a/tests/test.c +++ b/tests/test.c @@ -1670,6 +1670,37 @@ static void test_create_config(void **state) } /** + * @brief Start with empty gadget, add all functions from given one + */ +static void test_create_function(void **state) +{ + usbg_state *s = NULL; + usbg_gadget *g = NULL; + usbg_function *f = NULL; + struct test_state *ts; + struct test_state *empty; + struct test_gadget *tg; + struct test_function *tf; + + ts = (struct test_state *)(*state); + *state = NULL; + + empty = build_empty_gadget_state(ts); + + init_with_state(empty, &s); + *state = s; + + for (tg = ts->gadgets; tg->name; tg++) { + g = usbg_get_gadget(s, tg->name); + assert_non_null(g); + for (tf = tg->functions; tf->instance; tf++) { + pull_create_function(tf); + usbg_create_function(g, tf->type, tf->instance, + tf->attrs, &f); + assert_func_equal(f, tf); + } + } +} /** * @brief Test only one given function for attribute getting @@ -2335,6 +2366,14 @@ static struct CMUnitTest tests[] = { */ USBG_TEST_TS("test_set_f_ffs_attrs", test_set_function_attrs, setup_f_ffs_writable_attrs), + /** + * @usbg_test + * @test_desc{test_create_all_functions, + * Create full set of functions in empty state, + * usbg_get_binding_name_len} + */ + USBG_TEST_TS("test_create_all_functions", + test_create_function, setup_all_funcs_state), #ifndef DOXYGEN }; diff --git a/tests/usbg-test.c b/tests/usbg-test.c index 917a5a0..c332795 100644 --- a/tests/usbg-test.c +++ b/tests/usbg-test.c @@ -1116,6 +1116,21 @@ void pull_function_attrs(struct test_function *func, usbg_function_attrs *attrs) pull_function_net_attrs(func, &attrs->attrs.net); } +void pull_create_function(struct test_function *tf) +{ + char *path; + int tmp; + + tmp = asprintf(&path, "%s/%s", tf->path, tf->name); + if (tmp < 0) + fail(); + free_later(path); + + EXPECT_MKDIR(path); + if (tf->attrs) + pull_function_attrs(tf, tf->attrs); +} + void assert_func_equal(usbg_function *f, struct test_function *expected) { assert_string_equal(f->instance, expected->instance); diff --git a/tests/usbg-test.h b/tests/usbg-test.h index aa90a2e..127b90e 100644 --- a/tests/usbg-test.h +++ b/tests/usbg-test.h @@ -314,6 +314,12 @@ void push_config_strs(struct test_config *config, int lang, usbg_config_strs *st void pull_create_config(struct test_config *tc); /** + * @brief Prepare for creating function + * @param[in] tf Test function to be created + */ +void pull_create_function(struct test_function *tf); + +/** * @brief Copy state without configs and functions * @param[in] ts State to bo copied * @return State with empty gadgets