1 //===-- SharedClusterTest.cpp ---------------------------------------------===//
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-exception
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Utility/SharedCluster.h"
10 #include "gmock/gmock.h"
11 #include "gtest/gtest.h"
13 using namespace lldb_private
;
16 class DestructNotifier
{
18 DestructNotifier(std::vector
<int> &Queue
, int Key
) : Queue(Queue
), Key(Key
) {}
19 ~DestructNotifier() { Queue
.push_back(Key
); }
21 std::vector
<int> &Queue
;
26 TEST(SharedCluster
, ClusterManager
) {
27 std::vector
<int> Queue
;
29 auto CM
= ClusterManager
<DestructNotifier
>::Create();
30 auto *One
= new DestructNotifier(Queue
, 1);
31 auto *Two
= new DestructNotifier(Queue
, 2);
32 CM
->ManageObject(One
);
33 CM
->ManageObject(Two
);
35 ASSERT_THAT(Queue
, testing::IsEmpty());
37 std::shared_ptr
<DestructNotifier
> OnePtr
= CM
->GetSharedPointer(One
);
38 ASSERT_EQ(OnePtr
->Key
, 1);
39 ASSERT_THAT(Queue
, testing::IsEmpty());
42 std::shared_ptr
<DestructNotifier
> OnePtrCopy
= OnePtr
;
43 ASSERT_EQ(OnePtrCopy
->Key
, 1);
44 ASSERT_THAT(Queue
, testing::IsEmpty());
48 std::shared_ptr
<DestructNotifier
> TwoPtr
= CM
->GetSharedPointer(Two
);
49 ASSERT_EQ(TwoPtr
->Key
, 2);
50 ASSERT_THAT(Queue
, testing::IsEmpty());
53 ASSERT_THAT(Queue
, testing::IsEmpty());
55 ASSERT_THAT(Queue
, testing::IsEmpty());
57 ASSERT_THAT(Queue
, testing::ElementsAre(1, 2));