index 1ad96d123f6b6431b87f8cfc3a83872ccc37fb1b..6fb2938e75f1b64319d268cd1a904ae7a902bc80 100644 (file)
--- a/t/unit/utils/dbi_test.c
+++ b/t/unit/utils/dbi_test.c
# include "config.h"
#endif /* HAVE_CONFIG_H */
-#include "libsysdb_test.h"
+#include "testutils.h"
#include "utils/dbi.h"
#include <check.h>
dbi_driver_list_r(dbi_driver curr, dbi_inst inst);
#endif
+const dbi_inst INST = (void *)0x4711;
+
int
-dbi_initialize_r(const char __attribute__((unused)) *driverdir,
- dbi_inst __attribute__((unused)) *pInst)
+dbi_initialize_r(const char __attribute__((unused)) *driverdir, dbi_inst *pInst)
{
+ if (pInst)
+ *pInst = INST;
return 0;
} /* dbi_initialize_r */
void
-dbi_shutdown_r(dbi_inst __attribute__((unused)) inst)
+dbi_shutdown_r(dbi_inst inst)
{
+ fail_unless(inst == INST,
+ "dbi_shutdown_r() called with unexpected inst=%p; expected %p",
+ inst, INST);
} /* dbi_shutdown_r */
dbi_driver
-dbi_driver_open_r(const char *name, dbi_inst __attribute__((unused)) inst)
+dbi_driver_open_r(const char *name, dbi_inst inst)
{
+ fail_unless(inst == INST,
+ "dbi_driver_open_r() called with unexpected inst=%p; expected %p",
+ inst, INST);
+
if (strcmp(name, "mockdriver"))
return NULL;
return (dbi_driver)"mockdriver";
} /* dbi_driver_open */
dbi_driver
-dbi_driver_list_r(dbi_driver curr, dbi_inst __attribute__((unused)) inst)
+dbi_driver_list_r(dbi_driver curr, dbi_inst inst)
{
+ fail_unless(inst == INST,
+ "dbi_driver_list_r() called with unexpected inst=%p; expected %p",
+ inst, INST);
+
if (!curr)
return "mockdriver";
return NULL;
void
dbi_shutdown(void)
{
- dbi_shutdown_r(NULL);
+ dbi_shutdown_r(INST);
} /* dbi_shutdown */
dbi_driver
dbi_driver_open(const char *name)
{
- return dbi_driver_open_r(name, NULL);
+ return dbi_driver_open_r(name, INST);
} /* dbi_driver_open */
dbi_driver
dbi_driver_list(dbi_driver curr)
{
- return dbi_driver_list_r(curr, NULL);
+ return dbi_driver_list_r(curr, INST);
} /* dbi_driver_list */
#endif
user_data, TEST_MAGIC);
for (i = 0; i < n; ++i) {
- int expected_type = DBI_TYPE_TO_SC(current_query->field_types[i]);
+ int expected_type = DBI_TYPE_TO_SDB(current_query->field_types[i]);
mock_data_t expected_data;
fail_unless((int)data[i].type == expected_type,
case SDB_TYPE_DATETIME:
fail_unless(data[i].data.datetime
== SECS_TO_SDB_TIME(expected_data.datetime),
- "query callback received unexpected data "PRIscTIME
- " for column %zu; expected: "PRIscTIME,
+ "query callback received unexpected data "PRIsdbTIME
+ " for column %zu; expected: "PRIsdbTIME,
data[i].data.integer, i,
SECS_TO_SDB_TIME(expected_data.integer));
break;
START_TEST(test_sdb_dbi_client_connect)
{
- int check = sdb_dbi_client_connect(client);
+ sdb_dbi_options_t *opts;
+ int check;
+
+ check = sdb_dbi_client_connect(client);
fail_unless(check == 0,
"sdb_dbi_client_connect() = %i; expected: 0", check);
-
fail_unless(dbi_conn_connect_called == 1,
"sdb_dbi_client_create() called dbi_conn_connect %i times; "
"expected: 1", dbi_conn_connect_called);
+
+ /* calling it again shall reconnect */
+ check = sdb_dbi_client_connect(client);
+ fail_unless(check == 0,
+ "repeated sdb_dbi_client_connect() = %i; expected: 0", check);
+ fail_unless(dbi_conn_connect_called == 2,
+ "repeated sdb_dbi_client_create() called dbi_conn_connect %i times; "
+ "expected: 2", dbi_conn_connect_called);
+
+ opts = sdb_dbi_options_create();
+ fail_unless(opts != NULL,
+ "sdb_dbi_options_create() returned NULL; expected <opts>");
+ check = sdb_dbi_options_add(opts, "a", "1");
+ fail_unless(check == 0,
+ "sdb_dbi_options_add('a', '1') = %d; expected: 0", check);
+ check = sdb_dbi_options_add(opts, "b", "2");
+ fail_unless(check == 0,
+ "sdb_dbi_options_add('b', '2') = %d; expected: 0", check);
+
+ check = sdb_dbi_client_set_options(client, opts);
+ fail_unless(check == 0,
+ "sdb_dbi_client_set_options() = %d; expected: 0", check);
+ /* reconnect with options */
+ check = sdb_dbi_client_connect(client);
+ fail_unless(check == 0,
+ "repeated, with options sdb_dbi_client_connect() = %i; expected: 0",
+ check);
+ fail_unless(dbi_conn_connect_called == 3,
+ "repeated, with options sdb_dbi_client_create() called "
+ "dbi_conn_connect %i times; expected: 3", dbi_conn_connect_called);
+
+ /* The client takes ownership of the options, so no need to destroy it. */
}
END_TEST
}
END_TEST
-/*
- * test API
- */
-
-Suite *
-util_dbi_suite(void)
+TEST_MAIN("utils::dbi")
{
- Suite *s = suite_create("utils::dbi");
- TCase *tc;
-
- tc = tcase_create("core");
+ TCase *tc = tcase_create("core");
tcase_add_checked_fixture(tc, setup, teardown);
tcase_add_test(tc, test_sdb_dbi_client_connect);
tcase_add_test(tc, test_sdb_dbi_client_check_conn);
tcase_add_test(tc, test_sdb_dbi_exec_query);
- suite_add_tcase(s, tc);
-
- return s;
-} /* util_llist_suite */
+ ADD_TCASE(tc);
+}
+TEST_MAIN_END
/* vim: set tw=78 sw=4 ts=4 noexpandtab : */