]> git.ipfire.org Git - people/ms/libloc.git/blobdiff - src/test-signature.c
downloader: Change user-agent to location
[people/ms/libloc.git] / src / test-signature.c
index aacd7637f9a8493eed3cfaa439909ef5334d770f..cbbe15f7f7fc0578ed490a17c2c3feb6843f1767 100644 (file)
@@ -38,8 +38,14 @@ int main(int argc, char** argv) {
        }
 
        // Open private key
-       FILE* private_key = fopen(ABS_SRCDIR "/examples/private-key.pem", "r");
-       if (!private_key) {
+       FILE* private_key1 = fopen(ABS_SRCDIR "/examples/private-key.pem", "r");
+       if (!private_key1) {
+               fprintf(stderr, "Could not open private key file: %s\n", strerror(errno));
+               exit(EXIT_FAILURE);
+       }
+
+       FILE* private_key2 = fopen(ABS_SRCDIR "/examples/private-key.pem", "r");
+       if (!private_key2) {
                fprintf(stderr, "Could not open private key file: %s\n", strerror(errno));
                exit(EXIT_FAILURE);
        }
@@ -51,33 +57,24 @@ int main(int argc, char** argv) {
 
        // Create an empty database
        struct loc_writer* writer;
-       err = loc_writer_new(ctx, &writer, LOC_DATABASE_VERSION_LATEST, private_key);
+       err = loc_writer_new(ctx, &writer, private_key1, private_key2);
        if (err < 0)
                exit(EXIT_FAILURE);
 
-       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);
        }
 
-       err = loc_writer_write(writer, f);
+       err = loc_writer_write(writer, f, LOC_DATABASE_VERSION_UNSET);
        if (err) {
                fprintf(stderr, "Could not write database: %s\n", strerror(err));
                exit(EXIT_FAILURE);
        }
        loc_writer_unref(writer);
 
-       // Close the file
-       fclose(f);
-
        // 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) {
@@ -108,10 +105,11 @@ int main(int argc, char** argv) {
 
        // Close the database
        loc_database_unref(db);
-
        loc_unref(ctx);
+       fclose(f);
 
-       fclose(private_key);
+       fclose(private_key1);
+       fclose(private_key2);
        fclose(public_key);
 
        return EXIT_SUCCESS;