diff options
author | Robin Krahl <me@robin-krahl.de> | 2016-03-10 04:21:10 +0100 |
---|---|---|
committer | Robin Krahl <me@robin-krahl.de> | 2016-03-10 04:21:10 +0100 |
commit | 913fc9d2c2935e0faf34657747286ce83af21853 (patch) | |
tree | bb4c060bd6de36642a0b54bf7dc0cbe8c7c57938 /dbfp_check.c | |
parent | 2ae18059f986154efe06fe7fda92a1bb53cca50a (diff) | |
download | dbfp-913fc9d2c2935e0faf34657747286ce83af21853.tar.gz dbfp-913fc9d2c2935e0faf34657747286ce83af21853.tar.bz2 |
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.
Diffstat (limited to 'dbfp_check.c')
-rw-r--r-- | dbfp_check.c | 36 |
1 files changed, 14 insertions, 22 deletions
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 |