summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPawel Szewczyk <p.szewczyk@samsung.com>2015-05-26 10:46:49 +0200
committerKrzysztof Opasiak <k.opasiak@samsung.com>2015-07-30 15:56:26 +0200
commit896f3789ad213e090fb2792b7aac641b967ee049 (patch)
tree2e5ee58f8d07020b8230caf7ede885751ddce973
parent679abafed1790d270af01fa2d707d772a9a44e83 (diff)
downloadlibusbg-896f3789ad213e090fb2792b7aac641b967ee049.tar.gz
libusbg-896f3789ad213e090fb2792b7aac641b967ee049.tar.bz2
libusbg-896f3789ad213e090fb2792b7aac641b967ee049.zip
libusbg: tests: Move initialization from for_each functions to tests
Instead of passing void **state as argument for for_each_* functions and initializing state there, we make initialization first and pass initialized state as argument for them. It looks more natural this way. This also allows to run these functions multiple times in single test function. Change-Id: If84bbedf374f1f0ebf70315cea950dcd2e527d18 Signed-off-by: Pawel Szewczyk <p.szewczyk@samsung.com> Reviewed-by: Krzysztof Opasiak <k.opasiak@samsung.com>
-rw-r--r--tests/test.c120
-rw-r--r--tests/usbg-test.c24
-rw-r--r--tests/usbg-test.h20
3 files changed, 116 insertions, 48 deletions
diff --git a/tests/test.c b/tests/test.c
index 8f02f0a..4e4783b 100644
--- a/tests/test.c
+++ b/tests/test.c
@@ -422,7 +422,11 @@ static int setup_random_len_gadget_strs_data(void **state)
*/
static void test_get_gadget(void **state)
{
- for_each_test_gadget(state, assert_gadget_equal);
+ usbg_state *s = NULL;
+ struct test_state *ts;
+
+ safe_init_with_state(state, &ts, &s);
+ for_each_test_gadget(ts, s, assert_gadget_equal);
}
/**
@@ -484,7 +488,11 @@ static void try_get_gadget_name(usbg_gadget *g, struct test_gadget *tg)
*/
static void test_get_gadget_name(void **state)
{
- for_each_test_gadget(state, try_get_gadget_name);
+ usbg_state *s = NULL;
+ struct test_state *ts;
+
+ safe_init_with_state(state, &ts, &s);
+ for_each_test_gadget(ts, s, try_get_gadget_name);
}
static void try_get_gadget_name_len(usbg_gadget *g, struct test_gadget *tg)
@@ -503,7 +511,11 @@ static void try_get_gadget_name_len(usbg_gadget *g, struct test_gadget *tg)
*/
static void test_get_gadget_name_len(void **state)
{
- for_each_test_gadget(state, try_get_gadget_name_len);
+ usbg_state *s = NULL;
+ struct test_state *ts;
+
+ safe_init_with_state(state, &ts, &s);
+ for_each_test_gadget(ts, s, try_get_gadget_name_len);
}
/**
@@ -535,7 +547,11 @@ static void try_cpy_gadget_name(usbg_gadget *g, struct test_gadget *tg)
*/
static void test_cpy_gadget_name(void **state)
{
- for_each_test_gadget(state, try_cpy_gadget_name);
+ usbg_state *s = NULL;
+ struct test_state *ts;
+
+ safe_init_with_state(state, &ts, &s);
+ for_each_test_gadget(ts, s, try_cpy_gadget_name);
}
/**
@@ -591,7 +607,11 @@ static void test_init(void **state)
*/
static void test_get_function(void **state)
{
- for_each_test_function(state, assert_func_equal);
+ usbg_state *s = NULL;
+ struct test_state *ts;
+
+ safe_init_with_state(state, &ts, &s);
+ for_each_test_function(ts, s, assert_func_equal);
}
/**
@@ -687,7 +707,11 @@ static void try_get_function_instance(usbg_function *f, struct test_function *tf
*/
static void test_get_function_instance(void **state)
{
- for_each_test_function(state, try_get_function_instance);
+ usbg_state *s = NULL;
+ struct test_state *ts;
+
+ safe_init_with_state(state, &ts, &s);
+ for_each_test_function(ts, s, try_get_function_instance);
}
/**
@@ -718,7 +742,11 @@ static void try_cpy_function_instance(usbg_function *f, struct test_function *tf
*/
static void test_cpy_function_instance(void **state)
{
- for_each_test_function(state, try_cpy_function_instance);
+ usbg_state *s = NULL;
+ struct test_state *ts;
+
+ safe_init_with_state(state, &ts, &s);
+ for_each_test_function(ts, s, try_cpy_function_instance);
}
/**
@@ -742,7 +770,11 @@ static void try_get_function_type(usbg_function *f, struct test_function *tf)
*/
static void test_get_function_type(void **state)
{
- for_each_test_function(state, try_get_function_type);
+ usbg_state *s = NULL;
+ struct test_state *ts;
+
+ safe_init_with_state(state, &ts, &s);
+ for_each_test_function(ts, s, try_get_function_type);
}
/**
@@ -765,7 +797,11 @@ static void try_get_function_instance_len(usbg_function *f, struct test_function
*/
static void test_get_function_instance_len(void **state)
{
- for_each_test_function(state, try_get_function_instance_len);
+ usbg_state *s = NULL;
+ struct test_state *ts;
+
+ safe_init_with_state(state, &ts, &s);
+ for_each_test_function(ts, s, try_get_function_instance_len);
}
/**
@@ -829,7 +865,11 @@ static void test_cpy_configfs_path(void **state)
*/
static void test_get_config(void **state)
{
- for_each_test_config(state, assert_config_equal);
+ usbg_state *s = NULL;
+ struct test_state *ts;
+
+ safe_init_with_state(state, &ts, &s);
+ for_each_test_config(ts, s, assert_config_equal);
}
static void test_get_config_without_label(void **state)
@@ -903,7 +943,11 @@ static void try_get_config_label(usbg_config *c, struct test_config *tc)
*/
static void test_get_config_label(void **state)
{
- for_each_test_config(state, try_get_config_label);
+ usbg_state *s = NULL;
+ struct test_state *ts;
+
+ safe_init_with_state(state, &ts, &s);
+ for_each_test_config(ts, s, try_get_config_label);
}
/**
@@ -925,7 +969,11 @@ static void try_get_config_id(usbg_config *c, struct test_config *tc)
*/
static void test_get_config_id(void **state)
{
- for_each_test_config(state, try_get_config_id);
+ usbg_state *s = NULL;
+ struct test_state *ts;
+
+ safe_init_with_state(state, &ts, &s);
+ for_each_test_config(ts, s, try_get_config_id);
}
/**
@@ -1225,7 +1273,11 @@ static void try_get_binding_target(struct test_binding *tb, usbg_binding *b)
*/
static void test_get_binding_target(void **state)
{
- for_each_binding(state, try_get_binding_target);
+ usbg_state *s = NULL;
+ struct test_state *ts;
+
+ safe_init_with_state(state, &ts, &s);
+ for_each_binding(ts, s, try_get_binding_target);
}
/**
@@ -1250,7 +1302,11 @@ static void try_get_binding_name(struct test_binding *tb, usbg_binding *b)
*/
static void test_get_binding_name(void **state)
{
- for_each_binding(state, try_get_binding_name);
+ usbg_state *s = NULL;
+ struct test_state *ts;
+
+ safe_init_with_state(state, &ts, &s);
+ for_each_binding(ts, s, try_get_binding_name);
}
/**
@@ -1273,7 +1329,11 @@ static void try_get_binding_name_len(struct test_binding *tb, usbg_binding *b)
*/
static void test_get_binding_name_len(void **state)
{
- for_each_binding(state, try_get_binding_name_len);
+ usbg_state *s = NULL;
+ struct test_state *ts;
+
+ safe_init_with_state(state, &ts, &s);
+ for_each_binding(ts, s, try_get_binding_name_len);
}
/**
@@ -1295,7 +1355,11 @@ static void try_set_config_strs(usbg_config *c, struct test_config *tc)
*/
static void test_set_config_strs(void **state)
{
- for_each_test_config(state, try_set_config_strs);
+ usbg_state *s = NULL;
+ struct test_state *ts;
+
+ safe_init_with_state(state, &ts, &s);
+ for_each_test_config(ts, s, try_set_config_strs);
}
/**
@@ -1317,7 +1381,11 @@ static void try_set_config_string(usbg_config *c, struct test_config *tc)
*/
static void test_set_config_string(void **state)
{
- for_each_test_config(state, try_set_config_string);
+ usbg_state *s = NULL;
+ struct test_state *ts;
+
+ safe_init_with_state(state, &ts, &s);
+ for_each_test_config(ts, s, try_set_config_string);
}
/**
@@ -1342,7 +1410,11 @@ static void try_get_config_strs(usbg_config *c, struct test_config *tc)
*/
static void test_get_config_strs(void **state)
{
- for_each_test_config(state, try_get_config_strs);
+ usbg_state *s = NULL;
+ struct test_state *ts;
+
+ safe_init_with_state(state, &ts, &s);
+ for_each_test_config(ts, s, try_get_config_strs);
}
/**
@@ -1369,7 +1441,11 @@ static void try_get_config_attrs(usbg_config *c, struct test_config *tc)
*/
static void test_get_config_attrs(void **state)
{
- for_each_test_config(state, try_get_config_attrs);
+ usbg_state *s = NULL;
+ struct test_state *ts;
+
+ safe_init_with_state(state, &ts, &s);
+ for_each_test_config(ts, s, try_get_config_attrs);
}
/**
@@ -1391,7 +1467,11 @@ static void try_set_config_attrs(usbg_config *c, struct test_config *tc)
*/
static void test_set_config_attrs(void **state)
{
- for_each_test_config(state, try_set_config_attrs);
+ usbg_state *s = NULL;
+ struct test_state *ts;
+
+ safe_init_with_state(state, &ts, &s);
+ for_each_test_config(ts, s, try_set_config_attrs);
}
/**
diff --git a/tests/usbg-test.c b/tests/usbg-test.c
index 3aeb2d1..8e70025 100644
--- a/tests/usbg-test.c
+++ b/tests/usbg-test.c
@@ -1100,17 +1100,13 @@ void assert_gadget_strs_equal(usbg_gadget_strs *actual, usbg_gadget_strs *expect
assert_string_equal(get_gadget_str(actual, i), get_gadget_str(expected, i));
}
-void for_each_test_function(void **state, FunctionTest fun)
+void for_each_test_function(struct test_state *ts, usbg_state *s, FunctionTest fun)
{
- usbg_state *s = NULL;
- struct test_state *ts;
struct test_gadget *tg;
struct test_function *tf;
usbg_gadget *g = NULL;
usbg_function *f = NULL;
- safe_init_with_state(state, &ts, &s);
-
for (tg = ts->gadgets; tg->name; ++tg) {
g = usbg_get_gadget(s, tg->name);
assert_non_null(g);
@@ -1121,17 +1117,13 @@ void for_each_test_function(void **state, FunctionTest fun)
}
}
-void for_each_test_config(void **state, ConfigTest fun)
+void for_each_test_config(struct test_state *ts, usbg_state *s, ConfigTest fun)
{
- usbg_state *s = NULL;
usbg_gadget *g = NULL;
usbg_config *c = NULL;
- struct test_state *ts;
struct test_gadget *tg;
struct test_config *tc;
- safe_init_with_state(state, &ts, &s);
-
for (tg = ts->gadgets; tg->name; tg++) {
g = usbg_get_gadget(s, tg->name);
assert_non_null(g);
@@ -1142,19 +1134,15 @@ void for_each_test_config(void **state, ConfigTest fun)
}
}
-void for_each_binding(void **state, BindingTestFunc fun)
+void for_each_binding(struct test_state *ts, usbg_state *s, 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;
- safe_init_with_state(state, &ts, &s);
-
for (tg = ts->gadgets; tg->name; tg++) {
g = usbg_get_gadget(s, tg->name);
assert_non_null(g);
@@ -1172,15 +1160,11 @@ void for_each_binding(void **state, BindingTestFunc fun)
}
}
-void for_each_test_gadget(void **state, GadgetTestFunc fun)
+void for_each_test_gadget(struct test_state *ts, usbg_state *s, GadgetTestFunc fun)
{
- struct test_state *ts;
struct test_gadget *tg;
- usbg_state *s = NULL;
usbg_gadget *g = NULL;
- safe_init_with_state(state, &ts, &s);
-
for (tg = ts->gadgets; tg->name; ++tg) {
g = usbg_get_gadget(s, tg->name);
assert_non_null(g);
diff --git a/tests/usbg-test.h b/tests/usbg-test.h
index 9bb6bfd..5fad226 100644
--- a/tests/usbg-test.h
+++ b/tests/usbg-test.h
@@ -414,10 +414,11 @@ typedef void (*FunctionTest)(usbg_function *f, struct test_function *tf);
/**
* @brief Call given function for all usb functions present in given state
- * @param[in] state Properly prepared state to be tested
+ * @param[in] ts Test state to be tested
+ * @param[in] s Properly prepared usbg state to be tested
* @param[in] fun Function to be called on each usb function in state
*/
-void for_each_test_function(void **state, FunctionTest fun);
+void for_each_test_function(struct test_state *ts, usbg_state *s, FunctionTest fun);
/**
* @brief Function that performs some test on given usbg config
@@ -426,10 +427,11 @@ typedef void (*ConfigTest)(usbg_config *c, struct test_config *tc);
/**
* @brief Call given function for all usb configs present in given state
- * @param[in] state Properly prepared state to be tested
+ * @param[in] ts Test state to be tested
+ * @param[in] s Properly prepared usbg state to be tested
* @param[in] fun Function to be called on each usb function in state
*/
-void for_each_test_config(void **state, ConfigTest fun);
+void for_each_test_config(struct test_state *ts, usbg_state *s, ConfigTest fun);
/**
* @brief Function that performs test on given usbg binding
@@ -438,10 +440,11 @@ 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] ts Test state to be tested
+ * @param[in] s Properly prepared usbg 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);
+void for_each_binding(struct test_state *ts, usbg_state *s, BindingTestFunc fun);
/**
* @brief Function that performs test on given usbg gadget
@@ -450,10 +453,11 @@ typedef void (*GadgetTestFunc)(usbg_gadget *g, struct test_gadget *tg);
/**
* @brief Call given function for all usb gadgets present in given state
- * @param[in] state Properly prepared state to be tested
+ * @param[in] ts Test state to be tested
+ * @param[in] s Properly prepared usbg state to be tested
* @param[in] fun Function to be called on each usb gadget in state
*/
-void for_each_test_gadget(void **state, GadgetTestFunc fun);
+void for_each_test_gadget(struct test_state *ts, usbg_state *s, GadgetTestFunc fun);
static inline void *safe_calloc(int count, size_t size)
{