1 //===-- FlagsTest.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 "gtest/gtest.h"
11 #include "lldb/Utility/Flags.h"
13 using namespace lldb_private
;
19 eAllFlags
= (eFlag0
| eFlag1
| eFlag2
)
22 TEST(Flags
, GetBitSize
) {
24 // Methods like ClearCount depend on this specific value, so we test
26 EXPECT_EQ(32U, f
.GetBitSize());
32 EXPECT_EQ(0x3U
, f
.Get());
38 EXPECT_EQ(0x3U
, f
.Get());
41 EXPECT_EQ(0x2U
, f
.Get());
44 EXPECT_EQ(0x0U
, f
.Get());
50 EXPECT_FALSE(f
.AllSet(eFlag0
| eFlag1
));
53 EXPECT_FALSE(f
.AllSet(eFlag0
| eFlag1
));
56 EXPECT_TRUE(f
.AllSet(eFlag0
| eFlag1
));
59 EXPECT_FALSE(f
.AllSet(eFlag0
| eFlag1
));
62 EXPECT_FALSE(f
.AllSet(eFlag0
| eFlag1
));
68 EXPECT_FALSE(f
.AnySet(eFlag0
| eFlag1
));
71 EXPECT_TRUE(f
.AnySet(eFlag0
| eFlag1
));
74 EXPECT_TRUE(f
.AnySet(eFlag0
| eFlag1
));
77 EXPECT_TRUE(f
.AnySet(eFlag0
| eFlag1
));
80 EXPECT_FALSE(f
.AnySet(eFlag0
| eFlag1
));
86 EXPECT_FALSE(f
.Test(eFlag0
));
87 EXPECT_FALSE(f
.Test(eFlag1
));
88 EXPECT_FALSE(f
.Test(eFlag2
));
91 EXPECT_TRUE(f
.Test(eFlag0
));
92 EXPECT_FALSE(f
.Test(eFlag1
));
93 EXPECT_FALSE(f
.Test(eFlag2
));
96 EXPECT_TRUE(f
.Test(eFlag0
));
97 EXPECT_TRUE(f
.Test(eFlag1
));
98 EXPECT_FALSE(f
.Test(eFlag2
));
101 EXPECT_FALSE(f
.Test(eFlag0
));
102 EXPECT_TRUE(f
.Test(eFlag1
));
103 EXPECT_FALSE(f
.Test(eFlag2
));
105 // FIXME: Should Flags assert on Test(eFlag0 | eFlag1) (more than one bit)?
108 TEST(Flags
, AllClear
) {
111 EXPECT_TRUE(f
.AllClear(eFlag0
| eFlag1
));
114 EXPECT_FALSE(f
.AllClear(eFlag0
| eFlag1
));
118 EXPECT_FALSE(f
.AllClear(eFlag0
| eFlag1
));
121 EXPECT_TRUE(f
.AnyClear(eFlag0
| eFlag1
));
124 TEST(Flags
, AnyClear
) {
126 EXPECT_TRUE(f
.AnyClear(eFlag0
| eFlag1
));
129 EXPECT_TRUE(f
.AnyClear(eFlag0
| eFlag1
));
133 EXPECT_FALSE(f
.AnyClear(eFlag0
| eFlag1
));
136 EXPECT_TRUE(f
.AnyClear(eFlag0
| eFlag1
));
139 EXPECT_TRUE(f
.AnyClear(eFlag0
| eFlag1
));
142 TEST(Flags
, IsClear
) {
145 EXPECT_TRUE(f
.IsClear(eFlag0
));
146 EXPECT_TRUE(f
.IsClear(eFlag1
));
149 EXPECT_FALSE(f
.IsClear(eFlag0
));
150 EXPECT_TRUE(f
.IsClear(eFlag1
));
153 EXPECT_FALSE(f
.IsClear(eFlag0
));
154 EXPECT_FALSE(f
.IsClear(eFlag1
));
157 EXPECT_TRUE(f
.IsClear(eFlag0
));
158 EXPECT_FALSE(f
.IsClear(eFlag1
));
161 EXPECT_TRUE(f
.IsClear(eFlag0
));
162 EXPECT_TRUE(f
.IsClear(eFlag1
));