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 > void test_graph_bundle(Graph& g, boost::mpl::true_) |
16 | { |
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); |
23 | ignore(b2); |
24 | |
25 | GraphBundle const& cb1 = ::as_const(g)[graph_bundle]; |
26 | GraphBundle const& cb2 = get_property(g); |
27 | ignore(cb1); |
28 | ignore(cb2); |
29 | } |
30 | |
31 | template < typename Graph > void test_graph_bundle(Graph& g, boost::mpl::false_) |
32 | { |
33 | } |
34 | |
35 | /** @name Test Vertex Bundle |
36 | * Exercise the vertex bundle. Note that this is expected to be of type |
37 | * VertexBundle. |
38 | */ |
39 | //@{ |
40 | template < typename Graph, typename VertexSet > |
41 | void test_vertex_bundle(Graph& g, VertexSet const& verts, boost::mpl::true_) |
42 | { |
43 | using namespace boost; |
44 | BOOST_CONCEPT_ASSERT((GraphConcept< Graph >)); |
45 | typedef typename graph_traits< Graph >::vertex_descriptor Vertex; |
46 | BOOST_CONCEPT_ASSERT( |
47 | (PropertyGraphConcept< Graph, Vertex, vertex_bundle_t >)); |
48 | |
49 | // Test bundling via the graph object on the lollipop vertex. |
50 | Vertex v = verts[5]; |
51 | VertexBundle& b = g[v]; |
52 | b.value = 10; |
53 | BOOST_ASSERT(g[v].value == 10); |
54 | |
55 | // Test bundling via the property map. |
56 | typedef typename property_map< Graph, int VertexBundle::* >::type BundleMap; |
57 | BOOST_CONCEPT_ASSERT((ReadWritePropertyMapConcept< BundleMap, Vertex >)); |
58 | BundleMap map = get(&VertexBundle::value, g); |
59 | put(map, v, 5); |
60 | BOOST_ASSERT(get(map, v) == 5); |
61 | |
62 | typedef typename property_map< Graph, int VertexBundle::* >::const_type |
63 | ConstBundleMap; |
64 | BOOST_CONCEPT_ASSERT( |
65 | (ReadablePropertyMapConcept< ConstBundleMap, Vertex >)); |
66 | ConstBundleMap cmap = get(&VertexBundle::value, (Graph const&)g); |
67 | BOOST_ASSERT(get(cmap, v) == 5); |
68 | } |
69 | |
70 | template < typename Graph, typename VertexSet > |
71 | void test_vertex_bundle(Graph&, VertexSet const&, boost::mpl::false_) |
72 | { |
73 | } |
74 | //@} |
75 | |
76 | /** @name Test Edge Bundle |
77 | * Exercise the edge bundle. Note that this is expected to be of type |
78 | * EdgeBundle. |
79 | */ |
80 | //@{ |
81 | template < typename Graph, typename VertexSet > |
82 | void test_edge_bundle(Graph& g, VertexSet const& verts, boost::mpl::true_) |
83 | { |
84 | using namespace boost; |
85 | BOOST_CONCEPT_ASSERT((GraphConcept< Graph >)); |
86 | typedef typename boost::graph_traits< Graph >::edge_descriptor Edge; |
87 | BOOST_CONCEPT_ASSERT((PropertyGraphConcept< Graph, Edge, edge_bundle_t >)); |
88 | |
89 | std::cout << "...test_edge_bundle\n" ; |
90 | |
91 | // Test bundling via the graph object on the lollipop edge. |
92 | Edge e = boost::edge(verts[5], verts[3], g).first; |
93 | EdgeBundle& b = g[e]; |
94 | b.value = 10; |
95 | BOOST_ASSERT(g[e].value == 10); |
96 | |
97 | // Test bundling via the property map. |
98 | typedef typename boost::property_map< Graph, int EdgeBundle::* >::type |
99 | BundleMap; |
100 | BOOST_CONCEPT_ASSERT((ReadWritePropertyMapConcept< BundleMap, Edge >)); |
101 | BundleMap map = get(&EdgeBundle::value, g); |
102 | put(map, e, 5); |
103 | BOOST_ASSERT(get(map, e) == 5); |
104 | |
105 | typedef typename boost::property_map< Graph, int EdgeBundle::* >::const_type |
106 | ConstBundleMap; |
107 | BOOST_CONCEPT_ASSERT((ReadablePropertyMapConcept< BundleMap, Edge >)); |
108 | ConstBundleMap cmap = get(&EdgeBundle::value, (Graph const&)g); |
109 | BOOST_ASSERT(get(cmap, e) == 5); |
110 | } |
111 | |
112 | template < typename Graph, typename VertexSet > |
113 | void test_edge_bundle(Graph&, VertexSet const&, boost::mpl::false_) |
114 | { |
115 | } |
116 | //@} |
117 | |
118 | /** |
119 | * Test the properties of a graph. Basically, we expect these to be one of |
120 | * bundled or not. This test could also be expanded to test non-bundled |
121 | * properties. This just bootstraps the tests. |
122 | */ |
123 | template < typename Graph, typename VertexSet > |
124 | void test_properties(Graph& g, VertexSet const& verts) |
125 | { |
126 | using namespace boost; |
127 | |
128 | typename has_bundled_graph_property< Graph >::type graph_bundled; |
129 | typename has_bundled_vertex_property< Graph >::type vertex_bundled; |
130 | typename has_bundled_edge_property< Graph >::type edge_bundled; |
131 | |
132 | test_graph_bundle(g, graph_bundled); |
133 | test_vertex_bundle(g, verts, vertex_bundled); |
134 | test_edge_bundle(g, verts, edge_bundled); |
135 | } |
136 | //@} |
137 | |
138 | #endif |
139 | |