summaryrefslogtreecommitdiff
path: root/tests/usbg-test.c
diff options
context:
space:
mode:
authorPawel Szewczyk <p.szewczyk@samsung.com>2015-03-02 14:33:05 +0100
committerKrzysztof Opasiak <k.opasiak@samsung.com>2015-03-06 16:12:08 +0100
commitd52162ad7d5b74d33a9d76b19a587e6ef30a9ab2 (patch)
tree6a195d5643e78b61a343c029e85528cf0b46ddd6 /tests/usbg-test.c
parent6f75bee561ac1a6ab427c224194b4f150e198b49 (diff)
downloadlibusbg-d52162ad7d5b74d33a9d76b19a587e6ef30a9ab2.tar.gz
libusbg-d52162ad7d5b74d33a9d76b19a587e6ef30a9ab2.tar.bz2
libusbg-d52162ad7d5b74d33a9d76b19a587e6ef30a9ab2.zip
libusbg: tests: Add simulation of configfs for config strings
Allows config strings to be get from and set on virtual filesystem. Signed-off-by: Pawel Szewczyk <p.szewczyk@samsung.com> Add more documentation. Add push_config_string() function. Change-Id: Ie04321cee9ac2a6defe0b01a650a847e1ac0a581 Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
Diffstat (limited to 'tests/usbg-test.c')
-rw-r--r--tests/usbg-test.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/tests/usbg-test.c b/tests/usbg-test.c
index ae9e133..62d25de 100644
--- a/tests/usbg-test.c
+++ b/tests/usbg-test.c
@@ -398,6 +398,7 @@ static void cpy_test_config(struct test_config *to,
/* Reuse label */
to->label = from->label;
to->id = from->id;
+ to->strs = from->strs;
if (from->bound_funcs) {
/* If at least one function is not writable
@@ -902,6 +903,68 @@ void push_gadget_strs(struct test_gadget *gadget, int lang, usbg_gadget_strs *st
push_gadget_str(gadget, gadget_str_names[i], lang, get_gadget_str(strs, i));
}
+void pull_config_string(struct test_config *config, int lang, const char *str)
+{
+ char *path;
+ int tmp;
+
+
+ tmp = asprintf(&path, "%s/%s/strings/0x%x",
+ config->path, config->name, lang);
+ if (tmp < 0)
+ fail();
+ free_later(path);
+
+ srand(time(NULL));
+ tmp = rand() % 2;
+
+ if (tmp) {
+ EXPECT_OPENDIR(path);
+ } else {
+ EXPECT_OPENDIR_ERROR(path, ENOENT);
+ EXPECT_MKDIR(path);
+ }
+
+ tmp = asprintf(&path, "%s/configuration", path);
+ if (tmp < 0)
+ fail();
+ free_later(path);
+
+ EXPECT_WRITE(path, str);
+}
+
+void pull_config_strs(struct test_config *config, int lang, usbg_config_strs *strs)
+{
+ pull_config_string(config, lang, strs->configuration);
+}
+
+void push_config_string(struct test_config *config, int lang, const char *str)
+{
+ char *path;
+ int tmp;
+
+
+ tmp = asprintf(&path, "%s/%s/strings/0x%x",
+ config->path, config->name, lang);
+ if (tmp < 0)
+ fail();
+ free_later(path);
+
+ EXPECT_OPENDIR(path);
+
+ tmp = asprintf(&path, "%s/configuration", path);
+ if (tmp < 0)
+ fail();
+ free_later(path);
+
+ PUSH_FILE(path, str);
+}
+
+void push_config_strs(struct test_config *config, int lang, usbg_config_strs *strs)
+{
+ push_config_string(config, lang, strs->configuration);
+}
+
void assert_func_equal(usbg_function *f, struct test_function *expected)
{
assert_string_equal(f->instance, expected->instance);