|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r50231 - trunk/libs/graph/test
From: asutton_at_[hidden]
Date: 2008-12-10 10:46:05
Author: asutton
Date: 2008-12-10 10:46:05 EST (Wed, 10 Dec 2008)
New Revision: 50231
URL: http://svn.boost.org/trac/boost/changeset/50231
Log:
Added tests for out edge and adjacency components under add_vertex.
For some reason, adjacency_iterators seem to remain valid if no operations
on other graph types are executed prior to their use, which is completely
at odds with what I would expect.
Text files modified:
trunk/libs/graph/test/adj_list_invalidation.cpp | 99 ++++++++++++++++++++++++++++++++-------
1 files changed, 80 insertions(+), 19 deletions(-)
Modified: trunk/libs/graph/test/adj_list_invalidation.cpp
==============================================================================
--- trunk/libs/graph/test/adj_list_invalidation.cpp (original)
+++ trunk/libs/graph/test/adj_list_invalidation.cpp 2008-12-10 10:46:05 EST (Wed, 10 Dec 2008)
@@ -1,7 +1,10 @@
#include <iostream>
+#include <string>
#include <boost/graph/adjacency_list.hpp>
+#include "../../../../../gpld/common/typestr.hpp"
+
using namespace std;
using namespace boost;
@@ -13,9 +16,22 @@
{
// Build a simple (barbell) graph.
typedef typename graph_traits<Graph>::vertex_descriptor Vertex;
- Vertex u = add_vertex(g);
- Vertex v = add_vertex(g);
- add_edge(u, v, g);
+ Vertex u = add_vertex(10, g);
+ Vertex v = add_vertex(20, g);
+ add_edge(u, v, 100, g);
+}
+
+// Invalid iterators and descriptors will cause a segfault.
+template <typename Graph, typename Iterator, typename Descriptor>
+void test(Graph& g, Iterator i, Descriptor d, string const& str)
+{
+ int x;
+ cout << "... " << str << " iter" << endl;
+ x = g[*i];
+// cout << "... " << x << endl;
+ cout << "... " << str << " desc" << endl;
+ x = g[d];
+// cout << "... " << x << endl;
}
template <typename Graph>
@@ -33,11 +49,7 @@
// Add a vertex, see what breaks.
add_vertex(g);
- int x;
- cout << "...edge iter" << endl;
- x = g[*i];
- cout << "...edge desc" << endl;
- x = g[e];
+ test(g, i, e, "edges");
};
template <typename Graph>
@@ -55,25 +67,74 @@
// Add a vertex, see what breaks.
add_vertex(g);
- int x;
- cout << "...vert iter" << endl;
- x = g[*i];
- cout << "...vert desc" << endl;
- x = g[v];
+ test(g, i, v, "vertices");
+}
+
+template <typename Graph>
+void invalidate_out_edges()
+{
+ typedef typename graph_traits<Graph>::edge_descriptor Edge;
+ typedef typename graph_traits<Graph>::out_edge_iterator OutIterator;
+
+ Graph g;
+ make_graph(g);
+
+ // The actual test. These are valid here.
+ OutIterator i = out_edges(*vertices(g).first, g).first;
+ Edge e = *i;
+
+ // Add a vertex, see what breaks.
+ add_vertex(g);
+ test(g, i, e, "out edges");
}
+template <typename Graph>
+void invalidate_adj_verts()
+{
+ typedef typename graph_traits<Graph>::vertex_descriptor Vertex;
+ typedef typename graph_traits<Graph>::adjacency_iterator AdjIterator;
+
+ Graph g;
+ make_graph(g);
+
+ // The actual test. These are valid here.
+ AdjIterator i = adjacent_vertices(*vertices(g).first, g).first;
+ Vertex v = *i;
+
+ // Add a vertex, see what breaks.
+ add_vertex(g);
+ test(g, i, v, "adjacent vertices");
+}
+
+
int main()
{
typedef adjacency_list<vecS, vecS, undirectedS, int, int> VVU;
-// invalidate_vertices<VVU>();
-// invalidate_edges<VVU>();
+ cout << "vecS vecS undirectedS" << endl;
+ invalidate_vertices<VVU>();
+ invalidate_edges<VVU>();
+ invalidate_out_edges<VVU>();
+ invalidate_adj_verts<VVU>();
+
+ typedef adjacency_list<vecS, vecS, bidirectionalS, int, int> VVB;
+ cout << "vecS vecS bidirectionals" << endl;
+ invalidate_vertices<VVB>();
+ invalidate_edges<VVB>();
+ invalidate_out_edges<VVB>();
+ invalidate_adj_verts<VVB>();
typedef adjacency_list<vecS, vecS, directedS, int, int> VVD;
-// invalidate_vertices<VVD>();
+ cout << "vecS vecS directedS" << endl;
+ invalidate_vertices<VVD>();
// invalidate_edges<VVD>();
+// invalidate_out_edges<VVD>();
+// invalidate_adj_verts<VVD>();
- typedef adjacency_list<vecS, vecS, bidirectionalS, int, int> VVB;
-// invalidate_vertices<VVB>();
-// invalidate_edges<VVB>();
+ typedef adjacency_list<vecS, listS, directedS, int, int> VLD;
+ cout << "vecS listS directedS" << endl;
+ invalidate_vertices<VLD>();
+ invalidate_edges<VLD>();
+ invalidate_out_edges<VLD>();
+ invalidate_adj_verts<VLD>();
}
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk