5#include "core/fxcrt/unowned_ptr.h"
13#include "testing/gtest/include/gtest/gtest.h"
14#include "third_party/base/containers/contains.h"
16#if defined(PDF_USE_PARTITION_ALLOC)
17#include "partition_alloc/shim/allocator_shim_default_dispatch_to_partition_alloc.h"
23template <
typename T,
typename C =
std::less<T>>
24class NoLinearSearchSet :
public std::set<T, C> {
26 typename std::set<T, C>::iterator begin()
noexcept =
delete;
27 typename std::set<T, C>::const_iterator cbegin()
const noexcept =
delete;
35void DeleteDangling() {
36 auto ptr2 =
std::make_unique<Clink>();
38 auto ptr1 =
std::make_unique<Clink>();
39 ptr2->next_ = ptr1.get();
43void AssignDangling() {
44 auto ptr2 =
std::make_unique<Clink>();
46 auto ptr1 =
std::make_unique<Clink>();
47 ptr2->next_ = ptr1.get();
49 ptr2->next_ =
nullptr;
52void ReleaseDangling() {
53 auto ptr2 =
std::make_unique<Clink>();
55 auto ptr1 =
std::make_unique<Clink>();
56 ptr2->next_ = ptr1.get();
58 ptr2->next_.ExtractAsDangling();
74 auto obj =
std::make_unique<Clink>();
76 EXPECT_EQ(obj.get(), ptr);
80 std::unique_ptr<Clink> obj = std::make_unique<Clink>();
83 EXPECT_EQ(obj.get(), ptr2);
84 EXPECT_EQ(obj.get(), ptr1);
88 std::unique_ptr<Clink> obj = std::make_unique<Clink>();
91 EXPECT_EQ(obj.get(), ptr2);
96 std::unique_ptr<Clink> obj = std::make_unique<Clink>();
99 EXPECT_EQ(obj.get(), ptr2);
100 EXPECT_EQ(obj.get(), ptr1);
104 std::unique_ptr<Clink> obj = std::make_unique<Clink>();
106 UnownedPtr<
const Clink> ptr2(std::move(ptr1));
107 EXPECT_EQ(obj.get(), ptr2);
112 std::unique_ptr<Clink> obj = std::make_unique<Clink>();
119 std::unique_ptr<Clink> obj = std::make_unique<Clink>();
122 EXPECT_EQ(obj.get(), ptr);
126 std::unique_ptr<Clink> obj = std::make_unique<Clink>();
130 EXPECT_EQ(obj.get(), ptr1);
131 EXPECT_EQ(obj.get(), ptr2);
135 std::unique_ptr<Clink> obj = std::make_unique<Clink>();
138 ptr2 =
std::move(ptr1);
140 EXPECT_EQ(obj.get(), ptr2);
144 std::unique_ptr<Clink> obj = std::make_unique<Clink>();
148 EXPECT_EQ(obj.get(), ptr1);
149 EXPECT_EQ(obj.get(), ptr2);
153 std::unique_ptr<Clink> obj = std::make_unique<Clink>();
156 ptr2 =
std::move(ptr1);
158 EXPECT_EQ(obj.get(), ptr2);
162 auto ptr1 =
std::make_unique<Clink>();
164 auto ptr2 =
std::make_unique<Clink>();
165 ptr2->next_ = ptr1.get();
170#if defined(UNOWNED_PTR_DANGLING_CHECKS)
171 EXPECT_DEATH(DeleteDangling(),
"");
178 auto ptr1 =
std::make_unique<Clink>();
180 auto ptr2 =
std::make_unique<Clink>();
181 ptr2->next_ = ptr1.get();
182 ptr2->next_ =
nullptr;
187#if defined(UNOWNED_PTR_DANGLING_CHECKS)
188 EXPECT_DEATH(AssignDangling(),
"");
195 auto ptr2 =
std::make_unique<Clink>();
197 auto ptr1 =
std::make_unique<Clink>();
198 ptr2->next_ = ptr1.get();
199 ptr2->next_.ExtractAsDangling();
204#if defined(UNOWNED_PTR_DANGLING_CHECKS)
205 EXPECT_DEATH(ReleaseDangling(),
"");
214 EXPECT_TRUE(ptr1 == ptr1);
217 EXPECT_TRUE(ptr1 == ptr2);
220 EXPECT_TRUE(&foo == ptr3);
221 EXPECT_TRUE(ptr3 == &foo);
222 EXPECT_FALSE(ptr1 == ptr3);
225 EXPECT_TRUE(ptr1 == ptr3);
231 EXPECT_FALSE(ptr1 != ptr1);
234 EXPECT_FALSE(ptr1 != ptr2);
237 EXPECT_FALSE(&foo != ptr3);
238 EXPECT_FALSE(ptr3 != &foo);
239 EXPECT_TRUE(ptr1 != ptr3);
242 EXPECT_FALSE(ptr1 != ptr3);
250 EXPECT_FALSE(ptr1 < ptr1);
251 EXPECT_TRUE(ptr1 < ptr2);
252 EXPECT_FALSE(ptr2 < ptr1);
259 NoLinearSearchSet<UnownedPtr<
int>, std::less<>> holder;
261 EXPECT_NE(holder.end(), holder.find(&foos[0]));
262 EXPECT_EQ(holder.end(), holder.find(&foos[1]));
263 EXPECT_TRUE(pdfium::Contains(holder, &foos[0]));
264 EXPECT_FALSE(pdfium::Contains(holder, &foos[1]));
267#if defined(PDF_USE_PARTITION_ALLOC)
268#if BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC) &&
269 BUILDFLAG(ENABLE_BACKUP_REF_PTR_SUPPORT) &&
270 !BUILDFLAG(ENABLE_DANGLING_RAW_PTR_CHECKS) &&
271 BUILDFLAG(HAS_64_BIT_POINTERS)
TEST(CFX_BytrString, EqualNoCase)