#include #include "Flag.h" enum class TestFlag : uint8_t { FLAG0, FLAG1, FLAG2, FLAG3, FLAG4 }; /** * Test bitset flags (compile-time methods) */ TEST(FlagTests, FlagMethodTestCompileTime) { using enum TestFlag; auto flag = Flag{}; // Test setting and reading single flags, exclusively flag.Reset(); ASSERT_TRUE(flag.HasOnly()); flag.Reset(); ASSERT_TRUE(flag.HasOnly()); ASSERT_FALSE(flag.HasOnly()); // Test setting and reading multiple flags, exclusively flag.Reset(); ASSERT_FALSE(flag.Has()); ASSERT_TRUE(flag.Has()); ASSERT_TRUE(flag.Has()); ASSERT_TRUE((flag.Has())); ASSERT_FALSE(flag.HasOnly()); ASSERT_FALSE(flag.HasOnly()); ASSERT_TRUE((flag.HasOnly())); // Test flags are being properly reset for next batch of tests flag.Reset(); ASSERT_TRUE(flag.Has()); ASSERT_TRUE(flag.HasOnly()); ASSERT_FALSE(flag.Has()); ASSERT_FALSE((flag.Has())); // Test setting and reading single flags, non-exclusively flag.Set(); ASSERT_TRUE(flag.Has()); ASSERT_FALSE(flag.Has()); // Test setting and reading multiple flags, non-exclusively flag.Set(); ASSERT_TRUE((flag.Has())); ASSERT_TRUE(flag.Has()); ASSERT_FALSE((flag.Has())); ASSERT_TRUE((flag.Has())); ASSERT_FALSE(flag.Has()); ASSERT_FALSE((flag.Has())); // Test unsetting and reading multiple flags, non-exclusively flag.Unset(); ASSERT_FALSE((flag.Has())); ASSERT_FALSE(flag.Has()); ASSERT_TRUE((flag.Has())); ASSERT_FALSE((flag.Has())); ASSERT_FALSE(flag.Has()); ASSERT_FALSE((flag.Has())); } /** * Test bitset flags (run-time methods) */ TEST(FlagTests, FlagMethodTestRunTime) { using enum TestFlag; auto flag = Flag{}; // Test setting and reading single flags, exclusively flag.Reset(FLAG0); ASSERT_TRUE(flag.HasOnly(FLAG0)); flag.Reset(FLAG2); ASSERT_TRUE(flag.HasOnly(FLAG2)); ASSERT_FALSE(flag.HasOnly(FLAG1)); // Test setting and reading multiple flags, exclusively flag.Reset(FLAG3, FLAG1); ASSERT_FALSE(flag.Has(FLAG2)); ASSERT_TRUE(flag.Has(FLAG3)); ASSERT_TRUE(flag.Has(FLAG1)); ASSERT_TRUE(flag.Has(FLAG3, FLAG1)); ASSERT_FALSE(flag.HasOnly(FLAG3)); ASSERT_FALSE(flag.HasOnly(FLAG1)); ASSERT_TRUE(flag.HasOnly(FLAG3, FLAG1)); // Test flags are being properly reset for next batch of tests flag.Reset(FLAG0); ASSERT_TRUE(flag.Has(FLAG0)); ASSERT_TRUE(flag.HasOnly(FLAG0)); ASSERT_FALSE(flag.Has(FLAG3)); ASSERT_FALSE(flag.Has(FLAG3, FLAG1, FLAG2)); // Test setting and reading single flags, non-exclusively flag.Set(FLAG3); ASSERT_TRUE(flag.Has(FLAG3)); ASSERT_FALSE(flag.Has(FLAG1)); // Test setting and reading multiple flags, non-exclusively flag.Set(FLAG2, FLAG4); ASSERT_TRUE(flag.Has(FLAG2, FLAG4)); ASSERT_TRUE(flag.Has(FLAG3)); ASSERT_FALSE(flag.Has(FLAG3, FLAG1)); ASSERT_TRUE(flag.Has(FLAG3, FLAG2, FLAG4)); ASSERT_FALSE(flag.Has(FLAG1)); ASSERT_FALSE(flag.Has(FLAG1, FLAG3, FLAG2, FLAG4)); // Test unsetting and reading multiple flags, non-exclusively flag.Unset(FLAG3, FLAG1); ASSERT_FALSE(flag.Has(FLAG3, FLAG1)); ASSERT_FALSE(flag.Has(FLAG3)); ASSERT_TRUE(flag.Has(FLAG2, FLAG4)); ASSERT_FALSE(flag.Has(FLAG3, FLAG2, FLAG4)); ASSERT_FALSE(flag.Has(FLAG1)); ASSERT_FALSE(flag.Has(FLAG1, FLAG3, FLAG2, FLAG4)); }