1 //===- llvm/unittest/ADT/BitmaskEnumTest.cpp - BitmaskEnum unit tests -----===//
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 "llvm/ADT/BitmaskEnum.h"
10 #include "gtest/gtest.h"
21 LLVM_MARK_AS_BITMASK_ENUM(F4
)
24 TEST(BitmaskEnumTest
, BitwiseOr
) {
32 TEST(BitmaskEnumTest
, BitwiseOrEquals
) {
37 // |= should return a reference to the LHS.
43 TEST(BitmaskEnumTest
, BitwiseAnd
) {
44 Flags f
= static_cast<Flags
>(3) & F2
;
47 f
= (f
| F3
) & (F1
| F2
| F3
);
51 TEST(BitmaskEnumTest
, BitwiseAndEquals
) {
52 Flags f
= F1
| F2
| F3
;
56 // &= should return a reference to the LHS.
61 TEST(BitmaskEnumTest
, BitwiseXor
) {
62 Flags f
= (F1
| F2
) ^ (F2
| F3
);
69 TEST(BitmaskEnumTest
, BitwiseXorEquals
) {
74 // ^= should return a reference to the LHS.
79 TEST(BitmaskEnumTest
, BitwiseNot
) {
81 EXPECT_EQ(14, f
); // Largest value for f is 15.
85 enum class FlagsClass
{
90 LLVM_MARK_AS_BITMASK_ENUM(F3
)
93 TEST(BitmaskEnumTest
, ScopedEnum
) {
94 FlagsClass f
= (FlagsClass::F1
& ~FlagsClass::F0
) | FlagsClass::F2
;
96 EXPECT_EQ(7, static_cast<int>(f
));
100 enum Flags
{ F0
= 0, F1
= 1, F2
= 2, F3
= 4, LLVM_MARK_AS_BITMASK_ENUM(F3
) };
102 static Flags
getFlags() {
109 TEST(BitmaskEnumTest
, EnumInStruct
) { EXPECT_EQ(3, Container::getFlags()); }
116 enum FlagsInNamespace
{
121 LLVM_MARK_AS_BITMASK_ENUM(F3
)
128 TEST(BitmaskEnumTest
, EnumInNamespace
) {
129 foo::bar::FlagsInNamespace f
= ~foo::bar::F0
& (foo::bar::F1
| foo::bar::F2
);