1 /* -*- mode: C -*-  */
2 /*
3    IGraph R package.
4    Copyright (C) 2005-2012  Gabor Csardi <csardi.gabor@gmail.com>
5    334 Harvard st, Cambridge MA, 02139 USA
6 
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11 
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16 
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20    02110-1301 USA
21 
22 */
23 
24 #include <igraph.h>
25 
main()26 int main() {
27 
28     igraph_t g;
29     FILE *input;
30 
31     /* Without names and weights */
32     input = fopen("igraph_read_graph_lgl-1.lgl", "r");
33     if (!input) {
34         return 1;
35     }
36     igraph_read_graph_lgl(&g, input, 0, IGRAPH_ADD_WEIGHTS_NO, 1);
37     fclose(input);
38     if (!igraph_is_directed(&g)) {
39         return 2;
40     }
41     igraph_write_graph_edgelist(&g, stdout);
42     igraph_destroy(&g);
43 
44     /* With names and weights */
45     input = fopen("igraph_read_graph_lgl-2.lgl", "r");
46     if (!input) {
47         return 3;
48     }
49     igraph_read_graph_lgl(&g, input, 0, IGRAPH_ADD_WEIGHTS_NO, 1);
50     fclose(input);
51     if (!igraph_is_directed(&g)) {
52         return 4;
53     }
54     igraph_write_graph_ncol(&g, stdout, 0, 0);
55     igraph_destroy(&g);
56 
57     /* Same graph, but forcing undirected mode */
58     input = fopen("igraph_read_graph_lgl-2.lgl", "r");
59     igraph_read_graph_lgl(&g, input, 0, IGRAPH_ADD_WEIGHTS_NO, 0);
60     fclose(input);
61     if (igraph_is_directed(&g)) {
62         return 5;
63     }
64     igraph_write_graph_ncol(&g, stdout, 0, 0);
65     igraph_destroy(&g);
66 
67     /* Erroneous LGL file (empty vertex name) */
68     input = fopen("igraph_read_graph_lgl-3.lgl", "r");
69     if (!input) {
70         return 6;
71     }
72     igraph_set_error_handler(igraph_error_handler_ignore);
73     if (igraph_read_graph_lgl(&g, input, 0, IGRAPH_ADD_WEIGHTS_NO, 1) !=
74         IGRAPH_PARSEERROR) {
75         return 7;
76     }
77     fclose(input);
78 
79     return 0;
80 }
81