libusbgx: tests: Add create function test
authorPawel Szewczyk <p.szewczyk@samsung.com>
Mon, 25 May 2015 13:11:28 +0000 (15:11 +0200)
committerKrzysztof Opasiak <k.opasiak@samsung.com>
Tue, 22 Dec 2015 20:45:37 +0000 (21:45 +0100)
Change-Id: I3a47f0d16b9259f09bb4ea3eeb3734a89af43019
Signed-off-by: Pawel Szewczyk <p.szewczyk@samsung.com>
[Update description]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
tests/test.c
tests/usbg-test.c
tests/usbg-test.h

index aefce06..7b93b1c 100644 (file)
@@ -1670,6 +1670,37 @@ static void test_create_config(void **state)
 }
 
 /**
+ * @brief Start with empty gadget, add all functions from given one
+ */
+static void test_create_function(void **state)
+{
+       usbg_state *s = NULL;
+       usbg_gadget *g = NULL;
+       usbg_function *f = NULL;
+       struct test_state *ts;
+       struct test_state *empty;
+       struct test_gadget *tg;
+       struct test_function *tf;
+
+       ts = (struct test_state *)(*state);
+       *state = NULL;
+
+       empty = build_empty_gadget_state(ts);
+
+       init_with_state(empty, &s);
+       *state = s;
+
+       for (tg = ts->gadgets; tg->name; tg++) {
+               g = usbg_get_gadget(s, tg->name);
+               assert_non_null(g);
+               for (tf = tg->functions; tf->instance; tf++) {
+                       pull_create_function(tf);
+                       usbg_create_function(g, tf->type, tf->instance,
+                                       tf->attrs, &f);
+                       assert_func_equal(f, tf);
+               }
+       }
+}
 
 /**
  * @brief Test only one given function for attribute getting
@@ -2335,6 +2366,14 @@ static struct CMUnitTest tests[] = {
         */
        USBG_TEST_TS("test_set_f_ffs_attrs",
                     test_set_function_attrs, setup_f_ffs_writable_attrs),
+       /**
+        * @usbg_test
+        * @test_desc{test_create_all_functions,
+        * Create full set of functions in empty state,
+        * usbg_get_binding_name_len}
+        */
+       USBG_TEST_TS("test_create_all_functions",
+                    test_create_function, setup_all_funcs_state),
 
 #ifndef DOXYGEN
 };
index 917a5a0..c332795 100644 (file)
@@ -1116,6 +1116,21 @@ void pull_function_attrs(struct test_function *func, usbg_function_attrs *attrs)
                pull_function_net_attrs(func, &attrs->attrs.net);
 }
 
+void pull_create_function(struct test_function *tf)
+{
+       char *path;
+       int tmp;
+
+       tmp = asprintf(&path, "%s/%s", tf->path, tf->name);
+       if (tmp < 0)
+               fail();
+       free_later(path);
+
+       EXPECT_MKDIR(path);
+       if (tf->attrs)
+               pull_function_attrs(tf, tf->attrs);
+}
+
 void assert_func_equal(usbg_function *f, struct test_function *expected)
 {
        assert_string_equal(f->instance, expected->instance);
index aa90a2e..127b90e 100644 (file)
@@ -314,6 +314,12 @@ void push_config_strs(struct test_config *config, int lang, usbg_config_strs *st
 void pull_create_config(struct test_config *tc);
 
 /**
+ * @brief Prepare for creating function
+ * @param[in] tf Test function to be created
+ */
+void pull_create_function(struct test_function *tf);
+
+/**
  * @brief Copy state without configs and functions
  * @param[in] ts State to bo copied
  * @return State with empty gadgets