brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.2 KiB · bfb1ea4 Raw
52 lines · cpp
1//===-- FunctionTests.cpp -------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#include "support/Function.h"10#include "gmock/gmock.h"11#include "gtest/gtest.h"12 13namespace clang {14namespace clangd {15namespace {16 17TEST(EventTest, Subscriptions) {18  Event<int> E;19  int N = 0;20  {21    Event<int>::Subscription SubA;22    // No subscriptions are active.23    E.broadcast(42);24    EXPECT_EQ(0, N);25 26    Event<int>::Subscription SubB = E.observe([&](int) { ++N; });27    // Now one is active.28    E.broadcast(42);29    EXPECT_EQ(1, N);30 31    SubA = E.observe([&](int) { ++N; });32    // Both are active.33    EXPECT_EQ(1, N);34    E.broadcast(42);35    EXPECT_EQ(3, N);36 37    SubA = std::move(SubB);38    // One is active.39    EXPECT_EQ(3, N);40    E.broadcast(42);41    EXPECT_EQ(4, N);42  }43  // None are active.44  EXPECT_EQ(4, N);45  E.broadcast(42);46  EXPECT_EQ(4, N);47}48 49} // namespace50} // namespace clangd51} // namespace clang52