Home | History | Annotate | Download | only in unittests
      1 //===- StringTableTest.cpp ------------------------------------------------===//
      2 //
      3 //                     The MCLinker Project
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 #include "StringTableTest.h"
     10 #include "mcld/LD/StringTable.h"
     11 #include <cstring>
     12 
     13 using namespace mcld;
     14 using namespace mcldtest;
     15 
     16 
     17 // Constructor can do set-up work for all test here.
     18 StringTableTest::StringTableTest()
     19 {
     20   // create testee. modify it if need
     21   Resolver* R = new Resolver();
     22   StrSymPool* Pool = new StrSymPool(1, 1, *R);
     23   m_pTestee = new StringTable(*Pool);
     24 }
     25 
     26 // Destructor can do clean-up work that doesn't throw exceptions here.
     27 StringTableTest::~StringTableTest()
     28 {
     29   delete m_pTestee;
     30 }
     31 
     32 // SetUp() will be called immediately before each test.
     33 void StringTableTest::SetUp()
     34 {
     35 }
     36 
     37 // TearDown() will be called immediately after each test.
     38 void StringTableTest::TearDown()
     39 {
     40 }
     41 
     42 //==========================================================================//
     43 // Testcases
     44 //
     45 TEST_F(StringTableTest, different_string_size) {
     46   int size = 127-32;
     47   for (int i = 32; i < 127; ++i) {
     48     char c[2];
     49     c[0] = i;
     50     c[1] = '\0';
     51     ASSERT_NE(m_pTestee->insert(c), c);
     52   }
     53   ASSERT_EQ(m_pTestee->size(), size);
     54 }
     55 
     56 TEST_F(StringTableTest, traverse_begin_to_end) {
     57   m_pTestee->insert("Hello");
     58   m_pTestee->insert("World");
     59   m_pTestee->insert("Media");
     60   m_pTestee->insert("Tek");
     61   StringTable::iterator it = m_pTestee->begin();
     62   ASSERT_STREQ(*it, "Hello");
     63   ++it;
     64   ASSERT_STREQ(*it, "World");
     65   ++it;
     66   ASSERT_STREQ(*it, "Media");
     67   ++it;
     68   ASSERT_STREQ(*it, "Tek");
     69   ++it;
     70   ASSERT_EQ(it, m_pTestee->end());
     71 }
     72 
     73 TEST_F(StringTableTest, null_string) {
     74   m_pTestee->insert("");
     75   ASSERT_STREQ(*(m_pTestee->begin()), "");
     76   ASSERT_EQ(m_pTestee->size(), 1);
     77 }
     78