static void context_test (int sock) { char response[100]; char *cmp; cpg_context_set (cpg_handle, response); cpg_context_get (cpg_handle, (void**)&cmp); if (response != cmp) { snprintf (response, 100, "%s", FAIL_STR); } else { snprintf (response, 100, "%s", OK_STR); } send (sock, response, strlen (response), 0); }
int main (void) { cpg_handle_t handle[INSTANCES]; cs_error_t res; void *context[INSTANCES]; int i, j; void *ctx; signal (SIGINT, sigintr_handler); for (i = 0; i < INSTANCES; i++) { res = cpg_initialize (&handle[i], &callbacks); if (res != CS_OK) { printf ("FAIL %d\n", res); exit (-1); } } for (j = 0; j < ITERATIONS; j++) { for (i = 0; i < INSTANCES; i++) { context[i] = malloc (20); res = cpg_context_set (handle[i], context[i]); if (res != CS_OK) { printf ("FAIL %d\n", res); exit (-1); } } for (i = 0; i < INSTANCES; i++) { res = cpg_context_get (handle[i], &ctx); if (res != CS_OK) { printf ("FAIL %d\n", res); exit (-1); } if (ctx != context[i]) { printf ("FAIL\n"); exit (-1); } free (ctx); } } for (i = 0; i < INSTANCES; i++) { cpg_finalize (handle[i]); } printf ("PASS\n"); return (0); }
static void context_test (int sock) { char response[100]; char *cmp; ssize_t rc; size_t send_len; cpg_context_set (cpg_handle, response); cpg_context_get (cpg_handle, (void**)&cmp); if (response != cmp) { snprintf (response, 100, "%s", FAIL_STR); } else { snprintf (response, 100, "%s", OK_STR); } send_len = strlen (response); rc = send (sock, response, send_len, 0); assert(rc == send_len); }