usbg_state *s = NULL;
struct test_state *st;
- st = (struct test_state *)(*state);
- *state = NULL;
-
- init_with_state(st, &s);
- *state = s;
+ safe_init_with_state(state, &st, &s);
g = usbg_get_gadget(s, "non-existing-gadget");
assert_null(g);
usbg_state *s = NULL;
struct test_state *st;
- st = (struct test_state *)(*state);
- *state = NULL;
-
- init_with_state(st, &s);
- *state = s;
+ safe_init_with_state(state, &st, &s);
g = usbg_get_first_gadget(s);
assert_non_null(g);
char name[USBG_MAX_NAME_LENGTH];
int ret;
- st = (struct test_state *)(*state);
- *state = NULL;
-
- init_with_state(st, &s);
- *state = s;
+ safe_init_with_state(state, &st, &s);
for (i = 0; st->gadgets[i].name; i++) {
g = usbg_get_gadget(s, st->gadgets[i].name);
usbg_state *s = NULL;
struct test_state *st;
- st = (struct test_state *)(*state);
- *state = NULL;
-
- init_with_state(st, &s);
- *state = s;
+ safe_init_with_state(state, &st, &s);
assert_state_equal(s, st);
}
usbg_function *f = NULL;
struct test_state *st;
- st = (struct test_state *)(*state);
- *state = NULL;
-
- init_with_state(st, &s);
- *state = s;
+ safe_init_with_state(state, &st, &s);
g = usbg_get_first_gadget(s);
assert_non_null(g);
struct test_state *st;
const char *path;
- st = (struct test_state *)(*state);
- *state = NULL;
-
- init_with_state(st, &s);
- *state = s;
+ safe_init_with_state(state, &st, &s);
path = usbg_get_configfs_path(s);
assert_path_equal(path, st->configfs_path);
struct test_state *st;
int ret, len;
- st = (struct test_state *)(*state);
- *state = NULL;
-
- init_with_state(st, &s);
- *state = s;
+ safe_init_with_state(state, &st, &s);
ret = usbg_get_configfs_path_len(s);
len = strlen(st->configfs_path);
char path[PATH_MAX];
int ret;
- st = (struct test_state *)(*state);
- *state = NULL;
-
- init_with_state(st, &s);
- *state = s;
+ safe_init_with_state(state, &st, &s);
ret = usbg_cpy_configfs_path(s, path, PATH_MAX);
assert_int_equal(ret, USBG_SUCCESS);
struct test_gadget *tg;
struct test_config *tc;
- ts = (struct test_state *)(*state);
- *state = NULL;
-
- init_with_state(ts, &s);
- *state = s;
+ safe_init_with_state(state, &ts, &s);
for (tg = ts->gadgets; tg->name; tg++) {
g = usbg_get_gadget(s, tg->name);
struct test_state *ts;
struct test_gadget *tg;
- ts = (struct test_state *)(*state);
- *state = NULL;
-
- init_with_state(ts, &s);
- *state = s;
+ safe_init_with_state(state, &ts, &s);
for (tg = ts->gadgets; tg->name; tg++) {
g = usbg_get_gadget(s, tg->name);
usbg_state *s = NULL;
struct test_state *ts;
- ts = (struct test_state *)(*state);
- *state = NULL;
-
- init_with_state(ts, &s);
- *state = s;
+ safe_init_with_state(state, &ts, &s);
try_get_gadget_attrs(s, ts, &min_gadget_attrs);
try_get_gadget_attrs(s, ts, &max_gadget_attrs);
usbg_state *s = NULL;
struct test_state *ts;
- ts = (struct test_state *)(*state);
- *state = NULL;
-
- init_with_state(ts, &s);
- *state = s;
+ safe_init_with_state(state, &ts, &s);
try_set_gadget_attrs(s, ts, &min_gadget_attrs);
try_set_gadget_attrs(s, ts, &max_gadget_attrs);
usbg_state *s = NULL;
struct test_state *ts;
- ts = (struct test_state *)(*state);
- *state = NULL;
-
- init_with_state(ts, &s);
- *state = s;
+ safe_init_with_state(state, &ts, &s);
try_set_specific_gadget_attr(s, ts, &min_gadget_attrs);
try_set_specific_gadget_attr(s, ts, &max_gadget_attrs);
usbg_udc *u = NULL;
usbg_gadget *g = NULL;
- ts = (struct test_state *)(*state);
- *state = NULL;
-
- init_with_state(ts, &s);
- *state = s;
+ safe_init_with_state(state, &ts, &s);
for (tu = ts->udcs; *tu; tu++) {
u = usbg_get_udc(s, *tu);
assert_int_equal(usbg_ret, USBG_SUCCESS);
}
+void safe_init_with_state(void **state, struct test_state **ts, usbg_state **s)
+{
+ *ts = (struct test_state *)(*state);
+ *state = NULL;
+
+ init_with_state(*ts, s);
+ *state = *s;
+}
+
static int get_config_attr(usbg_config_attrs *attrs, config_attr attr)
{
int ret;
usbg_gadget *g = NULL;
usbg_function *f = NULL;
- ts = (struct test_state *)(*state);
- *state = NULL;
-
- init_with_state(ts, &s);
- *state = s;
+ safe_init_with_state(state, &ts, &s);
for (tg = ts->gadgets; tg->name; ++tg) {
g = usbg_get_gadget(s, tg->name);
struct test_gadget *tg;
struct test_config *tc;
- ts = (struct test_state *)(*state);
- *state = NULL;
-
- init_with_state(ts, &s);
- *state = s;
+ safe_init_with_state(state, &ts, &s);
for (tg = ts->gadgets; tg->name; tg++) {
g = usbg_get_gadget(s, tg->name);
usbg_config *c = NULL;
usbg_binding *b = NULL;
- ts = (struct test_state *)(*state);
- *state = NULL;
-
- init_with_state(ts, &s);
- *state = s;
+ safe_init_with_state(state, &ts, &s);
for (tg = ts->gadgets; tg->name; tg++) {
g = usbg_get_gadget(s, tg->name);
usbg_state *s = NULL;
usbg_gadget *g = NULL;
- ts = (struct test_state *)(*state);
- *state = NULL;
-
- init_with_state(ts, &s);
- *state = s;
+ safe_init_with_state(state, &ts, &s);
for (tg = ts->gadgets; tg->name; ++tg) {
g = usbg_get_gadget(s, tg->name);