Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
string_pool_template_unittest.cpp
Go to the documentation of this file.
1// Copyright 2016 The PDFium Authors
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/string_pool_template.h"
6#include "core/fxcrt/fx_string.h"
7#include "testing/gtest/include/gtest/gtest.h"
8
9namespace fxcrt {
10
12 ByteStringPool pool;
13
14 ByteString null1;
15 ByteString null2;
16 ByteString goats1("goats");
17 ByteString goats2("goats");
18
19 // Underlying storage, if non-null, is not shared.
20 EXPECT_FALSE(null1.m_pData.Get());
21 EXPECT_FALSE(null2.m_pData.Get());
22 EXPECT_NE(goats1.m_pData, goats2.m_pData);
23
24 ByteString interned_null1 = pool.Intern(null1);
25 ByteString interned_null2 = pool.Intern(null2);
26 ByteString interned_goats1 = pool.Intern(goats1);
27 ByteString interned_goats2 = pool.Intern(goats2);
28
29 // Strings are logically equal after being interned.
30 EXPECT_EQ(null1, interned_null1);
31 EXPECT_EQ(null2, interned_null2);
32 EXPECT_EQ(goats1, interned_goats1);
33 EXPECT_EQ(goats2, interned_goats2);
34
35 // Interned underlying storage, if non-null, belongs to first seen.
36 EXPECT_FALSE(interned_null1.m_pData.Get());
37 EXPECT_FALSE(interned_null2.m_pData.Get());
38 EXPECT_EQ(goats1.m_pData, interned_goats1.m_pData);
39 EXPECT_EQ(goats1.m_pData, interned_goats2.m_pData);
40
41 pool.Clear();
42 ByteString reinterned_null2 = pool.Intern(null2);
43 ByteString reinterned_null1 = pool.Intern(null2);
44 ByteString reinterned_goats2 = pool.Intern(goats2);
45 ByteString reinterned_goats1 = pool.Intern(goats2);
46
47 // After clearing pool, storage was re-interned using second strings.
48 EXPECT_FALSE(interned_null1.m_pData.Get());
49 EXPECT_FALSE(interned_null2.m_pData.Get());
50 EXPECT_EQ(goats2.m_pData, reinterned_goats1.m_pData);
51 EXPECT_EQ(goats2.m_pData, reinterned_goats2.m_pData);
52}
53
55 WideStringPool pool;
56
57 WideString null1;
58 WideString null2;
59 WideString goats1(L"goats");
60 WideString goats2(L"goats");
61
62 // Underlying storage, if non-null, is not shared.
63 EXPECT_FALSE(null1.m_pData.Get());
64 EXPECT_FALSE(null2.m_pData.Get());
65 EXPECT_NE(goats1.m_pData, goats2.m_pData);
66
67 WideString interned_null1 = pool.Intern(null1);
68 WideString interned_null2 = pool.Intern(null2);
69 WideString interned_goats1 = pool.Intern(goats1);
70 WideString interned_goats2 = pool.Intern(goats2);
71
72 // Strings are logically equal after being interned.
73 EXPECT_EQ(null1, interned_null1);
74 EXPECT_EQ(null2, interned_null2);
75 EXPECT_EQ(goats1, interned_goats1);
76 EXPECT_EQ(goats2, interned_goats2);
77
78 // Interned underlying storage, if non-null, belongs to first seen.
79 EXPECT_FALSE(interned_null1.m_pData.Get());
80 EXPECT_FALSE(interned_null2.m_pData.Get());
81 EXPECT_EQ(goats1.m_pData, interned_goats1.m_pData);
82 EXPECT_EQ(goats1.m_pData, interned_goats2.m_pData);
83
84 pool.Clear();
85 WideString reinterned_null2 = pool.Intern(null2);
86 WideString reinterned_null1 = pool.Intern(null2);
87 WideString reinterned_goats2 = pool.Intern(goats2);
88 WideString reinterned_goats1 = pool.Intern(goats2);
89
90 // After clearing pool, storage was re-interned using second strings.
91 EXPECT_FALSE(interned_null1.m_pData.Get());
92 EXPECT_FALSE(interned_null2.m_pData.Get());
93 EXPECT_EQ(goats2.m_pData, reinterned_goats1.m_pData);
94 EXPECT_EQ(goats2.m_pData, reinterned_goats2.m_pData);
95}
96
97} // namespace fxcrt
ByteString(const char *ptr)
WideString(const wchar_t *ptr)
TEST(StringPool, ByteString)
TEST(StringPool, WideString)