From: Sebastian Harl Date: Wed, 29 Jan 2014 09:33:44 +0000 (+0100) Subject: dbi_test: Mocked required dbi*_copy_idx() functions. X-Git-Tag: sysdb-0.1.0~232 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=8cc37c99efec90fd5138bd3ff0829b8522daf76e;p=sysdb.git dbi_test: Mocked required dbi*_copy_idx() functions. --- diff --git a/t/utils/dbi_test.c b/t/utils/dbi_test.c index 10447e9..c54ea31 100644 --- a/t/utils/dbi_test.c +++ b/t/utils/dbi_test.c @@ -331,6 +331,17 @@ dbi_result_get_string_idx(dbi_result res, unsigned int i) return get_golden_data(res, i).string; } /* dbi_result_get_string_idx */ +char * +dbi_result_get_string_copy_idx(dbi_result res, unsigned int i) +{ + fail_unless(current_query->field_types[i - 1] == DBI_TYPE_STRING, + "dbi_result_get_string_copy_idx() called for non-string " + "column type %u", current_query->field_types[i - 1]); + if (! get_golden_data(res, i).string) + return NULL; + return strdup(get_golden_data(res, i).string); +} /* dbi_result_get_string_copy_idx */ + time_t dbi_result_get_datetime_idx(dbi_result res, unsigned int i) { @@ -379,6 +390,19 @@ dbi_result_get_binary_idx(dbi_result res, unsigned int i) return get_golden_data(res, i).binary.datum; } /* dbi_result_get_binary_idx */ +unsigned char * +dbi_result_get_binary_copy_idx(dbi_result res, unsigned int i) +{ + const char *data; + fail_unless(current_query->field_types[i - 1] == DBI_TYPE_BINARY, + "dbi_result_get_binary_copy_idx() called for non-binary " + "column type %u", current_query->field_types[i - 1]); + data = (const char *)get_golden_data(res, i).binary.datum; + if (! data) + return NULL; + return (unsigned char *)strdup(data); +} /* dbi_result_get_binary_copy_idx */ + static unsigned long long dbi_result_free_called = 0; int dbi_result_free(dbi_result res) @@ -467,7 +491,7 @@ query_callback(sdb_dbi_client_t *c, data[i].data.decimal, i, expected_data.decimal); break; case SDB_TYPE_STRING: - fail_unless(data[i].data.string == expected_data.string, + fail_unless(!strcmp(data[i].data.string, expected_data.string), "query callback received unexpected data %s " "for column %zu; expected: %s", data[i].data.string, i, expected_data.string); @@ -487,8 +511,9 @@ query_callback(sdb_dbi_client_t *c, "binary data length %zu for column %zu; " "expected: %lli", data[i].data.binary.length, i, expected_data.binary.length); - fail_unless(data[i].data.binary.datum == + fail_unless(!memcmp(data[i].data.binary.datum, expected_data.binary.datum, + expected_data.binary.length), "query callback received unexpected binary data %p " "for column %zu; expected: %p", data[i].data.binary.datum, i,