mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-10-19 02:52:53 +02:00
SmallPtrSetTest: Check that iterators are still valid after erase()
llvm-svn: 259151
This commit is contained in:
parent
0ba61fb676
commit
a51e4b9705
@ -210,3 +210,42 @@ TEST(SmallPtrSetTest, SwapTest) {
|
||||
EXPECT_TRUE(a.count(&buf[1]));
|
||||
EXPECT_TRUE(a.count(&buf[3]));
|
||||
}
|
||||
|
||||
void checkEraseAndIterators(SmallPtrSetImpl<int*> &S) {
|
||||
int buf[3];
|
||||
|
||||
S.insert(&buf[0]);
|
||||
S.insert(&buf[1]);
|
||||
S.insert(&buf[2]);
|
||||
|
||||
// Iterators must still be valid after erase() calls;
|
||||
auto B = S.begin();
|
||||
auto M = std::next(B);
|
||||
auto E = S.end();
|
||||
EXPECT_TRUE(*B == &buf[0] || *B == &buf[1] || *B == &buf[2]);
|
||||
EXPECT_TRUE(*M == &buf[0] || *M == &buf[1] || *M == &buf[2]);
|
||||
EXPECT_TRUE(*B != *M);
|
||||
int *Removable = *std::next(M);
|
||||
// No iterator points to Removable now.
|
||||
EXPECT_TRUE(Removable == &buf[0] || Removable == &buf[1] ||
|
||||
Removable == &buf[2]);
|
||||
EXPECT_TRUE(Removable != *B && Removable != *M);
|
||||
|
||||
S.erase(Removable);
|
||||
|
||||
// B,M,E iterators should still be valid
|
||||
EXPECT_EQ(B, S.begin());
|
||||
EXPECT_EQ(M, std::next(B));
|
||||
EXPECT_EQ(E, S.end());
|
||||
EXPECT_EQ(std::next(M), E);
|
||||
}
|
||||
|
||||
TEST(SmallPtrSetTest, EraseTest) {
|
||||
// Test when set stays small.
|
||||
SmallPtrSet<int *, 8> B;
|
||||
checkEraseAndIterators(B);
|
||||
|
||||
// Test when set grows big.
|
||||
SmallPtrSet<int *, 2> A;
|
||||
checkEraseAndIterators(A);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user