aboutsummaryrefslogtreecommitdiff
path: root/dbfp_check.c
diff options
context:
space:
mode:
Diffstat (limited to 'dbfp_check.c')
-rw-r--r--dbfp_check.c71
1 files changed, 29 insertions, 42 deletions
diff --git a/dbfp_check.c b/dbfp_check.c
index 29db4a3..f816cfc 100644
--- a/dbfp_check.c
+++ b/dbfp_check.c
@@ -12,6 +12,10 @@
static char *api_key;
+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);
+
START_TEST(test_dbfp_create)
{
struct dbfp dbfp;
@@ -55,57 +59,27 @@ START_TEST(test_dbfp_location_simple)
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(locations, NULL);
-
- ck_assert_str_eq(locations[0].name, "Freiburg(Breisgau) Hbf");
- ck_assert_str_eq(locations[0].id, "008000107");
- ck_assert(locations[0].lon == 7.841173f);
- ck_assert(locations[0].lat == 47.997696f);
-
- for (i = 0; i < n; i++) {
- free(locations[i].name);
- free(locations[i].id);
- }
+ assert_location_eq(n, locations, 0, "Freiburg(Breisgau) Hbf",
+ "008000107", 7.841173f, 47.997696f);
+ for (i = 0; i < n; i++)
+ dbfp_location_close(&locations[i]);
free(locations);
- locations = NULL;
err = dbfp_query_location_name(&dbfp, "freib", &n, &locations);
ck_assert_int_eq(err, 0);
-
- ck_assert_int_gt(n, 0);
- ck_assert_ptr_ne(locations, NULL);
-
- ck_assert_str_eq(locations[0].name, "Freiburg(Breisgau) Hbf");
- ck_assert_str_eq(locations[0].id, "008000107");
- ck_assert(locations[0].lon == 7.841173f);
- ck_assert(locations[0].lat == 47.997696f);
-
- for (i = 0; i < n; i++) {
- free(locations[i].name);
- free(locations[i].id);
- }
+ assert_location_eq(n, locations, 0, "Freiburg(Breisgau) Hbf",
+ "008000107", 7.841173f, 47.997696f);
+ for (i = 0; i < n; i++)
+ dbfp_location_close(&locations[i]);
free(locations);
- locations = NULL;
err = dbfp_query_location_name(&dbfp, "freiburg im", &n, &locations);
ck_assert_int_eq(err, 0);
-
- ck_assert_int_gt(n, 0);
- ck_assert_ptr_ne(locations, NULL);
-
- ck_assert_str_eq(locations[0].name, "Freiburg(Breisgau) Hbf");
- ck_assert_str_eq(locations[0].id, "008000107");
- ck_assert(locations[0].lon == 7.841173f);
- ck_assert(locations[0].lat == 47.997696f);
-
- for (i = 0; i < n; i++) {
- free(locations[i].name);
- free(locations[i].id);
- }
+ assert_location_eq(n, locations, 0, "Freiburg(Breisgau) Hbf",
+ "008000107", 7.841173f, 47.997696f);
+ for (i = 0; i < n; i++)
+ dbfp_location_close(&locations[i]);
free(locations);
- locations = NULL;
dbfp_close(&dbfp);
}
@@ -143,3 +117,16 @@ int main(int argc, char **argv)
return (num_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}
+
+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)
+{
+ ck_assert_ptr_ne(locations, NULL);
+ ck_assert_uint_lt(i, n);
+
+ ck_assert_str_eq(locations[i].name, name);
+ ck_assert_str_eq(locations[i].id, id);
+ ck_assert(locations[i].lon == lon);
+ ck_assert(locations[i].lat == lat);
+}