libusbgx: tests: Fix tests to use correct usbg_state field
authorKrzysztof Opasiak <k.opasiak@samsung.com>
Tue, 3 Feb 2015 13:16:42 +0000 (14:16 +0100)
committerKrzysztof Opasiak <k.opasiak@samsung.com>
Tue, 22 Dec 2015 20:45:29 +0000 (21:45 +0100)
Due to recent changes in usbg_state, lets
introduce configfs_path field in state test_state
structure and fill it.

Since now path field should not be filled as it's
filled by prepare_state() function and generates
subsystem path using given configfs path.

Change-Id: I50e606c9f8c5eb478ac48fc453840b9a3efdd117
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
tests/test.c
tests/usbg-test.c
tests/usbg-test.h

index 9016d69..657fae9 100644 (file)
@@ -161,7 +161,7 @@ static struct test_gadget all_funcs_gadgets[] = {
  * @brief Simple state
  */
 static struct test_state simple_state = {
-       .path = "config",
+       .configfs_path = "config",
        .gadgets = simple_gadgets,
        .udcs = simple_udcs
 };
@@ -179,7 +179,7 @@ void setup_simple_state(void **state)
  * @brief State with all functions avaible
  */
 static struct test_state all_funcs_state = {
-       .path = "all_funcs_configfs",
+       .configfs_path = "all_funcs_configfs",
        .gadgets = all_funcs_gadgets,
         .udcs = simple_udcs
 };
@@ -201,7 +201,7 @@ void init_with_state(struct test_state *in, usbg_state **out)
        int usbg_ret;
 
        push_init(in);
-       usbg_ret = usbg_init(in->path, out);
+       usbg_ret = usbg_init(in->configfs_path, out);
        assert_int_equal(usbg_ret, USBG_SUCCESS);
 }
 
index 95168f9..d4dff77 100644 (file)
@@ -169,8 +169,8 @@ void prepare_gadget(struct test_state *state, struct test_gadget *g)
        int tmp;
        int count;
 
-       tmp = asprintf(&g->path, "%s/usb_gadget", state->path);
-       if (tmp < 0)
+       g->path = strdup(state->path);
+       if (!g->path)
                fail();
 
        free_later(g->path);
@@ -217,6 +217,13 @@ void prepare_state(struct test_state *state)
 {
        struct test_gadget *g;
        int count = 0;
+       int tmp;
+
+       tmp = asprintf(&(state->path), "%s/usb_gadget", state->configfs_path);
+       if (tmp < 0)
+               fail();
+       free_later(state->path);
+
 
        for (g = state->gadgets; g->name; g++) {
                prepare_gadget(state, g);
@@ -309,17 +316,11 @@ static void push_gadget(struct test_gadget *g)
 void push_init(struct test_state *state)
 {
        char **udc;
-       char *path;
        struct test_gadget *g;
        int count = 0;
        int tmp;
 
-       tmp = asprintf(&path, "%s/usb_gadget", state->path);
-       if (tmp < 0)
-               fail();
-       free_later(path);
-
-       EXPECT_OPENDIR(path);
+       EXPECT_OPENDIR(state->path);
 
        for (udc = state->udcs; *udc; udc++)
                count++;
@@ -332,7 +333,7 @@ void push_init(struct test_state *state)
        for (g = state->gadgets; g->name; g++)
                count++;
 
-       PUSH_DIR(path, count);
+       PUSH_DIR(state->path, count);
        for (g = state->gadgets; g->name; g++) {
                PUSH_DIR_ENTRY(g->name, DT_DIR);
        }
@@ -384,6 +385,7 @@ void assert_state_equal(usbg_state *s, struct test_state *expected)
        int i = 0;
 
        assert_string_equal(s->path, expected->path);
+       assert_string_equal(s->configfs_path, expected->configfs_path);
 
        usbg_for_each_gadget(g, s)
                assert_gadget_equal(g, &expected->gadgets[i++]);
index 7169e65..171b5e6 100644 (file)
@@ -36,6 +36,8 @@ struct test_gadget
 
 struct test_state
 {
+       char *configfs_path;
+       /* filled by prepare_state() */
        char *path;
        struct test_gadget *gadgets;
        char **udcs;
@@ -143,3 +145,4 @@ void assert_gadget_equal(usbg_gadget *g, struct test_gadget *expected);
  * @param[in] expected Pointer to test state struct with expected values
  */
 void assert_state_equal(usbg_state *s, struct test_state *expected);
+