Skip to content

Commit

Permalink
[wip] add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Jari27 committed Mar 2, 2025
1 parent ab4843e commit acd18f0
Showing 1 changed file with 50 additions and 11 deletions.
61 changes: 50 additions & 11 deletions tests/basic/test_one_shot_keys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,31 @@
*/

#include "action_util.h"
#include "config.h"
#include "keyboard_report_util.hpp"
#include "test_common.hpp"
#include <gtest/gtest.h>
#include <stdint.h>

using testing::_;
using testing::InSequence;

class OneShot : public TestFixture {};
class OneShotParametrizedTestFixture : public ::testing::WithParamInterface<std::pair<KeymapKey, KeymapKey>>, public OneShot {};

TEST_F(OneShot, OSMWithoutAdditionalKeypressDoesNothing) {
TEST_F(OneShot, OSMWithoutAdditionalKeypressSetsOneShotModsButDoesNotSendReport) {
TestDriver driver;
auto osm_key = KeymapKey(0, 0, 0, OSM(MOD_LSFT), KC_LSFT);
auto a_key = KeymapKey(0, 0, 0, KC_A);

set_keymap({osm_key});

/* Press and release OSM key*/
/* Press and release OSM key should set one shot mods*/
EXPECT_NO_REPORT(driver);
tap_key(osm_key);
EXPECT_EQ(get_oneshot_mods(), MOD_LSFT);
VERIFY_AND_CLEAR(driver);

/* OSM are added when an actual report is send */
EXPECT_REPORT(driver, (osm_key.report_code));
send_keyboard_report();
VERIFY_AND_CLEAR(driver);

/* Make unit-test pass */
clear_oneshot_mods();
clear_oneshot_mods(); // reset state
}

#if defined(ONESHOT_TIMEOUT)
Expand Down Expand Up @@ -277,6 +275,47 @@ TEST_F(OneShot, OSMHoldNotLockingOSMs) {
VERIFY_AND_CLEAR(driver);
}

TEST_F(OneShot, OSMTapThenHoldNotLockingOSMs) {
TestDriver driver;
InSequence s;
KeymapKey osm_key = KeymapKey{0, 0, 0, OSM(MOD_LSFT), KC_LSFT};
KeymapKey regular_key = KeymapKey{0, 1, 0, KC_A};

set_keymap({osm_key, regular_key});

/* Press and release OSM */
EXPECT_NO_REPORT(driver);
tap_key(osm_key);
VERIFY_AND_CLEAR(driver);

/* Press and hold OSM */
EXPECT_REPORT(driver, (osm_key.report_code)).Times(1);
osm_key.press();
run_one_scan_loop();
idle_for(TAPPING_TERM);
// EXPECT_EQ(get_oneshot_mods(), b02); // one shot mods should be disabled
VERIFY_AND_CLEAR(driver);

/* Release OSM1 */
EXPECT_EMPTY_REPORT(driver);
osm_key.release();
run_one_scan_loop();
// EXPECT_EQ(get_oneshot_mods(), 0); // one shot mods should be disabled
VERIFY_AND_CLEAR(driver);

/* Press regular key */
EXPECT_REPORT(driver, (regular_key.report_code)).Times(1); // no mod
regular_key.press();
run_one_scan_loop();
VERIFY_AND_CLEAR(driver);

/* Release regular key */
EXPECT_EMPTY_REPORT(driver);
regular_key.release();
run_one_scan_loop();
VERIFY_AND_CLEAR(driver);
}

TEST_F(OneShot, OSLWithAdditionalKeypress) {
TestDriver driver;
InSequence s;
Expand Down Expand Up @@ -686,4 +725,4 @@ TEST_F(OneShot, OSLWithLongModTapKeyAndRegularKey) {
regular_key.release();
run_one_scan_loop();
VERIFY_AND_CLEAR(driver);
}
}

0 comments on commit acd18f0

Please sign in to comment.