sym_eager_pk_tests.cpp 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /* Copyright 2021 Simon Arlott
  2. *
  3. * This program is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "gtest/gtest.h"
  17. #include "debounce_test_common.h"
  18. TEST_F(DebounceTest, OneKeyShort1) {
  19. addEvents({ /* Time, Inputs, Outputs */
  20. {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
  21. {1, {{0, 1, UP}}, {}},
  22. {5, {}, {{0, 1, UP}}},
  23. /* Press key again after 1ms delay (debounce has not yet finished) */
  24. {6, {{0, 1, DOWN}}, {}},
  25. {10, {}, {{0, 1, DOWN}}}, /* 5ms after UP at time 5 */
  26. });
  27. runEvents();
  28. }
  29. TEST_F(DebounceTest, OneKeyShort2) {
  30. addEvents({ /* Time, Inputs, Outputs */
  31. {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
  32. {1, {{0, 1, UP}}, {}},
  33. {5, {}, {{0, 1, UP}}},
  34. /* Press key again after 2ms delay (debounce has not yet finished) */
  35. {7, {{0, 1, DOWN}}, {}},
  36. {10, {}, {{0, 1, DOWN}}}, /* 5ms after UP at time 5 */
  37. });
  38. runEvents();
  39. }
  40. TEST_F(DebounceTest, OneKeyShort3) {
  41. addEvents({ /* Time, Inputs, Outputs */
  42. {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
  43. {1, {{0, 1, UP}}, {}},
  44. {5, {}, {{0, 1, UP}}},
  45. /* Press key again after 3ms delay (debounce has not yet finished) */
  46. {8, {{0, 1, DOWN}}, {}},
  47. {10, {}, {{0, 1, DOWN}}}, /* 5ms after UP at time 5 */
  48. });
  49. runEvents();
  50. }
  51. TEST_F(DebounceTest, OneKeyShort4) {
  52. addEvents({ /* Time, Inputs, Outputs */
  53. {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
  54. {1, {{0, 1, UP}}, {}},
  55. {5, {}, {{0, 1, UP}}},
  56. /* Press key again after 4ms delay (debounce has not yet finished) */
  57. {9, {{0, 1, DOWN}}, {}},
  58. {10, {}, {{0, 1, DOWN}}}, /* 5ms after UP at time 5 */
  59. });
  60. runEvents();
  61. }
  62. TEST_F(DebounceTest, OneKeyShort5) {
  63. addEvents({ /* Time, Inputs, Outputs */
  64. {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
  65. {1, {{0, 1, UP}}, {}},
  66. {5, {}, {{0, 1, UP}}},
  67. /* Press key again after 5ms delay (debounce has finished) */
  68. {10, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
  69. });
  70. runEvents();
  71. }
  72. TEST_F(DebounceTest, OneKeyShort6) {
  73. addEvents({ /* Time, Inputs, Outputs */
  74. {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
  75. {1, {{0, 1, UP}}, {}},
  76. {5, {}, {{0, 1, UP}}},
  77. /* Press key after after 6ms delay (debounce has finished) */
  78. {11, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
  79. });
  80. runEvents();
  81. }
  82. TEST_F(DebounceTest, OneKeyBouncing1) {
  83. addEvents({ /* Time, Inputs, Outputs */
  84. {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
  85. {1, {{0, 1, UP}}, {}},
  86. {2, {{0, 1, DOWN}}, {}},
  87. {3, {{0, 1, UP}}, {}},
  88. {4, {{0, 1, DOWN}}, {}},
  89. {5, {{0, 1, UP}}, {{0, 1, UP}}},
  90. /* Press key again after 1ms delay (debounce has not yet finished) */
  91. {6, {{0, 1, DOWN}}, {}},
  92. {10, {}, {{0, 1, DOWN}}}, /* 5ms after UP at time 5 */
  93. });
  94. runEvents();
  95. }
  96. TEST_F(DebounceTest, OneKeyBouncing2) {
  97. addEvents({ /* Time, Inputs, Outputs */
  98. {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
  99. /* Change twice in the same time period */
  100. {1, {{0, 1, UP}}, {}},
  101. {1, {{0, 1, DOWN}}, {}},
  102. /* Change three times in the same time period */
  103. {2, {{0, 1, UP}}, {}},
  104. {2, {{0, 1, DOWN}}, {}},
  105. {2, {{0, 1, UP}}, {}},
  106. /* Change three times in the same time period */
  107. {3, {{0, 1, DOWN}}, {}},
  108. {3, {{0, 1, UP}}, {}},
  109. {3, {{0, 1, DOWN}}, {}},
  110. /* Change twice in the same time period */
  111. {4, {{0, 1, UP}}, {}},
  112. {4, {{0, 1, DOWN}}, {}},
  113. {5, {{0, 1, UP}}, {{0, 1, UP}}},
  114. /* Press key again after 1ms delay (debounce has not yet finished) */
  115. {6, {{0, 1, DOWN}}, {}},
  116. {10, {}, {{0, 1, DOWN}}}, /* 5ms after UP at time 5 */
  117. });
  118. runEvents();
  119. }
  120. TEST_F(DebounceTest, OneKeyLong) {
  121. addEvents({ /* Time, Inputs, Outputs */
  122. {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
  123. {25, {{0, 1, UP}}, {{0, 1, UP}}},
  124. {50, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
  125. });
  126. runEvents();
  127. }
  128. TEST_F(DebounceTest, TwoKeysShort) {
  129. addEvents({ /* Time, Inputs, Outputs */
  130. {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
  131. {1, {{0, 1, UP}}, {}},
  132. {2, {{0, 2, DOWN}}, {{0, 2, DOWN}}},
  133. {3, {{0, 2, UP}}, {}},
  134. {5, {}, {{0, 1, UP}}},
  135. /* Press key again after 1ms delay (debounce has not yet finished) */
  136. {6, {{0, 1, DOWN}}, {}},
  137. {7, {}, {{0, 2, UP}}},
  138. /* Press key again after 1ms delay (debounce has not yet finished) */
  139. {9, {{0, 2, DOWN}}, {}},
  140. {10, {}, {{0, 1, DOWN}}}, /* 5ms after UP at time 5 */
  141. {12, {}, {{0, 2, DOWN}}}, /* 5ms after UP at time 7 */
  142. });
  143. runEvents();
  144. }
  145. TEST_F(DebounceTest, OneKeyDelayedScan1) {
  146. addEvents({ /* Time, Inputs, Outputs */
  147. {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
  148. /* Processing is very late but the change will now be accepted */
  149. {300, {{0, 1, UP}}, {{0, 1, UP}}},
  150. });
  151. time_jumps_ = true;
  152. runEvents();
  153. }
  154. TEST_F(DebounceTest, OneKeyDelayedScan2) {
  155. addEvents({ /* Time, Inputs, Outputs */
  156. {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
  157. /* Processing is very late but the change will now be accepted even with a 1 scan delay */
  158. {300, {}, {}},
  159. {300, {{0, 1, UP}}, {{0, 1, UP}}},
  160. });
  161. time_jumps_ = true;
  162. runEvents();
  163. }
  164. TEST_F(DebounceTest, OneKeyDelayedScan3) {
  165. addEvents({ /* Time, Inputs, Outputs */
  166. {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
  167. /* Processing is very late but the change will now be accepted even with a 1ms delay */
  168. {300, {}, {}},
  169. {301, {{0, 1, UP}}, {{0, 1, UP}}},
  170. });
  171. time_jumps_ = true;
  172. runEvents();
  173. }
  174. TEST_F(DebounceTest, OneKeyDelayedScan4) {
  175. addEvents({ /* Time, Inputs, Outputs */
  176. {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
  177. /* Processing is a bit late but the change will now be accepted */
  178. {50, {{0, 1, UP}}, {{0, 1, UP}}},
  179. });
  180. time_jumps_ = true;
  181. runEvents();
  182. }
  183. TEST_F(DebounceTest, OneKeyDelayedScan5) {
  184. addEvents({ /* Time, Inputs, Outputs */
  185. {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
  186. /* Processing is very late but the change will now be accepted even with a 1 scan delay */
  187. {50, {}, {}},
  188. {50, {{0, 1, UP}}, {{0, 1, UP}}},
  189. });
  190. time_jumps_ = true;
  191. runEvents();
  192. }
  193. TEST_F(DebounceTest, OneKeyDelayedScan6) {
  194. addEvents({ /* Time, Inputs, Outputs */
  195. {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
  196. /* Processing is very late but the change will now be accepted even with a 1ms delay */
  197. {50, {}, {}},
  198. {51, {{0, 1, UP}}, {{0, 1, UP}}},
  199. });
  200. time_jumps_ = true;
  201. runEvents();
  202. }