aboutsummaryrefslogtreecommitdiff
path: root/dbfp_check.c
diff options
context:
space:
mode:
authorRobin Krahl <me@robin-krahl.de>2016-03-08 04:43:39 +0100
committerRobin Krahl <me@robin-krahl.de>2016-03-08 04:43:39 +0100
commit1648e81474b552ba499102e13f9f3ed863501757 (patch)
tree5bab6daabf8ee746efd9fbab3cdfabc6c498cfcc /dbfp_check.c
parent745c643c2f900c8efeb0ac0a8ea3a519b3a790ac (diff)
downloaddbfp-1648e81474b552ba499102e13f9f3ed863501757.tar.gz
dbfp-1648e81474b552ba499102e13f9f3ed863501757.tar.bz2
add rudimentary location support
The function dbfp_query_location_name performs the location.name query and returns a list of all stations that match the search term. The implementation has two flaws: there is no URL encoding, and malformatted query results will not lead to a meaningful error message. There are two new test cases: basic tests some basic functionality, as setting the API key and accessing the API. location adds a simple test for the location.name query.
Diffstat (limited to 'dbfp_check.c')
-rw-r--r--dbfp_check.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/dbfp_check.c b/dbfp_check.c
index 35daaef..067918f 100644
--- a/dbfp_check.c
+++ b/dbfp_check.c
@@ -5,10 +5,13 @@
*/
#include <check.h>
+#include <stdio.h>
#include <stdlib.h>
#include "dbfp.h"
+static char *api_key;
+
START_TEST(test_dbfp_create)
{
struct dbfp dbfp;
@@ -21,20 +24,82 @@ START_TEST(test_dbfp_create)
}
END_TEST
+START_TEST(test_dbfp_access)
+{
+ struct dbfp dbfp;
+ struct dbfp_status status;
+ int err;
+
+ 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);
+
+ dbfp_close(&dbfp);
+}
+END_TEST
+
+START_TEST(test_dbfp_location_simple)
+{
+ struct dbfp dbfp;
+ struct dbfp_status status;
+ int err;
+ 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);
+
+ 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");
+
+ free(locs);
+
+ dbfp_close(&dbfp);
+}
+END_TEST
+
int main(int argc, char **argv)
{
int num_failed = 0;
Suite *s;
SRunner *sr;
TCase *tc_basic;
+ TCase *tc_location;
+
+ api_key = getenv("DBFP_API_KEY");
+ if (!api_key) {
+ fprintf(stderr, "DBFP_API_KEY not set\n");
+ return EXIT_FAILURE;
+ }
s = suite_create("dbfp");
sr = srunner_create(s);
tc_basic = tcase_create("basic");
tcase_add_test(tc_basic, test_dbfp_create);
+ tcase_add_test(tc_basic, test_dbfp_access);
suite_add_tcase(s, tc_basic);
+ tc_location = tcase_create("location");
+ tcase_add_test(tc_location, test_dbfp_location_simple);
+ suite_add_tcase(s, tc_location);
+
srunner_run_all(sr, CK_ENV);
num_failed = srunner_ntests_failed(sr);
srunner_free(sr);