[AArch64,ELF] Restrict MOVZ/MOVK to non-PIC large code model (#70178)
[llvm-project.git] / lldb / unittests / Utility / FlagsTest.cpp
blobc33a19547a6faf248808bb9ea25970a9449487be
1 //===-- FlagsTest.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-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "gtest/gtest.h"
11 #include "lldb/Utility/Flags.h"
13 using namespace lldb_private;
15 enum DummyFlags {
16 eFlag0 = 1 << 0,
17 eFlag1 = 1 << 1,
18 eFlag2 = 1 << 2,
19 eAllFlags = (eFlag0 | eFlag1 | eFlag2)
22 TEST(Flags, GetBitSize) {
23 Flags f;
24 // Methods like ClearCount depend on this specific value, so we test
25 // against it here.
26 EXPECT_EQ(32U, f.GetBitSize());
29 TEST(Flags, Reset) {
30 Flags f;
31 f.Reset(0x3);
32 EXPECT_EQ(0x3U, f.Get());
35 TEST(Flags, Clear) {
36 Flags f;
37 f.Reset(0x3);
38 EXPECT_EQ(0x3U, f.Get());
40 f.Clear(0x5);
41 EXPECT_EQ(0x2U, f.Get());
43 f.Clear();
44 EXPECT_EQ(0x0U, f.Get());
47 TEST(Flags, AllSet) {
48 Flags f;
50 EXPECT_FALSE(f.AllSet(eFlag0 | eFlag1));
52 f.Set(eFlag0);
53 EXPECT_FALSE(f.AllSet(eFlag0 | eFlag1));
55 f.Set(eFlag1);
56 EXPECT_TRUE(f.AllSet(eFlag0 | eFlag1));
58 f.Clear(eFlag1);
59 EXPECT_FALSE(f.AllSet(eFlag0 | eFlag1));
61 f.Clear(eFlag0);
62 EXPECT_FALSE(f.AllSet(eFlag0 | eFlag1));
65 TEST(Flags, AnySet) {
66 Flags f;
68 EXPECT_FALSE(f.AnySet(eFlag0 | eFlag1));
70 f.Set(eFlag0);
71 EXPECT_TRUE(f.AnySet(eFlag0 | eFlag1));
73 f.Set(eFlag1);
74 EXPECT_TRUE(f.AnySet(eFlag0 | eFlag1));
76 f.Clear(eFlag1);
77 EXPECT_TRUE(f.AnySet(eFlag0 | eFlag1));
79 f.Clear(eFlag0);
80 EXPECT_FALSE(f.AnySet(eFlag0 | eFlag1));
83 TEST(Flags, Test) {
84 Flags f;
86 EXPECT_FALSE(f.Test(eFlag0));
87 EXPECT_FALSE(f.Test(eFlag1));
88 EXPECT_FALSE(f.Test(eFlag2));
90 f.Set(eFlag0);
91 EXPECT_TRUE(f.Test(eFlag0));
92 EXPECT_FALSE(f.Test(eFlag1));
93 EXPECT_FALSE(f.Test(eFlag2));
95 f.Set(eFlag1);
96 EXPECT_TRUE(f.Test(eFlag0));
97 EXPECT_TRUE(f.Test(eFlag1));
98 EXPECT_FALSE(f.Test(eFlag2));
100 f.Clear(eFlag0);
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) {
109 Flags f;
111 EXPECT_TRUE(f.AllClear(eFlag0 | eFlag1));
113 f.Set(eFlag0);
114 EXPECT_FALSE(f.AllClear(eFlag0 | eFlag1));
116 f.Set(eFlag1);
117 f.Clear(eFlag0);
118 EXPECT_FALSE(f.AllClear(eFlag0 | eFlag1));
120 f.Clear(eFlag1);
121 EXPECT_TRUE(f.AnyClear(eFlag0 | eFlag1));
124 TEST(Flags, AnyClear) {
125 Flags f;
126 EXPECT_TRUE(f.AnyClear(eFlag0 | eFlag1));
128 f.Set(eFlag0);
129 EXPECT_TRUE(f.AnyClear(eFlag0 | eFlag1));
131 f.Set(eFlag1);
132 f.Set(eFlag0);
133 EXPECT_FALSE(f.AnyClear(eFlag0 | eFlag1));
135 f.Clear(eFlag1);
136 EXPECT_TRUE(f.AnyClear(eFlag0 | eFlag1));
138 f.Clear(eFlag0);
139 EXPECT_TRUE(f.AnyClear(eFlag0 | eFlag1));
142 TEST(Flags, IsClear) {
143 Flags f;
145 EXPECT_TRUE(f.IsClear(eFlag0));
146 EXPECT_TRUE(f.IsClear(eFlag1));
148 f.Set(eFlag0);
149 EXPECT_FALSE(f.IsClear(eFlag0));
150 EXPECT_TRUE(f.IsClear(eFlag1));
152 f.Set(eFlag1);
153 EXPECT_FALSE(f.IsClear(eFlag0));
154 EXPECT_FALSE(f.IsClear(eFlag1));
156 f.Clear(eFlag0);
157 EXPECT_TRUE(f.IsClear(eFlag0));
158 EXPECT_FALSE(f.IsClear(eFlag1));
160 f.Clear(eFlag1);
161 EXPECT_TRUE(f.IsClear(eFlag0));
162 EXPECT_TRUE(f.IsClear(eFlag1));