Skip to content

Commit

Permalink
feat: add expected error testing
Browse files Browse the repository at this point in the history
  • Loading branch information
headblockhead committed Aug 18, 2024
1 parent b36f6ff commit 5c3a9d4
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 6 deletions.
58 changes: 52 additions & 6 deletions tests/keyboard_modifier_press_release.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ int main() {
// no modifiers adding no modifiers is no modifiers
uint8_t current_modifier = 0b00000000;
modifiers = 0;
keyboard_modifier_press(&test_key, 0, 0, 1, current_modifier);
enum squirrel_error err =
keyboard_modifier_press(&test_key, 0, 0, 1, current_modifier);
if (err != ERR_NONE) {
return 255;
}
if (modifiers != 0b00000000) {
return 1;
}
Expand All @@ -20,7 +24,11 @@ int main() {
current_modifier = 0b00000001;
for (uint8_t i = 0; i < 8; i++) {
modifiers = 0;
keyboard_modifier_press(&test_key, 0, 0, 1, current_modifier);
enum squirrel_error err =
keyboard_modifier_press(&test_key, 0, 0, 1, current_modifier);
if (err != ERR_NONE) {
return 255;
}
if (modifiers != current_modifier) {
return 2;
}
Expand All @@ -32,19 +40,37 @@ int main() {
for (uint8_t i = 0; i < 8; i++) {
// modifiers stack, ORd to become the same number
uint8_t old_modifiers = modifiers;
keyboard_modifier_press(&test_key, 0, 0, 1, current_modifier);
enum squirrel_error err =
keyboard_modifier_press(&test_key, 0, 0, 1, current_modifier);
if (err != ERR_NONE) {
return 255;
}
if (modifiers != (old_modifiers | current_modifier)) {
return 3;
}
current_modifier = current_modifier << 1;
}

// checking expected errors:
// incorrect arguments error.
err = keyboard_modifier_press(&test_key, 0, 0, 2, 0, 0); // too many arguments
if (err != ERR_KEY_FUNC_WRONG_ARGUMENT_COUNT) {
return 254;
}
err = keyboard_modifier_press(&test_key, 0, 0, 0); // too few arguments
if (err != ERR_KEY_FUNC_WRONG_ARGUMENT_COUNT) {
return 254;
}

// keyboard_modifier_release

// no modifiers removing no modifiers is no modifiers
current_modifier = 0b00000000;
modifiers = 0;
keyboard_modifier_release(&test_key, 0, 0, 1, current_modifier);
err = keyboard_modifier_release(&test_key, 0, 0, 1, current_modifier);
if (err != ERR_NONE) {
return 255;
}
if (modifiers != 0b00000000) {
return 4;
}
Expand All @@ -53,7 +79,11 @@ int main() {
current_modifier = 0b00000001;
for (uint8_t i = 0; i < 8; i++) {
modifiers = current_modifier;
keyboard_modifier_release(&test_key, 0, 0, 1, current_modifier);
enum squirrel_error err =
keyboard_modifier_release(&test_key, 0, 0, 1, current_modifier);
if (err != ERR_NONE) {
return 255;
}
if (modifiers != 0b000000000) {
return 5;
}
Expand All @@ -66,12 +96,28 @@ int main() {
for (uint8_t i = 0; i < 8; i++) {
// modifiers stack, ORd to become the same number
uint8_t old_modifiers = modifiers;
keyboard_modifier_release(&test_key, 0, 0, 1, current_modifier);
enum squirrel_error err =
keyboard_modifier_release(&test_key, 0, 0, 1, current_modifier);
if (err != ERR_NONE) {
return 255;
}
if (modifiers != (old_modifiers & ~current_modifier)) {
return 6;
}
current_modifier = current_modifier << 1;
}

// checking expected errors:
// incorrect arguments error.
err =
keyboard_modifier_release(&test_key, 0, 0, 2, 0, 0); // too many arguments
if (err != ERR_KEY_FUNC_WRONG_ARGUMENT_COUNT) {
return 254;
}
err = keyboard_modifier_release(&test_key, 0, 0, 0); // too few arguments
if (err != ERR_KEY_FUNC_WRONG_ARGUMENT_COUNT) {
return 254;
}

return 0;
};
1 change: 1 addition & 0 deletions tests/quantum_passthrough_press_release.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
// squirrel_quantum.c
int main() {
// quantum_passthrough_press

return 1; // placeholder
};

0 comments on commit 5c3a9d4

Please sign in to comment.