libusbgx: tests: Add simulation of configfs for getting bindings
authorPawel Szewczyk <p.szewczyk@samsung.com>
Wed, 18 Feb 2015 10:51:34 +0000 (11:51 +0100)
committerKrzysztof Opasiak <k.opasiak@samsung.com>
Tue, 22 Dec 2015 20:45:34 +0000 (21:45 +0100)
Signed-off-by: Pawel Szewczyk <p.szewczyk@samsung.com>
Add asserts for gadget, config and bindings.

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

index 5359eb9..ae9e133 100644 (file)
@@ -1082,3 +1082,37 @@ void for_each_test_config(void **state, ConfigTest fun)
                }
        }
 }
+
+void for_each_binding(void **state, BindingTestFunc fun)
+{
+       struct test_state *ts;
+       struct test_gadget *tg;
+       struct test_config *tc;
+       struct test_binding *tb;
+       usbg_state *s = NULL;
+       usbg_gadget *g = NULL;
+       usbg_config *c = NULL;
+       usbg_binding *b = NULL;
+
+       ts = (struct test_state *)(*state);
+       *state = NULL;
+
+       init_with_state(ts, &s);
+       *state = s;
+
+       for (tg = ts->gadgets; tg->name; tg++) {
+               g = usbg_get_gadget(s, tg->name);
+               assert_non_null(g);
+               for (tc = tg->configs; tc->label; tc++) {
+                       c = usbg_get_config(g, tc->id, tc->label);
+                       assert_non_null(c);
+
+                       b = usbg_get_first_binding(c);
+                       for (tb = tc->bindings; tb->name; ++tb) {
+                               assert_non_null(b);
+                               fun(tb, b);
+                               b = usbg_get_next_binding(b);
+                       }
+               }
+       }
+}
index 2ddb250..a79fd3e 100644 (file)
@@ -357,4 +357,16 @@ typedef void (*ConfigTest)(usbg_config *c, struct test_config *tc);
  */
 void for_each_test_config(void **state, ConfigTest fun);
 
+/**
+ * @brief Function that performs test on given usbg binding
+ */
+typedef void (*BindingTestFunc)(struct test_binding *tb, usbg_binding *b);
+
+/**
+ * @brief Call given function for all usb bindings present in given state
+ * @param[in] state Properly prepared state to be tested
+ * @param[in] fun Function to be called on each usb binding in state
+ */
+void for_each_binding(void **state, BindingTestFunc fun);
+
 #endif /* USBG_TEST_H */