You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

287 lines
6.1 KiB

  1. #define mu_assert(message, test) \
  2. do { \
  3. if (!(test)) { \
  4. return message; \
  5. } \
  6. } while (0)
  7. #define RED "\033[0;31m"
  8. #define GREEN "\033[0;32m"
  9. #define NC "\033[0m"
  10. enum ASSERT_TYPES {
  11. UINT,
  12. INT
  13. };
  14. #define BUFF_SIZE 1024
  15. char buffer[BUFF_SIZE];
  16. #define ASSERT_EQ(type, actual, expected) \
  17. do { \
  18. if (actual != expected) { \
  19. switch (type) { \
  20. case UINT: \
  21. snprintf(buffer, BUFF_SIZE, "\nline %d\nvar %s\nactual = %u\nexpected = %u\n", __LINE__, #actual, actual, expected); \
  22. break; \
  23. case INT: \
  24. snprintf(buffer, BUFF_SIZE, "\nline %d\nvar %s\nactual = %d\nexpected = %d\n", __LINE__, #actual, actual, expected); \
  25. break; \
  26. default: \
  27. snprintf(buffer, BUFF_SIZE, "\nline %d\nunsupported ASSERT_EQ type\n", __LINE__); \
  28. break; \
  29. } \
  30. printf("%s\n", buffer); \
  31. passed = false; \
  32. all_passed = false; \
  33. } \
  34. } while (0)
  35. #include <stdio.h>
  36. #include <stdint.h>
  37. #include <stddef.h>
  38. #include <stdbool.h>
  39. #include <string.h>
  40. #define MATRIX_ROWS 2
  41. #define MATRIX_COLS 10
  42. #define LAYOUT_test( \
  43. k09, k08, k07, k06, k05, k04, k03, k02, k01, k00, \
  44. k19, k18, k17, k16, k15, k14, k13, k12, k11, k10 \
  45. ) { \
  46. { k00, k01, k02, k03, k04, k05, k06, k07, k08, k09}, \
  47. { k10, k11, k12, k13, k14, k15, k16, k17, k18, k19}, \
  48. }
  49. #define PROGMEM
  50. #define memcpy_P memcpy
  51. const struct Chord* pgm_read_word(const struct Chord* const* chord) {return *chord;}
  52. typedef struct {
  53. uint8_t col;
  54. uint8_t row;
  55. } keypos_t;
  56. typedef struct {
  57. keypos_t key;
  58. bool pressed;
  59. uint16_t time;
  60. } keyevent_t;
  61. typedef struct {
  62. bool interrupted :1;
  63. bool reserved2 :1;
  64. bool reserved1 :1;
  65. bool reserved0 :1;
  66. uint8_t count :4;
  67. } tap_t;
  68. typedef struct {
  69. keyevent_t event;
  70. tap_t tap;
  71. } keyrecord_t;
  72. keyrecord_t pressed = {{{0,0},true,0}, {0,0,0,0,0}};
  73. keyrecord_t depressed = {{{0,0},false,0}, {0,0,0,0,0}};
  74. enum keycodes {
  75. KC_NO,
  76. KC_TILDE,
  77. KC_GRAVE,
  78. KC_EXCLAIM,
  79. KC_1,
  80. KC_AT,
  81. KC_2,
  82. KC_HASH,
  83. KC_3,
  84. KC_DOLLAR,
  85. KC_4,
  86. KC_PERCENT,
  87. KC_5,
  88. KC_CIRCUMFLEX,
  89. KC_6,
  90. KC_AMPERSAND,
  91. KC_7,
  92. KC_ASTERISK,
  93. KC_8,
  94. KC_LEFT_PAREN,
  95. KC_9,
  96. KC_RIGHT_PAREN,
  97. KC_0,
  98. KC_UNDERSCORE,
  99. KC_MINUS,
  100. KC_PLUS,
  101. KC_EQUAL,
  102. KC_LEFT_CURLY_BRACE,
  103. KC_LBRACKET,
  104. KC_RIGHT_CURLY_BRACE,
  105. KC_RBRACKET,
  106. KC_PIPE,
  107. KC_BSLASH,
  108. KC_COLON,
  109. KC_SCOLON,
  110. KC_DOUBLE_QUOTE,
  111. KC_QUOTE,
  112. KC_LEFT_ANGLE_BRACKET,
  113. KC_COMMA,
  114. KC_RIGHT_ANGLE_BRACKET,
  115. KC_DOT,
  116. KC_QUESTION,
  117. KC_SLASH,
  118. KC_Q,
  119. KC_W,
  120. KC_E,
  121. KC_R,
  122. KC_T,
  123. KC_Y,
  124. KC_U,
  125. KC_I,
  126. KC_O,
  127. KC_P,
  128. KC_A,
  129. KC_S,
  130. KC_D,
  131. KC_F,
  132. KC_G,
  133. KC_H,
  134. KC_J,
  135. KC_K,
  136. KC_L,
  137. KC_Z,
  138. KC_X,
  139. KC_C,
  140. KC_V,
  141. KC_B,
  142. KC_N,
  143. KC_M,
  144. KC_ESC,
  145. KC_LSFT,
  146. KC_LCTL,
  147. KC_LGUI,
  148. KC_LALT,
  149. KC_RALT,
  150. KC_RCTL,
  151. KC_RGUI,
  152. KC_RSFT,
  153. KC_TAB,
  154. KC_DEL,
  155. KC_INS,
  156. KC_BSPC,
  157. KC_ENTER,
  158. KC_SPACE,
  159. KC_F1,
  160. KC_F2,
  161. KC_F3,
  162. KC_F4,
  163. KC_F5,
  164. KC_F6,
  165. KC_F7,
  166. KC_F8,
  167. KC_F9,
  168. KC_F10,
  169. KC_F11,
  170. KC_F12,
  171. KC_LEFT,
  172. KC_DOWN,
  173. KC_UP,
  174. KC_RIGHT,
  175. SAFE_RANGE
  176. };
  177. #define HISTORY 20
  178. int16_t current_time;
  179. uint8_t keyboard_history[HISTORY][SAFE_RANGE-1];
  180. int16_t time_history[HISTORY];
  181. uint8_t history_index;
  182. void register_code(int16_t keycode) {
  183. history_index++;
  184. for (int j = 0; j < SAFE_RANGE-1; j++) {
  185. keyboard_history[history_index][j] = keyboard_history[history_index-1][j];
  186. }
  187. keyboard_history[history_index][keycode] = 1;
  188. time_history[history_index] = current_time;
  189. };
  190. void unregister_code(int16_t keycode) {
  191. history_index++;
  192. for (int j = 0; j < SAFE_RANGE-1; j++) {
  193. keyboard_history[history_index][j] = keyboard_history[history_index-1][j];
  194. }
  195. keyboard_history[history_index][keycode] = 0;
  196. time_history[history_index] = current_time;
  197. };
  198. void send_keyboard_report(void) { /*still don't know what this does*/ };
  199. void matrix_scan_user (void);
  200. void wait_ms(uint16_t ms) {
  201. current_time += ms;
  202. };
  203. uint16_t timer_read(void) {
  204. uint16_t result = current_time;
  205. return result;
  206. };
  207. uint16_t timer_elapsed(uint16_t timer) {
  208. uint16_t result = current_time - timer;
  209. return result;
  210. };
  211. void layer_move(int16_t layer) { /*ignoring for now*/ };
  212. void clear_keyboard(void) {
  213. history_index++;
  214. for (int j = 0; j < SAFE_RANGE-1; j++) {
  215. keyboard_history[history_index][j] = 0;
  216. }
  217. time_history[history_index] = current_time;
  218. };
  219. void reset_keyboard(void) { /*ignoring for now*/ };
  220. void pause_ms(uint16_t ms) {
  221. for (int i = 0; i < ms; i++) {
  222. current_time++;
  223. matrix_scan_user();
  224. }
  225. };
  226. #define TEST(name) \
  227. do { \
  228. printf("%s\n", name); \
  229. passed = true; \
  230. do { \
  231. uint8_t clear_state = ACTIVATED; \
  232. struct Chord clear_chord PROGMEM = {0, QWERTY, &clear_state, NULL, 0, 0, clear}; \
  233. clear_chord.function(&clear_chord); \
  234. } while (0); \
  235. current_time = 0; \
  236. history_index = 0; \
  237. for (int j = 0; j < SAFE_RANGE-1; j++) { \
  238. keyboard_history[0][j] = 0; \
  239. } \
  240. time_history[0] = 0; \
  241. for (int i = 1; i < HISTORY; i++) { \
  242. for (int j = 0; j < SAFE_RANGE-1; j++) { \
  243. keyboard_history[i][j] = -1; \
  244. } \
  245. time_history[i] = -1; \
  246. }
  247. #define END_TEST \
  248. if (passed) { \
  249. printf(GREEN"PASSED"NC"\n"); \
  250. } else { \
  251. printf(RED"FAILED"NC"\n"); \
  252. } \
  253. } while(0);
  254. #define MAIN \
  255. int main(int argc, char **argv) { \
  256. bool passed = true; \
  257. bool all_passed = true;
  258. #define END \
  259. printf("\n"); \
  260. if (all_passed) { \
  261. printf(GREEN"ALL TESTS PASSED"NC"\n"); \
  262. } else { \
  263. printf(RED"TESTS FAILED"NC"\n"); \
  264. } \
  265. return 1 - all_passed; \
  266. }