From: Bill Wendling Date: Thu, 8 Jan 2009 09:31:36 +0000 (+0000) Subject: Some generic clean-ups. Also make the StringMapEntryInitializer specialization apply... X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=6b223d71e5e5e123137f0f056541de4212f5c878;p=oota-llvm.git Some generic clean-ups. Also make the StringMapEntryInitializer specialization apply only to the tests that are actually testing it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@61923 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/unittests/ADT/StringMapTest.cpp b/unittests/ADT/StringMapTest.cpp index bceff19c12d..9f9f2e4c795 100644 --- a/unittests/ADT/StringMapTest.cpp +++ b/unittests/ADT/StringMapTest.cpp @@ -11,19 +11,6 @@ #include "llvm/ADT/StringMap.h" using namespace llvm; -namespace llvm { - -template <> -class StringMapEntryInitializer { -public: - template - static void Initialize(StringMapEntry &T, InitTy InitVal) { - T.second = InitVal; - } -}; - -} - namespace { // Test fixture @@ -83,13 +70,13 @@ const char* StringMapTest::testKeyFirst = testKey; const char* StringMapTest::testKeyLast = testKey + sizeof(testKey) - 1; const std::string StringMapTest::testKeyStr(testKey); -// Empty map tests +// Empty map tests. TEST_F(StringMapTest, EmptyMapTest) { SCOPED_TRACE("EmptyMapTest"); assertEmptyMap(); } -// Constant map tests +// Constant map tests. TEST_F(StringMapTest, ConstEmptyMapTest) { const StringMap& constTestMap = testMap; @@ -106,18 +93,18 @@ TEST_F(StringMapTest, ConstEmptyMapTest) { EXPECT_EQ(0u, constTestMap.count(testKeyStr)); EXPECT_TRUE(constTestMap.find(testKey) == constTestMap.end()); EXPECT_TRUE(constTestMap.find(testKeyFirst, testKeyLast) == - constTestMap.end()); + constTestMap.end()); EXPECT_TRUE(constTestMap.find(testKeyStr) == constTestMap.end()); } -// A map with a single entry +// A map with a single entry. TEST_F(StringMapTest, SingleEntryMapTest) { SCOPED_TRACE("SingleEntryMapTest"); testMap[testKey] = testValue; assertSingleItemMap(); } -// Test clear() method +// Test clear() method. TEST_F(StringMapTest, ClearTest) { SCOPED_TRACE("ClearTest"); testMap[testKey] = testValue; @@ -125,7 +112,7 @@ TEST_F(StringMapTest, ClearTest) { assertEmptyMap(); } -// Test erase(iterator) method +// Test erase(iterator) method. TEST_F(StringMapTest, EraseIteratorTest) { SCOPED_TRACE("EraseIteratorTest"); testMap[testKey] = testValue; @@ -133,7 +120,7 @@ TEST_F(StringMapTest, EraseIteratorTest) { assertEmptyMap(); } -// Test erase(value) method +// Test erase(value) method. TEST_F(StringMapTest, EraseValueTest) { SCOPED_TRACE("EraseValueTest"); testMap[testKey] = testValue; @@ -141,7 +128,7 @@ TEST_F(StringMapTest, EraseValueTest) { assertEmptyMap(); } -// Test inserting two values and erasing one +// Test inserting two values and erasing one. TEST_F(StringMapTest, InsertAndEraseTest) { SCOPED_TRACE("InsertAndEraseTest"); testMap[testKey] = testValue; @@ -150,30 +137,7 @@ TEST_F(StringMapTest, InsertAndEraseTest) { assertSingleItemMap(); } -// Test StringMapEntry::Create() method. -// DISABLED because this fails without a StringMapEntryInitializer, and -// I can't get it to compile with one. -TEST_F(StringMapTest, StringMapEntryTest) { - MallocAllocator A; - StringMap::value_type* entry = - StringMap::value_type::Create( - testKeyFirst, testKeyLast, A, 1u); - EXPECT_STREQ(testKey, entry->first()); - EXPECT_EQ(1u, entry->second); -} - -// Test insert() method -// DISABLED because this fails without a StringMapEntryInitializer, and -// I can't get it to compile with one. -TEST_F(StringMapTest, InsertTest) { - SCOPED_TRACE("InsertTest"); - testMap.insert( - StringMap::value_type::Create( - testKeyFirst, testKeyLast, testMap.getAllocator(), 1u)); - assertSingleItemMap(); -} - -// A more complex iteration test +// A more complex iteration test. TEST_F(StringMapTest, IterationTest) { bool visited[100]; @@ -200,4 +164,39 @@ TEST_F(StringMapTest, IterationTest) { } } +} // end anonymous namespace + +namespace llvm { + +template <> +class StringMapEntryInitializer { +public: + template + static void Initialize(StringMapEntry &T, InitTy InitVal) { + T.second = InitVal; + } +}; + +} // end llvm namespace + +namespace { + +// Test StringMapEntry::Create() method. +TEST_F(StringMapTest, StringMapEntryTest) { + StringMap::value_type* entry = + StringMap::value_type::Create( + testKeyFirst, testKeyLast, 1u); + EXPECT_STREQ(testKey, entry->first()); + EXPECT_EQ(1u, entry->second); +} + +// Test insert() method. +TEST_F(StringMapTest, InsertTest) { + SCOPED_TRACE("InsertTest"); + testMap.insert( + StringMap::value_type::Create( + testKeyFirst, testKeyLast, testMap.getAllocator(), 1u)); + assertSingleItemMap(); } + +} // end anonymous namespace