logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

test_tap_dance_layers.cpp (23254B)


  1. // Copyright 2022 Sergey Vlasov (@sigprof)
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include "keyboard_report_util.hpp"
  4. #include "keycode.h"
  5. #include "test_common.hpp"
  6. #include "action_tapping.h"
  7. #include "test_keymap_key.hpp"
  8. #include "tap_dance_defs.h"
  9. using testing::_;
  10. using testing::InSequence;
  11. struct TapDanceKeyParams {
  12. std::string name; // Tap dance name (part of test name)
  13. uint16_t keycode; // Tap dance keycode (TD(n))
  14. uint16_t expect_on_tap; // Keycode for single tap
  15. uint16_t expect_on_hold; // Keycode for single hold (may be MO(1))
  16. uint16_t expect_on_double_tap; // Keycode for double tap (may be MO(1))
  17. uint16_t expect_on_double_hold; // Keycode for double hold (may be MO(1))
  18. };
  19. struct OtherKeyLayerParams {
  20. uint16_t keycode; // Keycode in the keymap
  21. uint16_t expect_on_press; // Keycode to expect on press
  22. uint16_t expect_on_release; // Keycode to expect on release (may be KC_NO if none)
  23. };
  24. struct OtherKeyParams {
  25. std::string name; // Other key name (part of test name)
  26. OtherKeyLayerParams l0; // Keycodes for layer 0
  27. OtherKeyLayerParams l1; // Keycodes for layer 1
  28. };
  29. typedef std::tuple<TapDanceKeyParams, OtherKeyParams> TapDanceLayersParams;
  30. class TapDanceLayers : public ::testing::WithParamInterface<TapDanceLayersParams>, public TestFixture {
  31. protected:
  32. TapDanceKeyParams tap_dance;
  33. OtherKeyParams other_key;
  34. std::unique_ptr<KeymapKey> key_td, key_td_l1, key_other, key_other_l1;
  35. void SetUp() override {
  36. std::tie(tap_dance, other_key) = GetParam();
  37. key_td = std::make_unique<KeymapKey>(0, 1, 0, tap_dance.keycode);
  38. key_td_l1 = std::make_unique<KeymapKey>(1, 1, 0, KC_TRNS);
  39. key_other = std::make_unique<KeymapKey>(0, 2, 0, other_key.l0.keycode);
  40. key_other_l1 = std::make_unique<KeymapKey>(1, 2, 0, other_key.l1.keycode);
  41. set_keymap({*key_td, *key_td_l1, *key_other, *key_other_l1});
  42. }
  43. };
  44. static const TapDanceKeyParams tap_dance_keys[] = {
  45. TapDanceKeyParams{
  46. "LayerMove",
  47. TD(TD_L_MOVE),
  48. KC_APP,
  49. KC_APP,
  50. MO(1),
  51. MO(1),
  52. },
  53. TapDanceKeyParams{
  54. "LayerToggle",
  55. TD(TD_L_TOGG),
  56. KC_APP,
  57. KC_APP,
  58. MO(1),
  59. MO(1),
  60. },
  61. TapDanceKeyParams{
  62. "CustomLT",
  63. TD(TD_LT_APP),
  64. KC_APP,
  65. MO(1),
  66. KC_RCTL,
  67. KC_RCTL,
  68. },
  69. };
  70. static const OtherKeyParams other_keys[] = {
  71. OtherKeyParams{
  72. "Builtin",
  73. OtherKeyLayerParams{KC_A, KC_A, KC_NO},
  74. OtherKeyLayerParams{KC_B, KC_B, KC_NO},
  75. },
  76. OtherKeyParams{
  77. "CustomFast",
  78. OtherKeyLayerParams{FAST_AB, KC_A, KC_B},
  79. OtherKeyLayerParams{FAST_CD, KC_C, KC_D},
  80. },
  81. OtherKeyParams{
  82. "CustomSlow",
  83. OtherKeyLayerParams{SLOW_AB, KC_A, KC_B},
  84. OtherKeyLayerParams{SLOW_CD, KC_C, KC_D},
  85. },
  86. };
  87. // clang-format off
  88. INSTANTIATE_TEST_CASE_P(
  89. Layers,
  90. TapDanceLayers,
  91. ::testing::Combine(
  92. ::testing::ValuesIn(tap_dance_keys),
  93. ::testing::ValuesIn(other_keys)
  94. ),
  95. [](const ::testing::TestParamInfo<TapDanceLayersParams>& info) {
  96. return std::get<0>(info.param).name + std::get<1>(info.param).name;
  97. }
  98. );
  99. // clang-format on
  100. // Test single tap of the tap dance key with tapping term delay after the tap.
  101. TEST_P(TapDanceLayers, SingleTap) {
  102. TestDriver driver;
  103. InSequence s;
  104. // The tap of the tap dance key does not result in sending a report
  105. // immediately.
  106. EXPECT_NO_REPORT(driver);
  107. tap_key(*key_td);
  108. // After the tapping term expires, a tap event for the single tap keycode
  109. // is generated.
  110. idle_for(TAPPING_TERM - 1);
  111. EXPECT_REPORT(driver, (tap_dance.expect_on_tap));
  112. EXPECT_EMPTY_REPORT(driver);
  113. run_one_scan_loop();
  114. // Pressing the other key produces the reports for the layer 0 mapping of
  115. // that key.
  116. EXPECT_REPORT(driver, (other_key.l0.expect_on_press));
  117. if (other_key.l0.expect_on_release != KC_NO) {
  118. EXPECT_EMPTY_REPORT(driver);
  119. }
  120. key_other->press();
  121. run_one_scan_loop();
  122. // Releasing the other key produces the reports for the layer 0 mapping of
  123. // that key.
  124. if (other_key.l0.expect_on_release != KC_NO) {
  125. EXPECT_REPORT(driver, (other_key.l0.expect_on_release));
  126. }
  127. EXPECT_EMPTY_REPORT(driver);
  128. key_other->release();
  129. run_one_scan_loop();
  130. }
  131. // Test single tap of the tap dance key without a delay between the tap dance
  132. // key and the other key.
  133. TEST_P(TapDanceLayers, SingleTapFast) {
  134. TestDriver driver;
  135. InSequence s;
  136. // The tap of the tap dance key does not result in sending a report
  137. // immediately.
  138. EXPECT_NO_REPORT(driver);
  139. tap_key(*key_td);
  140. // A quick press of the other key causes the tap event for the tap dance to
  141. // be sent before the press event for the other key, and the layer 0
  142. // mapping is used for the other key.
  143. EXPECT_REPORT(driver, (tap_dance.expect_on_tap));
  144. EXPECT_EMPTY_REPORT(driver);
  145. EXPECT_REPORT(driver, (other_key.l0.expect_on_press));
  146. if (other_key.l0.expect_on_release != KC_NO) {
  147. EXPECT_EMPTY_REPORT(driver);
  148. }
  149. key_other->press();
  150. run_one_scan_loop();
  151. // Releasing the other key produces the reports for the layer 0 mapping of
  152. // that key.
  153. if (other_key.l0.expect_on_release != KC_NO) {
  154. EXPECT_REPORT(driver, (other_key.l0.expect_on_release));
  155. }
  156. EXPECT_EMPTY_REPORT(driver);
  157. key_other->release();
  158. run_one_scan_loop();
  159. }
  160. // Test single hold of the tap dance key with tapping term delay after the hold
  161. // (test variant for tap dances which switch the layer on hold).
  162. TEST_P(TapDanceLayers, SingleHoldLayer) {
  163. if (tap_dance.expect_on_hold != MO(1)) {
  164. // Do nothing - the SingleHoldKeycode test would run instead.
  165. return;
  166. }
  167. TestDriver driver;
  168. InSequence s;
  169. // No report gets sent immediately after the hold of the tap dance key.
  170. EXPECT_NO_REPORT(driver);
  171. key_td->press();
  172. run_one_scan_loop();
  173. // After the tapping term expires, the tap dance finishes and switches the
  174. // layer, but does not send a report.
  175. EXPECT_NO_REPORT(driver);
  176. idle_for(TAPPING_TERM);
  177. run_one_scan_loop();
  178. // Pressing the other key produces the reports for the layer 1 mapping of
  179. // that key.
  180. EXPECT_REPORT(driver, (other_key.l1.expect_on_press));
  181. if (other_key.l1.expect_on_release != KC_NO) {
  182. EXPECT_EMPTY_REPORT(driver);
  183. }
  184. key_other->press();
  185. run_one_scan_loop();
  186. // Releasing the tap dance key does not produce a report.
  187. EXPECT_NO_REPORT(driver);
  188. key_td->release();
  189. run_one_scan_loop();
  190. // Releasing the other key produces the report for the layer 1 mapping of
  191. // that key.
  192. if (other_key.l1.expect_on_release != KC_NO) {
  193. EXPECT_REPORT(driver, (other_key.l1.expect_on_release));
  194. }
  195. EXPECT_EMPTY_REPORT(driver);
  196. key_other->release();
  197. run_one_scan_loop();
  198. }
  199. // Test single hold of the tap dance key with tapping term delay after the hold
  200. // (test variant for tap dances which send a keycode on single hold).
  201. TEST_P(TapDanceLayers, SingleHoldKeycode) {
  202. if (tap_dance.expect_on_hold == MO(1)) {
  203. // Do nothing - the SingleHoldLayer test would run instead.
  204. return;
  205. }
  206. TestDriver driver;
  207. InSequence s;
  208. // No report gets sent immediately after the hold of the tap dance key.
  209. EXPECT_NO_REPORT(driver);
  210. key_td->press();
  211. run_one_scan_loop();
  212. // After the tapping term expires, the tap dance sends the report with the
  213. // hold keycode.
  214. EXPECT_NO_REPORT(driver);
  215. idle_for(TAPPING_TERM);
  216. EXPECT_REPORT(driver, (tap_dance.expect_on_hold));
  217. run_one_scan_loop();
  218. // Pressing the other key produces the reports for the layer 0 mapping of
  219. // that key.
  220. EXPECT_REPORT(driver, (tap_dance.expect_on_hold, other_key.l0.expect_on_press));
  221. if (other_key.l0.expect_on_release != KC_NO) {
  222. EXPECT_REPORT(driver, (tap_dance.expect_on_hold));
  223. }
  224. key_other->press();
  225. run_one_scan_loop();
  226. // Releasing the tap dance key sends the release report for the
  227. // corresponding hold keycode.
  228. if (other_key.l0.expect_on_release != KC_NO) {
  229. EXPECT_EMPTY_REPORT(driver);
  230. } else {
  231. EXPECT_REPORT(driver, (other_key.l0.expect_on_press));
  232. }
  233. key_td->release();
  234. run_one_scan_loop();
  235. // Releasing the other key produces the reports for the layer 0 mapping of
  236. // that key.
  237. if (other_key.l0.expect_on_release != KC_NO) {
  238. EXPECT_REPORT(driver, (other_key.l0.expect_on_release));
  239. }
  240. EXPECT_EMPTY_REPORT(driver);
  241. key_other->release();
  242. run_one_scan_loop();
  243. }
  244. // Test single hold of the tap dance key without tapping term delay after the
  245. // hold (test variant for tap dances which switch the layer on hold).
  246. TEST_P(TapDanceLayers, SingleHoldFastLayer) {
  247. if (tap_dance.expect_on_hold != MO(1)) {
  248. // Do nothing - the SingleHoldFastKeycode test would run instead.
  249. return;
  250. }
  251. TestDriver driver;
  252. InSequence s;
  253. // No report gets sent immediately after the hold of the tap dance key.
  254. EXPECT_NO_REPORT(driver);
  255. key_td->press();
  256. run_one_scan_loop();
  257. // Pressing the other key produces the reports for the layer 1 mapping of
  258. // that key.
  259. EXPECT_REPORT(driver, (other_key.l1.expect_on_press));
  260. if (other_key.l1.expect_on_release != KC_NO) {
  261. EXPECT_EMPTY_REPORT(driver);
  262. }
  263. key_other->press();
  264. run_one_scan_loop();
  265. // Releasing the tap dance key does not produce a report.
  266. EXPECT_NO_REPORT(driver);
  267. key_td->release();
  268. run_one_scan_loop();
  269. // Releasing the other key produces the reports for the layer 1 mapping of
  270. // that key.
  271. if (other_key.l1.expect_on_release != KC_NO) {
  272. EXPECT_REPORT(driver, (other_key.l1.expect_on_release));
  273. }
  274. EXPECT_EMPTY_REPORT(driver);
  275. key_other->release();
  276. run_one_scan_loop();
  277. }
  278. // Test single hold of the tap dance key without tapping term delay after the hold
  279. // (test variant for tap dances which send a keycode on single hold).
  280. TEST_P(TapDanceLayers, SingleHoldFastKeycode) {
  281. if (tap_dance.expect_on_hold == MO(1)) {
  282. // Do nothing - the SingleHoldFastLayer test would run instead.
  283. return;
  284. }
  285. TestDriver driver;
  286. InSequence s;
  287. // No report gets sent immediately after the hold of the tap dance key.
  288. EXPECT_NO_REPORT(driver);
  289. key_td->press();
  290. run_one_scan_loop();
  291. // Pressing the other key produces first the report for the tap dance hold
  292. // keycode, and then the reports for the layer 0 mapping of the other key.
  293. EXPECT_REPORT(driver, (tap_dance.expect_on_hold));
  294. EXPECT_REPORT(driver, (tap_dance.expect_on_hold, other_key.l0.expect_on_press));
  295. if (other_key.l0.expect_on_release != KC_NO) {
  296. EXPECT_REPORT(driver, (tap_dance.expect_on_hold));
  297. }
  298. key_other->press();
  299. run_one_scan_loop();
  300. // Releasing the tap dance key sends a release report for the corresponding
  301. // hold keycode.
  302. if (other_key.l0.expect_on_release != KC_NO) {
  303. EXPECT_EMPTY_REPORT(driver);
  304. } else {
  305. EXPECT_REPORT(driver, (other_key.l0.expect_on_press));
  306. }
  307. key_td->release();
  308. run_one_scan_loop();
  309. // Releasing the other key produces the report for the layer 0 mapping of
  310. // that key.
  311. if (other_key.l0.expect_on_release != KC_NO) {
  312. EXPECT_REPORT(driver, (other_key.l0.expect_on_release));
  313. }
  314. EXPECT_EMPTY_REPORT(driver);
  315. key_other->release();
  316. run_one_scan_loop();
  317. }
  318. // Test double tap of the tap dance key with tapping term delay after the hold
  319. // (test variant for tap dances which switch the layer on double tap).
  320. TEST_P(TapDanceLayers, DoubleTapLayer) {
  321. if (tap_dance.expect_on_double_tap != MO(1)) {
  322. // Do nothing - the DoubleTapKeycode test would run instead.
  323. return;
  324. }
  325. TestDriver driver;
  326. InSequence s;
  327. // No report gets sent immediately after the double tap of the tap dance
  328. // key.
  329. EXPECT_NO_REPORT(driver);
  330. tap_key(*key_td);
  331. tap_key(*key_td);
  332. // After the tapping term this tap dance does not send a report too.
  333. EXPECT_NO_REPORT(driver);
  334. idle_for(TAPPING_TERM);
  335. run_one_scan_loop();
  336. // Pressing the other key produces the reports for the layer 1 mapping of
  337. // that key.
  338. EXPECT_REPORT(driver, (other_key.l1.expect_on_press));
  339. if (other_key.l1.expect_on_release != KC_NO) {
  340. EXPECT_EMPTY_REPORT(driver);
  341. }
  342. key_other->press();
  343. run_one_scan_loop();
  344. // Releasing the other key produces the report for the layer 1 mapping of
  345. // that key.
  346. if (other_key.l1.expect_on_release != KC_NO) {
  347. EXPECT_REPORT(driver, (other_key.l1.expect_on_release));
  348. }
  349. EXPECT_EMPTY_REPORT(driver);
  350. key_other->release();
  351. run_one_scan_loop();
  352. }
  353. // Test double tap of the tap dance key with tapping term delay after the hold
  354. // (test variant for tap dances which send a keycode on double tap).
  355. TEST_P(TapDanceLayers, DoubleTapKeycode) {
  356. if (tap_dance.expect_on_double_tap == MO(1)) {
  357. // Do nothing - the DoubleTapLayer test would run instead.
  358. return;
  359. }
  360. TestDriver driver;
  361. InSequence s;
  362. // No report gets sent immediately after the double tap of the tap dance
  363. // key.
  364. EXPECT_NO_REPORT(driver);
  365. tap_key(*key_td);
  366. tap_key(*key_td);
  367. // After the tapping term this tap dance sends the double tap keycode.
  368. idle_for(TAPPING_TERM - 1);
  369. EXPECT_REPORT(driver, (tap_dance.expect_on_double_tap));
  370. EXPECT_EMPTY_REPORT(driver);
  371. run_one_scan_loop();
  372. // Pressing the other key produces the reports for the layer 0 mapping of
  373. // that key.
  374. EXPECT_REPORT(driver, (other_key.l0.expect_on_press));
  375. if (other_key.l0.expect_on_release != KC_NO) {
  376. EXPECT_EMPTY_REPORT(driver);
  377. }
  378. key_other->press();
  379. run_one_scan_loop();
  380. // Releasing the other key produces the report for the layer 0 mapping of
  381. // that key.
  382. if (other_key.l0.expect_on_release != KC_NO) {
  383. EXPECT_REPORT(driver, (other_key.l0.expect_on_release));
  384. }
  385. EXPECT_EMPTY_REPORT(driver);
  386. key_other->release();
  387. run_one_scan_loop();
  388. }
  389. // Test double tap of the tap dance key without tapping term delay after the
  390. // hold (test variant for tap dances which switch the layer on double tap).
  391. TEST_P(TapDanceLayers, DoubleTapFastLayer) {
  392. if (tap_dance.expect_on_double_tap != MO(1)) {
  393. // Do nothing - the DoubleTapFastKeycode test would run instead.
  394. return;
  395. }
  396. TestDriver driver;
  397. InSequence s;
  398. // No report gets sent immediately after the double tap of the tap dance
  399. // key.
  400. EXPECT_NO_REPORT(driver);
  401. tap_key(*key_td);
  402. tap_key(*key_td);
  403. // Pressing the other key produces the reports for the layer 1 mapping of
  404. // that key.
  405. EXPECT_REPORT(driver, (other_key.l1.expect_on_press));
  406. if (other_key.l1.expect_on_release != KC_NO) {
  407. EXPECT_EMPTY_REPORT(driver);
  408. }
  409. key_other->press();
  410. run_one_scan_loop();
  411. // Releasing the other key produces the report for the layer 1 mapping of
  412. // that key.
  413. if (other_key.l1.expect_on_release != KC_NO) {
  414. EXPECT_REPORT(driver, (other_key.l1.expect_on_release));
  415. }
  416. EXPECT_EMPTY_REPORT(driver);
  417. key_other->release();
  418. run_one_scan_loop();
  419. }
  420. // Test double tap of the tap dance key without tapping term delay after the
  421. // hold (test variant for tap dances which send a keycode on double tap).
  422. TEST_P(TapDanceLayers, DoubleTapFastKeycode) {
  423. if (tap_dance.expect_on_double_tap == MO(1)) {
  424. // Do nothing - the DoubleTapFastLayer test would run instead.
  425. return;
  426. }
  427. TestDriver driver;
  428. InSequence s;
  429. // No report gets sent immediately after the double tap of the tap dance
  430. // key.
  431. EXPECT_NO_REPORT(driver);
  432. tap_key(*key_td);
  433. tap_key(*key_td);
  434. // Pressing the other key produces first the report for the tap dance
  435. // double tap keycode, and then the reports for the layer 0 mapping of the
  436. // other key.
  437. EXPECT_REPORT(driver, (tap_dance.expect_on_double_tap));
  438. EXPECT_EMPTY_REPORT(driver);
  439. EXPECT_REPORT(driver, (other_key.l0.expect_on_press));
  440. if (other_key.l0.expect_on_release != KC_NO) {
  441. EXPECT_EMPTY_REPORT(driver);
  442. }
  443. key_other->press();
  444. run_one_scan_loop();
  445. // Releasing the other key produces the report for the layer 0 mapping of
  446. // that key.
  447. if (other_key.l0.expect_on_release != KC_NO) {
  448. EXPECT_REPORT(driver, (other_key.l0.expect_on_release));
  449. }
  450. EXPECT_EMPTY_REPORT(driver);
  451. key_other->release();
  452. run_one_scan_loop();
  453. }
  454. // Test double hold of the tap dance key with tapping term delay after the hold
  455. // (test variant for tap dances which switch the layer on double hold).
  456. TEST_P(TapDanceLayers, DoubleHoldLayer) {
  457. if (tap_dance.expect_on_double_hold != MO(1)) {
  458. // Do nothing - the DoubleHoldKeycode test would run instead.
  459. return;
  460. }
  461. TestDriver driver;
  462. InSequence s;
  463. // No report gets sent immediately after the double hold of the tap dance
  464. // key.
  465. EXPECT_NO_REPORT(driver);
  466. tap_key(*key_td);
  467. key_td->press();
  468. run_one_scan_loop();
  469. // After the tapping term expires, the tap dance finishes and switches the
  470. // layer, but does not send a report.
  471. EXPECT_NO_REPORT(driver);
  472. idle_for(TAPPING_TERM);
  473. run_one_scan_loop();
  474. // Pressing the other key produces the reports for the layer 1 mapping of
  475. // that key.
  476. EXPECT_REPORT(driver, (other_key.l1.expect_on_press));
  477. if (other_key.l1.expect_on_release != KC_NO) {
  478. EXPECT_EMPTY_REPORT(driver);
  479. }
  480. key_other->press();
  481. run_one_scan_loop();
  482. // Releasing the tap dance key does not produce a report.
  483. EXPECT_NO_REPORT(driver);
  484. key_td->release();
  485. run_one_scan_loop();
  486. // Releasing the other key produces the report for the layer 1 mapping of
  487. // that key.
  488. if (other_key.l1.expect_on_release != KC_NO) {
  489. EXPECT_REPORT(driver, (other_key.l1.expect_on_release));
  490. }
  491. EXPECT_EMPTY_REPORT(driver);
  492. key_other->release();
  493. run_one_scan_loop();
  494. }
  495. // Test double hold of the tap dance key with tapping term delay after the hold
  496. // (test variant for tap dances which send a keycode on double hold).
  497. TEST_P(TapDanceLayers, DoubleHoldKeycode) {
  498. if (tap_dance.expect_on_double_hold == MO(1)) {
  499. // Do nothing - the DoubleHoldLayer test would run instead.
  500. return;
  501. }
  502. TestDriver driver;
  503. InSequence s;
  504. // No report gets sent immediately after the double hold of the tap dance
  505. // key.
  506. EXPECT_NO_REPORT(driver);
  507. tap_key(*key_td);
  508. key_td->press();
  509. run_one_scan_loop();
  510. // After the tapping term expires, the tap dance sends the report with the
  511. // double hold keycode.
  512. EXPECT_NO_REPORT(driver);
  513. idle_for(TAPPING_TERM);
  514. EXPECT_REPORT(driver, (tap_dance.expect_on_double_hold));
  515. run_one_scan_loop();
  516. // Pressing the other key produces the reports for the layer 0 mapping of
  517. // that key.
  518. EXPECT_REPORT(driver, (tap_dance.expect_on_double_hold, other_key.l0.expect_on_press));
  519. if (other_key.l0.expect_on_release != KC_NO) {
  520. EXPECT_REPORT(driver, (tap_dance.expect_on_double_hold));
  521. }
  522. key_other->press();
  523. run_one_scan_loop();
  524. // Releasing the tap dance key sends the release report for the
  525. // corresponding double hold keycode.
  526. if (other_key.l0.expect_on_release != KC_NO) {
  527. EXPECT_EMPTY_REPORT(driver);
  528. } else {
  529. EXPECT_REPORT(driver, (other_key.l0.expect_on_press));
  530. }
  531. key_td->release();
  532. run_one_scan_loop();
  533. // Releasing the other key produces the reports for the layer 0 mapping of
  534. // that key.
  535. if (other_key.l0.expect_on_release != KC_NO) {
  536. EXPECT_REPORT(driver, (other_key.l0.expect_on_release));
  537. }
  538. EXPECT_EMPTY_REPORT(driver);
  539. key_other->release();
  540. run_one_scan_loop();
  541. }
  542. // Test double hold of the tap dance key without tapping term delay after the
  543. // hold (test variant for tap dances which switch the layer on double hold).
  544. TEST_P(TapDanceLayers, DoubleHoldFastLayer) {
  545. if (tap_dance.expect_on_double_hold != MO(1)) {
  546. // Do nothing - the DoubleHoldFastKeycode test would run instead.
  547. return;
  548. }
  549. TestDriver driver;
  550. InSequence s;
  551. // No report gets sent immediately after the double hold of the tap dance
  552. // key.
  553. EXPECT_NO_REPORT(driver);
  554. tap_key(*key_td);
  555. key_td->press();
  556. run_one_scan_loop();
  557. // Pressing the other key produces the reports for the layer 1 mapping of
  558. // that key.
  559. EXPECT_REPORT(driver, (other_key.l1.expect_on_press));
  560. if (other_key.l1.expect_on_release != KC_NO) {
  561. EXPECT_EMPTY_REPORT(driver);
  562. }
  563. key_other->press();
  564. run_one_scan_loop();
  565. // Releasing the tap dance key does not produce a report.
  566. EXPECT_NO_REPORT(driver);
  567. key_td->release();
  568. run_one_scan_loop();
  569. // Releasing the other key produces the reports for the layer 1 mapping of
  570. // that key.
  571. if (other_key.l1.expect_on_release != KC_NO) {
  572. EXPECT_REPORT(driver, (other_key.l1.expect_on_release));
  573. }
  574. EXPECT_EMPTY_REPORT(driver);
  575. key_other->release();
  576. run_one_scan_loop();
  577. }
  578. // Test double hold of the tap dance key without tapping term delay after the hold
  579. // (test variant for tap dances which send a keycode on double hold).
  580. TEST_P(TapDanceLayers, DoubleHoldFastKeycode) {
  581. if (tap_dance.expect_on_double_hold == MO(1)) {
  582. // Do nothing - the DoubleHoldFastLayer test would run instead.
  583. return;
  584. }
  585. TestDriver driver;
  586. InSequence s;
  587. // No report gets sent immediately after the double hold of the tap dance
  588. // key.
  589. EXPECT_NO_REPORT(driver);
  590. tap_key(*key_td);
  591. key_td->press();
  592. run_one_scan_loop();
  593. // Pressing the other key produces first the report for the tap dance
  594. // double hold keycode, and then the reports for the layer 0 mapping of the
  595. // other key.
  596. EXPECT_REPORT(driver, (tap_dance.expect_on_double_hold));
  597. EXPECT_REPORT(driver, (tap_dance.expect_on_double_hold, other_key.l0.expect_on_press));
  598. if (other_key.l0.expect_on_release != KC_NO) {
  599. EXPECT_REPORT(driver, (tap_dance.expect_on_double_hold));
  600. }
  601. key_other->press();
  602. run_one_scan_loop();
  603. // Releasing the tap dance key sends a release report for the corresponding
  604. // double hold keycode.
  605. if (other_key.l0.expect_on_release != KC_NO) {
  606. EXPECT_EMPTY_REPORT(driver);
  607. } else {
  608. EXPECT_REPORT(driver, (other_key.l0.expect_on_press));
  609. }
  610. key_td->release();
  611. run_one_scan_loop();
  612. // Releasing the other key produces the report for the layer 0 mapping of
  613. // that key.
  614. if (other_key.l0.expect_on_release != KC_NO) {
  615. EXPECT_REPORT(driver, (other_key.l0.expect_on_release));
  616. }
  617. EXPECT_EMPTY_REPORT(driver);
  618. key_other->release();
  619. run_one_scan_loop();
  620. }