test_properties.hpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. #ifndef TEST_PROPERTIES_HPP
  7. #define TEST_PROPERTIES_HPP
  8. #include <boost/concept/assert.hpp>
  9. template<typename T> T const& as_const(T& x) { return x; }
  10. template<typename T> void ignore(T const&) { }
  11. template<typename Graph>
  12. void test_graph_bundle(Graph& g, boost::mpl::true_) {
  13. using namespace boost;
  14. std::cout << "...test_graph_bundle\n";
  15. GraphBundle& b1 = g[graph_bundle];
  16. GraphBundle& b2 = get_property(g);
  17. ignore(b1); ignore(b2);
  18. GraphBundle const& cb1 = ::as_const(g)[graph_bundle];
  19. GraphBundle const& cb2 = get_property(g);
  20. ignore(cb1); ignore(cb2);
  21. }
  22. template<typename Graph>
  23. void test_graph_bundle(Graph& g, boost::mpl::false_)
  24. { }
  25. /** @name Test Vertex Bundle
  26. * Exercise the vertex bundle. Note that this is expected to be of type
  27. * VertexBundle.
  28. */
  29. //@{
  30. template <typename Graph, typename VertexSet>
  31. void test_vertex_bundle(Graph& g, VertexSet const& verts, boost::mpl::true_) {
  32. using namespace boost;
  33. BOOST_CONCEPT_ASSERT((GraphConcept<Graph>));
  34. typedef typename graph_traits<Graph>::vertex_descriptor Vertex;
  35. BOOST_CONCEPT_ASSERT((PropertyGraphConcept<Graph, Vertex, vertex_bundle_t>));
  36. // Test bundling via the graph object on the lollipop vertex.
  37. Vertex v = verts[5];
  38. VertexBundle& b = g[v];
  39. b.value = 10;
  40. BOOST_ASSERT(g[v].value == 10);
  41. // Test bundling via the property map.
  42. typedef typename property_map<Graph, int VertexBundle::*>::type BundleMap;
  43. BOOST_CONCEPT_ASSERT((ReadWritePropertyMapConcept<BundleMap, Vertex>));
  44. BundleMap map = get(&VertexBundle::value, g);
  45. put(map, v, 5);
  46. BOOST_ASSERT(get(map, v) == 5);
  47. typedef typename property_map<Graph, int VertexBundle::*>::const_type ConstBundleMap;
  48. BOOST_CONCEPT_ASSERT((ReadablePropertyMapConcept<ConstBundleMap, Vertex>));
  49. ConstBundleMap cmap = get(&VertexBundle::value, (Graph const&)g);
  50. BOOST_ASSERT(get(cmap, v) == 5);
  51. }
  52. template <typename Graph, typename VertexSet>
  53. void test_vertex_bundle(Graph&, VertexSet const&, boost::mpl::false_)
  54. { }
  55. //@}
  56. /** @name Test Edge Bundle
  57. * Exercise the edge bundle. Note that this is expected to be of type
  58. * EdgeBundle.
  59. */
  60. //@{
  61. template <typename Graph, typename VertexSet>
  62. void test_edge_bundle(Graph& g, VertexSet const& verts, boost::mpl::true_) {
  63. using namespace boost;
  64. BOOST_CONCEPT_ASSERT((GraphConcept<Graph>));
  65. typedef typename boost::graph_traits<Graph>::edge_descriptor Edge;
  66. BOOST_CONCEPT_ASSERT((PropertyGraphConcept<Graph, Edge, edge_bundle_t>));
  67. std::cout << "...test_edge_bundle\n";
  68. // Test bundling via the graph object on the lollipop edge.
  69. Edge e = boost::edge(verts[5], verts[3], g).first;
  70. EdgeBundle& b = g[e];
  71. b.value = 10;
  72. BOOST_ASSERT(g[e].value == 10);
  73. // Test bundling via the property map.
  74. typedef typename boost::property_map<Graph, int EdgeBundle::*>::type BundleMap;
  75. BOOST_CONCEPT_ASSERT((ReadWritePropertyMapConcept<BundleMap, Edge>));
  76. BundleMap map = get(&EdgeBundle::value, g);
  77. put(map, e, 5);
  78. BOOST_ASSERT(get(map, e) == 5);
  79. typedef typename boost::property_map<Graph, int EdgeBundle::*>::const_type ConstBundleMap;
  80. BOOST_CONCEPT_ASSERT((ReadablePropertyMapConcept<BundleMap, Edge>));
  81. ConstBundleMap cmap = get(&EdgeBundle::value, (Graph const&)g);
  82. BOOST_ASSERT(get(cmap, e) == 5);
  83. }
  84. template <typename Graph, typename VertexSet>
  85. void test_edge_bundle(Graph&, VertexSet const&, boost::mpl::false_)
  86. { }
  87. //@}
  88. /**
  89. * Test the properties of a graph. Basically, we expect these to be one of
  90. * bundled or not. This test could also be expanded to test non-bundled
  91. * properties. This just bootstraps the tests.
  92. */
  93. template <typename Graph, typename VertexSet>
  94. void test_properties(Graph& g, VertexSet const& verts) {
  95. using namespace boost;
  96. typename has_bundled_graph_property<Graph>::type graph_bundled;
  97. typename has_bundled_vertex_property<Graph>::type vertex_bundled;
  98. typename has_bundled_edge_property<Graph>::type edge_bundled;
  99. test_graph_bundle(g, graph_bundled);
  100. test_vertex_bundle(g, verts, vertex_bundled);
  101. test_edge_bundle(g, verts, edge_bundled);
  102. }
  103. //@}
  104. #endif