chromium/base/threading/thread_checker_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/threading/thread_checker.h"

#include <memory>

#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/ref_counted.h"
#include "base/sequence_token.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/bind.h"
#include "base/test/gtest_util.h"
#include "base/test/test_simple_task_runner.h"
#include "base/threading/simple_thread.h"
#include "base/threading/thread_local.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace base::internal {
namespace {

// A thread that runs a callback.
class RunCallbackThread : public SimpleThread {};

// Runs a callback on a new thread synchronously.
void RunCallbackOnNewThreadSynchronously(OnceClosure callback) {}

void ExpectCalledOnValidThread(ThreadCheckerImpl* thread_checker) {}

void ExpectNotCalledOnValidThread(ThreadCheckerImpl* thread_checker) {}

void ExpectNotCalledOnValidThreadWithSequenceTokenThreadBound(
    ThreadCheckerImpl* thread_checker,
    SequenceToken sequence_token) {}

}  // namespace

TEST(ThreadCheckerTest, AllowedSameThreadNoSequenceToken) {}

TEST(ThreadCheckerTest, AllowedSameThreadAndSequenceDifferentThreadBoundTasks) {}

TEST(ThreadCheckerTest, AllowedSameThreadSequenceAndTaskNotThreadBound) {}

TEST(ThreadCheckerTest,
     DisallowedSameThreadAndSequenceDifferentTasksNotThreadBound) {}

TEST(ThreadCheckerTest, DisallowedDifferentThreadsNoSequenceToken) {}

TEST(ThreadCheckerTest, DisallowedDifferentThreadsSameSequence) {}

TEST(ThreadCheckerTest, DisallowedSameThreadDifferentSequence) {}

TEST(ThreadCheckerTest, DetachFromThread) {}

TEST(ThreadCheckerTest, DetachFromThreadWithSequenceToken) {}

// Owns a ThreadCheckerImpl and asserts that CalledOnValidThread() is valid
// in ~ThreadCheckerOwner.
class ThreadCheckerOwner {};

// Verifies ThreadCheckerImpl::CalledOnValidThread() returns true if called
// during thread destruction.
TEST(ThreadCheckerTest, CalledOnValidThreadFromThreadDestruction) {}

// Variant of CalledOnValidThreadFromThreadDestruction that calls
// ThreadCheckerImpl::DetachFromThread().
TEST(ThreadCheckerTest, CalledOnValidThreadFromThreadDestructionDetached) {}

TEST(ThreadCheckerTest, Move) {}

TEST(ThreadCheckerTest, MoveAssignIntoDetached) {}

TEST(ThreadCheckerTest, MoveFromDetachedRebinds) {}

TEST(ThreadCheckerTest, MoveOffThreadBanned) {}

namespace {

// This fixture is a helper for unit testing the thread checker macros as it is
// not possible to inline ExpectDeathOnOtherThread() and
// ExpectNoDeathOnOtherThreadAfterDetach() as lambdas since binding
// |Unretained(&my_sequence_checker)| wouldn't compile on non-dcheck builds
// where it won't be defined.
class ThreadCheckerMacroTest : public testing::Test {};

}  // namespace

TEST_F(ThreadCheckerMacroTest, Macros) {}

}  // namespace base::internal