X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=unittests%2FADT%2FStringMapTest.cpp;h=ea91348a5bdf730e92085d5778ad1c78b6de18bc;hb=a75ce9f5d2236d93c117e861e60e6f3f748c9555;hp=3f135f6bd7b830f633bdaf60f08e4b0904a43c58;hpb=1ed3663b49c7a00fa2bec8a70ee59fe05b9173ec;p=oota-llvm.git diff --git a/unittests/ADT/StringMapTest.cpp b/unittests/ADT/StringMapTest.cpp index 3f135f6bd7b..ea91348a5bd 100644 --- a/unittests/ADT/StringMapTest.cpp +++ b/unittests/ADT/StringMapTest.cpp @@ -9,6 +9,7 @@ #include "gtest/gtest.h" #include "llvm/ADT/StringMap.h" +#include "llvm/Support/DataTypes.h" using namespace llvm; namespace { @@ -21,7 +22,7 @@ protected: static const char testKey[]; static const uint32_t testValue; static const char* testKeyFirst; - static const char* testKeyLast; + static size_t testKeyLength; static const std::string testKeyStr; void assertEmptyMap() { @@ -34,10 +35,11 @@ protected: // Lookup tests EXPECT_EQ(0u, testMap.count(testKey)); - EXPECT_EQ(0u, testMap.count(testKeyFirst, testKeyLast)); + EXPECT_EQ(0u, testMap.count(StringRef(testKeyFirst, testKeyLength))); EXPECT_EQ(0u, testMap.count(testKeyStr)); EXPECT_TRUE(testMap.find(testKey) == testMap.end()); - EXPECT_TRUE(testMap.find(testKeyFirst, testKeyLast) == testMap.end()); + EXPECT_TRUE(testMap.find(StringRef(testKeyFirst, testKeyLength)) == + testMap.end()); EXPECT_TRUE(testMap.find(testKeyStr) == testMap.end()); } @@ -56,10 +58,11 @@ protected: // Lookup tests EXPECT_EQ(1u, testMap.count(testKey)); - EXPECT_EQ(1u, testMap.count(testKeyFirst, testKeyLast)); + EXPECT_EQ(1u, testMap.count(StringRef(testKeyFirst, testKeyLength))); EXPECT_EQ(1u, testMap.count(testKeyStr)); EXPECT_TRUE(testMap.find(testKey) == testMap.begin()); - EXPECT_TRUE(testMap.find(testKeyFirst, testKeyLast) == testMap.begin()); + EXPECT_TRUE(testMap.find(StringRef(testKeyFirst, testKeyLength)) == + testMap.begin()); EXPECT_TRUE(testMap.find(testKeyStr) == testMap.begin()); } }; @@ -67,16 +70,16 @@ protected: const char StringMapTest::testKey[] = "key"; const uint32_t StringMapTest::testValue = 1u; const char* StringMapTest::testKeyFirst = testKey; -const char* StringMapTest::testKeyLast = testKey + sizeof(testKey) - 1; +size_t StringMapTest::testKeyLength = 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; @@ -89,22 +92,22 @@ TEST_F(StringMapTest, ConstEmptyMapTest) { // Lookup tests EXPECT_EQ(0u, constTestMap.count(testKey)); - EXPECT_EQ(0u, constTestMap.count(testKeyFirst, testKeyLast)); + EXPECT_EQ(0u, constTestMap.count(StringRef(testKeyFirst, testKeyLength))); EXPECT_EQ(0u, constTestMap.count(testKeyStr)); EXPECT_TRUE(constTestMap.find(testKey) == constTestMap.end()); - EXPECT_TRUE(constTestMap.find(testKeyFirst, testKeyLast) == - constTestMap.end()); + EXPECT_TRUE(constTestMap.find(StringRef(testKeyFirst, testKeyLength)) == + 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; @@ -112,7 +115,7 @@ TEST_F(StringMapTest, ClearTest) { assertEmptyMap(); } -// Test erase(iterator) method +// Test erase(iterator) method. TEST_F(StringMapTest, EraseIteratorTest) { SCOPED_TRACE("EraseIteratorTest"); testMap[testKey] = testValue; @@ -120,7 +123,7 @@ TEST_F(StringMapTest, EraseIteratorTest) { assertEmptyMap(); } -// Test erase(value) method +// Test erase(value) method. TEST_F(StringMapTest, EraseValueTest) { SCOPED_TRACE("EraseValueTest"); testMap[testKey] = testValue; @@ -128,7 +131,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; @@ -137,29 +140,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, DISABLED_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 -// DISABLED because this fails without a StringMapEntryInitializer, and -// I can't get it to compile with one. -TEST_F(StringMapTest, DISABLED_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]; @@ -186,4 +167,41 @@ 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, testKeyFirst + testKeyLength, 1u); + EXPECT_STREQ(testKey, entry->first()); + EXPECT_EQ(1u, entry->second); + free(entry); +} + +// Test insert() method. +TEST_F(StringMapTest, InsertTest) { + SCOPED_TRACE("InsertTest"); + testMap.insert( + StringMap::value_type::Create( + testKeyFirst, testKeyFirst + testKeyLength, + testMap.getAllocator(), 1u)); + assertSingleItemMap(); } + +} // end anonymous namespace