ladybird/AK/Tests/TestEnumBits.cpp
Brian Gianforcaro 1682f0b760 Everything: Move to SPDX license identifiers in all files.
SPDX License Identifiers are a more compact / standardized
way of representing file license information.

See: https://spdx.dev/resources/use/#identifiers

This was done with the `ambr` search and replace tool.

 ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-22 11:22:27 +02:00

70 lines
1.7 KiB
C++

/*
* Copyright (c) 2021, Brian Gianforcaro <b.gianfo@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/EnumBits.h>
#include <AK/TestSuite.h>
enum class VideoIntro : u8 {
None = 0x0,
Well = 0x1,
Hello = 0x2,
Friends = 0x4,
ExclimationMark = 0x8,
CompleteIntro = Well | Hello | Friends | ExclimationMark,
};
AK_ENUM_BITWISE_OPERATORS(VideoIntro);
TEST_CASE(bitwise_or)
{
auto intro = VideoIntro::Well | VideoIntro::Hello | VideoIntro::Friends | VideoIntro::ExclimationMark;
EXPECT_EQ(intro, VideoIntro::CompleteIntro);
}
TEST_CASE(bitwise_and)
{
auto intro = VideoIntro::CompleteIntro;
EXPECT_EQ(intro & VideoIntro::Hello, VideoIntro::Hello);
}
TEST_CASE(bitwise_xor)
{
auto intro = VideoIntro::Well | VideoIntro::Hello | VideoIntro::Friends;
EXPECT_EQ(intro ^ VideoIntro::CompleteIntro, VideoIntro::ExclimationMark);
}
TEST_CASE(bitwise_not)
{
auto intro = ~VideoIntro::CompleteIntro;
EXPECT_EQ(intro & VideoIntro::CompleteIntro, VideoIntro::None);
}
TEST_CASE(bitwise_or_equal)
{
auto intro = VideoIntro::Well | VideoIntro::Hello | VideoIntro::Friends;
EXPECT_EQ(intro |= VideoIntro::ExclimationMark, VideoIntro::CompleteIntro);
}
TEST_CASE(bitwise_and_equal)
{
auto intro = VideoIntro::CompleteIntro;
EXPECT_EQ(intro &= VideoIntro::Hello, VideoIntro::Hello);
}
TEST_CASE(bitwise_xor_equal)
{
auto intro = VideoIntro::Well | VideoIntro::Hello | VideoIntro::Friends;
EXPECT_EQ(intro ^= VideoIntro::CompleteIntro, VideoIntro::ExclimationMark);
}
TEST_CASE(has_flag)
{
auto intro = VideoIntro::Hello | VideoIntro::Friends;
EXPECT(has_flag(intro, VideoIntro::Friends));
EXPECT(!has_flag(intro, VideoIntro::Well));
}
TEST_MAIN(EnumBits)