// (C) Copyright 2009 Andrew Sutton // // Use, modification and distribution are subject to the // Boost Software License, Version 1.0 (See accompanying file // LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) #ifndef TEST_PROPERTIES_HPP #define TEST_PROPERTIES_HPP #include template T const& as_const(T& x) { return x; } template void ignore(T const&) { } template void test_graph_bundle(Graph& g, boost::mpl::true_) { using namespace boost; std::cout << "...test_graph_bundle\n"; typedef typename graph_property_type::type Property; typedef typename graph_bundle_type::type Bundle; GraphBundle& b1 = g[graph_bundle]; GraphBundle& b2 = get_property(g); ignore(b1); ignore(b2); GraphBundle const& cb1 = as_const(g)[graph_bundle]; GraphBundle const& cb2 = get_property(g); ignore(cb1); ignore(cb2); } template void test_graph_bundle(Graph& g, boost::mpl::false_) { } /** @name Test Vertex Bundle * Exercise the vertex bundle. Note that this is expected to be of type * VertexBundle. */ //@{ template void test_vertex_bundle(Graph& g, VertexSet const& verts, boost::mpl::true_) { using namespace boost; BOOST_CONCEPT_ASSERT((GraphConcept)); typedef typename graph_traits::vertex_descriptor Vertex; BOOST_CONCEPT_ASSERT((PropertyGraphConcept)); // Test bundling via the graph object on the lollipop vertex. Vertex v = verts[5]; VertexBundle& b = g[v]; b.value = 10; BOOST_ASSERT(g[v].value == 10); // Test bundling via the property map. typedef typename property_map::type BundleMap; BOOST_CONCEPT_ASSERT((ReadWritePropertyMapConcept)); BundleMap map = get(&VertexBundle::value, g); put(map, v, 5); BOOST_ASSERT(get(map, v) == 5); typedef typename property_map::const_type ConstBundleMap; BOOST_CONCEPT_ASSERT((ReadablePropertyMapConcept)); ConstBundleMap cmap = get(&VertexBundle::value, (Graph const&)g); BOOST_ASSERT(get(cmap, v) == 5); } template void test_vertex_bundle(Graph&, VertexSet const&, boost::mpl::false_) { } //@} /** @name Test Edge Bundle * Exercise the edge bundle. Note that this is expected to be of type * EdgeBundle. */ //@{ template void test_edge_bundle(Graph& g, VertexSet const& verts, boost::mpl::true_) { using namespace boost; BOOST_CONCEPT_ASSERT((GraphConcept)); typedef typename boost::graph_traits::edge_descriptor Edge; BOOST_CONCEPT_ASSERT((PropertyGraphConcept)); std::cout << "...test_edge_bundle\n"; // Test bundling via the graph object on the lollipop edge. Edge e = boost::edge(verts[5], verts[3], g).first; EdgeBundle& b = g[e]; b.value = 10; BOOST_ASSERT(g[e].value == 10); // Test bundling via the property map. typedef typename boost::property_map::type BundleMap; BOOST_CONCEPT_ASSERT((ReadWritePropertyMapConcept)); BundleMap map = get(&EdgeBundle::value, g); put(map, e, 5); BOOST_ASSERT(get(map, e) == 5); typedef typename boost::property_map::const_type ConstBundleMap; BOOST_CONCEPT_ASSERT((ReadablePropertyMapConcept)); ConstBundleMap cmap = get(&EdgeBundle::value, (Graph const&)g); BOOST_ASSERT(get(cmap, e) == 5); } template void test_edge_bundle(Graph&, VertexSet const&, boost::mpl::false_) { } //@} /** * Test the properties of a graph. Basically, we expect these to be one of * bundled or not. This test could also be expanded to test non-bundled * properties. This just bootstraps the tests. */ template void test_properties(Graph& g, VertexSet const& verts) { using namespace boost; typename has_bundled_graph_property::type graph_bundled; typename has_bundled_vertex_property::type vertex_bundled; typename has_bundled_edge_property::type edge_bundled; test_graph_bundle(g, graph_bundled); test_vertex_bundle(g, verts, vertex_bundled); test_edge_bundle(g, verts, edge_bundled); } //@} #endif