X-Git-Url: http://git.ipfire.org/?p=people%2Fms%2Flibloc.git;a=blobdiff_plain;f=src%2Ftest-network.c;h=b7b51201231b31630b431903f06ffc06cdbeebad;hp=1007bd1df3f19fcdf7897fc0ca71d92a0ddc22ff;hb=2a30e4de98bd3362868f2673fa679559c42a6fbe;hpb=107780412a259fda3c346678090609c1b5b4c15c diff --git a/src/test-network.c b/src/test-network.c index 1007bd1..b7b5120 100644 --- a/src/test-network.c +++ b/src/test-network.c @@ -21,6 +21,7 @@ #include #include +#include #include #include @@ -139,6 +140,37 @@ int main(int argc, char** argv) { loc_network_unref(network3); loc_network_unref(network4); loc_network_tree_unref(tree); + + // And open it again from disk + f = fopen("test.db", "r"); + if (!f) { + fprintf(stderr, "Could not open file for reading: %s\n", strerror(errno)); + exit(EXIT_FAILURE); + } + + struct loc_database* db; + err = loc_database_new(ctx, &db, f); + if (err) { + fprintf(stderr, "Could not open database: %s\n", strerror(-err)); + exit(EXIT_FAILURE); + } + + // Lookup an exact match + err = loc_database_lookup_from_string(db, "2001:db8::", &network1); + if (err) { + fprintf(stderr, "Could not look up the given IP address\n"); + exit(EXIT_FAILURE); + } + loc_network_unref(network1); + + // Lookup a non-exact match + err = loc_database_lookup_from_string(db, "2001:db8:fffe:1::", &network1); + if (err) { + fprintf(stderr, "Could not look up the given IP address\n"); + exit(EXIT_FAILURE); + } + loc_network_unref(network1); + loc_unref(ctx); return EXIT_SUCCESS;