1 : // Copyright 2013 Google Inc. All Rights Reserved.
2 : //
3 : // Licensed under the Apache License, Version 2.0 (the "License");
4 : // you may not use this file except in compliance with the License.
5 : // You may obtain a copy of the License at
6 : //
7 : // http://www.apache.org/licenses/LICENSE-2.0
8 : //
9 : // Unless required by applicable law or agreed to in writing, software
10 : // distributed under the License is distributed on an "AS IS" BASIS,
11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : // See the License for the specific language governing permissions and
13 : // limitations under the License.
14 :
15 : #include "syzygy/core/string_table.h"
16 :
17 : #include "gtest/gtest.h"
18 :
19 : namespace core {
20 :
21 : namespace {
22 :
23 : class TestStringTable : public StringTable {
24 : public:
25 : using StringTable::string_table_;
26 : };
27 :
28 : } // namespace
29 :
30 E : TEST(StringTableTest, DefaultConstructor) {
31 E : TestStringTable strtab;
32 E : EXPECT_TRUE(strtab.string_table_.empty());
33 E : }
34 :
35 E : TEST(StringTableTest, InternString) {
36 E : TestStringTable strtab;
37 :
38 : // The pool is initially empty.
39 E : EXPECT_EQ(0U, strtab.string_table_.size());
40 :
41 E : const std::string& str1 = strtab.InternString("foo");
42 E : const std::string& str2 = strtab.InternString("bar");
43 E : const std::string& str3 = strtab.InternString("foo");
44 E : const std::string& str4 = strtab.InternString("foo");
45 E : const std::string& str5 = strtab.InternString("bat");
46 :
47 : // Validate the size of the internal strings pool.
48 E : EXPECT_EQ(3U, strtab.string_table_.size());
49 :
50 : // Validate string sharing.
51 E : EXPECT_FALSE(str1.c_str() == str2.c_str());
52 E : EXPECT_TRUE(str1.c_str() == str3.c_str());
53 E : EXPECT_TRUE(str1.c_str() == str4.c_str());
54 E : EXPECT_FALSE(str1.c_str() == str5.c_str());
55 E : }
56 :
57 : } // namespace core
|