TEST(FlagStatus, negative_lock_clear) { FlagStatus flagStatus; { Vector_ModifierFlag v; v.push_back(ModifierFlag::COMMAND_L); v.push_back(ModifierFlag::FN); v.push_back(ModifierFlag::SHIFT_L); flagStatus.negative_lock_increase(v); EXPECT_EQ(Flags(0), flagStatus.makeFlags()); flagStatus.increase(v); EXPECT_EQ(Flags(0), flagStatus.makeFlags()); flagStatus.increase(v); EXPECT_EQ(ModifierFlag::COMMAND_L | ModifierFlag::FN | ModifierFlag::SHIFT_L, flagStatus.makeFlags()); flagStatus.reset(); EXPECT_EQ(Flags(0), flagStatus.makeFlags()); flagStatus.increase(v); EXPECT_EQ(Flags(0), flagStatus.makeFlags()); flagStatus.negative_lock_clear(); EXPECT_EQ(ModifierFlag::COMMAND_L | ModifierFlag::FN | ModifierFlag::SHIFT_L, flagStatus.makeFlags()); } }
TEST(FlagStatus, negative_lock_increase) { FlagStatus flagStatus; // ---------------------------------------- flagStatus.negative_lock_increase(ModifierFlag::COMMAND_L); EXPECT_EQ(Flags(0), flagStatus.makeFlags()); flagStatus.increase(ModifierFlag::COMMAND_L); EXPECT_EQ(Flags(0), flagStatus.makeFlags()); flagStatus.increase(ModifierFlag::COMMAND_L); EXPECT_EQ(Flags(ModifierFlag::COMMAND_L), flagStatus.makeFlags()); // ---------------------------------------- // lock don't cancel by reset & set. flagStatus.reset(); flagStatus.set(KeyCode::A, Flags(0)); EXPECT_EQ(Flags(0), flagStatus.makeFlags()); flagStatus.increase(ModifierFlag::COMMAND_L); EXPECT_EQ(Flags(0), flagStatus.makeFlags()); flagStatus.increase(ModifierFlag::COMMAND_L); EXPECT_EQ(Flags(ModifierFlag::COMMAND_L), flagStatus.makeFlags()); // ---------------------------------------- flagStatus.reset(); flagStatus.negative_lock_decrease(ModifierFlag::COMMAND_L); EXPECT_EQ(Flags(0), flagStatus.makeFlags()); flagStatus.increase(ModifierFlag::COMMAND_L); EXPECT_EQ(Flags(ModifierFlag::COMMAND_L), flagStatus.makeFlags()); }
TEST(FlagStatus, ScopedTemporaryFlagsChanger) { { FlagStatus flagStatus; flagStatus.increase(ModifierFlag::SHIFT_L); flagStatus.increase(ModifierFlag::SHIFT_L); flagStatus.increase(ModifierFlag::SHIFT_L); flagStatus.increase(ModifierFlag::SHIFT_L); flagStatus.increase(ModifierFlag::SHIFT_R); flagStatus.temporary_increase(ModifierFlag::CONTROL_L); flagStatus.lock_increase(ModifierFlag::COMMAND_R); flagStatus.sticky_increase(ModifierFlag::OPTION_R); EXPECT_EQ(Flags(ModifierFlag::SHIFT_L | ModifierFlag::SHIFT_R | ModifierFlag::CONTROL_L | ModifierFlag::COMMAND_R | ModifierFlag::OPTION_R), flagStatus.makeFlags()); { FlagStatus::ScopedTemporaryFlagsChanger stfc(flagStatus, ModifierFlag::FN | ModifierFlag::OPTION_L | ModifierFlag::SHIFT_R); EXPECT_EQ(Flags(ModifierFlag::FN | ModifierFlag::OPTION_L | ModifierFlag::SHIFT_R), flagStatus.makeFlags()); } EXPECT_EQ(Flags(ModifierFlag::SHIFT_L | ModifierFlag::SHIFT_R | ModifierFlag::CONTROL_L | ModifierFlag::COMMAND_R | ModifierFlag::OPTION_R), flagStatus.makeFlags()); flagStatus.decrease(ModifierFlag::SHIFT_L); flagStatus.decrease(ModifierFlag::SHIFT_L); flagStatus.decrease(ModifierFlag::SHIFT_L); EXPECT_EQ(Flags(ModifierFlag::SHIFT_L | ModifierFlag::SHIFT_R | ModifierFlag::CONTROL_L | ModifierFlag::COMMAND_R | ModifierFlag::OPTION_R), flagStatus.makeFlags()); flagStatus.decrease(ModifierFlag::SHIFT_L); EXPECT_EQ(Flags(ModifierFlag::SHIFT_R | ModifierFlag::CONTROL_L | ModifierFlag::COMMAND_R | ModifierFlag::OPTION_R), flagStatus.makeFlags()); } // ------------------------------------------------------------ { FlagStatus flagStatus; flagStatus.decrease(ModifierFlag::SHIFT_L); flagStatus.decrease(ModifierFlag::SHIFT_L); { Flags flags(ModifierFlag::SHIFT_R); FlagStatus::ScopedTemporaryFlagsChanger stfc(flagStatus, flags); EXPECT_EQ(Flags(ModifierFlag::SHIFT_R), flagStatus.makeFlags()); } flagStatus.increase(ModifierFlag::SHIFT_L); flagStatus.increase(ModifierFlag::SHIFT_L); EXPECT_EQ(Flags(0), flagStatus.makeFlags()); } }
TEST(FlagStatus, increase) { FlagStatus flagStatus; // Do nothing with ModifierFlag::NONE. flagStatus.increase(ModifierFlag::NONE); EXPECT_EQ(Flags(0), flagStatus.makeFlags()); flagStatus.increase(ModifierFlag::SHIFT_L); EXPECT_EQ(Flags(ModifierFlag::SHIFT_L), flagStatus.makeFlags()); flagStatus.increase(ModifierFlag::COMMAND_L | ModifierFlag::CONTROL_L); EXPECT_EQ(Flags(ModifierFlag::COMMAND_L | ModifierFlag::CONTROL_L | ModifierFlag::SHIFT_L), flagStatus.makeFlags()); flagStatus.increase(ModifierFlag::NONE); EXPECT_EQ(Flags(ModifierFlag::COMMAND_L | ModifierFlag::CONTROL_L | ModifierFlag::SHIFT_L), flagStatus.makeFlags()); }
TEST(FlagStatus, decrease) { FlagStatus flagStatus; flagStatus.increase(ModifierFlag::COMMAND_L | ModifierFlag::CONTROL_L); EXPECT_EQ(Flags(ModifierFlag::COMMAND_L | ModifierFlag::CONTROL_L), flagStatus.makeFlags()); flagStatus.decrease(ModifierFlag::CONTROL_L); EXPECT_EQ(Flags(ModifierFlag::COMMAND_L), flagStatus.makeFlags()); }
TEST(FlagStatus, getStickyFlags) { FlagStatus flagStatus; EXPECT_EQ(Flags(0), flagStatus.getStickyFlags()); flagStatus.increase(ModifierFlag::SHIFT_L); flagStatus.temporary_increase(ModifierFlag::SHIFT_R); flagStatus.sticky_increase(ModifierFlag::COMMAND_L); flagStatus.sticky_increase(ModifierFlag::OPTION_L); EXPECT_EQ(ModifierFlag::COMMAND_L | ModifierFlag::OPTION_L, flagStatus.getStickyFlags()); }
TEST(FlagStatus, temporary_decrease) { FlagStatus flagStatus; flagStatus.increase(ModifierFlag::COMMAND_L | ModifierFlag::CONTROL_L); EXPECT_EQ(Flags(ModifierFlag::COMMAND_L | ModifierFlag::CONTROL_L), flagStatus.makeFlags()); flagStatus.temporary_decrease(ModifierFlag::CONTROL_L); EXPECT_EQ(Flags(ModifierFlag::COMMAND_L), flagStatus.makeFlags()); // temporary_increase will reset by flagStatus.set flagStatus.set(KeyCode::COMMAND_L, Flags(ModifierFlag::COMMAND_L)); EXPECT_EQ(Flags(ModifierFlag::COMMAND_L | ModifierFlag::CONTROL_L), flagStatus.makeFlags()); }
TEST(FlagStatus, decrease) { FlagStatus flagStatus; { Vector_ModifierFlag v; v.push_back(ModifierFlag::COMMAND_L); v.push_back(ModifierFlag::CONTROL_L); flagStatus.increase(v); EXPECT_EQ(Flags(ModifierFlag::COMMAND_L | ModifierFlag::CONTROL_L), flagStatus.makeFlags()); } flagStatus.decrease(ModifierFlag::CONTROL_L); EXPECT_EQ(Flags(ModifierFlag::COMMAND_L), flagStatus.makeFlags()); }
TEST(FlagStatus, temporary_increase) { FlagStatus flagStatus; // Do nothing with ModifierFlag::NONE. flagStatus.temporary_increase(ModifierFlag::NONE); EXPECT_EQ(Flags(0), flagStatus.makeFlags()); flagStatus.increase(ModifierFlag::COMMAND_L | ModifierFlag::CONTROL_L); EXPECT_EQ(Flags(ModifierFlag::COMMAND_L | ModifierFlag::CONTROL_L), flagStatus.makeFlags()); flagStatus.temporary_increase(ModifierFlag::OPTION_L); EXPECT_EQ(Flags(ModifierFlag::COMMAND_L | ModifierFlag::CONTROL_L | ModifierFlag::OPTION_L), flagStatus.makeFlags()); // temporary_increase will reset by flagStatus.set flagStatus.set(KeyCode::COMMAND_L, Flags(ModifierFlag::COMMAND_L)); EXPECT_EQ(Flags(ModifierFlag::COMMAND_L | ModifierFlag::CONTROL_L), flagStatus.makeFlags()); }
TEST(FlagStatus, lock_clear) { FlagStatus flagStatus; { Vector_ModifierFlag v; v.push_back(ModifierFlag::COMMAND_L); v.push_back(ModifierFlag::FN); v.push_back(ModifierFlag::SHIFT_L); flagStatus.lock_increase(v); EXPECT_EQ(ModifierFlag::COMMAND_L | ModifierFlag::FN | ModifierFlag::SHIFT_L, flagStatus.makeFlags()); } { flagStatus.increase(ModifierFlag::CAPSLOCK); EXPECT_EQ(ModifierFlag::CAPSLOCK | ModifierFlag::COMMAND_L | ModifierFlag::FN | ModifierFlag::SHIFT_L, flagStatus.makeFlags()); } flagStatus.lock_clear(); EXPECT_EQ(Flags(0), flagStatus.makeFlags()); }
TEST(FlagStatus, increase) { { FlagStatus flagStatus; // Do nothing with ModifierFlag::NONE. flagStatus.increase(ModifierFlag::NONE); EXPECT_EQ(Flags(0), flagStatus.makeFlags()); flagStatus.increase(ModifierFlag::SHIFT_L); EXPECT_EQ(Flags(ModifierFlag::SHIFT_L), flagStatus.makeFlags()); { Vector_ModifierFlag v; v.push_back(ModifierFlag::COMMAND_L); v.push_back(ModifierFlag::CONTROL_L); flagStatus.increase(v); EXPECT_EQ(Flags(ModifierFlag::COMMAND_L | ModifierFlag::CONTROL_L | ModifierFlag::SHIFT_L), flagStatus.makeFlags()); } flagStatus.increase(ModifierFlag::NONE); EXPECT_EQ(Flags(ModifierFlag::COMMAND_L | ModifierFlag::CONTROL_L | ModifierFlag::SHIFT_L), flagStatus.makeFlags()); } { FlagStatus flagStatus; Vector_ModifierFlag v; v.push_back(ModifierFlag::COMMAND_L); v.push_back(ModifierFlag::CONTROL_L); flagStatus.increase(ModifierFlag::SHIFT_L, v); EXPECT_EQ(Flags(ModifierFlag::COMMAND_L | ModifierFlag::CONTROL_L | ModifierFlag::SHIFT_L), flagStatus.makeFlags()); } { FlagStatus flagStatus; Vector_ModifierFlag v; v.push_back(ModifierFlag::COMMAND_L); v.push_back(ModifierFlag::CONTROL_L); flagStatus.increase(ModifierFlag::COMMAND_L, v); EXPECT_EQ(Flags(ModifierFlag::COMMAND_L | ModifierFlag::CONTROL_L), flagStatus.makeFlags()); flagStatus.decrease(v); EXPECT_EQ(Flags(0), flagStatus.makeFlags()); } }
TEST(FlagStatus, isOn) { { FlagStatus flagStatus; { Vector_ModifierFlag modifierFlags; EXPECT_TRUE(flagStatus.isOn(modifierFlags)); } { Vector_ModifierFlag modifierFlags; modifierFlags.push_back(ModifierFlag(ModifierFlag::ZERO)); EXPECT_TRUE(flagStatus.isOn(modifierFlags)); } { Vector_ModifierFlag modifierFlags; modifierFlags.push_back(ModifierFlag::NONE); EXPECT_TRUE(flagStatus.isOn(modifierFlags)); } { Vector_ModifierFlag modifierFlags; modifierFlags.push_back(ModifierFlag::NONE); modifierFlags.push_back(ModifierFlag::ZERO); EXPECT_TRUE(flagStatus.isOn(modifierFlags)); } } { FlagStatus flagStatus; flagStatus.increase(ModifierFlag::SHIFT_L); { Vector_ModifierFlag modifierFlags; modifierFlags.push_back(ModifierFlag::SHIFT_L); EXPECT_TRUE(flagStatus.isOn(modifierFlags)); } { Vector_ModifierFlag modifierFlags; modifierFlags.push_back(ModifierFlag::SHIFT_L); modifierFlags.push_back(ModifierFlag::NONE); EXPECT_TRUE(flagStatus.isOn(modifierFlags)); } { Vector_ModifierFlag modifierFlags; modifierFlags.push_back(ModifierFlag::SHIFT_R); EXPECT_FALSE(flagStatus.isOn(modifierFlags)); } { Vector_ModifierFlag modifierFlags; modifierFlags.push_back(ModifierFlag::SHIFT_L); modifierFlags.push_back(ModifierFlag::ZERO); EXPECT_TRUE(flagStatus.isOn(modifierFlags)); } } { FlagStatus flagStatus; flagStatus.increase(ModifierFlag::SHIFT_L); flagStatus.increase(ModifierFlag::ZERO); { Vector_ModifierFlag modifierFlags; modifierFlags.push_back(ModifierFlag::SHIFT_L); EXPECT_TRUE(flagStatus.isOn(modifierFlags)); } { Vector_ModifierFlag modifierFlags; modifierFlags.push_back(ModifierFlag::SHIFT_L); modifierFlags.push_back(ModifierFlag::NONE); EXPECT_TRUE(flagStatus.isOn(modifierFlags)); } { Vector_ModifierFlag modifierFlags; modifierFlags.push_back(ModifierFlag::SHIFT_R); EXPECT_FALSE(flagStatus.isOn(modifierFlags)); } { Vector_ModifierFlag modifierFlags; modifierFlags.push_back(ModifierFlag::SHIFT_L); modifierFlags.push_back(ModifierFlag::ZERO); EXPECT_TRUE(flagStatus.isOn(modifierFlags)); } { Vector_ModifierFlag modifierFlags; modifierFlags.push_back(ModifierFlag::SHIFT_L); modifierFlags.push_back(ModifierFlag::ZERO); modifierFlags.push_back(ModifierFlag::NONE); EXPECT_TRUE(flagStatus.isOn(modifierFlags)); } } { FlagStatus flagStatus; flagStatus.increase(ModifierFlag::SHIFT_L); flagStatus.increase(ModifierFlag::CONTROL_R); flagStatus.increase(ModifierFlag::COMMAND_R); { Vector_ModifierFlag modifierFlags; modifierFlags.push_back(ModifierFlag::SHIFT_L); EXPECT_TRUE(flagStatus.isOn(modifierFlags)); } { Vector_ModifierFlag modifierFlags; modifierFlags.push_back(ModifierFlag::SHIFT_L); modifierFlags.push_back(ModifierFlag::NONE); EXPECT_FALSE(flagStatus.isOn(modifierFlags)); } { Vector_ModifierFlag modifierFlags; modifierFlags.push_back(ModifierFlag::SHIFT_R); EXPECT_FALSE(flagStatus.isOn(modifierFlags)); } { Vector_ModifierFlag modifierFlags; modifierFlags.push_back(ModifierFlag::SHIFT_L); modifierFlags.push_back(ModifierFlag::CONTROL_R); modifierFlags.push_back(ModifierFlag::COMMAND_R); modifierFlags.push_back(ModifierFlag::NONE); EXPECT_TRUE(flagStatus.isOn(modifierFlags)); } } }