|
| 1 | +#include "maxminddb_test_helper.h" |
| 2 | + |
| 3 | +static void test_db_opens_and_lookup_succeeds(const char *filename, |
| 4 | + const char *open_msg) { |
| 5 | + char *db_file = bad_database_path(filename); |
| 6 | + |
| 7 | + MMDB_s mmdb; |
| 8 | + int status = MMDB_open(db_file, MMDB_MODE_MMAP, &mmdb); |
| 9 | + cmp_ok(status, "==", MMDB_SUCCESS, open_msg); |
| 10 | + |
| 11 | + if (status != MMDB_SUCCESS) { |
| 12 | + diag("MMDB_open failed: %s", MMDB_strerror(status)); |
| 13 | + free(db_file); |
| 14 | + return; |
| 15 | + } |
| 16 | + |
| 17 | + int gai_error, mmdb_error; |
| 18 | + MMDB_lookup_string(&mmdb, "1.2.3.4", &gai_error, &mmdb_error); |
| 19 | + cmp_ok(gai_error, "==", 0, "getaddrinfo succeeded"); |
| 20 | + cmp_ok(mmdb_error, "==", MMDB_SUCCESS, "lookup succeeded"); |
| 21 | + |
| 22 | + MMDB_close(&mmdb); |
| 23 | + free(db_file); |
| 24 | +} |
| 25 | + |
| 26 | +void test_empty_map_last_in_metadata(void) { |
| 27 | + test_db_opens_and_lookup_succeeds( |
| 28 | + "libmaxminddb-empty-map-last-in-metadata.mmdb", |
| 29 | + "opened MMDB with empty map at end of metadata"); |
| 30 | +} |
| 31 | + |
| 32 | +void test_empty_array_last_in_metadata(void) { |
| 33 | + test_db_opens_and_lookup_succeeds( |
| 34 | + "libmaxminddb-empty-array-last-in-metadata.mmdb", |
| 35 | + "opened MMDB with empty array at end of metadata"); |
| 36 | +} |
| 37 | + |
| 38 | +int main(void) { |
| 39 | + plan(NO_PLAN); |
| 40 | + test_empty_map_last_in_metadata(); |
| 41 | + test_empty_array_last_in_metadata(); |
| 42 | + done_testing(); |
| 43 | +} |
0 commit comments