]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/graph/test/graphml_test.cpp
Add patch for failing prerm scripts
[ceph.git] / ceph / src / boost / libs / graph / test / graphml_test.cpp
CommitLineData
7c673cae
FG
1// Copyright (C) 2006 Tiago de Paula Peixoto <tiago@forked.de>
2//
3// Boost Software License - Version 1.0 - August 17th, 2003
4//
5// Permission is hereby granted, free of charge, to any person or organization
6// obtaining a copy of the software and accompanying documentation covered by
7// this license (the "Software") to use, reproduce, display, distribute,
8// execute, and transmit the Software, and to prepare derivative works of the
9// Software, and to permit third-parties to whom the Software is furnished to
10// do so, all subject to the following:
11//
12// The copyright notices in the Software and this entire statement, including
13// the above license grant, this restriction and the following disclaimer,
14// must be included in all copies of the Software, in whole or in part, and
15// all derivative works of the Software, unless such copies or derivative
16// works are solely in the form of machine-executable object code generated by
17// a source language processor.
18//
19// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
22// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
23// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
24// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25// DEALINGS IN THE SOFTWARE.
26
27// Authors: Tiago de Paula Peixoto
28
29#include <boost/graph/adjacency_list.hpp>
30#include <boost/graph/graphml.hpp>
31#include <boost/test/minimal.hpp>
32#include <cmath>
33#include <fstream>
34#include <string>
35
36
37using namespace std;
38using namespace boost;
39
40int test_main(int argc, char** argv)
41{
42 typedef adjacency_list<vecS,vecS,directedS,
43 property<vertex_color_t,int,
44 property<vertex_name_t,string> >,
45 property<edge_weight_t,double>,
46 property<graph_name_t, string> > graph_t;
47 graph_t g;
48 dynamic_properties dp;
49 dp.property("foo",get(vertex_color_t(),g));
50 dp.property("weight",get(edge_weight_t(),g));
51 dp.property("name",get(vertex_name_t(),g));
52 boost::ref_property_map<graph_t*,std::string>
53 gname(get_property(g, graph_name));
54 dp.property("description",gname);
55
56 ifstream ifile(argv[1]);
57 read_graphml(ifile, g, dp);
58 ifile.close();
59
60 BOOST_CHECK(num_vertices(g) == 9);
61 BOOST_CHECK(num_edges(g) == 9);
62 BOOST_CHECK(get(vertex_color_t(), g, vertex(2,g)) == 100);
63 BOOST_CHECK(get(vertex_color_t(), g, vertex(3,g)) == 42);
64 BOOST_CHECK(std::abs(get(edge_weight_t(), g, edge(vertex(0,g),vertex(1,g),g).first) - 0.0) < 0.00001);
65 BOOST_CHECK(std::abs(get(edge_weight_t(), g, edge(vertex(1,g),vertex(2,g),g).first) - 0.8) < 0.00001);
66 BOOST_CHECK(get("description", dp, &g) == "Root graph.");
67
68
69 ofstream ofile("graphml_test_out.xml");
70 write_graphml(ofile, g, dp);
71 ofile.close();
72
73 graph_t g2;
74 dynamic_properties dp2;
75 dp2.property("foo",get(vertex_color_t(),g2));
76 dp2.property("weight",get(edge_weight_t(),g2));
77 dp2.property("name",get(vertex_name_t(),g2));
78 boost::ref_property_map<graph_t*,std::string>
79 gname2(get_property(g2, graph_name));
80 dp2.property("description",gname2);
81 ifile.open("graphml_test_out.xml");
82 read_graphml(ifile, g2, dp2);
83 ifile.close();
84
85 BOOST_CHECK(num_vertices(g) == num_vertices(g2));
86 BOOST_CHECK(num_edges(g) == num_edges(g2));
87 BOOST_CHECK(get("description", dp, &g) == get("description", dp2, &g2));
88
89 graph_traits<graph_t>::vertex_iterator v, v_end;
90 for (boost::tie(v,v_end) = vertices(g); v != v_end; ++v)
91 BOOST_CHECK(get(vertex_color_t(), g, *v) == get(vertex_color_t(), g2, *v));
92
93 graph_traits<graph_t>::edge_iterator e, e_end;
94 for (boost::tie(e,e_end) = edges(g); e != e_end; ++e)
95 BOOST_CHECK(std::abs(get(edge_weight_t(), g, *e) - get(edge_weight_t(), g2, *e)) < 0.00001);
96
97 return 0;
98}