From e0fa9b973eb7a0e389aca6183159d9aa5c75a87c Mon Sep 17 00:00:00 2001 From: Krzysztof Opasiak Date: Fri, 27 Feb 2015 15:42:52 +0100 Subject: [PATCH] libusbgx: tests: Support static binding definition Sometimes we would like to define bindings names other than default one. To achieve this we allocate bindings only if they has not been allocated earlier. Change-Id: Ifbad9b1069dd1a41d4a9f87c427c991538a8417f Signed-off-by: Krzysztof Opasiak Reviewed-by: Pawel Szewczyk --- tests/usbg-test.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/tests/usbg-test.c b/tests/usbg-test.c index 0b0b8ac..5359eb9 100644 --- a/tests/usbg-test.c +++ b/tests/usbg-test.c @@ -171,10 +171,12 @@ void prepare_binding(struct test_binding *b, struct test_function *f, char *fpat if (!f->name) prepare_function(f, fpath); - b->name = strdup(f->name); - if (b->name == NULL) - fail(); - free_later(b->name); + if (!b->name) { + b->name = strdup(f->name); + if (b->name == NULL) + fail(); + free_later(b->name); + } b->target = f; } @@ -184,6 +186,7 @@ void prepare_config(struct test_config *c, char *cpath, char *fpath) int tmp; int count = 0; struct test_function *f; + struct test_binding *b; int i; tmp = asprintf(&c->name, "%s.%d", @@ -194,13 +197,19 @@ void prepare_config(struct test_config *c, char *cpath, char *fpath) c->path = cpath; - for (f = c->bound_funcs; f->instance; f++) - count++; + /* check if bindings has been already filled */ + if (!c->bindings) { + for (f = c->bound_funcs; f->instance; f++) + count++; - c->bindings = calloc(count + 1, sizeof(*c->bindings)); - if (c->bindings == NULL) - fail(); - free_later(c->bindings); + c->bindings = calloc(count + 1, sizeof(*c->bindings)); + if (c->bindings == NULL) + fail(); + free_later(c->bindings); + } else { + for (b = c->bindings; b->name; b++) + count++; + } for (i = 0; i < count; i++) prepare_binding(&c->bindings[i], &c->bound_funcs[i], fpath); -- 2.7.4