]> git.ipfire.org Git - location/libloc.git/blobdiff - src/test-as.c
location-importer.in: skip networks with unknown country codes
[location/libloc.git] / src / test-as.c
index 7a2f34ea5e62f26ced81ca2fe979950d2783114d..2d61675f3866c04879cabad65a3e186d594432ae 100644 (file)
@@ -17,6 +17,7 @@
 #include <errno.h>
 #include <stdlib.h>
 #include <string.h>
+#include <syslog.h>
 
 #include <loc/libloc.h>
 #include <loc/database.h>
@@ -32,6 +33,9 @@ int main(int argc, char** argv) {
        if (err < 0)
                exit(EXIT_FAILURE);
 
+       // Enable debug logging
+       loc_set_log_priority(ctx, LOG_DEBUG);
+
        // Create a database
        struct loc_writer* writer;
        err = loc_writer_new(ctx, &writer, NULL, NULL);
@@ -49,7 +53,7 @@ int main(int argc, char** argv) {
                loc_as_unref(as);
        }
 
-       FILE* f = fopen("test.db", "w+");
+       FILE* f = tmpfile();
        if (!f) {
                fprintf(stderr, "Could not open file for writing: %s\n", strerror(errno));
                exit(EXIT_FAILURE);
@@ -60,17 +64,10 @@ int main(int argc, char** argv) {
                fprintf(stderr, "Could not write database: %s\n", strerror(-err));
                exit(EXIT_FAILURE);
        }
-       fclose(f);
 
        loc_writer_unref(writer);
 
        // 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) {
@@ -98,7 +95,7 @@ int main(int argc, char** argv) {
        // Enumerator
 
        struct loc_database_enumerator* enumerator;
-       err = loc_database_enumerator_new(&enumerator, db, LOC_DB_ENUMERATE_ASES);
+       err = loc_database_enumerator_new(&enumerator, db, LOC_DB_ENUMERATE_ASES, 0);
        if (err) {
                fprintf(stderr, "Could not create a database enumerator\n");
                exit(EXIT_FAILURE);
@@ -125,6 +122,7 @@ int main(int argc, char** argv) {
        loc_database_enumerator_unref(enumerator);
        loc_database_unref(db);
        loc_unref(ctx);
+       fclose(f);
 
        return EXIT_SUCCESS;
 }