chromium/base/functional/callback_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/functional/callback.h"

#include <memory>
#include <utility>

#include "base/functional/bind.h"
#include "base/functional/callback_internal.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/ref_counted.h"
#include "base/notreached.h"
#include "base/strings/string_number_conversions.h"
#include "base/test/bind.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 {

void NopInvokeFunc() {}

// White-box testpoints to inject into a callback object for checking
// comparators and emptiness APIs. Use a BindState that is specialized based on
// a type we declared in the anonymous namespace above to remove any chance of
// colliding with another instantiation and breaking the one-definition-rule.
struct FakeBindState : internal::BindStateBase {};

namespace {

class CallbackTest : public ::testing::Test {};

TEST_F(CallbackTest, Types) {}

// Ensure we can create unbound callbacks. We need this to be able to store
// them in class members that can be initialized later.
TEST_F(CallbackTest, DefaultConstruction) {}

TEST_F(CallbackTest, IsNull) {}

TEST_F(CallbackTest, Equals) {}

TEST_F(CallbackTest, Reset) {}

TEST_F(CallbackTest, Move) {}

TEST_F(CallbackTest, NullAfterMoveRun) {}

TEST_F(CallbackTest, MaybeValidReturnsTrue) {}

TEST_F(CallbackTest, ThenResetsOriginalCallback) {}

// A RepeatingCallback will implicitly convert to a OnceCallback, so a
// once_callback.Then(repeating_callback) should turn into a OnceCallback
// that holds 2 OnceCallbacks which it will run.
TEST_F(CallbackTest, ThenCanConvertRepeatingToOnce) {}

// `Then()` should should allow a return value of type `R` to be passed to a
// callback with one parameter of type `const R&` or type `R&&`.
TEST_F(CallbackTest, ThenWithCompatibleButNotSameType) {}

// A factory class for building an outer and inner callback for calling
// Then() on either a OnceCallback or RepeatingCallback with combinations of
// void return types, non-void, and move-only return types.
template <bool use_once, typename R, typename ThenR, typename... Args>
class CallbackThenTest;
CallbackThenTest<use_once, R (Args...), ThenR>;

CallbackThenOnceTest;
CallbackThenRepeatingTest;

TEST_F(CallbackTest, ThenOnce) {}

TEST_F(CallbackTest, ThenRepeating) {}

// WeakPtr detection in BindRepeating() requires a method, not just any
// function.
class ClassWithAMethod {};

TEST_F(CallbackTest, MaybeValidInvalidateWeakPtrsOnSameSequence) {}

TEST_F(CallbackTest, MaybeValidInvalidateWeakPtrsOnOtherSequence) {}

TEST_F(CallbackTest, ThenAfterWeakPtr) {}

class CallbackOwner : public base::RefCounted<CallbackOwner> {};

TEST_F(CallbackTest, CallbackHasLastRefOnContainingObject) {}

// According to legends, it is good practice to put death tests into their own
// test suite, so they are grouped separately from regular tests, since death
// tests are somewhat slow and have quirks that can slow down test running if
// intermixed.
TEST(CallbackDeathTest, RunNullCallbackChecks) {}

}  // namespace
}  // namespace base