END_TEST START_TEST (test_find_first_item) { pair = mk_kvpair("some_key", NULL); fail_unless(find_kvpair(pair, "some_key") == pair, "Identity search failed."); }
/* * Example callback that returns a list of forms. */ static enum conflate_mgmt_cb_result process_ping_test(void *opaque, conflate_handle_t *handle, const char *cmd, bool direct, kvpair_t *form, conflate_form_result *r) { kvpair_t *servers_p = find_kvpair(form, "servers"); if (!servers_p) { return RV_BADARG; } char **servers = servers_p->values; for (int i = 0; servers[i]; i++) { /* For each result we wish to send back, we begin a field set */ conflate_next_fieldset(r); /* All fields added now fall within the current fieldset */ conflate_add_field(r, "-set-", servers[i]); const char *vals[3] = { "val1", "val2", NULL }; conflate_add_field_multi(r, "test1", vals); conflate_add_field(r, "test2", "some val"); } return RV_OK; }
END_TEST START_TEST (test_find_missing_item) { kvpair_t *pair1 = mk_kvpair("some_key", NULL); pair = mk_kvpair("some_other_key", NULL); pair->next = pair1; fail_unless(find_kvpair(pair, "missing_key") == NULL, "Negative search failed."); }
END_TEST START_TEST (test_find_second_item) { kvpair_t *pair1 = mk_kvpair("some_key", NULL); pair = mk_kvpair("some_other_key", NULL); pair->next = pair1; fail_unless(find_kvpair(pair, "some_key") == pair1, "Depth search failed."); }
char *get_simple_kvpair_val(kvpair_t *pair, const char *key) { assert(key); char *rv = NULL; kvpair_t *found = find_kvpair(pair, key); if (found) { rv = found->values[0]; } return rv; }
static int append_kvpair_from_db(void* arg, int n, char **vals, char **cols) { (void)n; (void)cols; kvpair_t** pairs = (kvpair_t**)arg; kvpair_t* pair = find_kvpair(*pairs, vals[0]); /* If such a list doesn't already exist, one will be assigned to you */ if (!pair) { pair = mk_kvpair(vals[0], NULL); pair->next = *pairs; *pairs = pair; } add_kvpair_value(pair, vals[1]); return SQLITE_OK; }
END_TEST START_TEST (test_find_from_null) { fail_unless(find_kvpair(NULL, "some_key") == NULL, "Couldn't find from NULL."); }