4#include "gmock/gmock.h"
5#include "gtest/gtest.h"
15TEST(CancellationTest, CancellationTest) {
17 WithContext ContextWithCancellation(std::move(Task.first));
23TEST(CancellationTest, CancelerDiesContextLives) {
24 std::optional<WithContext> ContextWithCancellation;
27 ContextWithCancellation.emplace(std::move(Task.first));
35TEST(CancellationTest, TaskContextDiesHandleLives) {
38 WithContext ContextWithCancellation(std::move(Task.first));
48 enum { OuterReason = 1, InnerReason = 2 };
49 std::pair<Context, Canceler> Outer,
Inner;
53 WithContext WithOuter(Outer.first.clone());
59TEST(CancellationTest, Nested) {
61 NestedTasks CancelInner;
62 CancelInner.Inner.second();
63 EXPECT_EQ(NestedTasks::InnerReason,
isCancelled(CancelInner.Inner.first));
66 NestedTasks CancelOuter;
67 CancelOuter.Outer.second();
68 EXPECT_EQ(NestedTasks::OuterReason,
isCancelled(CancelOuter.Inner.first));
69 EXPECT_EQ(NestedTasks::OuterReason,
isCancelled(CancelOuter.Outer.first));
72TEST(CancellationTest, AsynCancellationTest) {
73 std::atomic<bool> HasCancelled(
false);
74 Notification Cancelled;
75 auto TaskToBeCancelled = [&](Context Ctx) {
76 WithContext ContextGuard(std::move(Ctx));
81 std::thread AsyncTask(TaskToBeCancelled, std::move(Task.first));
86 EXPECT_TRUE(HasCancelled);
std::pair< Context, Canceler > Inner
TEST(BackgroundQueueTest, Priority)
std::pair< Context, Canceler > cancelableTask(int Reason)
Defines a new task whose cancellation may be requested.
int isCancelled(const Context &Ctx)
If the current context is within a cancelled task, returns the reason.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//