diff options
author | Pawel Szewczyk <p.szewczyk@samsung.com> | 2015-05-25 15:11:28 +0200 |
---|---|---|
committer | Krzysztof Opasiak <k.opasiak@samsung.com> | 2015-07-30 15:56:52 +0200 |
commit | ff0eabc697b08dbbef5512497f4d234aada49f52 (patch) | |
tree | 32214e2684f486b37c73edc8811a5d1b53a724ae | |
parent | 0398c8135ac81303ef4e106ca42324b7274a3066 (diff) | |
download | libusbg-ff0eabc697b08dbbef5512497f4d234aada49f52.tar.gz libusbg-ff0eabc697b08dbbef5512497f4d234aada49f52.tar.bz2 libusbg-ff0eabc697b08dbbef5512497f4d234aada49f52.zip |
libusbg: tests: Add create function test
Change-Id: I3a47f0d16b9259f09bb4ea3eeb3734a89af43019
Signed-off-by: Pawel Szewczyk <p.szewczyk@samsung.com>
Reviewed-by: Krzysztof Opasiak <k.opasiak@samsung.com>
-rw-r--r-- | tests/test.c | 39 | ||||
-rw-r--r-- | tests/usbg-test.c | 15 | ||||
-rw-r--r-- | tests/usbg-test.h | 6 |
3 files changed, 60 insertions, 0 deletions
diff --git a/tests/test.c b/tests/test.c index 0c1ac5b..e544fe2 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 |