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
13using namespace mcld;
14using namespace mcldtest;
15
16// Constructor can do set-up work for all test here.
17StringTableTest::StringTableTest() {
18  // create testee. modify it if need
19  Resolver* R = new Resolver();
20  StrSymPool* Pool = new StrSymPool(1, 1, *R);
21  m_pTestee = new StringTable(*Pool);
22}
23
24// Destructor can do clean-up work that doesn't throw exceptions here.
25StringTableTest::~StringTableTest() {
26  delete m_pTestee;
27}
28
29// SetUp() will be called immediately before each test.
30void StringTableTest::SetUp() {
31}
32
33// TearDown() will be called immediately after each test.
34void StringTableTest::TearDown() {
35}
36
37//==========================================================================//
38// Testcases
39//
40TEST_F(StringTableTest, different_string_size) {
41  int size = 127 - 32;
42  for (int i = 32; i < 127; ++i) {
43    char c[2];
44    c[0] = i;
45    c[1] = '\0';
46    ASSERT_NE(m_pTestee->insert(c), c);
47  }
48  ASSERT_EQ(m_pTestee->size(), size);
49}
50
51TEST_F(StringTableTest, traverse_begin_to_end) {
52  m_pTestee->insert("Hello");
53  m_pTestee->insert("World");
54  m_pTestee->insert("Media");
55  m_pTestee->insert("Tek");
56  StringTable::iterator it = m_pTestee->begin();
57  ASSERT_STREQ(*it, "Hello");
58  ++it;
59  ASSERT_STREQ(*it, "World");
60  ++it;
61  ASSERT_STREQ(*it, "Media");
62  ++it;
63  ASSERT_STREQ(*it, "Tek");
64  ++it;
65  ASSERT_EQ(it, m_pTestee->end());
66}
67
68TEST_F(StringTableTest, null_string) {
69  m_pTestee->insert("");
70  ASSERT_STREQ(*(m_pTestee->begin()), "");
71  ASSERT_EQ(m_pTestee->size(), 1);
72}
73