-
Notifications
You must be signed in to change notification settings - Fork 98
Expand file tree
/
Copy pathenum_flags_tests.cpp
More file actions
55 lines (41 loc) · 1.02 KB
/
Copy pathenum_flags_tests.cpp
File metadata and controls
55 lines (41 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// LAF Base Library
// Copyright (C) 2024 Igara Studio S.A.
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#include <gtest/gtest.h>
#include "base/enum_flags.h"
#include "base/ints.h"
enum class U8 : uint8_t { A = 1, B = 2, C = 4 };
enum class U32 : uint32_t { A = 1, B = 256 };
LAF_ENUM_FLAGS(U8);
LAF_ENUM_FLAGS(U32);
TEST(EnumFlags, Uint8)
{
U8 a = {};
EXPECT_EQ(U8(0), a);
a |= U8::A;
EXPECT_EQ(U8::A, a);
a |= U8::B;
EXPECT_EQ(U8::A | U8::B, a);
EXPECT_EQ(U8::B, a & U8::B);
EXPECT_EQ(U8(0), a & U8::C);
EXPECT_EQ(U8::A | U8::B, a & (U8::A | U8::B));
a &= U8::B;
EXPECT_EQ(U8::B, a);
a ^= U8::C;
EXPECT_EQ(U8::B | U8::C, a);
}
TEST(EnumFlags, Conversion)
{
U32 a = U32::A | U32::B;
EXPECT_EQ(U32::A | U32::B, a);
EXPECT_EQ(uint32_t(U8::A), uint32_t(U32::A));
U8 b = U8(a);
EXPECT_EQ(U8::A, b); // U32::B is lost in uint8_t
}
int main(int argc, char** argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}