libusbgx: tests: Add simulation of configfs for getting gadget strings
authorPawel Szewczyk <p.szewczyk@samsung.com>
Wed, 18 Feb 2015 09:53:49 +0000 (10:53 +0100)
committerKrzysztof Opasiak <k.opasiak@samsung.com>
Tue, 22 Dec 2015 20:45:34 +0000 (21:45 +0100)
Allows to test getting gadget strings the same way as setting them.

Change-Id: I3197865955e22d3ec38f7b81f8050e95f24cdaf8
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 5dd9258..47bbdca 100644 (file)
@@ -554,6 +554,42 @@ void pull_gadget_strs(struct test_gadget *gadget, int lang, usbg_gadget_strs *st
                pull_gadget_str(gadget, gadget_str_names[i], lang, get_gadget_str(strs, i));
 }
 
+static void push_gadget_str_dir(struct test_gadget *gadget, int lang)
+{
+       char *dir;
+       int tmp;
+       tmp = asprintf(&dir, "%s/%s/strings/0x%x",
+                       gadget->path, gadget->name, lang);
+       if (tmp < 0)
+               fail();
+       free_later(dir);
+
+       EXPECT_OPENDIR(dir);
+}
+
+static void push_gadget_str(struct test_gadget *gadget, const char *attr_name,
+               int lang, const char *content)
+{
+       char *path;
+       int tmp;
+
+       tmp = asprintf(&path, "%s/%s/strings/0x%x/%s",
+                       gadget->path, gadget->name, lang, attr_name);
+       if (tmp < 0)
+               fail();
+       free_later(path);
+       PUSH_FILE(path, content);
+}
+
+void push_gadget_strs(struct test_gadget *gadget, int lang, usbg_gadget_strs *strs)
+{
+       int i;
+
+       push_gadget_str_dir(gadget, lang);
+       for (i = 0; i < GADGET_STR_MAX; i++)
+               push_gadget_str(gadget, gadget_str_names[i], lang, get_gadget_str(strs, i));
+}
+
 void assert_func_equal(usbg_function *f, struct test_function *expected)
 {
        assert_string_equal(f->instance, expected->instance);
@@ -672,6 +708,13 @@ void assert_gadget_attrs_equal(usbg_gadget_attrs *actual,
                assert_int_equal(get_gadget_attr(actual, i), get_gadget_attr(expected, i));
 }
 
+void assert_gadget_strs_equal(usbg_gadget_strs *actual, usbg_gadget_strs *expected)
+{
+       int i;
+       for (i = 0; i < GADGET_STR_MAX; i++)
+               assert_string_equal(get_gadget_str(actual, i), get_gadget_str(expected, i));
+}
+
 void for_each_test_function(void **state, FunctionTest fun)
 {
        usbg_state *s = NULL;
index 059e427..f6dcf3c 100644 (file)
@@ -197,6 +197,11 @@ void pull_gadget_string(struct test_gadget *gadget, int lang,
 void pull_gadget_strs(struct test_gadget *gadget, int lang, usbg_gadget_strs *strs);
 
 /**
+ * @brief prepare for reading gadget's strings
+ */
+void push_gadget_strs(struct test_gadget *gadget, int lang, usbg_gadget_strs *strs);
+
+/**
  * @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.
@@ -291,6 +296,11 @@ void assert_gadget_attrs_equal(usbg_gadget_attrs *actual,
                usbg_gadget_attrs *expected);
 
 /**
+ * @brief Assert that given gadget strings are equal
+ */
+void assert_gadget_strs_equal(usbg_gadget_strs *actual, usbg_gadget_strs *expected);
+
+/**
  * @brief Function that performs some test on given usbg function
 */
 typedef void (*FunctionTest)(usbg_function *f, struct test_function *tf);