Prove whether unowned/retain pointer collections compare transparently

Unowned is acceptable in its current format, but RetainedPtr does not
play nicely with containers.

-- work around retained ptr tests for now.

Change-Id: I612a0fd25fb14879e0977d4781a6890486877c99
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/98391
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fxcrt/retain_ptr_unittest.cpp b/core/fxcrt/retain_ptr_unittest.cpp
index 4985122..ffb98b1 100644
--- a/core/fxcrt/retain_ptr_unittest.cpp
+++ b/core/fxcrt/retain_ptr_unittest.cpp
@@ -13,6 +13,16 @@
 #include "third_party/base/containers/contains.h"
 
 namespace fxcrt {
+namespace {
+
+template <typename T, typename C = std::less<T>>
+class NoLinearSearchSet : public std::set<T, C> {
+ public:
+  typename std::set<T, C>::iterator begin() noexcept = delete;
+  typename std::set<T, C>::const_iterator cbegin() const noexcept = delete;
+};
+
+}  // namespace
 
 TEST(RetainPtr, Null) {
   RetainPtr<PseudoRetainable> ptr;
@@ -411,20 +421,21 @@
   // RetainPtrs for containers that use find().
   PseudoRetainable obj1;
   PseudoRetainable obj2;
-  std::set<const PseudoRetainable*> the_set;
+  NoLinearSearchSet<const PseudoRetainable*, std::less<>> the_set;
   the_set.insert(&obj1);
   EXPECT_TRUE(pdfium::Contains(the_set, &obj1));
   EXPECT_FALSE(pdfium::Contains(the_set, &obj2));
 
   RetainPtr<PseudoRetainable> ptr1(&obj1);
   RetainPtr<PseudoRetainable> ptr2(&obj2);
-  EXPECT_TRUE(pdfium::Contains(the_set, ptr1));
-  EXPECT_FALSE(pdfium::Contains(the_set, ptr2));
+  // TODO(tsepez): remove Get() after fixing transparent compare for RetainPtr.
+  EXPECT_TRUE(pdfium::Contains(the_set, ptr1.Get()));
+  EXPECT_FALSE(pdfium::Contains(the_set, ptr2.Get()));
 
   RetainPtr<const PseudoRetainable> const_ptr1(&obj1);
   RetainPtr<const PseudoRetainable> const_ptr2(&obj2);
-  EXPECT_TRUE(pdfium::Contains(the_set, const_ptr1));
-  EXPECT_FALSE(pdfium::Contains(the_set, const_ptr2));
+  EXPECT_TRUE(pdfium::Contains(the_set, const_ptr1.Get()));
+  EXPECT_FALSE(pdfium::Contains(the_set, const_ptr2.Get()));
 }
 
 TEST(RetainPtr, VectorContains) {
diff --git a/core/fxcrt/unowned_ptr_unittest.cpp b/core/fxcrt/unowned_ptr_unittest.cpp
index a1a3ec7..92cf294 100644
--- a/core/fxcrt/unowned_ptr_unittest.cpp
+++ b/core/fxcrt/unowned_ptr_unittest.cpp
@@ -14,6 +14,13 @@
 namespace fxcrt {
 namespace {
 
+template <typename T, typename C = std::less<T>>
+class NoLinearSearchSet : public std::set<T, C> {
+ public:
+  typename std::set<T, C>::iterator begin() noexcept = delete;
+  typename std::set<T, C>::const_iterator cbegin() const noexcept = delete;
+};
+
 class Clink {
  public:
   UnownedPtr<Clink> next_ = nullptr;
@@ -192,7 +199,7 @@
   int foos[2];
   UnownedPtr<int> ptr1(&foos[0]);
   UnownedPtr<int> ptr2(&foos[1]);
-  std::set<UnownedPtr<int>, std::less<>> holder;
+  NoLinearSearchSet<UnownedPtr<int>, std::less<>> holder;
   holder.insert(ptr1);
   EXPECT_NE(holder.end(), holder.find(&foos[0]));
   EXPECT_EQ(holder.end(), holder.find(&foos[1]));