]>
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.";
38 const char* LICENSE
= "CC";
40 int main(int argc
, char** argv
) {
49 struct loc_writer
* writer
;
50 err
= loc_writer_new(ctx
, &writer
);
55 err
= loc_writer_set_vendor(writer
, VENDOR
);
57 fprintf(stderr
, "Could not set vendor\n");
62 const char* vendor
= loc_writer_get_vendor(writer
);
64 printf("Vendor is: %s\n", vendor
);
66 fprintf(stderr
, "Could not retrieve vendor\n");
71 err
= loc_writer_set_description(writer
, DESCRIPTION
);
73 fprintf(stderr
, "Could not set description\n");
77 // Retrieve description
78 const char* description
= loc_writer_get_description(writer
);
80 printf("Description is: %s\n", description
);
82 fprintf(stderr
, "Could not retrieve description\n");
87 err
= loc_writer_set_license(writer
, LICENSE
);
89 fprintf(stderr
, "Could not set license\n");
94 const char* license
= loc_writer_get_license(writer
);
96 printf("License is: %s\n", license
);
98 fprintf(stderr
, "Could not retrieve license\n");
102 FILE* f
= fopen("test.db", "w");
104 fprintf(stderr
, "Could not open file for writing: %s\n", strerror(errno
));
108 err
= loc_writer_write(writer
, f
);
110 fprintf(stderr
, "Could not write database: %s\n", strerror(err
));
113 loc_writer_unref(writer
);
118 // And open it again from disk
119 f
= fopen("test.db", "r");
121 fprintf(stderr
, "Could not open file for reading: %s\n", strerror(errno
));
125 struct loc_database
* db
;
126 err
= loc_database_new(ctx
, &db
, f
);
128 fprintf(stderr
, "Could not open database: %s\n", strerror(-err
));
132 vendor
= loc_database_get_vendor(db
);
134 fprintf(stderr
, "Could not retrieve vendor\n");
136 } else if (strcmp(vendor
, VENDOR
) != 0) {
137 fprintf(stderr
, "Vendor doesn't match: %s != %s\n", vendor
, VENDOR
);
141 // Close the database
142 loc_database_unref(db
);