Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
bugs fixed in graph destructors
[simgrid.git] / testsuite / xbt / graphxml_usage.c
1 /*      $Id$      */
2
3 /* A few basic tests for the graphxml library                               */
4
5 /* Copyright (c) 2006 Darina Dimitrova, Arnaud Legrand. All rights reserved.*/
6
7 /* This program is free software; you can redistribute it and/or modify it
8  * under the terms of the license (GNU LGPL) which comes with this package. */
9
10 #include <stdio.h>
11 #include <xbt/module.h>
12 #include "xbt/graph.h"
13 #include "xbt/graphxml.h"
14 #include "xbt/dynar.h"
15 #include <malloc.h>
16
17
18
19 void test(char *graph_file);
20 void test(char *graph_file)
21 {
22   int i,j;
23
24   unsigned long n;
25   xbt_dynar_t dynar=NULL;
26   xbt_dynar_t dynar1=NULL;
27   xbt_graph_t graph = xbt_graph_read(graph_file);
28   n=xbt_dynar_length(xbt_graph_get_nodes( graph));
29
30
31   double *d=xbt_graph_get_length_matrix(graph);
32   
33   for(i=0;i<n;i++)
34     {
35       for(j=0;j<n;j++)
36         {
37           fprintf(stderr,"%le\t",d[i*n+j] );
38         }
39       fprintf(stderr,"\n" );
40     }
41   dynar = xbt_graph_get_nodes(graph);
42
43  
44   while(xbt_dynar_length(dynar))
45     xbt_graph_free_node(graph,*((xbt_node_t*)xbt_dynar_get_ptr(dynar,0)),NULL,NULL);
46
47   dynar = xbt_graph_get_edges(graph);
48   printf("%lu edges\n",xbt_dynar_length(dynar));
49  dynar1 = xbt_graph_get_nodes(graph);
50  printf("%lu nodes\n",xbt_dynar_length(dynar1));
51 /*  free(d); */
52   xbt_graph_free_graph(graph, NULL, NULL, NULL);
53 }
54
55 int main(int argc, char** argv)
56 {
57   xbt_init(&argc,argv);
58   if(argc==1) 
59     {
60      fprintf(stderr,"Usage : %s graph.xml\n",argv[0]);
61   
62      return 1;
63   }
64   test(argv[1]);
65
66   return 0;
67 }