]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/graph/test/graphml_test.cpp
bump version to 19.2.0-pve1
[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>
f67539c2 31#include <boost/core/lightweight_test.hpp>
7c673cae
FG
32#include <cmath>
33#include <fstream>
34#include <string>
35
7c673cae
FG
36using namespace std;
37using namespace boost;
38
f67539c2 39int main(int argc, char** argv)
7c673cae 40{
f67539c2
TL
41 typedef adjacency_list< vecS, vecS, directedS,
42 property< vertex_color_t, int, property< vertex_name_t, string > >,
43 property< edge_weight_t, double >, property< graph_name_t, string > >
44 graph_t;
7c673cae
FG
45 graph_t g;
46 dynamic_properties dp;
f67539c2
TL
47 dp.property("foo", get(vertex_color_t(), g));
48 dp.property("weight", get(edge_weight_t(), g));
49 dp.property("name", get(vertex_name_t(), g));
50 boost::ref_property_map< graph_t*, std::string > gname(
51 get_property(g, graph_name));
52 dp.property("description", gname);
7c673cae
FG
53
54 ifstream ifile(argv[1]);
55 read_graphml(ifile, g, dp);
56 ifile.close();
57
f67539c2
TL
58 BOOST_TEST(num_vertices(g) == 9);
59 BOOST_TEST(num_edges(g) == 9);
60 BOOST_TEST(get(vertex_color_t(), g, vertex(2, g)) == 100);
61 BOOST_TEST(get(vertex_color_t(), g, vertex(3, g)) == 42);
62 BOOST_TEST(std::abs(get(edge_weight_t(), g,
63 edge(vertex(0, g), vertex(1, g), g).first)
64 - 0.0)
65 < 0.00001);
66 BOOST_TEST(std::abs(get(edge_weight_t(), g,
67 edge(vertex(1, g), vertex(2, g), g).first)
68 - 0.8)
69 < 0.00001);
70 BOOST_TEST(get("description", dp, &g) == "Root graph.");
7c673cae
FG
71
72 ofstream ofile("graphml_test_out.xml");
73 write_graphml(ofile, g, dp);
74 ofile.close();
75
76 graph_t g2;
77 dynamic_properties dp2;
f67539c2
TL
78 dp2.property("foo", get(vertex_color_t(), g2));
79 dp2.property("weight", get(edge_weight_t(), g2));
80 dp2.property("name", get(vertex_name_t(), g2));
81 boost::ref_property_map< graph_t*, std::string > gname2(
82 get_property(g2, graph_name));
83 dp2.property("description", gname2);
7c673cae
FG
84 ifile.open("graphml_test_out.xml");
85 read_graphml(ifile, g2, dp2);
86 ifile.close();
87
f67539c2
TL
88 BOOST_TEST(num_vertices(g) == num_vertices(g2));
89 BOOST_TEST(num_edges(g) == num_edges(g2));
90 BOOST_TEST(get("description", dp, &g) == get("description", dp2, &g2));
7c673cae 91
f67539c2
TL
92 graph_traits< graph_t >::vertex_iterator v, v_end;
93 for (boost::tie(v, v_end) = vertices(g); v != v_end; ++v)
94 BOOST_TEST(
95 get(vertex_color_t(), g, *v) == get(vertex_color_t(), g2, *v));
7c673cae 96
f67539c2
TL
97 graph_traits< graph_t >::edge_iterator e, e_end;
98 for (boost::tie(e, e_end) = edges(g); e != e_end; ++e)
99 BOOST_TEST(
100 std::abs(get(edge_weight_t(), g, *e) - get(edge_weight_t(), g2, *e))
101 < 0.00001);
7c673cae 102
f67539c2 103 return boost::report_errors();
7c673cae 104}