Пример #1
0
TEST(FlagStatus, getLockedFlags) {
  FlagStatus flagStatus;

  EXPECT_EQ(Flags(0), flagStatus.getLockedFlags());

  flagStatus.increase(ModifierFlag::SHIFT_L);
  flagStatus.temporary_increase(ModifierFlag::SHIFT_R);
  flagStatus.lock_increase(ModifierFlag::COMMAND_L);
  flagStatus.lock_increase(ModifierFlag::OPTION_L);
  EXPECT_EQ(ModifierFlag::COMMAND_L | ModifierFlag::OPTION_L, flagStatus.getLockedFlags());
}
Пример #2
0
TEST(FlagStatus, CapsLock) {
  FlagStatus flagStatus;

  flagStatus.set(KeyCode::CAPSLOCK, Flags(ModifierFlag::CAPSLOCK));
  EXPECT_EQ(Flags(ModifierFlag::CAPSLOCK), flagStatus.makeFlags());

  flagStatus.reset();

  flagStatus.set(KeyCode::A, Flags(ModifierFlag::CAPSLOCK));
  EXPECT_EQ(Flags(ModifierFlag::CAPSLOCK), flagStatus.makeFlags());

  // from other keyboard
  flagStatus.set(KeyCode::A, Flags(0));
  EXPECT_EQ(Flags(ModifierFlag::CAPSLOCK), flagStatus.makeFlags());

  flagStatus.set(KeyCode::A, Flags(ModifierFlag::CAPSLOCK));
  EXPECT_EQ(Flags(ModifierFlag::CAPSLOCK), flagStatus.makeFlags());

  // reset
  flagStatus.set(KeyCode::CAPSLOCK, Flags(0));
  EXPECT_EQ(Flags(), flagStatus.makeFlags());

  // soft caps
  flagStatus.lock_increase(ModifierFlag::CAPSLOCK);
  flagStatus.set(KeyCode::A, Flags(0));
  EXPECT_EQ(Flags(ModifierFlag::CAPSLOCK), flagStatus.makeFlags());

  // soft caps will be canceled by hardware caps
  flagStatus.set(KeyCode::CAPSLOCK, Flags(0));
  EXPECT_EQ(Flags(0), flagStatus.makeFlags());
}
Пример #3
0
TEST(FlagStatus, lock_clear) {
  FlagStatus flagStatus;

  flagStatus.lock_increase(ModifierFlag::COMMAND_L | ModifierFlag::FN | ModifierFlag::SHIFT_L);
  EXPECT_EQ(ModifierFlag::COMMAND_L | ModifierFlag::FN | ModifierFlag::SHIFT_L, flagStatus.makeFlags());

  flagStatus.lock_clear();
  EXPECT_EQ(Flags(0), flagStatus.makeFlags());
}
Пример #4
0
TEST(FlagStatus, lock_increase) {
  FlagStatus flagStatus;

  // Do nothing with ModifierFlag::NONE.
  flagStatus.lock_increase(ModifierFlag::NONE);
  EXPECT_EQ(Flags(0), flagStatus.makeFlags());

  flagStatus.lock_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(ModifierFlag::COMMAND_L), flagStatus.makeFlags());

  flagStatus.lock_decrease(ModifierFlag::COMMAND_L);
  EXPECT_EQ(Flags(), flagStatus.makeFlags());
}
Пример #5
0
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());
  }
}
Пример #6
0
TEST(FlagStatus, lock_toggle) {
  FlagStatus flagStatus;

  flagStatus.lock_increase(ModifierFlag::COMMAND_L);
  EXPECT_EQ(Flags(ModifierFlag::COMMAND_L), flagStatus.makeFlags());

  flagStatus.lock_toggle(ModifierFlag::COMMAND_L);
  EXPECT_EQ(Flags(0), flagStatus.makeFlags());

  flagStatus.lock_toggle(ModifierFlag::COMMAND_L);
  EXPECT_EQ(Flags(ModifierFlag::COMMAND_L), flagStatus.makeFlags());
}
Пример #7
0
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());
}