]>
git.ipfire.org Git - people/ms/libloc.git/blob - src/test-database.c
2 libloc - A library to determine the location of someone on the Internet
4 Copyright (C) 2017 IPFire Development Team <info@ipfire.org>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
26 #include <loc/libloc.h>
27 #include <loc/database.h>
28 #include <loc/writer.h>
30 const char* VENDOR
= "Test Vendor";
31 const char* DESCRIPTION
=
32 "Lorem ipsum dolor sit amet, consectetur adipiscing elit. "
33 "Proin ultrices pulvinar dolor, et sollicitudin eros ultricies "
34 "vitae. Nam in volutpat libero. Nulla facilisi. Pellentesque "
35 "tempor felis enim. Integer congue nisi in maximus pretium. "
36 "Pellentesque et turpis elementum, luctus mi at, interdum erat. "
37 "Maecenas ut venenatis nunc.";
39 int main(int argc
, char** argv
) {
48 struct loc_writer
* writer
;
49 err
= loc_writer_new(ctx
, &writer
);
54 err
= loc_writer_set_vendor(writer
, VENDOR
);
56 fprintf(stderr
, "Could not set vendor\n");
61 const char* vendor
= loc_writer_get_vendor(writer
);
63 printf("Vendor is: %s\n", vendor
);
65 fprintf(stderr
, "Could not retrieve vendor\n");
70 err
= loc_writer_set_description(writer
, DESCRIPTION
);
72 fprintf(stderr
, "Could not set description\n");
76 // Retrieve description
77 const char* description
= loc_writer_get_description(writer
);
79 printf("Description is: %s\n", description
);
81 fprintf(stderr
, "Could not retrieve description\n");
85 FILE* f
= fopen("test.db", "w");
87 fprintf(stderr
, "Could not open file for writing: %s\n", strerror(errno
));
91 err
= loc_writer_write(writer
, f
);
93 fprintf(stderr
, "Could not write database: %s\n", strerror(err
));
96 loc_writer_unref(writer
);
101 // And open it again from disk
102 f
= fopen("test.db", "r");
104 fprintf(stderr
, "Could not open file for reading: %s\n", strerror(errno
));
108 struct loc_database
* db
;
109 err
= loc_database_new(ctx
, &db
, f
);
111 fprintf(stderr
, "Could not open database: %s\n", strerror(-err
));
115 vendor
= loc_database_get_vendor(db
);
117 fprintf(stderr
, "Could not retrieve vendor\n");
119 } else if (strcmp(vendor
, VENDOR
) != 0) {
120 fprintf(stderr
, "Vendor doesn't match: %s != %s\n", vendor
, VENDOR
);
124 // Close the database
125 loc_database_unref(db
);