libusbgx: tests: Add framework setup for creating config
authorPawel Szewczyk <p.szewczyk@samsung.com>
Thu, 19 Feb 2015 13:12:30 +0000 (14:12 +0100)
committerKrzysztof Opasiak <k.opasiak@samsung.com>
Tue, 22 Dec 2015 20:45:37 +0000 (21:45 +0100)
Change-Id: I19b4777e9b61c7dc63c8bb0644de2a63089e6bd3
Signed-off-by: Pawel Szewczyk <p.szewczyk@samsung.com>
[Update description]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
tests/usbg-test.c
tests/usbg-test.h

index 8e70025..53563b0 100644 (file)
@@ -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);
index 5fad226..e28ea55 100644 (file)
@@ -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.