aboutsummaryrefslogtreecommitdiff
path: root/dbfp_check.c
diff options
context:
space:
mode:
authorRobin Krahl <me@robin-krahl.de>2016-06-01 23:44:11 +0200
committerRobin Krahl <me@robin-krahl.de>2016-06-01 23:44:11 +0200
commit47d6867cc86d5239fea690565abe84c526edaa5b (patch)
tree3c2ac1d5cd035cec7e2439a1575689bc47e4d178 /dbfp_check.c
parent3e0a3f7da39fdbbd2565f28c04c54fb5b51773b4 (diff)
downloaddbfp-47d6867cc86d5239fea690565abe84c526edaa5b.tar.gz
dbfp-47d6867cc86d5239fea690565abe84c526edaa5b.tar.bz2
dbfp: implement dbfp_query_departure
Retrieves the next departures of a given station. The time handling needs to be checked, as the DB API always uses Europe/Berlin.
Diffstat (limited to 'dbfp_check.c')
-rw-r--r--dbfp_check.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/dbfp_check.c b/dbfp_check.c
index f816cfc..bda63e5 100644
--- a/dbfp_check.c
+++ b/dbfp_check.c
@@ -16,6 +16,11 @@ static void assert_location_eq(size_t n, struct dbfp_location *locations,
size_t i, const char *name, const char *id, float lon,
float lat);
+static void assert_departure_eq(size_t n, struct dbfp_departure *departures,
+ size_t i, const char *name, const char *type,
+ const char *stopid, const char *stop, time_t time,
+ const char *direction, const char *track);
+
START_TEST(test_dbfp_create)
{
struct dbfp dbfp;
@@ -85,6 +90,47 @@ START_TEST(test_dbfp_location_simple)
}
END_TEST
+START_TEST(test_dbfp_departure_simple)
+{
+ int err;
+ struct dbfp dbfp;
+ struct dbfp_departure *departures = NULL;
+ struct tm tm = { .tm_year = 116, .tm_mon = 5, .tm_mday = 1,
+ .tm_hour = 17, .tm_min = 42 };
+ time_t time = mktime(&tm);
+ size_t n;
+ size_t i;
+
+ err = dbfp_init(&dbfp, api_key);
+ ck_assert_int_eq(err, 0);
+
+ err = dbfp_query_departure(&dbfp, NULL, "8000105", 0, &n, &departures);
+ ck_assert_int_eq(err, 0);
+ ck_assert_int_gt(n, 0);
+ for (i = 0; i < n; i++)
+ dbfp_departure_close(&departures[i]);
+ free(departures);
+
+ err = dbfp_query_departure(&dbfp, NULL, "8000105", time, &n,
+ &departures);
+ ck_assert_int_eq(err, 0);
+ tm.tm_hour++;
+ time = mktime(&tm);
+ assert_departure_eq(n, departures, 0, "ICE 1556", "ICE", "8000105",
+ "Frankfurt(Main)Hbf", time, "Wiesbaden Hbf", "6");
+ tm.tm_min = 49;
+ time = mktime(&tm);
+ assert_departure_eq(n, departures, 1, "IC 2274", "IC", "8000105",
+ "Frankfurt(Main)Hbf", time, "Kassel-Wilhelmshöhe",
+ "11");
+ for (i = 0; i < n; i++)
+ dbfp_departure_close(&departures[i]);
+ free(departures);
+
+ dbfp_close(&dbfp);
+}
+END_TEST
+
int main(int argc, char **argv)
{
int num_failed = 0;
@@ -92,6 +138,7 @@ int main(int argc, char **argv)
SRunner *sr;
TCase *tc_basic;
TCase *tc_location;
+ TCase *tc_departure;
api_key = getenv("DBFP_API_KEY");
if (!api_key) {
@@ -111,6 +158,10 @@ int main(int argc, char **argv)
tcase_add_test(tc_location, test_dbfp_location_simple);
suite_add_tcase(s, tc_location);
+ tc_departure = tcase_create("departure");
+ tcase_add_test(tc_departure, test_dbfp_departure_simple);
+ suite_add_tcase(s, tc_departure);
+
srunner_run_all(sr, CK_ENV);
num_failed = srunner_ntests_failed(sr);
srunner_free(sr);
@@ -130,3 +181,20 @@ static void assert_location_eq(size_t n, struct dbfp_location *locations,
ck_assert(locations[i].lon == lon);
ck_assert(locations[i].lat == lat);
}
+
+static void assert_departure_eq(size_t n, struct dbfp_departure *departures,
+ size_t i, const char *name, const char *type,
+ const char *stopid, const char *stop, time_t time,
+ const char *direction, const char *track)
+{
+ ck_assert_ptr_ne(departures, NULL);
+ ck_assert_uint_lt(i, n);
+
+ ck_assert_str_eq(departures[i].name, name);
+ ck_assert_str_eq(departures[i].type, type);
+ ck_assert_str_eq(departures[i].stopid, stopid);
+ ck_assert_str_eq(departures[i].stop, stop);
+ ck_assert_uint_eq(departures[i].time, time);
+ ck_assert_str_eq(departures[i].direction, direction);
+ ck_assert_str_eq(departures[i].track, track);
+}