diff options
author | Pawel Szewczyk <p.szewczyk@samsung.com> | 2015-02-19 14:12:30 +0100 |
---|---|---|
committer | Krzysztof Opasiak <k.opasiak@samsung.com> | 2015-12-22 21:45:37 +0100 |
commit | 0d9c463f757c69c757990086a20bf021a35dc9ff (patch) | |
tree | ef42779397e8b64e0284f8e1133da65414a2178c /tests | |
parent | e036a3406f7e7025fd2f6e28e506cf78052796af (diff) | |
download | libusbg-0d9c463f757c69c757990086a20bf021a35dc9ff.tar.gz libusbg-0d9c463f757c69c757990086a20bf021a35dc9ff.tar.bz2 libusbg-0d9c463f757c69c757990086a20bf021a35dc9ff.zip |
libusbgx: tests: Add framework setup for creating config
Change-Id: I19b4777e9b61c7dc63c8bb0644de2a63089e6bd3
Signed-off-by: Pawel Szewczyk <p.szewczyk@samsung.com>
[Update description]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/usbg-test.c | 37 | ||||
-rw-r--r-- | tests/usbg-test.h | 13 |
2 files changed, 50 insertions, 0 deletions
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. |