From: Krzysztof Opasiak Date: Fri, 27 Feb 2015 14:42:52 +0000 (+0100) Subject: libusbgx: tests: Support static binding definition X-Git-Tag: libusbgx-v0.1.0~98 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e0fa9b973eb7a0e389aca6183159d9aa5c75a87c;p=platform%2Fupstream%2Flibusbg.git 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 --- 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);