summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPawel Szewczyk <p.szewczyk@samsung.com>2015-02-19 14:12:30 +0100
committerKrzysztof Opasiak <k.opasiak@samsung.com>2015-07-30 15:56:31 +0200
commit60558e475177e62d546860edd8468f4bde577e67 (patch)
tree42bbcf594a132358b5209969d9071ed67be571eb
parent896f3789ad213e090fb2792b7aac641b967ee049 (diff)
downloadlibusbg-60558e475177e62d546860edd8468f4bde577e67.tar.gz
libusbg-60558e475177e62d546860edd8468f4bde577e67.tar.bz2
libusbg-60558e475177e62d546860edd8468f4bde577e67.zip
libusbg: tests: Add framework setup for creating config
Change-Id: I19b4777e9b61c7dc63c8bb0644de2a63089e6bd3 Signed-off-by: Pawel Szewczyk <p.szewczyk@samsung.com> Reviewed-by: Krzysztof Opasiak <k.opasiak@samsung.com>
-rw-r--r--tests/usbg-test.c37
-rw-r--r--tests/usbg-test.h13
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.