Add KeyAddr versions of Press() & Release() to the simulator

This commit adds versions of `SimHarness::Press()` and `SimHarness::Release()`
functions that use a `KeyAddr` parameter instead of row & column integers.
to build the test.
pull/945/head
Michael Richters 4 years ago committed by Jesse Vincent
parent 7a12be25bc
commit 39f0bbe159
No known key found for this signature in database
GPG Key ID: CC228463465E40BC

@ -14,7 +14,6 @@
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Kaleidoscope.h"
#include "testing/SimHarness.h"
#include "testing/fix-macros.h"
@ -31,17 +30,25 @@ void SimHarness::RunCycles(size_t n) {
for (size_t i = 0; i < n; ++i) RunCycle();
}
void SimHarness::Press(uint8_t row, uint8_t col) {
void SimHarness::Press(KeyAddr key_addr) {
Kaleidoscope.device().keyScanner().setKeystate(
KeyAddr{row, col},
key_addr,
kaleidoscope::Device::Props::KeyScanner::KeyState::Pressed);
}
void SimHarness::Release(uint8_t row, uint8_t col) {
void SimHarness::Release(KeyAddr key_addr) {
Kaleidoscope.device().keyScanner().setKeystate(
KeyAddr{row, col},
key_addr,
kaleidoscope::Device::Props::KeyScanner::KeyState::NotPressed);
}
void SimHarness::Press(uint8_t row, uint8_t col) {
Press(KeyAddr{row, col});
}
void SimHarness::Release(uint8_t row, uint8_t col) {
Release(KeyAddr{row, col});
}
} // namespace testing
} // namespace kaleidoscope

@ -19,6 +19,9 @@
#include <cstddef>
#include <cstdint>
#include "Kaleidoscope.h"
#include "testing/fix-macros.h"
namespace kaleidoscope {
namespace testing {
@ -27,6 +30,8 @@ class SimHarness {
void RunCycle();
void RunCycles(size_t n);
void Press(KeyAddr key_addr);
void Release(KeyAddr key_addr);
void Press(uint8_t row, uint8_t col);
void Release(uint8_t row, uint8_t col);
};

@ -15,6 +15,7 @@
*/
#include "testing/setup-googletest.h"
#include "Kaleidoscope.h"
SETUP_GOOGLETEST();
@ -22,12 +23,14 @@ namespace kaleidoscope {
namespace testing {
namespace {
constexpr KeyAddr key_addr_A{2, 1};
using ::testing::IsEmpty;
class KeyboardReports : public VirtualDeviceTest {};
TEST_F(KeyboardReports, KeysActiveWhenPressed) {
sim_.Press(2, 1); // A
sim_.Press(key_addr_A); // A
auto state = RunCycle();
ASSERT_EQ(state->HIDReports()->Keyboard().size(), 1);
@ -35,7 +38,7 @@ TEST_F(KeyboardReports, KeysActiveWhenPressed) {
state->HIDReports()->Keyboard(0).ActiveKeycodes(),
Contains(Key_A));
sim_.Release(2, 1); // A
sim_.Release(key_addr_A); // A
state = RunCycle();
ASSERT_EQ(state->HIDReports()->Keyboard().size(), 1);

Loading…
Cancel
Save