diff options
author | Mehdi Amini <mehdi.amini@apple.com> | 2016-03-25 16:36:00 +0000 |
---|---|---|
committer | Mehdi Amini <mehdi.amini@apple.com> | 2016-03-25 16:36:00 +0000 |
commit | 169eda643cc6de94259ba3d899058e23a1b4046d (patch) | |
tree | 82dbd6ac4ad77c4540068815e903f1b0d789f08a | |
parent | c1384c138c0000368ea6751fc7b6ac164cae849b (diff) | |
download | bcm5719-llvm-169eda643cc6de94259ba3d899058e23a1b4046d.tar.gz bcm5719-llvm-169eda643cc6de94259ba3d899058e23a1b4046d.zip |
Improve StringMap unittests: reintroduce move count, but shield against std::pair internals
From: Mehdi Amini <mehdi.amini@apple.com>
llvm-svn: 264418
-rw-r--r-- | llvm/unittests/ADT/StringMapTest.cpp | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/llvm/unittests/ADT/StringMapTest.cpp b/llvm/unittests/ADT/StringMapTest.cpp index 07b4f48596d..4deb48c7ac1 100644 --- a/llvm/unittests/ADT/StringMapTest.cpp +++ b/llvm/unittests/ADT/StringMapTest.cpp @@ -391,14 +391,21 @@ TEST(StringMapCustomTest, InitialSizeTest) { for (auto Size : {1, 32, 67}) { StringMap<CountCtorCopyAndMove> Map(Size); auto NumBuckets = Map.getNumBuckets(); + + // Prepare the elts in a vector. We do this as a pre-step to shield us + // against the internals of std::pair which can introduce spurious move/copy + std::vector<std::pair<std::string, CountCtorCopyAndMove>> Elts; + for (int i = 0; i < Size; ++i) + Elts.emplace_back(Twine(i).str(), CountCtorCopyAndMove()); + CountCtorCopyAndMove::Move = 0; CountCtorCopyAndMove::Copy = 0; for (int i = 0; i < Size; ++i) - Map.insert(std::make_pair(Twine(i).str(), CountCtorCopyAndMove())); - // This relies on move-construction elision, and cannot be reliably tested. - // EXPECT_EQ((unsigned)Size * 3, CountCtorCopyAndMove::Move); - // No copy is expected. - EXPECT_EQ(0u, CountCtorCopyAndMove::Copy); + Map.insert(Elts[i]); + // After the inital copy, the map will move the Elts in the Entry. + EXPECT_EQ((unsigned)Size, CountCtorCopyAndMove::Move); + // We copy once the pair from the Elts vector + EXPECT_EQ((unsigned)Size, CountCtorCopyAndMove::Copy); // Check that the map didn't grow EXPECT_EQ(Map.getNumBuckets(), NumBuckets); } |