Esempio n. 1
0
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());
}
Esempio n. 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());
}
Esempio n. 3
0
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());
  }
}
Esempio n. 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());
}
Esempio n. 5
0
TEST(FlagStatus, lazy_increase) {
  FlagStatus flagStatus;

  // +1 (total 1)
  flagStatus.lazy_increase(ModifierFlag::SHIFT_L);
  EXPECT_EQ(Flags(0), flagStatus.makeFlags());

  // +0 (total 1)
  flagStatus.lazy_set_enable(true);
  EXPECT_EQ(Flags(ModifierFlag::SHIFT_L), flagStatus.makeFlags());

  // -1 (total 0)
  flagStatus.lazy_decrease(ModifierFlag::SHIFT_L);
  EXPECT_EQ(Flags(0), flagStatus.makeFlags());

  // +1 (total 1)
  flagStatus.lazy_increase(ModifierFlag::SHIFT_L);
  EXPECT_EQ(Flags(ModifierFlag::SHIFT_L), flagStatus.makeFlags());

  flagStatus.lazy_set_enable(false);
  EXPECT_EQ(Flags(0), flagStatus.makeFlags());

  // +2 (total 2)
  flagStatus.lazy_increase(ModifierFlag::SHIFT_L);
  EXPECT_EQ(Flags(0), flagStatus.makeFlags());

  // +0 (total 2)
  flagStatus.lazy_set_enable(true);
  EXPECT_EQ(Flags(ModifierFlag::SHIFT_L), flagStatus.makeFlags());

  // -1 (total 1)
  flagStatus.lazy_decrease(ModifierFlag::SHIFT_L);
  EXPECT_EQ(Flags(ModifierFlag::SHIFT_L), flagStatus.makeFlags());

  // => 0 (lazy modifier is disabled when reset.)
  flagStatus.reset();

  // +1 (total 1)
  flagStatus.lazy_increase(ModifierFlag::SHIFT_L);
  EXPECT_EQ(Flags(0), flagStatus.makeFlags());
}
Esempio n. 6
0
TEST(FlagStatus, makeFlags) {
  FlagStatus flagStatus;
  EXPECT_EQ(Flags(), flagStatus.makeFlags());

  flagStatus.set();
  EXPECT_EQ(Flags(), flagStatus.makeFlags());

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

  // down SHIFT_L
  flagStatus.set(KeyCode::SHIFT_L, Flags(ModifierFlag::SHIFT_L));
  EXPECT_EQ(Flags(ModifierFlag::SHIFT_L), flagStatus.makeFlags());

  // no effect with ModifierFlag::NONE
  flagStatus.set(KeyCode::A, Flags(ModifierFlag::NONE));
  EXPECT_EQ(Flags(ModifierFlag::SHIFT_L), flagStatus.makeFlags());

  // down CONTROL_
  flagStatus.set(KeyCode::CONTROL_L, ModifierFlag::CONTROL_L | ModifierFlag::SHIFT_L);
  EXPECT_EQ(Flags(ModifierFlag::SHIFT_L | ModifierFlag::CONTROL_L), flagStatus.makeFlags());

  // down A
  flagStatus.set(KeyCode::A, ModifierFlag::CONTROL_L | ModifierFlag::SHIFT_L);
  EXPECT_EQ(Flags(ModifierFlag::SHIFT_L | ModifierFlag::CONTROL_L), flagStatus.makeFlags());

  // up SHIFT_L
  flagStatus.set(KeyCode::SHIFT_L, Flags(ModifierFlag::CONTROL_L));
  EXPECT_EQ(Flags(ModifierFlag::CONTROL_L), flagStatus.makeFlags());

  // up CONTROL_L
  flagStatus.set(KeyCode::CONTROL_L, Flags(0));
  EXPECT_EQ(Flags(), flagStatus.makeFlags());

  // All flags
  flagStatus.reset();
  flagStatus.set(KeyCode::CAPSLOCK, Flags(ModifierFlag::CAPSLOCK));
  EXPECT_EQ(Flags(ModifierFlag::CAPSLOCK), flagStatus.makeFlags());

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

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

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

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

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

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

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

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

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

  flagStatus.reset();
  flagStatus.set(KeyCode::FN, Flags(ModifierFlag::FN));
  EXPECT_EQ(Flags(ModifierFlag::FN), flagStatus.makeFlags());
}