File: test_properties.hpp

package info (click to toggle)
boost1.88 1.88.0-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 576,932 kB
  • sloc: cpp: 4,149,234; xml: 136,789; ansic: 35,092; python: 33,910; asm: 5,698; sh: 4,604; ada: 1,681; makefile: 1,633; pascal: 1,139; perl: 1,124; sql: 640; yacc: 478; ruby: 271; java: 77; lisp: 24; csh: 6
file content (138 lines) | stat: -rw-r--r-- 4,475 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// (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 <boost/concept/assert.hpp>

template < typename T > T const& as_const(T& x) { return x; }
template < typename T > void ignore(T const&) {}

template < typename Graph > void test_graph_bundle(Graph& g, boost::mpl::true_)
{
    using namespace boost;
    std::cout << "...test_graph_bundle\n";

    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 < typename Graph > 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 < typename Graph, typename VertexSet >
void test_vertex_bundle(Graph& g, VertexSet const& verts, boost::mpl::true_)
{
    using namespace boost;
    BOOST_CONCEPT_ASSERT((GraphConcept< Graph >));
    typedef typename graph_traits< Graph >::vertex_descriptor Vertex;
    BOOST_CONCEPT_ASSERT(
        (PropertyGraphConcept< Graph, Vertex, vertex_bundle_t >));

    // 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< Graph, int VertexBundle::* >::type BundleMap;
    BOOST_CONCEPT_ASSERT((ReadWritePropertyMapConcept< BundleMap, Vertex >));
    BundleMap map = get(&VertexBundle::value, g);
    put(map, v, 5);
    BOOST_ASSERT(get(map, v) == 5);

    typedef typename property_map< Graph, int VertexBundle::* >::const_type
        ConstBundleMap;
    BOOST_CONCEPT_ASSERT(
        (ReadablePropertyMapConcept< ConstBundleMap, Vertex >));
    ConstBundleMap cmap = get(&VertexBundle::value, (Graph const&)g);
    BOOST_ASSERT(get(cmap, v) == 5);
}

template < typename Graph, typename VertexSet >
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 < typename Graph, typename VertexSet >
void test_edge_bundle(Graph& g, VertexSet const& verts, boost::mpl::true_)
{
    using namespace boost;
    BOOST_CONCEPT_ASSERT((GraphConcept< Graph >));
    typedef typename boost::graph_traits< Graph >::edge_descriptor Edge;
    BOOST_CONCEPT_ASSERT((PropertyGraphConcept< Graph, Edge, edge_bundle_t >));

    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< Graph, int EdgeBundle::* >::type
        BundleMap;
    BOOST_CONCEPT_ASSERT((ReadWritePropertyMapConcept< BundleMap, Edge >));
    BundleMap map = get(&EdgeBundle::value, g);
    put(map, e, 5);
    BOOST_ASSERT(get(map, e) == 5);

    typedef typename boost::property_map< Graph, int EdgeBundle::* >::const_type
        ConstBundleMap;
    BOOST_CONCEPT_ASSERT((ReadablePropertyMapConcept< BundleMap, Edge >));
    ConstBundleMap cmap = get(&EdgeBundle::value, (Graph const&)g);
    BOOST_ASSERT(get(cmap, e) == 5);
}

template < typename Graph, typename VertexSet >
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 < typename Graph, typename VertexSet >
void test_properties(Graph& g, VertexSet const& verts)
{
    using namespace boost;

    typename has_bundled_graph_property< Graph >::type graph_bundled;
    typename has_bundled_vertex_property< Graph >::type vertex_bundled;
    typename has_bundled_edge_property< Graph >::type edge_bundled;

    test_graph_bundle(g, graph_bundled);
    test_vertex_bundle(g, verts, vertex_bundled);
    test_edge_bundle(g, verts, edge_bundled);
}
//@}

#endif