1 //===- llvm/unittest/ADT/BitmaskEnumTest.cpp - BitmaskEnum unit tests -----===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/ADT/BitmaskEnum.h"
11 #include "gtest/gtest.h"
22 LLVM_MARK_AS_BITMASK_ENUM(F4
)
25 TEST(BitmaskEnumTest
, BitwiseOr
) {
33 TEST(BitmaskEnumTest
, BitwiseOrEquals
) {
38 // |= should return a reference to the LHS.
44 TEST(BitmaskEnumTest
, BitwiseAnd
) {
45 Flags f
= static_cast<Flags
>(3) & F2
;
48 f
= (f
| F3
) & (F1
| F2
| F3
);
52 TEST(BitmaskEnumTest
, BitwiseAndEquals
) {
53 Flags f
= F1
| F2
| F3
;
57 // &= should return a reference to the LHS.
62 TEST(BitmaskEnumTest
, BitwiseXor
) {
63 Flags f
= (F1
| F2
) ^ (F2
| F3
);
70 TEST(BitmaskEnumTest
, BitwiseXorEquals
) {
75 // ^= should return a reference to the LHS.
80 TEST(BitmaskEnumTest
, BitwiseNot
) {
82 EXPECT_EQ(14, f
); // Largest value for f is 15.
86 enum class FlagsClass
{
91 LLVM_MARK_AS_BITMASK_ENUM(F3
)
94 TEST(BitmaskEnumTest
, ScopedEnum
) {
95 FlagsClass f
= (FlagsClass::F1
& ~FlagsClass::F0
) | FlagsClass::F2
;
97 EXPECT_EQ(7, static_cast<int>(f
));
101 enum Flags
{ F0
= 0, F1
= 1, F2
= 2, F3
= 4, LLVM_MARK_AS_BITMASK_ENUM(F3
) };
103 static Flags
getFlags() {
110 TEST(BitmaskEnumTest
, EnumInStruct
) { EXPECT_EQ(3, Container::getFlags()); }
117 enum FlagsInNamespace
{
122 LLVM_MARK_AS_BITMASK_ENUM(F3
)
129 TEST(BitmaskEnumTest
, EnumInNamespace
) {
130 foo::bar::FlagsInNamespace f
= ~foo::bar::F0
& (foo::bar::F1
| foo::bar::F2
);