1 //===--- status_test.cpp - Tests for the Status and Expected classes ------===//
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 //===----------------------------------------------------------------------===//
11 #include "gtest/gtest.h"
20 RefCounter() { ++Count
; }
21 ~RefCounter() { --Count
; }
22 RefCounter(const RefCounter
&) = delete;
23 RefCounter
&operator=(const RefCounter
&) = delete;
26 int RefCounter::Count
;
28 TEST(Expected
, RefCounter
) {
29 RefCounter::Count
= 0;
30 using uptr
= std::unique_ptr
<RefCounter
>;
32 acxxel::Expected
<uptr
> E0(uptr(new RefCounter
));
33 EXPECT_FALSE(E0
.isError());
34 EXPECT_EQ(1, RefCounter::Count
);
36 acxxel::Expected
<uptr
> E1(std::move(E0
));
37 EXPECT_FALSE(E1
.isError());
38 EXPECT_EQ(1, RefCounter::Count
);
40 acxxel::Expected
<uptr
> E2(acxxel::Status("nothing in here yet"));
41 EXPECT_TRUE(E2
.isError());
42 EXPECT_EQ(1, RefCounter::Count
);
44 EXPECT_FALSE(E2
.isError());
45 EXPECT_EQ(1, RefCounter::Count
);
47 EXPECT_EQ(1, E2
.getValue()->Count
);
48 EXPECT_FALSE(E2
.isError());
49 EXPECT_EQ(1, RefCounter::Count
);
51 EXPECT_EQ(1, E2
.takeValue()->Count
);
52 EXPECT_EQ(0, RefCounter::Count
);