]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 | ||
f67539c2 TL |
12 | template < typename T > T const& as_const(T& x) { return x; } |
13 | template < typename T > void ignore(T const&) {} | |
7c673cae | 14 | |
f67539c2 TL |
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"; | |
7c673cae | 19 | |
f67539c2 TL |
20 | GraphBundle& b1 = g[graph_bundle]; |
21 | GraphBundle& b2 = get_property(g); | |
22 | ignore(b1); | |
23 | ignore(b2); | |
7c673cae | 24 | |
f67539c2 TL |
25 | GraphBundle const& cb1 = ::as_const(g)[graph_bundle]; |
26 | GraphBundle const& cb2 = get_property(g); | |
27 | ignore(cb1); | |
28 | ignore(cb2); | |
7c673cae FG |
29 | } |
30 | ||
f67539c2 TL |
31 | template < typename Graph > void test_graph_bundle(Graph& g, boost::mpl::false_) |
32 | { | |
33 | } | |
7c673cae FG |
34 | |
35 | /** @name Test Vertex Bundle | |
36 | * Exercise the vertex bundle. Note that this is expected to be of type | |
37 | * VertexBundle. | |
38 | */ | |
39 | //@{ | |
f67539c2 TL |
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 >)); | |
7c673cae FG |
48 | |
49 | // Test bundling via the graph object on the lollipop vertex. | |
f67539c2 TL |
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); | |
7c673cae FG |
68 | } |
69 | ||
f67539c2 | 70 | template < typename Graph, typename VertexSet > |
7c673cae | 71 | void test_vertex_bundle(Graph&, VertexSet const&, boost::mpl::false_) |
f67539c2 TL |
72 | { |
73 | } | |
7c673cae FG |
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 | //@{ | |
f67539c2 TL |
81 | template < typename Graph, typename VertexSet > |
82 | void test_edge_bundle(Graph& g, VertexSet const& verts, boost::mpl::true_) | |
83 | { | |
7c673cae | 84 | using namespace boost; |
f67539c2 TL |
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 >)); | |
7c673cae FG |
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. | |
f67539c2 TL |
98 | typedef typename boost::property_map< Graph, int EdgeBundle::* >::type |
99 | BundleMap; | |
100 | BOOST_CONCEPT_ASSERT((ReadWritePropertyMapConcept< BundleMap, Edge >)); | |
7c673cae FG |
101 | BundleMap map = get(&EdgeBundle::value, g); |
102 | put(map, e, 5); | |
103 | BOOST_ASSERT(get(map, e) == 5); | |
104 | ||
f67539c2 TL |
105 | typedef typename boost::property_map< Graph, int EdgeBundle::* >::const_type |
106 | ConstBundleMap; | |
107 | BOOST_CONCEPT_ASSERT((ReadablePropertyMapConcept< BundleMap, Edge >)); | |
7c673cae FG |
108 | ConstBundleMap cmap = get(&EdgeBundle::value, (Graph const&)g); |
109 | BOOST_ASSERT(get(cmap, e) == 5); | |
110 | } | |
111 | ||
f67539c2 | 112 | template < typename Graph, typename VertexSet > |
7c673cae | 113 | void test_edge_bundle(Graph&, VertexSet const&, boost::mpl::false_) |
f67539c2 TL |
114 | { |
115 | } | |
7c673cae FG |
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 | */ | |
f67539c2 TL |
123 | template < typename Graph, typename VertexSet > |
124 | void test_properties(Graph& g, VertexSet const& verts) | |
125 | { | |
126 | using namespace boost; | |
7c673cae | 127 | |
f67539c2 TL |
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; | |
7c673cae | 131 | |
f67539c2 TL |
132 | test_graph_bundle(g, graph_bundled); |
133 | test_vertex_bundle(g, verts, vertex_bundled); | |
134 | test_edge_bundle(g, verts, edge_bundled); | |
7c673cae FG |
135 | } |
136 | //@} | |
137 | ||
138 | #endif |