]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/graph/test/test_properties.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / graph / test / test_properties.hpp
1 // (C) Copyright 2009 Andrew Sutton
2 //
3 // Use, modification and distribution are subject to the
4 // Boost Software License, Version 1.0 (See accompanying file
5 // LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
6
7 #ifndef TEST_PROPERTIES_HPP
8 #define TEST_PROPERTIES_HPP
9
10 #include <boost/concept/assert.hpp>
11
12 template<typename T> T const& as_const(T& x) { return x; }
13 template<typename T> void ignore(T const&) { }
14
15 template<typename Graph>
16 void test_graph_bundle(Graph& g, boost::mpl::true_) {
17 using namespace boost;
18 std::cout << "...test_graph_bundle\n";
19
20 GraphBundle& b1 = g[graph_bundle];
21 GraphBundle& b2 = get_property(g);
22 ignore(b1); ignore(b2);
23
24 GraphBundle const& cb1 = ::as_const(g)[graph_bundle];
25 GraphBundle const& cb2 = get_property(g);
26 ignore(cb1); ignore(cb2);
27 }
28
29 template<typename Graph>
30 void test_graph_bundle(Graph& g, boost::mpl::false_)
31 { }
32
33 /** @name Test Vertex Bundle
34 * Exercise the vertex bundle. Note that this is expected to be of type
35 * VertexBundle.
36 */
37 //@{
38 template <typename Graph, typename VertexSet>
39 void test_vertex_bundle(Graph& g, VertexSet const& verts, boost::mpl::true_) {
40 using namespace boost;
41 BOOST_CONCEPT_ASSERT((GraphConcept<Graph>));
42 typedef typename graph_traits<Graph>::vertex_descriptor Vertex;
43 BOOST_CONCEPT_ASSERT((PropertyGraphConcept<Graph, Vertex, vertex_bundle_t>));
44
45 // Test bundling via the graph object on the lollipop vertex.
46 Vertex v = verts[5];
47 VertexBundle& b = g[v];
48 b.value = 10;
49 BOOST_ASSERT(g[v].value == 10);
50
51 // Test bundling via the property map.
52 typedef typename property_map<Graph, int VertexBundle::*>::type BundleMap;
53 BOOST_CONCEPT_ASSERT((ReadWritePropertyMapConcept<BundleMap, Vertex>));
54 BundleMap map = get(&VertexBundle::value, g);
55 put(map, v, 5);
56 BOOST_ASSERT(get(map, v) == 5);
57
58 typedef typename property_map<Graph, int VertexBundle::*>::const_type ConstBundleMap;
59 BOOST_CONCEPT_ASSERT((ReadablePropertyMapConcept<ConstBundleMap, Vertex>));
60 ConstBundleMap cmap = get(&VertexBundle::value, (Graph const&)g);
61 BOOST_ASSERT(get(cmap, v) == 5);
62 }
63
64 template <typename Graph, typename VertexSet>
65 void test_vertex_bundle(Graph&, VertexSet const&, boost::mpl::false_)
66 { }
67 //@}
68
69 /** @name Test Edge Bundle
70 * Exercise the edge bundle. Note that this is expected to be of type
71 * EdgeBundle.
72 */
73 //@{
74 template <typename Graph, typename VertexSet>
75 void test_edge_bundle(Graph& g, VertexSet const& verts, boost::mpl::true_) {
76 using namespace boost;
77 BOOST_CONCEPT_ASSERT((GraphConcept<Graph>));
78 typedef typename boost::graph_traits<Graph>::edge_descriptor Edge;
79 BOOST_CONCEPT_ASSERT((PropertyGraphConcept<Graph, Edge, edge_bundle_t>));
80
81 std::cout << "...test_edge_bundle\n";
82
83 // Test bundling via the graph object on the lollipop edge.
84 Edge e = boost::edge(verts[5], verts[3], g).first;
85 EdgeBundle& b = g[e];
86 b.value = 10;
87 BOOST_ASSERT(g[e].value == 10);
88
89 // Test bundling via the property map.
90 typedef typename boost::property_map<Graph, int EdgeBundle::*>::type BundleMap;
91 BOOST_CONCEPT_ASSERT((ReadWritePropertyMapConcept<BundleMap, Edge>));
92 BundleMap map = get(&EdgeBundle::value, g);
93 put(map, e, 5);
94 BOOST_ASSERT(get(map, e) == 5);
95
96 typedef typename boost::property_map<Graph, int EdgeBundle::*>::const_type ConstBundleMap;
97 BOOST_CONCEPT_ASSERT((ReadablePropertyMapConcept<BundleMap, Edge>));
98 ConstBundleMap cmap = get(&EdgeBundle::value, (Graph const&)g);
99 BOOST_ASSERT(get(cmap, e) == 5);
100 }
101
102 template <typename Graph, typename VertexSet>
103 void test_edge_bundle(Graph&, VertexSet const&, boost::mpl::false_)
104 { }
105 //@}
106
107 /**
108 * Test the properties of a graph. Basically, we expect these to be one of
109 * bundled or not. This test could also be expanded to test non-bundled
110 * properties. This just bootstraps the tests.
111 */
112 template <typename Graph, typename VertexSet>
113 void test_properties(Graph& g, VertexSet const& verts) {
114 using namespace boost;
115
116 typename has_bundled_graph_property<Graph>::type graph_bundled;
117 typename has_bundled_vertex_property<Graph>::type vertex_bundled;
118 typename has_bundled_edge_property<Graph>::type edge_bundled;
119
120 test_graph_bundle(g, graph_bundled);
121 test_vertex_bundle(g, verts, vertex_bundled);
122 test_edge_bundle(g, verts, edge_bundled);
123 }
124 //@}
125
126 #endif