File indexing completed on 2025-01-18 10:17:43
0001
0002 #include "catch.hpp"
0003
0004 #include <JANA/Utils/JStatusBits.h>
0005
0006 TEST_CASE("JStatusBitsTest_Unscoped") {
0007
0008 enum MyUnscopedEnum { FirstBit, SecondBit, ThirdBit, MyEnumSize };
0009 JStatusBits<MyUnscopedEnum> sut;
0010
0011 sut.SetStatusBit(FirstBit, true);
0012 REQUIRE(sut.GetStatusBit(FirstBit) == true);
0013 REQUIRE(sut.GetStatusBit(SecondBit) == false);
0014 REQUIRE(sut.GetStatusBit(ThirdBit) == false);
0015
0016 sut.SetStatusBit(ThirdBit, true);
0017 REQUIRE(sut.GetStatusBit(FirstBit) == true);
0018 REQUIRE(sut.GetStatusBit(SecondBit) == false);
0019 REQUIRE(sut.GetStatusBit(ThirdBit) == true);
0020
0021 sut.SetStatusBit(FirstBit, false);
0022 REQUIRE(sut.GetStatusBit(FirstBit) == false);
0023 REQUIRE(sut.GetStatusBit(SecondBit) == false);
0024 REQUIRE(sut.GetStatusBit(ThirdBit) == true);
0025
0026 sut.ClearStatusBit(ThirdBit);
0027 REQUIRE(sut.GetStatusBit(FirstBit) == false);
0028 REQUIRE(sut.GetStatusBit(SecondBit) == false);
0029 REQUIRE(sut.GetStatusBit(ThirdBit) == false);
0030
0031 sut.SetStatusBit(FirstBit, true);
0032 sut.ClearStatus();
0033 REQUIRE(sut.GetStatusBit(FirstBit) == false);
0034 REQUIRE(sut.GetStatusBit(SecondBit) == false);
0035 REQUIRE(sut.GetStatusBit(ThirdBit) == false);
0036 }
0037
0038 TEST_CASE("JStatusBitsTest_Scoped") {
0039
0040 enum class MyScopedEnum { FirstBit, SecondBit, ThirdBit };
0041 JStatusBits<MyScopedEnum> sut;
0042
0043 sut.SetStatusBit(MyScopedEnum::FirstBit, true);
0044 REQUIRE(sut.GetStatusBit(MyScopedEnum::FirstBit) == true);
0045 REQUIRE(sut.GetStatusBit(MyScopedEnum::SecondBit) == false);
0046 REQUIRE(sut.GetStatusBit(MyScopedEnum::ThirdBit) == false);
0047
0048 sut.SetStatusBit(MyScopedEnum::ThirdBit, true);
0049 REQUIRE(sut.GetStatusBit(MyScopedEnum::FirstBit) == true);
0050 REQUIRE(sut.GetStatusBit(MyScopedEnum::SecondBit) == false);
0051 REQUIRE(sut.GetStatusBit(MyScopedEnum::ThirdBit) == true);
0052
0053 sut.SetStatusBit(MyScopedEnum::FirstBit, false);
0054 REQUIRE(sut.GetStatusBit(MyScopedEnum::FirstBit) == false);
0055 REQUIRE(sut.GetStatusBit(MyScopedEnum::SecondBit) == false);
0056 REQUIRE(sut.GetStatusBit(MyScopedEnum::ThirdBit) == true);
0057
0058 sut.ClearStatusBit(MyScopedEnum::ThirdBit);
0059 REQUIRE(sut.GetStatusBit(MyScopedEnum::FirstBit) == false);
0060 REQUIRE(sut.GetStatusBit(MyScopedEnum::SecondBit) == false);
0061 REQUIRE(sut.GetStatusBit(MyScopedEnum::ThirdBit) == false);
0062
0063 sut.SetStatusBit(MyScopedEnum::FirstBit, true);
0064 sut.ClearStatus();
0065 REQUIRE(sut.GetStatusBit(MyScopedEnum::FirstBit) == false);
0066 REQUIRE(sut.GetStatusBit(MyScopedEnum::SecondBit) == false);
0067 REQUIRE(sut.GetStatusBit(MyScopedEnum::ThirdBit) == false);
0068 }