chromium/base/memory/weak_ptr_unittest.cc

// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/memory/weak_ptr.h"

#include <memory>
#include <string>

#include "base/debug/leak_annotations.h"
#include "base/functional/bind.h"
#include "base/location.h"
#include "base/synchronization/waitable_event.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/gtest_util.h"
#include "base/test/test_timeouts.h"
#include "base/threading/thread.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace base {

namespace subtle {

class BindWeakPtrFactoryForTesting {};

}  // namespace subtle

namespace {

WeakPtr<int> PassThru(WeakPtr<int> ptr) {}

template <class T>
class OffThreadObjectCreator {};

struct Base {};
struct Derived : public Base {};

struct TargetBase {};

struct Target : public TargetBase {};

struct DerivedTarget : public Target {};

// A class inheriting from Target and defining a nested type called 'Base'.
// To guard against strange compilation errors.
struct DerivedTargetWithNestedBase : public Target {};

// A struct with a virtual destructor.
struct VirtualDestructor {};

// A class inheriting from Target where Target is not the first base, and where
// the first base has a virtual method table. This creates a structure where the
// Target base is not positioned at the beginning of
// DerivedTargetMultipleInheritance.
struct DerivedTargetMultipleInheritance : public VirtualDestructor,
                                          public Target {};

struct Arrow {};
struct TargetWithFactory : public Target {};

// Helper class to create and destroy weak pointer copies
// and delete objects on a background thread.
class BackgroundThread : public Thread {};

}  // namespace

TEST(WeakPtrFactoryTest, Basic) {}

TEST(WeakPtrFactoryTest, Comparison) {}

TEST(WeakPtrFactoryTest, Move) {}

TEST(WeakPtrFactoryTest, OutOfScope) {}

TEST(WeakPtrFactoryTest, Multiple) {}

TEST(WeakPtrFactoryTest, MultipleStaged) {}

TEST(WeakPtrFactoryTest, Dereference) {}

TEST(WeakPtrFactoryTest, UpCast) {}

TEST(WeakPtrTest, ConstructFromNullptr) {}

TEST(WeakPtrFactoryTest, BooleanTesting) {}

TEST(WeakPtrFactoryTest, ComparisonToNull) {}

struct ReallyBaseClass {};
struct BaseClass : ReallyBaseClass {};
struct OtherBaseClass {};
struct WithWeak final : BaseClass, OtherBaseClass {};

TEST(WeakPtrTest, ConversionOffsetsPointer) {}

TEST(WeakPtrTest, InvalidateWeakPtrs) {}

// Tests that WasInvalidated() is true only for invalidated WeakPtrs (not
// nullptr) and doesn't DCHECK (e.g. because of a dereference attempt).
TEST(WeakPtrTest, WasInvalidatedByFactoryDestruction) {}

// As above, but testing InvalidateWeakPtrs().
TEST(WeakPtrTest, WasInvalidatedByInvalidateWeakPtrs) {}

// A WeakPtr should not be reported as 'invalidated' if nullptr was assigned to
// it.
TEST(WeakPtrTest, WasInvalidatedWhilstNull) {}

TEST(WeakPtrTest, MaybeValidOnSameSequence) {}

TEST(WeakPtrTest, MaybeValidOnOtherSequence) {}

TEST(WeakPtrTest, HasWeakPtrs) {}

TEST(WeakPtrTest, ObjectAndWeakPtrOnDifferentThreads) {}

TEST(WeakPtrTest, WeakPtrInitiateAndUseOnDifferentThreads) {}

TEST(WeakPtrTest, MoveOwnershipImplicitly) {}

TEST(WeakPtrTest, MoveOwnershipOfUnreferencedObject) {}

TEST(WeakPtrTest, MoveOwnershipAfterInvalidate) {}

TEST(WeakPtrTest, MainThreadRefOutlivesBackgroundThreadRef) {}

TEST(WeakPtrTest, BackgroundThreadRefOutlivesMainThreadRef) {}

TEST(WeakPtrTest, OwnerThreadDeletesObject) {}

TEST(WeakPtrTest, NonOwnerThreadCanCopyAndAssignWeakPtr) {}

TEST(WeakPtrTest, NonOwnerThreadCanCopyAndAssignWeakPtrBase) {}

TEST(WeakPtrTest, NonOwnerThreadCanDeleteWeakPtr) {}

TEST(WeakPtrTest, ConstUpCast) {}

TEST(WeakPtrTest, ConstGetWeakPtr) {}

TEST(WeakPtrTest, GetMutableWeakPtr) {}

TEST(WeakPtrDeathTest, BindToCurrentSequence) {}

TEST(WeakPtrDeathTest, WeakPtrCopyDoesNotChangeThreadBinding) {}

TEST(WeakPtrDeathTest, NonOwnerThreadDereferencesWeakPtrAfterReference) {}

TEST(WeakPtrDeathTest, NonOwnerThreadDeletesWeakPtrAfterReference) {}

TEST(WeakPtrDeathTest, NonOwnerThreadDeletesObjectAfterReference) {}

TEST(WeakPtrDeathTest, NonOwnerThreadReferencesObjectAfterDeletion) {}

TEST(WeakPtrDeathTest, ArrowOperatorChecksOnBadDereference) {}

TEST(WeakPtrDeathTest, StarOperatorChecksOnBadDereference) {}

}  // namespace base