@@ -14,6 +14,11 @@ class StatNameTest : public testing::Test {
1414public:
1515 StatNameTest () {}
1616 SymbolTableImpl table_;
17+
18+ SymbolVec getSymbols (StatNamePtr stat_name_ptr) {
19+ StatNameImpl& impl = dynamic_cast <StatNameImpl&>(*stat_name_ptr.get ());
20+ return impl.symbol_vec_ ;
21+ }
1722};
1823
1924TEST_F (StatNameTest, TestArbitrarySymbolRoundtrip) {
@@ -32,9 +37,9 @@ TEST_F(StatNameTest, TestUnusualDelimitersRoundtrip) {
3237}
3338
3439TEST_F (StatNameTest, TestSuccessfulDoubleLookup) {
35- auto stat_name_1 = table_.encode (" foo.bar.baz" );
36- auto stat_name_2 = table_.encode (" foo.bar.baz" );
37- EXPECT_EQ (stat_name_1-> toSymbols (), stat_name_2-> toSymbols ( ));
40+ StatNamePtr stat_name_1 = table_.encode (" foo.bar.baz" );
41+ StatNamePtr stat_name_2 = table_.encode (" foo.bar.baz" );
42+ EXPECT_EQ (getSymbols ( std::move (stat_name_1)), getSymbols ( std::move (stat_name_2) ));
3843}
3944
4045TEST_F (StatNameTest, TestSuccessfulDecode) {
@@ -48,39 +53,33 @@ TEST_F(StatNameTest, TestSuccessfulDecode) {
4853TEST_F (StatNameTest, TestDifferentStats) {
4954 auto stat_name_1 = table_.encode (" foo.bar" );
5055 auto stat_name_2 = table_.encode (" bar.foo" );
51- EXPECT_NE (stat_name_1->toSymbols (), stat_name_2->toSymbols ());
5256 EXPECT_NE (stat_name_1->toString (), stat_name_2->toString ());
57+ EXPECT_NE (getSymbols (std::move (stat_name_1)), getSymbols (std::move (stat_name_2)));
5358}
5459
5560TEST_F (StatNameTest, TestSymbolConsistency) {
5661 auto stat_name_1 = table_.encode (" foo.bar" );
5762 auto stat_name_2 = table_.encode (" bar.foo" );
5863 // We expect the encoding of "foo" in one context to be the same as another.
59- EXPECT_EQ (stat_name_1->toSymbols ()[0 ], stat_name_2->toSymbols ()[1 ]);
60- EXPECT_EQ (stat_name_2->toSymbols ()[0 ], stat_name_1->toSymbols ()[1 ]);
64+ SymbolVec vec_1 = getSymbols (std::move (stat_name_1));
65+ SymbolVec vec_2 = getSymbols (std::move (stat_name_2));
66+ EXPECT_EQ (vec_1[0 ], vec_2[1 ]);
67+ EXPECT_EQ (vec_2[0 ], vec_1[1 ]);
6168}
6269
63- // We also wish to test the internals of what gets called inside a SymbolTable, even though these
64- // functions are not user-facing.
65- class SymbolTableTest : public testing ::Test {
66- public:
67- SymbolTableTest () {}
68- SymbolTableImpl table_;
69- };
70-
7170// TODO(ambuc): Test decoding an invalid symbol vector. This will probably need a test which
7271// implements a mock StatNameImpl, so that it can get access to .decode(), which is protected.
7372
7473// Even though the symbol table does manual reference counting, curr_counter_ is monotonically
7574// increasing. So encoding "foo", freeing the sole stat containing "foo", and then re-encoding
7675// "foo" will produce a different symbol each time.
77- TEST_F (SymbolTableTest , TestNewValueAfterFree) {
76+ TEST_F (StatNameTest , TestNewValueAfterFree) {
7877 {
7978 StatNamePtr stat_name_1 = table_.encode (" foo" );
80- SymbolVec stat_name_1_symbols = stat_name_1-> toSymbols ( );
79+ SymbolVec stat_name_1_symbols = getSymbols ( std::move (stat_name_1) );
8180 stat_name_1.reset ();
8281 StatNamePtr stat_name_2 = table_.encode (" foo" );
83- SymbolVec stat_name_2_symbols = stat_name_2-> toSymbols ( );
82+ SymbolVec stat_name_2_symbols = getSymbols ( std::move (stat_name_2) );
8483 EXPECT_NE (stat_name_1_symbols, stat_name_2_symbols);
8584 }
8685
@@ -90,11 +89,11 @@ TEST_F(SymbolTableTest, TestNewValueAfterFree) {
9089 // "bar" to have a different symbol.
9190 StatNamePtr stat_foo = table_.encode (" foo" );
9291 StatNamePtr stat_foobar_1 = table_.encode (" foo.bar" );
93- SymbolVec stat_foobar_1_symbols = stat_foobar_1-> toSymbols ( );
92+ SymbolVec stat_foobar_1_symbols = getSymbols ( std::move (stat_foobar_1) );
9493 stat_foobar_1.reset ();
9594
9695 StatNamePtr stat_foobar_2 = table_.encode (" foo.bar" );
97- SymbolVec stat_foobar_2_symbols = stat_foobar_2-> toSymbols ( );
96+ SymbolVec stat_foobar_2_symbols = getSymbols ( std::move (stat_foobar_2) );
9897
9998 EXPECT_EQ (stat_foobar_1_symbols[0 ],
10099 stat_foobar_2_symbols[0 ]); // Both "foo" components have the same symbol,
@@ -103,7 +102,7 @@ TEST_F(SymbolTableTest, TestNewValueAfterFree) {
103102 }
104103}
105104
106- TEST_F (SymbolTableTest , TestShrinkingExpectation) {
105+ TEST_F (StatNameTest , TestShrinkingExpectation) {
107106 // We expect that as we free stat names, the memory used to store those underlying symbols will
108107 // be freed.
109108 // ::size() is a public function, but should only be used for testing.
0 commit comments