From: Krzysztof Opasiak Date: Tue, 3 Feb 2015 13:16:42 +0000 (+0100) Subject: libusbgx: tests: Fix tests to use correct usbg_state field X-Git-Tag: libusbgx-v0.1.0~127 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c3c2223d442b34d86c1da94c3619bdada70814c2;p=platform%2Fupstream%2Flibusbg.git libusbgx: tests: Fix tests to use correct usbg_state field 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 --- diff --git a/tests/test.c b/tests/test.c index 9016d69..657fae9 100644 --- a/tests/test.c +++ b/tests/test.c @@ -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); } diff --git a/tests/usbg-test.c b/tests/usbg-test.c index 95168f9..d4dff77 100644 --- a/tests/usbg-test.c +++ b/tests/usbg-test.c @@ -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++]); diff --git a/tests/usbg-test.h b/tests/usbg-test.h index 7169e65..171b5e6 100644 --- a/tests/usbg-test.h +++ b/tests/usbg-test.h @@ -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); +