| 1 |
//=== llvm/unittest/ADT/DepthFirstIteratorTest.cpp - DFS iterator tests ---===// |
| 2 |
// |
| 3 |
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 |
// See https://llvm.org/LICENSE.txt for license information. |
| 5 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 |
// |
| 7 |
//===----------------------------------------------------------------------===// |
| 8 |
|
| 9 |
#include "llvm/ADT/DepthFirstIterator.h" |
| 10 |
#include "TestGraph.h" |
| 11 |
#include "gtest/gtest.h" |
| 12 |
|
| 13 |
using namespace llvm; |
| 14 |
|
| 15 |
namespace llvm { |
| 16 |
|
| 17 |
template <typename T> struct CountedSet { |
| 18 |
typedef typename SmallPtrSet<T, 4>::iterator iterator; |
| 19 |
|
| 20 |
SmallPtrSet<T, 4> S; |
| 21 |
int InsertVisited = 0; |
| 22 |
|
| 23 |
std::pair<iterator, bool> insert(const T &Item) { |
| 24 |
InsertVisited++; |
| 25 |
return S.insert(Item); |
| 26 |
} |
| 27 |
|
| 28 |
size_t count(const T &Item) const { return S.count(Item); } |
| 29 |
|
| 30 |
void completed(T) { } |
| 31 |
}; |
| 32 |
|
| 33 |
template <typename T> class df_iterator_storage<CountedSet<T>, true> { |
| 34 |
public: |
| 35 |
df_iterator_storage(CountedSet<T> &VSet) : Visited(VSet) {} |
| 36 |
|
| 37 |
CountedSet<T> &Visited; |
| 38 |
}; |
| 39 |
|
| 40 |
TEST(DepthFirstIteratorTest, ActuallyUpdateIterator) { |
| 41 |
typedef CountedSet<Graph<3>::NodeType *> StorageT; |
| 42 |
typedef df_iterator<Graph<3>, StorageT, true> DFIter; |
| 43 |
|
| 44 |
Graph<3> G; |
| 45 |
G.AddEdge(0, 1); |
| 46 |
G.AddEdge(0, 2); |
| 47 |
StorageT S; |
| 48 |
for (auto N : make_range(DFIter::begin(G, S), DFIter::end(G, S))) |
| 49 |
(void)N; |
| 50 |
|
| 51 |
EXPECT_EQ(3, S.InsertVisited); |
| 52 |
} |
| 53 |
} |