blob: 0e3e0e66d71e0083103e27ad4d0e71d9d2127227 [file] [log] [blame]
Tim Shen608ca252016-08-22 21:59:26 +00001//=== llvm/unittest/ADT/DepthFirstIteratorTest.cpp - DFS iterator tests ---===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Tim Shen608ca252016-08-22 21:59:26 +00006//
7//===----------------------------------------------------------------------===//
8
Tim Shen608ca252016-08-22 21:59:26 +00009#include "llvm/ADT/DepthFirstIterator.h"
Chandler Carruth9a67b072017-06-06 11:06:56 +000010#include "TestGraph.h"
Tim Shen608ca252016-08-22 21:59:26 +000011#include "gtest/gtest.h"
12
13using namespace llvm;
14
15namespace llvm {
16
17template <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); }
David Callahanc1051ab2016-10-05 21:36:16 +000029
30 void completed(T) { }
Tim Shen608ca252016-08-22 21:59:26 +000031};
32
33template <typename T> class df_iterator_storage<CountedSet<T>, true> {
34public:
35 df_iterator_storage(CountedSet<T> &VSet) : Visited(VSet) {}
36
37 CountedSet<T> &Visited;
38};
39
40TEST(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}