OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 PDFium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "core/fxcrt/include/cfx_string_pool_template.h" | |
6 #include "core/fxcrt/include/fx_string.h" | |
7 #include "testing/fx_string_testhelpers.h" | |
8 #include "testing/gtest/include/gtest/gtest.h" | |
9 | |
10 TEST(fxcrt, ByteStringPool) { | |
11 CFX_ByteStringPool pool; | |
12 | |
13 CFX_ByteString null1; | |
14 CFX_ByteString null2; | |
15 CFX_ByteString goats1("goats"); | |
16 CFX_ByteString goats2("goats"); | |
17 | |
18 // Underlying storage, if non-null, is not shared. | |
dsinclair
2016/09/15 20:23:26
Doesn't this check that the underlying storage is
Tom Sepez
2016/09/15 20:51:24
Yes, I think that's inline with the comment, for a
| |
19 EXPECT_EQ(nullptr, null1.m_pData.Get()); | |
20 EXPECT_EQ(nullptr, null2.m_pData.Get()); | |
21 EXPECT_NE(goats1.m_pData, goats2.m_pData); | |
Tom Sepez
2016/09/15 20:52:37
Note that we don't get here because operator== on
| |
22 | |
23 CFX_ByteString interned_null1 = pool.Intern(null1); | |
24 CFX_ByteString interned_null2 = pool.Intern(null2); | |
25 CFX_ByteString interned_goats1 = pool.Intern(goats1); | |
26 CFX_ByteString interned_goats2 = pool.Intern(goats2); | |
27 | |
28 // Strings are logically equal after being interned. | |
29 EXPECT_EQ(null1, interned_null1); | |
30 EXPECT_EQ(null2, interned_null2); | |
31 EXPECT_EQ(goats1, interned_goats1); | |
32 EXPECT_EQ(goats2, interned_goats2); | |
33 | |
dsinclair
2016/09/15 20:23:26
Should EXPECT_EQ(interned_goats1, interned_goats2)
Tom Sepez
2016/09/15 20:51:24
Yes, but that should be covered by the basic strin
| |
34 // Interned underlying storage, if non-null, belongs to first seen. | |
35 EXPECT_EQ(nullptr, interned_null1.m_pData.Get()); | |
36 EXPECT_EQ(nullptr, interned_null2.m_pData.Get()); | |
37 EXPECT_EQ(goats1.m_pData, interned_goats1.m_pData); | |
38 EXPECT_EQ(goats1.m_pData, interned_goats2.m_pData); | |
39 | |
40 pool.Clear(); | |
41 CFX_ByteString reinterned_null2 = pool.Intern(null2); | |
42 CFX_ByteString reinterned_null1 = pool.Intern(null2); | |
dsinclair
2016/09/15 20:23:26
Is it intentional that the null1 and goats1 are po
Tom Sepez
2016/09/15 20:51:24
Yes, otherwise they're not equal.
| |
43 CFX_ByteString reinterned_goats2 = pool.Intern(goats2); | |
44 CFX_ByteString reinterned_goats1 = pool.Intern(goats2); | |
45 | |
46 // After clearing pool, storage was re-interned using second strings. | |
47 EXPECT_EQ(nullptr, interned_null1.m_pData.Get()); | |
48 EXPECT_EQ(nullptr, interned_null2.m_pData.Get()); | |
49 EXPECT_EQ(goats2.m_pData, reinterned_goats1.m_pData); | |
50 EXPECT_EQ(goats2.m_pData, reinterned_goats2.m_pData); | |
51 } | |
52 | |
53 TEST(fxcrt, WideStringPool) { | |
54 CFX_WideStringPool pool; | |
55 | |
56 CFX_WideString null1; | |
57 CFX_WideString null2; | |
58 CFX_WideString goats1(L"goats"); | |
59 CFX_WideString goats2(L"goats"); | |
60 | |
61 // Underlying storage, if non-null, is not shared. | |
62 EXPECT_EQ(nullptr, null1.m_pData.Get()); | |
63 EXPECT_EQ(nullptr, null2.m_pData.Get()); | |
64 EXPECT_NE(goats1.m_pData, goats2.m_pData); | |
65 | |
66 CFX_WideString interned_null1 = pool.Intern(null1); | |
67 CFX_WideString interned_null2 = pool.Intern(null2); | |
68 CFX_WideString interned_goats1 = pool.Intern(goats1); | |
69 CFX_WideString interned_goats2 = pool.Intern(goats2); | |
70 | |
71 // Strings are logically equal after being interned. | |
72 EXPECT_EQ(null1, interned_null1); | |
73 EXPECT_EQ(null2, interned_null2); | |
74 EXPECT_EQ(goats1, interned_goats1); | |
75 EXPECT_EQ(goats2, interned_goats2); | |
76 | |
77 // Interned underlying storage, if non-null, belongs to first seen. | |
78 EXPECT_EQ(nullptr, interned_null1.m_pData.Get()); | |
79 EXPECT_EQ(nullptr, interned_null2.m_pData.Get()); | |
80 EXPECT_EQ(goats1.m_pData, interned_goats1.m_pData); | |
81 EXPECT_EQ(goats1.m_pData, interned_goats2.m_pData); | |
82 | |
83 pool.Clear(); | |
84 CFX_WideString reinterned_null2 = pool.Intern(null2); | |
85 CFX_WideString reinterned_null1 = pool.Intern(null2); | |
86 CFX_WideString reinterned_goats2 = pool.Intern(goats2); | |
87 CFX_WideString reinterned_goats1 = pool.Intern(goats2); | |
88 | |
89 // After clearing pool, storage was re-interned using second strings. | |
90 EXPECT_EQ(nullptr, interned_null1.m_pData.Get()); | |
91 EXPECT_EQ(nullptr, interned_null2.m_pData.Get()); | |
92 EXPECT_EQ(goats2.m_pData, reinterned_goats1.m_pData); | |
93 EXPECT_EQ(goats2.m_pData, reinterned_goats2.m_pData); | |
94 } | |
OLD | NEW |