mirror of https://github.com/OpenTTD/OpenTTD
Codechange: add unit test against over optimisation of enum-bitmasks
parent
90f5a9440c
commit
0f5f5714b3
|
@ -13,6 +13,8 @@
|
|||
|
||||
#include "../stdafx.h"
|
||||
|
||||
#include "../core/enum_type.hpp"
|
||||
|
||||
#include "../3rdparty/catch2/catch.hpp"
|
||||
|
||||
enum TestEnum : int8_t {
|
||||
|
@ -29,3 +31,17 @@ TEST_CASE("EnumOverOptimisation_BoundsCheck")
|
|||
TestEnum three = static_cast<TestEnum>(3);
|
||||
CHECK(TWO < three);
|
||||
}
|
||||
|
||||
enum class TestEnumFlags : uint8_t {
|
||||
Zero = 0,
|
||||
One = 1 << 0,
|
||||
Two = 1 << 1,
|
||||
};
|
||||
DECLARE_ENUM_AS_BIT_SET(TestEnumFlags)
|
||||
|
||||
TEST_CASE("EnumOverOptimisation_Bitmask")
|
||||
{
|
||||
TestEnumFlags three = TestEnumFlags::One | TestEnumFlags::Two;
|
||||
CHECK(HasFlag(three, TestEnumFlags::One));
|
||||
CHECK(HasFlag(three, TestEnumFlags::Two));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue