mirror of
https://github.com/osiweb/unified_retro_keyboard.git
synced 2024-12-27 06:29:17 +00:00
Add tests for multiple keymap support.
This commit is contained in:
parent
16dc913f74
commit
a2a6be49a4
@ -31,8 +31,6 @@
|
|||||||
#define TESTCAPS(row, col, n) TESTMAP((row), (col), CAPS, n)
|
#define TESTCAPS(row, col, n) TESTMAP((row), (col), CAPS, n)
|
||||||
#define TESTCTRL(row, col, n) TESTMAP((row), (col), CTRL, n)
|
#define TESTCTRL(row, col, n) TESTMAP((row), (col), CTRL, n)
|
||||||
|
|
||||||
typedef asdf_keycode_t keycode_matrix_t[ASDF_NUM_ROWS][ASDF_NUM_COLS];
|
|
||||||
|
|
||||||
const char test_string[] = TEST_STRING;
|
const char test_string[] = TEST_STRING;
|
||||||
|
|
||||||
const asdf_keycode_t key_a = A;
|
const asdf_keycode_t key_a = A;
|
||||||
@ -44,10 +42,7 @@ typedef struct {
|
|||||||
} coord_t;
|
} coord_t;
|
||||||
|
|
||||||
|
|
||||||
static const keycode_matrix_t PLAIN_matrix = ASCII_PLAIN_MAP;
|
ASDF_TEST_DECLARATIONS;
|
||||||
static const keycode_matrix_t SHIFT_matrix = ASCII_SHIFT_MAP;
|
|
||||||
static const keycode_matrix_t CAPS_matrix = ASCII_CAPS_MAP;
|
|
||||||
static const keycode_matrix_t CTRL_matrix = ASCII_CTRL_MAP;
|
|
||||||
|
|
||||||
static uint32_t key_matrix[ASDF_NUM_ROWS];
|
static uint32_t key_matrix[ASDF_NUM_ROWS];
|
||||||
|
|
||||||
@ -72,7 +67,7 @@ coord_t *find_code(asdf_keycode_t code)
|
|||||||
|
|
||||||
for (uint32_t row = 0; !done && (row < ASDF_NUM_ROWS); row++) {
|
for (uint32_t row = 0; !done && (row < ASDF_NUM_ROWS); row++) {
|
||||||
for (uint32_t col = 0; !done && (col < ASDF_NUM_COLS); col++) {
|
for (uint32_t col = 0; !done && (col < ASDF_NUM_COLS); col++) {
|
||||||
if (PLAIN_matrix[row][col] == code) {
|
if (test_PLAIN_matrix[row][col] == code) {
|
||||||
done = 1;
|
done = 1;
|
||||||
location.row = row;
|
location.row = row;
|
||||||
location.col = col;
|
location.col = col;
|
||||||
@ -86,19 +81,19 @@ coord_t *find_code(asdf_keycode_t code)
|
|||||||
asdf_keycode_t shifted(asdf_keycode_t code)
|
asdf_keycode_t shifted(asdf_keycode_t code)
|
||||||
{
|
{
|
||||||
coord_t *location = find_code(code);
|
coord_t *location = find_code(code);
|
||||||
return SHIFT_matrix[location->row][location->col];
|
return test_SHIFT_matrix[location->row][location->col];
|
||||||
}
|
}
|
||||||
|
|
||||||
asdf_keycode_t caps(asdf_keycode_t code)
|
asdf_keycode_t caps(asdf_keycode_t code)
|
||||||
{
|
{
|
||||||
coord_t *xy = find_code(code);
|
coord_t *xy = find_code(code);
|
||||||
return CAPS_matrix[xy->row][xy->col];
|
return test_CAPS_matrix[xy->row][xy->col];
|
||||||
}
|
}
|
||||||
|
|
||||||
asdf_keycode_t ctrl(asdf_keycode_t code)
|
asdf_keycode_t ctrl(asdf_keycode_t code)
|
||||||
{
|
{
|
||||||
coord_t *xy = find_code(code);
|
coord_t *xy = find_code(code);
|
||||||
return CTRL_matrix[xy->row][xy->col];
|
return test_CTRL_matrix[xy->row][xy->col];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -149,7 +144,7 @@ void pressing_a_gives_nothing_before_debounce(void)
|
|||||||
|
|
||||||
// no keypress after only ASDF_DEBOUNCE_TIME_MS -1 ticks (not yet debounced):
|
// no keypress after only ASDF_DEBOUNCE_TIME_MS -1 ticks (not yet debounced):
|
||||||
keyscan_delay(ASDF_DEBOUNCE_TIME_MS - 1);
|
keyscan_delay(ASDF_DEBOUNCE_TIME_MS - 1);
|
||||||
TEST_ASSERT_EQUAL_INT32(ASDF_INVALID_CODE, (int32_t) asdf_get_code());
|
TEST_ASSERT_EQUAL_INT32(ASDF_INVALID_CODE, (int32_t) asdf_next_code());
|
||||||
}
|
}
|
||||||
|
|
||||||
// pressing 'A' gives 'a'
|
// pressing 'A' gives 'a'
|
||||||
@ -159,14 +154,14 @@ void pressing_a_gives_a(void)
|
|||||||
|
|
||||||
// no keypress after only ASDF_DEBOUNCE_TIME_MS -1 ticks (not yet debounced):
|
// no keypress after only ASDF_DEBOUNCE_TIME_MS -1 ticks (not yet debounced):
|
||||||
keyscan_delay(ASDF_DEBOUNCE_TIME_MS - 1);
|
keyscan_delay(ASDF_DEBOUNCE_TIME_MS - 1);
|
||||||
TEST_ASSERT_EQUAL_INT32(ASDF_INVALID_CODE, (int32_t) asdf_get_code());
|
TEST_ASSERT_EQUAL_INT32(ASDF_INVALID_CODE, (int32_t) asdf_next_code());
|
||||||
|
|
||||||
// allow the key to finish debounce
|
// allow the key to finish debounce
|
||||||
keyscan_delay(1);
|
keyscan_delay(1);
|
||||||
TEST_ASSERT_EQUAL_INT32((int32_t) key_a, (int32_t) asdf_get_code());
|
TEST_ASSERT_EQUAL_INT32((int32_t) key_a, (int32_t) asdf_next_code());
|
||||||
|
|
||||||
// no more codes in the buffer.
|
// no more codes in the buffer.
|
||||||
TEST_ASSERT_EQUAL_INT32(ASDF_INVALID_CODE, (int32_t) asdf_get_code());
|
TEST_ASSERT_EQUAL_INT32(ASDF_INVALID_CODE, (int32_t) asdf_next_code());
|
||||||
}
|
}
|
||||||
|
|
||||||
// pressing SHIFT+A gives 'A'
|
// pressing SHIFT+A gives 'A'
|
||||||
@ -174,7 +169,7 @@ void pressing_shift_a_gives_shifted_a(void)
|
|||||||
{
|
{
|
||||||
press(ACTION_SHIFT);
|
press(ACTION_SHIFT);
|
||||||
press(key_a);
|
press(key_a);
|
||||||
TEST_ASSERT_EQUAL_INT32((int32_t) shifted(key_a), (int32_t) asdf_get_code());
|
TEST_ASSERT_EQUAL_INT32((int32_t) shifted(key_a), (int32_t) asdf_next_code());
|
||||||
}
|
}
|
||||||
|
|
||||||
// pressing CAPS+A gives 'A'
|
// pressing CAPS+A gives 'A'
|
||||||
@ -184,7 +179,7 @@ void pressing_caps_a_gives_caps_a(void)
|
|||||||
release(ACTION_CAPS);
|
release(ACTION_CAPS);
|
||||||
press(key_a);
|
press(key_a);
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL_INT32((int32_t) caps(key_a), (int32_t) asdf_get_code());
|
TEST_ASSERT_EQUAL_INT32((int32_t) caps(key_a), (int32_t) asdf_next_code());
|
||||||
}
|
}
|
||||||
|
|
||||||
// pressing CTRL+A gives 0x01 (Ctrl-A)
|
// pressing CTRL+A gives 0x01 (Ctrl-A)
|
||||||
@ -192,7 +187,7 @@ void pressing_ctrl_a_gives_ctrl_a(void)
|
|||||||
{
|
{
|
||||||
press(ACTION_CTRL);
|
press(ACTION_CTRL);
|
||||||
press(key_a);
|
press(key_a);
|
||||||
TEST_ASSERT_EQUAL_INT32((int32_t) ctrl(key_a), (int32_t) asdf_get_code());
|
TEST_ASSERT_EQUAL_INT32((int32_t) ctrl(key_a), (int32_t) asdf_next_code());
|
||||||
}
|
}
|
||||||
|
|
||||||
// pressing REPT+A repeats 'a'
|
// pressing REPT+A repeats 'a'
|
||||||
@ -201,17 +196,17 @@ void pressing_rept_a_repeats_a(void)
|
|||||||
press(ACTION_REPEAT);
|
press(ACTION_REPEAT);
|
||||||
press(key_a);
|
press(key_a);
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL_INT32((int32_t) key_a, (uint32_t) asdf_get_code());
|
TEST_ASSERT_EQUAL_INT32((int32_t) key_a, (uint32_t) asdf_next_code());
|
||||||
|
|
||||||
// hold "a" for NUM_REPEATS repeat cycles:
|
// hold "a" for NUM_REPEATS repeat cycles:
|
||||||
keyscan_delay(NUM_REPEATS * ASDF_REPEAT_TIME_MS);
|
keyscan_delay(NUM_REPEATS * ASDF_REPEAT_TIME_MS);
|
||||||
|
|
||||||
for (int i = 0; i < NUM_REPEATS; i++) {
|
for (int i = 0; i < NUM_REPEATS; i++) {
|
||||||
TEST_ASSERT_EQUAL_INT32((int32_t) key_a, (uint32_t) asdf_get_code());
|
TEST_ASSERT_EQUAL_INT32((int32_t) key_a, (uint32_t) asdf_next_code());
|
||||||
}
|
}
|
||||||
|
|
||||||
// and verify there are no more codes in buffer:
|
// and verify there are no more codes in buffer:
|
||||||
TEST_ASSERT_EQUAL_INT32((int32_t) ASDF_INVALID_CODE, (int32_t) asdf_get_code());
|
TEST_ASSERT_EQUAL_INT32((int32_t) ASDF_INVALID_CODE, (int32_t) asdf_next_code());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -222,17 +217,17 @@ void pressing_shift_rept_a_repeats_shifted_a(void)
|
|||||||
press(ACTION_SHIFT);
|
press(ACTION_SHIFT);
|
||||||
press(key_a);
|
press(key_a);
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL_INT32((int32_t) shifted(key_a), (uint32_t) asdf_get_code());
|
TEST_ASSERT_EQUAL_INT32((int32_t) shifted(key_a), (uint32_t) asdf_next_code());
|
||||||
|
|
||||||
// hold "a" for NUM_REPEATS repeat cycles:
|
// hold "a" for NUM_REPEATS repeat cycles:
|
||||||
keyscan_delay(NUM_REPEATS * ASDF_REPEAT_TIME_MS);
|
keyscan_delay(NUM_REPEATS * ASDF_REPEAT_TIME_MS);
|
||||||
|
|
||||||
for (int i = 0; i < NUM_REPEATS; i++) {
|
for (int i = 0; i < NUM_REPEATS; i++) {
|
||||||
TEST_ASSERT_EQUAL_INT32((int32_t) shifted(key_a), (uint32_t) asdf_get_code());
|
TEST_ASSERT_EQUAL_INT32((int32_t) shifted(key_a), (uint32_t) asdf_next_code());
|
||||||
}
|
}
|
||||||
|
|
||||||
// and verify there are no more codes in buffer:
|
// and verify there are no more codes in buffer:
|
||||||
TEST_ASSERT_EQUAL_INT32((int32_t) ASDF_INVALID_CODE, (int32_t) asdf_get_code());
|
TEST_ASSERT_EQUAL_INT32((int32_t) ASDF_INVALID_CODE, (int32_t) asdf_next_code());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -244,18 +239,18 @@ void pressing_caps_rept_a_repeats_caps_a(void)
|
|||||||
|
|
||||||
press(key_a);
|
press(key_a);
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL_INT32((int32_t) caps(key_a), (uint32_t) asdf_get_code());
|
TEST_ASSERT_EQUAL_INT32((int32_t) caps(key_a), (uint32_t) asdf_next_code());
|
||||||
|
|
||||||
|
|
||||||
// hold "a" for NUM_REPEATS repeat cycles:
|
// hold "a" for NUM_REPEATS repeat cycles:
|
||||||
keyscan_delay(NUM_REPEATS * ASDF_REPEAT_TIME_MS);
|
keyscan_delay(NUM_REPEATS * ASDF_REPEAT_TIME_MS);
|
||||||
|
|
||||||
for (int i = 0; i < NUM_REPEATS; i++) {
|
for (int i = 0; i < NUM_REPEATS; i++) {
|
||||||
TEST_ASSERT_EQUAL_INT32((int32_t) caps(key_a), (uint32_t) asdf_get_code());
|
TEST_ASSERT_EQUAL_INT32((int32_t) caps(key_a), (uint32_t) asdf_next_code());
|
||||||
}
|
}
|
||||||
|
|
||||||
// and verify there are no more codes in buffer:
|
// and verify there are no more codes in buffer:
|
||||||
TEST_ASSERT_EQUAL_INT32((int32_t) ASDF_INVALID_CODE, (int32_t) asdf_get_code());
|
TEST_ASSERT_EQUAL_INT32((int32_t) ASDF_INVALID_CODE, (int32_t) asdf_next_code());
|
||||||
}
|
}
|
||||||
|
|
||||||
// pressing REPT+CTRL+A repeats CTRL-A
|
// pressing REPT+CTRL+A repeats CTRL-A
|
||||||
@ -265,18 +260,18 @@ void pressing_ctrl_rept_a_repeats_ctrl_a(void)
|
|||||||
press(ACTION_CTRL);
|
press(ACTION_CTRL);
|
||||||
|
|
||||||
press(key_a);
|
press(key_a);
|
||||||
TEST_ASSERT_EQUAL_INT32((int32_t) ctrl(key_a), (uint32_t) asdf_get_code());
|
TEST_ASSERT_EQUAL_INT32((int32_t) ctrl(key_a), (uint32_t) asdf_next_code());
|
||||||
|
|
||||||
|
|
||||||
// hold "a" for NUM_REPEATS repeat cycles:
|
// hold "a" for NUM_REPEATS repeat cycles:
|
||||||
keyscan_delay(NUM_REPEATS * ASDF_REPEAT_TIME_MS);
|
keyscan_delay(NUM_REPEATS * ASDF_REPEAT_TIME_MS);
|
||||||
|
|
||||||
for (int i = 0; i < NUM_REPEATS + 1; i++) {
|
for (int i = 0; i < NUM_REPEATS + 1; i++) {
|
||||||
TEST_ASSERT_EQUAL_INT32((int32_t) ctrl(key_a), (uint32_t) asdf_get_code());
|
TEST_ASSERT_EQUAL_INT32((int32_t) ctrl(key_a), (uint32_t) asdf_next_code());
|
||||||
}
|
}
|
||||||
|
|
||||||
// and verify there are no more codes in buffer:
|
// and verify there are no more codes in buffer:
|
||||||
TEST_ASSERT_EQUAL_INT32((int32_t) ASDF_INVALID_CODE, (int32_t) asdf_get_code());
|
TEST_ASSERT_EQUAL_INT32((int32_t) ASDF_INVALID_CODE, (int32_t) asdf_next_code());
|
||||||
}
|
}
|
||||||
|
|
||||||
// pressing and holding 'A' autorepeats 'A'
|
// pressing and holding 'A' autorepeats 'A'
|
||||||
@ -284,14 +279,14 @@ void holding_a_autorepeats_a(void)
|
|||||||
{
|
{
|
||||||
press(key_a);
|
press(key_a);
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL_INT32((int32_t) key_a, (uint32_t) asdf_get_code());
|
TEST_ASSERT_EQUAL_INT32((int32_t) key_a, (uint32_t) asdf_next_code());
|
||||||
|
|
||||||
// hold "a" for NUM_REPEATS repeat cycles:
|
// hold "a" for NUM_REPEATS repeat cycles:
|
||||||
keyscan_delay(ASDF_AUTOREPEAT_TIME_MS);
|
keyscan_delay(ASDF_AUTOREPEAT_TIME_MS);
|
||||||
TEST_ASSERT_EQUAL_INT32((int32_t) key_a, (uint32_t) asdf_get_code());
|
TEST_ASSERT_EQUAL_INT32((int32_t) key_a, (uint32_t) asdf_next_code());
|
||||||
|
|
||||||
// and verify there are no more codes in buffer:
|
// and verify there are no more codes in buffer:
|
||||||
TEST_ASSERT_EQUAL_INT32((int32_t) ASDF_INVALID_CODE, (int32_t) asdf_get_code());
|
TEST_ASSERT_EQUAL_INT32((int32_t) ASDF_INVALID_CODE, (int32_t) asdf_next_code());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -300,21 +295,21 @@ void holding_a_autorepeats_slow_then_fast(void)
|
|||||||
{
|
{
|
||||||
press(key_a);
|
press(key_a);
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL_INT32((int32_t) key_a, (uint32_t) asdf_get_code());
|
TEST_ASSERT_EQUAL_INT32((int32_t) key_a, (uint32_t) asdf_next_code());
|
||||||
|
|
||||||
// hold "a" for NUM_REPEATS repeat cycles:
|
// hold "a" for NUM_REPEATS repeat cycles:
|
||||||
keyscan_delay(ASDF_AUTOREPEAT_TIME_MS);
|
keyscan_delay(ASDF_AUTOREPEAT_TIME_MS);
|
||||||
TEST_ASSERT_EQUAL_INT32((int32_t) key_a, (uint32_t) asdf_get_code());
|
TEST_ASSERT_EQUAL_INT32((int32_t) key_a, (uint32_t) asdf_next_code());
|
||||||
|
|
||||||
// hold "a" for NUM_REPEATS repeat cycles:
|
// hold "a" for NUM_REPEATS repeat cycles:
|
||||||
keyscan_delay(NUM_REPEATS * ASDF_REPEAT_TIME_MS);
|
keyscan_delay(NUM_REPEATS * ASDF_REPEAT_TIME_MS);
|
||||||
|
|
||||||
for (int i = 0; i < NUM_REPEATS; i++) {
|
for (int i = 0; i < NUM_REPEATS; i++) {
|
||||||
TEST_ASSERT_EQUAL_INT32((int32_t) key_a, (uint32_t) asdf_get_code());
|
TEST_ASSERT_EQUAL_INT32((int32_t) key_a, (uint32_t) asdf_next_code());
|
||||||
}
|
}
|
||||||
|
|
||||||
// and verify there are no more codes in buffer:
|
// and verify there are no more codes in buffer:
|
||||||
TEST_ASSERT_EQUAL_INT32((int32_t) ASDF_INVALID_CODE, (int32_t) asdf_get_code());
|
TEST_ASSERT_EQUAL_INT32((int32_t) ASDF_INVALID_CODE, (int32_t) asdf_next_code());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -330,13 +325,13 @@ void pressing_a_then_b_before_debounce_gives_a_then_b(void)
|
|||||||
press(key_b);
|
press(key_b);
|
||||||
|
|
||||||
// first get back A
|
// first get back A
|
||||||
TEST_ASSERT_EQUAL_INT32((int32_t) key_a, (uint32_t) asdf_get_code());
|
TEST_ASSERT_EQUAL_INT32((int32_t) key_a, (uint32_t) asdf_next_code());
|
||||||
|
|
||||||
// next get back B
|
// next get back B
|
||||||
TEST_ASSERT_EQUAL_INT32((int32_t) key_b, (uint32_t) asdf_get_code());
|
TEST_ASSERT_EQUAL_INT32((int32_t) key_b, (uint32_t) asdf_next_code());
|
||||||
|
|
||||||
// and then verify there are no more codes in buffer:
|
// and then verify there are no more codes in buffer:
|
||||||
TEST_ASSERT_EQUAL_INT32((int32_t) ASDF_INVALID_CODE, (int32_t) asdf_get_code());
|
TEST_ASSERT_EQUAL_INT32((int32_t) ASDF_INVALID_CODE, (int32_t) asdf_next_code());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -350,11 +345,11 @@ void test_key_sequence_nkro(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < (int32_t) strlen(test_string); i++) {
|
for (int i = 0; i < (int32_t) strlen(test_string); i++) {
|
||||||
TEST_ASSERT_EQUAL_INT32((int32_t) test_string[i], (int32_t) asdf_get_code());
|
TEST_ASSERT_EQUAL_INT32((int32_t) test_string[i], (int32_t) asdf_next_code());
|
||||||
}
|
}
|
||||||
|
|
||||||
// and then verify there are no more codes in buffer:
|
// and then verify there are no more codes in buffer:
|
||||||
TEST_ASSERT_EQUAL_INT32((int32_t) ASDF_INVALID_CODE, (int32_t) asdf_get_code());
|
TEST_ASSERT_EQUAL_INT32((int32_t) ASDF_INVALID_CODE, (int32_t) asdf_next_code());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -372,11 +367,11 @@ void test_key_sequence_nkro_simultaneous_debounce(void)
|
|||||||
keyscan_delay(ASDF_DEBOUNCE_TIME_MS);
|
keyscan_delay(ASDF_DEBOUNCE_TIME_MS);
|
||||||
|
|
||||||
for (int i = 0; i < (int32_t) strlen(test_string); i++) {
|
for (int i = 0; i < (int32_t) strlen(test_string); i++) {
|
||||||
TEST_ASSERT_EQUAL_INT32((int32_t) test_string[i], (int32_t) asdf_get_code());
|
TEST_ASSERT_EQUAL_INT32((int32_t) test_string[i], (int32_t) asdf_next_code());
|
||||||
}
|
}
|
||||||
|
|
||||||
// and then verify there are no more codes in buffer:
|
// and then verify there are no more codes in buffer:
|
||||||
TEST_ASSERT_EQUAL_INT32((int32_t) ASDF_INVALID_CODE, (int32_t) asdf_get_code());
|
TEST_ASSERT_EQUAL_INT32((int32_t) ASDF_INVALID_CODE, (int32_t) asdf_next_code());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -395,16 +390,16 @@ void holding_a_briefly_then_holding_b_gives_a_and_repeats_b(void)
|
|||||||
keyscan_delay(NUM_REPEATS * ASDF_REPEAT_TIME_MS);
|
keyscan_delay(NUM_REPEATS * ASDF_REPEAT_TIME_MS);
|
||||||
|
|
||||||
// should get "a" back, then "b"
|
// should get "a" back, then "b"
|
||||||
TEST_ASSERT_EQUAL_INT32((int32_t) key_a, (uint32_t) asdf_get_code());
|
TEST_ASSERT_EQUAL_INT32((int32_t) key_a, (uint32_t) asdf_next_code());
|
||||||
TEST_ASSERT_EQUAL_INT32((int32_t) key_b, (uint32_t) asdf_get_code());
|
TEST_ASSERT_EQUAL_INT32((int32_t) key_b, (uint32_t) asdf_next_code());
|
||||||
|
|
||||||
// now get back NUM_REEPEATS repetitions of "b"
|
// now get back NUM_REEPEATS repetitions of "b"
|
||||||
for (int i = 0; i < NUM_REPEATS; i++) {
|
for (int i = 0; i < NUM_REPEATS; i++) {
|
||||||
TEST_ASSERT_EQUAL_INT32((int32_t) key_b, (uint32_t) asdf_get_code());
|
TEST_ASSERT_EQUAL_INT32((int32_t) key_b, (uint32_t) asdf_next_code());
|
||||||
}
|
}
|
||||||
|
|
||||||
// and then verify there are no more codes in buffer:
|
// and then verify there are no more codes in buffer:
|
||||||
TEST_ASSERT_EQUAL_INT32((int32_t) ASDF_INVALID_CODE, (int32_t) asdf_get_code());
|
TEST_ASSERT_EQUAL_INT32((int32_t) ASDF_INVALID_CODE, (int32_t) asdf_next_code());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -413,40 +408,40 @@ void holding_a_then_holding_b_autorepeats_a_then_autorepeats_b(void)
|
|||||||
{
|
{
|
||||||
press(key_a);
|
press(key_a);
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL_INT32((int32_t) key_a, (uint32_t) asdf_get_code());
|
TEST_ASSERT_EQUAL_INT32((int32_t) key_a, (uint32_t) asdf_next_code());
|
||||||
|
|
||||||
// hold "a" for AUTOREPEAT delay
|
// hold "a" for AUTOREPEAT delay
|
||||||
keyscan_delay(ASDF_AUTOREPEAT_TIME_MS);
|
keyscan_delay(ASDF_AUTOREPEAT_TIME_MS);
|
||||||
TEST_ASSERT_EQUAL_INT32((int32_t) key_a, (uint32_t) asdf_get_code());
|
TEST_ASSERT_EQUAL_INT32((int32_t) key_a, (uint32_t) asdf_next_code());
|
||||||
|
|
||||||
// hold "a" for NUM_REPEATS repeat cycles:
|
// hold "a" for NUM_REPEATS repeat cycles:
|
||||||
keyscan_delay(NUM_REPEATS * ASDF_REPEAT_TIME_MS);
|
keyscan_delay(NUM_REPEATS * ASDF_REPEAT_TIME_MS);
|
||||||
|
|
||||||
// empty the buffer to make room for 'B'
|
// empty the buffer to make room for 'B'
|
||||||
for (int i = 0; i < NUM_REPEATS; i++) {
|
for (int i = 0; i < NUM_REPEATS; i++) {
|
||||||
TEST_ASSERT_EQUAL_INT32((int32_t) key_a, (uint32_t) asdf_get_code());
|
TEST_ASSERT_EQUAL_INT32((int32_t) key_a, (uint32_t) asdf_next_code());
|
||||||
}
|
}
|
||||||
|
|
||||||
// now press "b" while "a" is autorepeating:
|
// now press "b" while "a" is autorepeating:
|
||||||
|
|
||||||
press(key_b);
|
press(key_b);
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL_INT32((int32_t) key_b, (uint32_t) asdf_get_code());
|
TEST_ASSERT_EQUAL_INT32((int32_t) key_b, (uint32_t) asdf_next_code());
|
||||||
|
|
||||||
// hold "a" for autorepeat delay
|
// hold "a" for autorepeat delay
|
||||||
keyscan_delay(ASDF_AUTOREPEAT_TIME_MS);
|
keyscan_delay(ASDF_AUTOREPEAT_TIME_MS);
|
||||||
TEST_ASSERT_EQUAL_INT32((int32_t) key_b, (uint32_t) asdf_get_code());
|
TEST_ASSERT_EQUAL_INT32((int32_t) key_b, (uint32_t) asdf_next_code());
|
||||||
|
|
||||||
// hold "a" for NUM_REPEATS repeat cycles:
|
// hold "a" for NUM_REPEATS repeat cycles:
|
||||||
keyscan_delay(NUM_REPEATS * ASDF_REPEAT_TIME_MS);
|
keyscan_delay(NUM_REPEATS * ASDF_REPEAT_TIME_MS);
|
||||||
|
|
||||||
// empty the buffer to make room for 'B'
|
// empty the buffer to make room for 'B'
|
||||||
for (int i = 0; i < NUM_REPEATS; i++) {
|
for (int i = 0; i < NUM_REPEATS; i++) {
|
||||||
TEST_ASSERT_EQUAL_INT32((int32_t) key_b, (uint32_t) asdf_get_code());
|
TEST_ASSERT_EQUAL_INT32((int32_t) key_b, (uint32_t) asdf_next_code());
|
||||||
}
|
}
|
||||||
|
|
||||||
// and verify there are no more codes in buffer:
|
// and verify there are no more codes in buffer:
|
||||||
TEST_ASSERT_EQUAL_INT32((int32_t) ASDF_INVALID_CODE, (int32_t) asdf_get_code());
|
TEST_ASSERT_EQUAL_INT32((int32_t) ASDF_INVALID_CODE, (int32_t) asdf_next_code());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pressing and holding 'A' then holding 'B' with repeat key held repeats 'A' then 'B'
|
// Pressing and holding 'A' then holding 'B' with repeat key held repeats 'A' then 'B'
|
||||||
@ -455,32 +450,32 @@ void repeating_with_a_then_adding_b_repeats_a_then_repeats_b(void)
|
|||||||
press(ACTION_REPEAT);
|
press(ACTION_REPEAT);
|
||||||
press(key_a);
|
press(key_a);
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL_INT32((int32_t) key_a, (uint32_t) asdf_get_code());
|
TEST_ASSERT_EQUAL_INT32((int32_t) key_a, (uint32_t) asdf_next_code());
|
||||||
|
|
||||||
// hold "a" for NUM_REPEATS repeat cycles:
|
// hold "a" for NUM_REPEATS repeat cycles:
|
||||||
keyscan_delay(NUM_REPEATS * ASDF_REPEAT_TIME_MS);
|
keyscan_delay(NUM_REPEATS * ASDF_REPEAT_TIME_MS);
|
||||||
|
|
||||||
// empty the buffer to make room for 'B'
|
// empty the buffer to make room for 'B'
|
||||||
for (int i = 0; i < NUM_REPEATS; i++) {
|
for (int i = 0; i < NUM_REPEATS; i++) {
|
||||||
TEST_ASSERT_EQUAL_INT32((int32_t) key_a, (uint32_t) asdf_get_code());
|
TEST_ASSERT_EQUAL_INT32((int32_t) key_a, (uint32_t) asdf_next_code());
|
||||||
}
|
}
|
||||||
|
|
||||||
// now press "b" while "a" is autorepeating:
|
// now press "b" while "a" is autorepeating:
|
||||||
|
|
||||||
press(key_b);
|
press(key_b);
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL_INT32((int32_t) key_b, (uint32_t) asdf_get_code());
|
TEST_ASSERT_EQUAL_INT32((int32_t) key_b, (uint32_t) asdf_next_code());
|
||||||
|
|
||||||
// hold "a" for NUM_REPEATS repeat cycles:
|
// hold "a" for NUM_REPEATS repeat cycles:
|
||||||
keyscan_delay(NUM_REPEATS * ASDF_REPEAT_TIME_MS);
|
keyscan_delay(NUM_REPEATS * ASDF_REPEAT_TIME_MS);
|
||||||
|
|
||||||
// empty the buffer to make room for 'B'
|
// empty the buffer to make room for 'B'
|
||||||
for (int i = 0; i < NUM_REPEATS; i++) {
|
for (int i = 0; i < NUM_REPEATS; i++) {
|
||||||
TEST_ASSERT_EQUAL_INT32((int32_t) key_b, (uint32_t) asdf_get_code());
|
TEST_ASSERT_EQUAL_INT32((int32_t) key_b, (uint32_t) asdf_next_code());
|
||||||
}
|
}
|
||||||
|
|
||||||
// and verify there are no more codes in buffer:
|
// and verify there are no more codes in buffer:
|
||||||
TEST_ASSERT_EQUAL_INT32((int32_t) ASDF_INVALID_CODE, (int32_t) asdf_get_code());
|
TEST_ASSERT_EQUAL_INT32((int32_t) ASDF_INVALID_CODE, (int32_t) asdf_next_code());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include "asdf_arch.h"
|
||||||
#include "unity.h"
|
#include "unity.h"
|
||||||
#include "asdf.h"
|
#include "asdf.h"
|
||||||
#include "asdf_ascii.h"
|
#include "asdf_ascii.h"
|
||||||
@ -8,41 +10,86 @@
|
|||||||
|
|
||||||
#define TESTALPHA 'a'
|
#define TESTALPHA 'a'
|
||||||
#define TESTNUM '2'
|
#define TESTNUM '2'
|
||||||
|
#define TESTKEYMAP_TAG PLAIN_MATRIX_1
|
||||||
|
#define NUM_DIPSWITCHES 4
|
||||||
|
|
||||||
#define TESTMAP(row, col, mapname, mapname2) \
|
// row: row number
|
||||||
|
// col: column number
|
||||||
|
// keymap_name: id of the file defining the matrix to be used.
|
||||||
|
// defnum: numerical order of the file defining the matrix to be used.
|
||||||
|
// mapindex: matrix of keymaps to be used (contains all modifier maps for the matrix).
|
||||||
|
// modifier_name: name of the modifier to be accessed within the map.
|
||||||
|
#define TESTMAP(row, col, keymap_name, defnum, mapindex, modifier_name) \
|
||||||
do { \
|
do { \
|
||||||
asdf_keycode_t expected = mapname##_matrix[(row)][(col)]; \
|
asdf_keymaps_select_keymap(ASDF_##mapindex##_MAP_INDEX); \
|
||||||
asdf_keycode_t result = asdf_keymaps_get_code((row), (col), MOD_ ## mapname2 ## _MAP); \
|
asdf_keycode_t expected = keymap_name##_##modifier_name##_matrix[(row)][(col)]; \
|
||||||
TEST_ASSERT_EQUAL_INT(expected, result); \
|
asdf_keycode_t result = asdf_keymaps_get_code((row), (col), MOD_##modifier_name##_MAP); \
|
||||||
} while (0);
|
asdf_keycode_t map_id = asdf_keymaps_get_code(0, 0, MOD_##modifier_name##_MAP); \
|
||||||
|
TEST_ASSERT_EQUAL_INT32((uint32_t) expected, (uint32_t) result); \
|
||||||
|
TEST_ASSERT_EQUAL_INT32((uint32_t) modifier_name##_MATRIX_##defnum, (uint32_t) map_id); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
#define TEST_VALID_CODE(position) do { \
|
#define TEST0MAP(row, col, modifier) TESTMAP(row, col, test, 1, TEST_PLAIN, modifier)
|
||||||
|
#define TEST1MAP(row, col, modifier) TESTMAP(row, col, test, 1, TEST_CAPS, modifier)
|
||||||
|
#define TEST2MAP(row, col, modifier) TESTMAP(row, col, test2, 2, TEST2_PLAIN, modifier)
|
||||||
|
#define TEST3MAP(row, col, modifier) TESTMAP(row, col, test2, 2, TEST2_CAPS, modifier)
|
||||||
|
|
||||||
|
|
||||||
|
#define TEST_VALID_CODE(position) \
|
||||||
|
do { \
|
||||||
coord_t pos = position; \
|
coord_t pos = position; \
|
||||||
TEST_ASSERT_FALSE(pos.row == -1); \
|
TEST_ASSERT_FALSE(pos.row == -1); \
|
||||||
TEST_ASSERT_FALSE(pos.col == -1); \
|
TEST_ASSERT_FALSE(pos.col == -1); \
|
||||||
} while (0);
|
} while (0)
|
||||||
|
|
||||||
#define TESTPLAIN(row, col, n) TESTMAP((row), (col), PLAIN, n)
|
// check against the "test" keymaps
|
||||||
#define TESTSHIFT(row, col, n) TESTMAP((row), (col), SHIFT, n)
|
#define TEST0PLAIN(row, col) TEST0MAP((row), (col), PLAIN)
|
||||||
#define TESTCAPS(row, col, n) TESTMAP((row), (col), CAPS, n)
|
#define TEST0SHIFT(row, col) TEST0MAP((row), (col), SHIFT)
|
||||||
#define TESTCTRL(row, col, n) TESTMAP((row), (col), CTRL, n)
|
#define TEST0CAPS(row, col) TEST0MAP((row), (col), CAPS)
|
||||||
|
#define TEST0CTRL(row, col) TEST0MAP((row), (col), CTRL)
|
||||||
|
|
||||||
typedef asdf_keycode_t keycode_matrix_t[ASDF_NUM_ROWS][ASDF_NUM_COLS];
|
#define TEST1PLAIN(row, col) TEST1MAP((row), (col), PLAIN)
|
||||||
|
#define TEST1SHIFT(row, col) TEST1MAP((row), (col), SHIFT)
|
||||||
|
#define TEST1CAPS(row, col) TEST1MAP((row), (col), CAPS)
|
||||||
|
#define TEST1CTRL(row, col) TEST1MAP((row), (col), CTRL)
|
||||||
|
|
||||||
|
// check against the "test2" keymaps
|
||||||
|
|
||||||
|
#define TEST2PLAIN(row, col) TEST2MAP((row), (col), PLAIN)
|
||||||
|
#define TEST2SHIFT(row, col) TEST2MAP((row), (col), SHIFT)
|
||||||
|
#define TEST2CAPS(row, col) TEST2MAP((row), (col), CAPS)
|
||||||
|
#define TEST2CTRL(row, col) TEST2MAP((row), (col), CTRL)
|
||||||
|
|
||||||
|
#define TEST3PLAIN(row, col) TEST3MAP((row), (col), PLAIN)
|
||||||
|
#define TEST3SHIFT(row, col) TEST3MAP((row), (col), SHIFT)
|
||||||
|
#define TEST3CAPS(row, col) TEST3MAP((row), (col), CAPS)
|
||||||
|
#define TEST3CTRL(row, col) TEST3MAP((row), (col), CTRL)
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t row;
|
int32_t row;
|
||||||
int32_t col;
|
int32_t col;
|
||||||
} coord_t;
|
} coord_t;
|
||||||
|
|
||||||
|
// The dip switch positions do not need to reflect real hardware. These
|
||||||
|
// positions reflect the organization of the test keymaps, to ensure that tools
|
||||||
|
// used to place the codes are functioning and are being properly used.
|
||||||
|
|
||||||
|
|
||||||
|
ASDF_KEYMAP_DECLARATIONS;
|
||||||
|
|
||||||
static const keycode_matrix_t PLAIN_matrix = ASCII_PLAIN_MAP;
|
|
||||||
static const keycode_matrix_t SHIFT_matrix = ASCII_SHIFT_MAP;
|
|
||||||
static const keycode_matrix_t CAPS_matrix = ASCII_CAPS_MAP;
|
|
||||||
static const keycode_matrix_t CTRL_matrix = ASCII_CTRL_MAP;
|
|
||||||
|
|
||||||
static coord_t alpha_sample;
|
static coord_t alpha_sample;
|
||||||
|
|
||||||
static coord_t num_sample;
|
static coord_t num_sample;
|
||||||
|
static coord_t keymap_tag;
|
||||||
|
|
||||||
|
uint32_t max(uint8_t first, uint8_t second)
|
||||||
|
{
|
||||||
|
uint32_t max = first;
|
||||||
|
if (second > max) {
|
||||||
|
max = second;
|
||||||
|
}
|
||||||
|
return max;
|
||||||
|
}
|
||||||
|
|
||||||
coord_t *find_code(asdf_keycode_t code)
|
coord_t *find_code(asdf_keycode_t code)
|
||||||
{
|
{
|
||||||
@ -51,7 +98,7 @@ coord_t *find_code(asdf_keycode_t code)
|
|||||||
|
|
||||||
for (uint32_t row = 0; !done && (row < ASDF_NUM_ROWS); row++) {
|
for (uint32_t row = 0; !done && (row < ASDF_NUM_ROWS); row++) {
|
||||||
for (uint32_t col = 0; !done && (col < ASDF_NUM_COLS); col++) {
|
for (uint32_t col = 0; !done && (col < ASDF_NUM_COLS); col++) {
|
||||||
if (PLAIN_matrix[row][col] == code) {
|
if (test_PLAIN_matrix[row][col] == code) {
|
||||||
done = 1;
|
done = 1;
|
||||||
location.row = row;
|
location.row = row;
|
||||||
location.col = col;
|
location.col = col;
|
||||||
@ -73,47 +120,234 @@ void setUp(void)
|
|||||||
|
|
||||||
temp = find_code(TESTNUM);
|
temp = find_code(TESTNUM);
|
||||||
num_sample = *temp;
|
num_sample = *temp;
|
||||||
|
|
||||||
|
temp = find_code(TESTKEYMAP_TAG);
|
||||||
|
keymap_tag = *temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tearDown(void) {}
|
void tearDown(void) {}
|
||||||
|
|
||||||
|
|
||||||
void test_chars_are_in_map(void) {
|
// set a keymap using the asdf_keymap dip-switch functions
|
||||||
|
void complicated_set_keymap(uint8_t mapnum)
|
||||||
|
{
|
||||||
|
void (*set_funcs[])(void) = { &asdf_keymaps_map_select_0_set, &asdf_keymaps_map_select_1_set,
|
||||||
|
&asdf_keymaps_map_select_2_set, &asdf_keymaps_map_select_3_set };
|
||||||
|
void (*clr_funcs[])(void) = { &asdf_keymaps_map_select_0_clear, &asdf_keymaps_map_select_1_clear,
|
||||||
|
&asdf_keymaps_map_select_2_clear,
|
||||||
|
&asdf_keymaps_map_select_3_clear };
|
||||||
|
|
||||||
|
for (uint8_t i = 0; i < NUM_DIPSWITCHES; i++) {
|
||||||
|
if (mapnum & 1) {
|
||||||
|
set_funcs[i]();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
clr_funcs[i]();
|
||||||
|
}
|
||||||
|
mapnum >>= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// the next two test check the preprocessor mechanism for allocating space for
|
||||||
|
// the largest defined keymap
|
||||||
|
|
||||||
|
// check to see that the largest number of columns is detected.
|
||||||
|
void test_num_cols_is_max_cols(void)
|
||||||
|
{
|
||||||
|
TEST_ASSERT_EQUAL_INT32(max(ASDF_TEST_NUM_COLS, ASDF_TEST2_NUM_COLS), ASDF_NUM_COLS);
|
||||||
|
}
|
||||||
|
|
||||||
|
// check to see that the largest number of rows is detected.
|
||||||
|
void test_num_rows_is_max_rows(void)
|
||||||
|
{
|
||||||
|
TEST_ASSERT_EQUAL_INT32(max(ASDF_TEST_NUM_ROWS, ASDF_TEST2_NUM_ROWS), ASDF_NUM_ROWS);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_chars_are_in_map(void)
|
||||||
|
{
|
||||||
TEST_VALID_CODE(alpha_sample);
|
TEST_VALID_CODE(alpha_sample);
|
||||||
TEST_VALID_CODE(num_sample);
|
TEST_VALID_CODE(num_sample);
|
||||||
}
|
}
|
||||||
|
|
||||||
void plain_map_gives_plain_values(void)
|
void keymap0_plain_gives_plain_values(void)
|
||||||
{
|
{
|
||||||
TESTPLAIN(alpha_sample.row, alpha_sample.col, PLAIN);
|
TEST0PLAIN(alpha_sample.row, alpha_sample.col);
|
||||||
TESTPLAIN(num_sample.row, num_sample.col, PLAIN);
|
TEST0PLAIN(num_sample.row, num_sample.col);
|
||||||
}
|
}
|
||||||
|
|
||||||
void shift_map_gives_shift_values(void)
|
void keymap0_shift_gives_shift_values(void)
|
||||||
{
|
{
|
||||||
TESTSHIFT(alpha_sample.row, alpha_sample.col, SHIFT);
|
TEST0SHIFT(alpha_sample.row, alpha_sample.col);
|
||||||
TESTSHIFT(num_sample.row, num_sample.col, SHIFT);
|
TEST0SHIFT(num_sample.row, num_sample.col);
|
||||||
}
|
}
|
||||||
void caps_map_gives_caps_values(void)
|
void keymap0_caps_gives_caps_values(void)
|
||||||
{
|
{
|
||||||
TESTCAPS(alpha_sample.row, alpha_sample.col, CAPS);
|
TEST0CAPS(alpha_sample.row, alpha_sample.col);
|
||||||
TESTCAPS(num_sample.row, num_sample.col, CAPS);
|
TEST0CAPS(num_sample.row, num_sample.col);
|
||||||
}
|
}
|
||||||
void ctrl_map_gives_ctrl_values(void)
|
void keymap0_ctrl_gives_ctrl_values(void)
|
||||||
{
|
{
|
||||||
TESTCTRL(alpha_sample.row, alpha_sample.col, CTRL);
|
TEST0CTRL(alpha_sample.row, alpha_sample.col);
|
||||||
TESTCTRL(num_sample.row, num_sample.col, CTRL);
|
TEST0CTRL(num_sample.row, num_sample.col);
|
||||||
|
}
|
||||||
|
|
||||||
|
void keymap2_plain_gives_plain_values(void)
|
||||||
|
{
|
||||||
|
TEST2PLAIN(alpha_sample.row, alpha_sample.col);
|
||||||
|
TEST2PLAIN(num_sample.row, num_sample.col);
|
||||||
|
}
|
||||||
|
|
||||||
|
void keymap2_shift_gives_shift_values(void)
|
||||||
|
{
|
||||||
|
TEST2SHIFT(alpha_sample.row, alpha_sample.col);
|
||||||
|
TEST2SHIFT(num_sample.row, num_sample.col);
|
||||||
|
}
|
||||||
|
void keymap2_caps_gives_caps_values(void)
|
||||||
|
{
|
||||||
|
TEST2CAPS(alpha_sample.row, alpha_sample.col);
|
||||||
|
TEST2CAPS(num_sample.row, num_sample.col);
|
||||||
|
}
|
||||||
|
void keymap2_ctrl_gives_ctrl_values(void)
|
||||||
|
{
|
||||||
|
TEST2CTRL(alpha_sample.row, alpha_sample.col);
|
||||||
|
TEST2CTRL(num_sample.row, num_sample.col);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void keymap1_capsmap_plain_maps_to_caps(void)
|
||||||
|
{
|
||||||
|
// set bit 0 to select keymap 1
|
||||||
|
asdf_keymaps_map_select_0_set();
|
||||||
|
TEST1CAPS(alpha_sample.row, alpha_sample.col);
|
||||||
|
TEST1CAPS(num_sample.row, num_sample.col);
|
||||||
|
}
|
||||||
|
|
||||||
|
void dip_switch_codes_are_in_last_row_test1_map(void)
|
||||||
|
{
|
||||||
|
coord_t dip_switches[NUM_DIPSWITCHES] = { { .row = ASDF_LAST_ROW, .col = 0 },
|
||||||
|
{ .row = ASDF_LAST_ROW, .col = 1 },
|
||||||
|
{ .row = ASDF_LAST_ROW, .col = 2 },
|
||||||
|
{ .row = ASDF_LAST_ROW, .col = 3 } };
|
||||||
|
for (uint8_t i = 0; i < NUM_DIPSWITCHES; i++) {
|
||||||
|
asdf_keycode_t code =
|
||||||
|
asdf_keymaps_get_code(dip_switches[i].row, dip_switches[i].col, ASDF_TEST_PLAIN_MAP_INDEX);
|
||||||
|
TEST_ASSERT_EQUAL_INT32((uint32_t) code, (uint32_t)(ACTION_MAPSEL_0 + i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void dip_switch_codes_are_in_last_row_test2_map(void)
|
||||||
|
{
|
||||||
|
coord_t dip_switches[NUM_DIPSWITCHES] = { { .row = ASDF_LAST_ROW, .col = 0 },
|
||||||
|
{ .row = ASDF_LAST_ROW, .col = 1 },
|
||||||
|
{ .row = ASDF_LAST_ROW, .col = 2 },
|
||||||
|
{ .row = ASDF_LAST_ROW, .col = 3 } };
|
||||||
|
for (uint8_t i = 0; i < NUM_DIPSWITCHES; i++) {
|
||||||
|
asdf_keycode_t code =
|
||||||
|
asdf_keymaps_get_code(dip_switches[i].row, dip_switches[i].col, ASDF_TEST2_PLAIN_MAP_INDEX);
|
||||||
|
TEST_ASSERT_EQUAL_INT32((uint32_t) code, (uint32_t)(ACTION_MAPSEL_0 + i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void dip_switch_properly_sets_bits(void)
|
||||||
|
{
|
||||||
|
char message[80];
|
||||||
|
|
||||||
|
|
||||||
|
sprintf(message, "Map 0 is %d.", PLAIN_MATRIX_1);
|
||||||
|
TEST_MESSAGE(message);
|
||||||
|
|
||||||
|
for (uint8_t i = 0; i < ASDF_NUM_KEYMAPS; i++) {
|
||||||
|
asdf_keycode_t expected;
|
||||||
|
asdf_keycode_t result;
|
||||||
|
asdf_keymaps_select_keymap(i);
|
||||||
|
expected = asdf_keymaps_get_code(keymap_tag.row, keymap_tag.col, MOD_PLAIN_MAP);
|
||||||
|
|
||||||
|
// set all keymap bits to '0'
|
||||||
|
asdf_keymaps_select_keymap(0);
|
||||||
|
complicated_set_keymap(i);
|
||||||
|
result = asdf_keymaps_get_code(keymap_tag.row, keymap_tag.col, MOD_PLAIN_MAP);
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL_INT32(expected, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void dip_switch_properly_clears_bits(void)
|
||||||
|
{
|
||||||
|
uint8_t mask = 0;
|
||||||
|
uint8_t next = 1;
|
||||||
|
char message[80];
|
||||||
|
|
||||||
|
|
||||||
|
sprintf(message, "Map 0 is %d.", PLAIN_MATRIX_1);
|
||||||
|
TEST_MESSAGE(message);
|
||||||
|
|
||||||
|
// calculate word with most 1's less than (or equal to) ASDF_NUM_KEYMAPS
|
||||||
|
while (next < ASDF_NUM_KEYMAPS) {
|
||||||
|
mask = next;
|
||||||
|
next = (next << 1) | 1;
|
||||||
|
}
|
||||||
|
for (uint8_t i = 0; i < ASDF_NUM_KEYMAPS; i++) {
|
||||||
|
asdf_keycode_t expected;
|
||||||
|
asdf_keycode_t result;
|
||||||
|
asdf_keymaps_select_keymap(i);
|
||||||
|
expected = asdf_keymaps_get_code(keymap_tag.row, keymap_tag.col, MOD_PLAIN_MAP);
|
||||||
|
|
||||||
|
// set as many keymap bits to '1' as possible.
|
||||||
|
asdf_keymaps_select_keymap(mask);
|
||||||
|
complicated_set_keymap(i);
|
||||||
|
result = asdf_keymaps_get_code(keymap_tag.row, keymap_tag.col, MOD_PLAIN_MAP);
|
||||||
|
TEST_ASSERT_EQUAL_INT32(expected, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void dip_switch_invalid_keymap_has_no_effect(void)
|
||||||
|
{
|
||||||
|
asdf_keycode_t map_id;
|
||||||
|
|
||||||
|
// First, assert that changing to matrix 2 works:
|
||||||
|
asdf_keymaps_select_keymap(ASDF_TEST2_PLAIN_MAP_INDEX);
|
||||||
|
map_id = asdf_keymaps_get_code(keymap_tag.row, keymap_tag.col, MOD_PLAIN_MAP);
|
||||||
|
TEST_ASSERT_EQUAL_INT32(PLAIN_MATRIX_2, map_id);
|
||||||
|
|
||||||
|
// assert that resetting keymap to 0 works:
|
||||||
|
asdf_keymaps_select_keymap(0);
|
||||||
|
map_id = asdf_keymaps_get_code(keymap_tag.row, keymap_tag.col, MOD_PLAIN_MAP);
|
||||||
|
TEST_ASSERT_EQUAL_INT32(PLAIN_MATRIX_1, map_id);
|
||||||
|
|
||||||
|
// selecting one above the highest keymap should have no effect
|
||||||
|
asdf_keymaps_select_keymap(ASDF_NUM_KEYMAPS);
|
||||||
|
map_id = asdf_keymaps_get_code(keymap_tag.row, keymap_tag.col, MOD_PLAIN_MAP);
|
||||||
|
TEST_ASSERT_EQUAL_INT32(PLAIN_MATRIX_1, map_id);
|
||||||
|
|
||||||
|
// selecting one above the highest keymap should have no effect
|
||||||
|
map_id = asdf_keymaps_get_code(keymap_tag.row, keymap_tag.col, MOD_PLAIN_MAP);
|
||||||
|
asdf_keymaps_select_keymap(UINT8_MAX);
|
||||||
|
TEST_ASSERT_EQUAL_INT32(PLAIN_MATRIX_1, map_id);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
UNITY_BEGIN();
|
UNITY_BEGIN();
|
||||||
|
RUN_TEST(test_num_rows_is_max_rows);
|
||||||
|
RUN_TEST(test_num_cols_is_max_cols);
|
||||||
RUN_TEST(test_chars_are_in_map);
|
RUN_TEST(test_chars_are_in_map);
|
||||||
RUN_TEST(plain_map_gives_plain_values);
|
RUN_TEST(keymap0_plain_gives_plain_values);
|
||||||
RUN_TEST(shift_map_gives_shift_values);
|
RUN_TEST(keymap0_shift_gives_shift_values);
|
||||||
RUN_TEST(caps_map_gives_caps_values);
|
RUN_TEST(keymap0_caps_gives_caps_values);
|
||||||
RUN_TEST(ctrl_map_gives_ctrl_values);
|
RUN_TEST(keymap0_ctrl_gives_ctrl_values);
|
||||||
|
RUN_TEST(keymap2_plain_gives_plain_values);
|
||||||
|
RUN_TEST(keymap2_shift_gives_shift_values);
|
||||||
|
RUN_TEST(keymap2_caps_gives_caps_values);
|
||||||
|
RUN_TEST(keymap2_ctrl_gives_ctrl_values);
|
||||||
|
RUN_TEST(keymap1_capsmap_plain_maps_to_caps);
|
||||||
|
RUN_TEST(dip_switch_codes_are_in_last_row_test1_map);
|
||||||
|
RUN_TEST(dip_switch_codes_are_in_last_row_test2_map);
|
||||||
|
RUN_TEST(dip_switch_properly_clears_bits);
|
||||||
|
RUN_TEST(dip_switch_properly_sets_bits);
|
||||||
|
RUN_TEST(dip_switch_invalid_keymap_has_no_effect);
|
||||||
return UNITY_END();
|
return UNITY_END();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user