]>
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>
29 const char* DESCRIPTION
=
30 "Lorem ipsum dolor sit amet, consectetur adipiscing elit. "
31 "Proin ultrices pulvinar dolor, et sollicitudin eros ultricies "
32 "vitae. Nam in volutpat libero. Nulla facilisi. Pellentesque "
33 "tempor felis enim. Integer congue nisi in maximus pretium. "
34 "Pellentesque et turpis elementum, luctus mi at, interdum erat. "
35 "Maecenas ut venenatis nunc.";
37 int main(int argc
, char** argv
) {
46 struct loc_database
* db
;
47 err
= loc_database_new(ctx
, &db
, 1024);
52 err
= loc_database_set_vendor(db
, "Test Vendor");
54 fprintf(stderr
, "Could not set vendor\n");
59 const char* vendor1
= loc_database_get_vendor(db
);
61 printf("Vendor is: %s\n", vendor1
);
63 fprintf(stderr
, "Could not retrieve vendor\n");
68 err
= loc_database_set_description(db
, DESCRIPTION
);
70 fprintf(stderr
, "Could not set description\n");
74 // Retrieve description
75 const char* description
= loc_database_get_description(db
);
77 printf("Description is: %s\n", description
);
79 fprintf(stderr
, "Could not retrieve description\n");
83 FILE* f
= fopen("test.db", "w");
85 fprintf(stderr
, "Could not open file for writing: %s\n", strerror(errno
));
89 err
= loc_database_write(db
, f
);
91 fprintf(stderr
, "Could not write database: %s\n", strerror(err
));
99 //loc_database_unref(db);
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
* db2
;
109 err
= loc_database_open(ctx
, &db2
, f
);
111 fprintf(stderr
, "Could not open database: %s\n", strerror(-err
));
115 const char* vendor2
= loc_database_get_vendor(db2
);
117 fprintf(stderr
, "Could not retrieve vendor\n");
119 } else if (strcmp(vendor1
, vendor2
) != 0) {
120 fprintf(stderr
, "Vendor doesn't match: %s != %s\n", vendor1
, vendor2
);
124 // Close the database
125 loc_database_unref(db2
);