From: Pawel Szewczyk Date: Thu, 19 Feb 2015 13:12:30 +0000 (+0100) Subject: libusbgx: tests: Add framework setup for creating config X-Git-Tag: libusbgx-v0.1.0~45 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0d9c463f757c69c757990086a20bf021a35dc9ff;p=platform%2Fupstream%2Flibusbg.git libusbgx: tests: Add framework setup for creating config Change-Id: I19b4777e9b61c7dc63c8bb0644de2a63089e6bd3 Signed-off-by: Pawel Szewczyk [Update description] Signed-off-by: Krzysztof Opasiak --- diff --git a/tests/usbg-test.c b/tests/usbg-test.c index 8e70025..53563b0 100644 --- a/tests/usbg-test.c +++ b/tests/usbg-test.c @@ -549,6 +549,30 @@ struct test_state *prepare_state(struct test_state *state) return new_state; } +struct test_state *build_empty_gadget_state(struct test_state *ts) +{ + struct test_state *ret; + struct test_gadget *tg; + int count = 0; + + ret = safe_malloc(sizeof(*ret)); + ret->udcs = ts->udcs; + ret->configfs_path = ts->configfs_path; + + for (tg = ts->gadgets; tg->name; ++tg) + count++; + + ret->gadgets = safe_calloc(count+1, sizeof(*ts->gadgets)); + memcpy(ret->gadgets, ts->gadgets, count*sizeof(*ts->gadgets)); + + for (tg = ret->gadgets; tg->name; ++tg) { + tg->configs = safe_calloc(1, sizeof(*tg->configs)); + tg->functions = safe_calloc(1, sizeof(*tg->functions)); + } + + return prepare_state(ret); +} + /* Simulation of configfs for init */ static void push_binding(struct test_config *conf, struct test_binding *binding) @@ -969,6 +993,19 @@ void assert_config_attrs_equal(usbg_config_attrs *actual, usbg_config_attrs *exp assert_int_equal(actual->bMaxPower, expected->bMaxPower); } +void pull_create_config(struct test_config *tc) +{ + char *path; + + safe_asprintf(&path, "%s/%s", tc->path, tc->name); + EXPECT_MKDIR(path); + + if (tc->attrs) + pull_config_attrs(tc, tc->attrs); + if (tc->strs) + pull_config_strs(tc, LANG_US_ENG, tc->strs); +} + 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 5fad226..e28ea55 100644 --- a/tests/usbg-test.h +++ b/tests/usbg-test.h @@ -289,6 +289,19 @@ void push_config_string(struct test_config *config, int lang, const char *str); void push_config_strs(struct test_config *config, int lang, usbg_config_strs *strs); /** + * @brief Prepare for creating config + * @param[in] tc Test config to be created + */ +void pull_create_config(struct test_config *tc); + +/** + * @brief Copy state without configs and functions + * @param[in] ts State to bo copied + * @return State with empty gadgets + */ +struct test_state *build_empty_gadget_state(struct test_state *ts); + +/** * @brief Store given pointer on cleanup stack * @details All stacked pointers will be freed by calling cleanup_queue. * This can be used to manage memory needed for single test casees.