END_TEST START_TEST (test_kvpair_storage) { char* args[] = {"arg1", "arg2", NULL}; kvpair_t *pair = mk_kvpair("some_key", args); fail_if(pair == NULL, "Didn't create a pair."); fail_unless(strcmp(pair->key, "some_key") == 0, "Key is broken."); fail_unless(strcmp(pair->values[0], "arg1") == 0, "First value is broken."); fail_unless(strcmp(pair->values[1], "arg2") == 0, "Second value is broken."); fail_unless(pair->used_values == 2, "Wrong number of used values."); fail_unless(pair->allocated_values >= pair->used_values, "Allocated values can't be smaller than used values."); fail_unless(pair->next == NULL, "Next pointer is non-null."); fail_unless(save_kvpairs(handle, pair, db_loc), "Failed to save kv pairs."); kvpair_t *dbpair = load_kvpairs(handle, db_loc); check_pair_equality(pair, dbpair); free_kvpair(pair); free_kvpair(dbpair); }
END_TEST START_TEST (test_copy_pair) { char *args1[] = {"arg1", "arg2", NULL}; char *args2[] = {"other", NULL}; kvpair_t *pair1 = mk_kvpair("some_key", args1); pair = mk_kvpair("some_other_key", args2); pair->next = pair1; kvpair_t *copy = dup_kvpair(pair); fail_if(copy == NULL, "Copy failed."); fail_if(copy == pair, "Copy something not an identity."); fail_unless(strcmp(copy->key, pair->key) == 0, "Keys don't match."); fail_if(copy->key == pair->key, "Keys were identical."); check_pair_equality(pair, copy); free_kvpair(copy); }