chromium/base/functional/function_ref_unittest.cc

// Copyright 2022 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/function_ref.h"

#include <stdint.h>

#include <concepts>
#include <optional>

#include "base/compiler_specific.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/abseil-cpp/absl/functional/function_ref.h"

namespace base {

namespace {

char Func(float) {}

}  // namespace

TEST(FunctionRef, Lambda) {}

TEST(FunctionRef, CapturingLambda) {}

TEST(FunctionRef, FunctionPtr) {}

TEST(FunctionRef, Functor) {}

TEST(FunctionRef, Method) {}

// If we construct from another `FunctionRef`, that should work fine, even if
// the input is destroyed before we call the output. In other words, we should
// reference the underlying callable, not the `FunctionRef`.
//
// We construct in a `noinline` function to maximize the chance that ASAN
// notices the use-after-free if we get this wrong.
NOINLINE void ConstructFromLValue(std::optional<FunctionRef<int()>>& ref) {}
NOINLINE void ConstructFromConstLValue(std::optional<FunctionRef<int()>>& ref) {}
NOINLINE void ConstructFromRValue(std::optional<FunctionRef<int()>>& ref) {}
NOINLINE void ConstructFromConstRValue(std::optional<FunctionRef<int()>>& ref) {}
TEST(FunctionRef, ConstructionFromOtherFunctionRefObjects) {}

// `FunctionRef` allows functors with convertible return types to be adapted.
TEST(FunctionRef, ConvertibleReturnTypes) {}

TEST(FunctionRef, ConstructionFromInexactMatches) {}

TEST(FunctionRef, ConstructionFromAbslFunctionRef) {}

}  // namespace base