From 913fc9d2c2935e0faf34657747286ce83af21853 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Thu, 10 Mar 2016 04:21:10 +0100 Subject: dbfp: improve error handling Get rid of the complicated dbfp_status structure and use plain old return codes. This leads to a cleaner interface and fixes the problem with unsufficient error handling introduced with 1648e81. The drawback is that the details of curl and expat errors are hidden from the user, but this can be adressed later. --- dbfp_check.c | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) (limited to 'dbfp_check.c') diff --git a/dbfp_check.c b/dbfp_check.c index 067918f..2c048d8 100644 --- a/dbfp_check.c +++ b/dbfp_check.c @@ -26,50 +26,42 @@ END_TEST START_TEST(test_dbfp_access) { - struct dbfp dbfp; - struct dbfp_status status; int err; + struct dbfp dbfp; + struct dbfp_location *locations = NULL; + size_t n; err = dbfp_init(&dbfp, api_key); ck_assert_int_eq(err, 0); - status = dbfp_query_location_name(&dbfp, "", NULL, NULL); - ck_assert_int_eq(status.error, 0); - ck_assert_int_eq(status.run_error, 0); - ck_assert_int_eq(status.parse_error, 0); - ck_assert_int_eq(status.curl_error, 0); - ck_assert_int_eq(status.api_error, 0); + err = dbfp_query_location_name(&dbfp, "", &n, &locations); + ck_assert_int_eq(err, 0); + free(locations); dbfp_close(&dbfp); } END_TEST START_TEST(test_dbfp_location_simple) { - struct dbfp dbfp; - struct dbfp_status status; int err; + struct dbfp dbfp; + struct dbfp_location *locations = NULL; size_t n; - struct dbfp_location *locs = NULL; err = dbfp_init(&dbfp, api_key); ck_assert_int_eq(err, 0); - status = dbfp_query_location_name(&dbfp, "freiburg", &n, &locs); - ck_assert_int_eq(status.error, 0); - ck_assert_int_eq(status.run_error, 0); - ck_assert_int_eq(status.parse_error, 0); - ck_assert_int_eq(status.curl_error, 0); - ck_assert_int_eq(status.api_error, 0); + err = dbfp_query_location_name(&dbfp, "freiburg", &n, &locations); + ck_assert_int_eq(err, 0); ck_assert_int_gt(n, 0); - ck_assert_ptr_ne(locs, NULL); - - ck_assert_str_eq(locs[0].name, "Freiburg(Breisgau) Hbf"); - ck_assert_str_eq(locs[0].id, "008000107"); + ck_assert_ptr_ne(locations, NULL); - free(locs); + ck_assert_str_eq(locations[0].name, "Freiburg(Breisgau) Hbf"); + ck_assert_str_eq(locations[0].id, "008000107"); + free(locations); dbfp_close(&dbfp); } END_TEST -- cgit v1.2.1