]>
git.ipfire.org Git - people/ms/libloc.git/blob - src/test-as.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.
21 #include <loc/libloc.h>
24 #define TEST_AS_COUNT 100
26 int main(int argc
, char** argv
) {
35 struct loc_database
* db
;
36 err
= loc_database_new(ctx
, &db
, 1024);
41 for (unsigned int i
= 1; i
<= TEST_AS_COUNT
; i
++) {
42 struct loc_as
* as
= loc_database_add_as(db
, i
);
44 sprintf(name
, "Test AS%u", i
);
45 loc_as_set_name(as
, name
);
50 FILE* f
= fopen("test.db", "w");
52 fprintf(stderr
, "Could not open file for writing: %s\n", strerror(errno
));
56 err
= loc_database_write(db
, f
);
58 fprintf(stderr
, "Could not write database: %s\n", strerror(-err
));
63 loc_database_unref(db
);
65 // And open it again from disk
66 f
= fopen("test.db", "r");
68 fprintf(stderr
, "Could not open file for reading: %s\n", strerror(errno
));
72 err
= loc_database_open(ctx
, &db
, f
);
74 fprintf(stderr
, "Could not open database: %s\n", strerror(-err
));
78 size_t as_count
= loc_database_count_as(db
);
79 if (as_count
!= TEST_AS_COUNT
) {
80 fprintf(stderr
, "Could not read all ASes\n");
84 loc_database_unref(db
);