File: ipv4_start_cache_t.c

package info (click to toggle)
python-maxminddb 3.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,600 kB
  • sloc: ansic: 7,565; python: 1,711; perl: 987; makefile: 273; sh: 190
file content (36 lines) | stat: -rw-r--r-- 994 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "maxminddb_test_helper.h"

void test_one_ip(MMDB_s *mmdb,
                 const char *ip,
                 const char *filename,
                 const char *mode_desc) {
    MMDB_lookup_result_s result =
        lookup_string_ok(mmdb, ip, filename, mode_desc);

    ok(result.found_entry,
       "got a result for an IPv4 address included in a larger-than-IPv4 subnet "
       "- %s - %s",
       ip,
       mode_desc);

    data_ok(&result, MMDB_DATA_TYPE_UTF8_STRING, "string value for IP", NULL);
}

void run_tests(int mode, const char *mode_desc) {
    const char *filename = "MaxMind-DB-no-ipv4-search-tree.mmdb";
    char *path = test_database_path(filename);
    MMDB_s *mmdb = open_ok(path, mode, mode_desc);
    free(path);

    test_one_ip(mmdb, "1.1.1.1", filename, mode_desc);
    test_one_ip(mmdb, "255.255.255.255", filename, mode_desc);

    MMDB_close(mmdb);
    free(mmdb);
}

int main(void) {
    plan(NO_PLAN);
    for_all_modes(&run_tests);
    done_testing();
}