Remove test dependency on change to KeyboardioHID/src/HIDReportObserver.h.

Signed-off-by: Eric Paniagua <epaniagua@google.com>
epan/testing/readable
Eric Paniagua 4 years ago
parent c21f367c2e
commit def72e6dde

@ -25,22 +25,9 @@
namespace kaleidoscope {
namespace testing {
State::State() {
HIDReportObserver::resetHook(
[this](uint8_t id, const void* data, int len, int result) {
this->ProcessHidReport(id, data, len, result);
});
}
State::~State() {
HIDReportObserver::resetHook(&State::DefaultProcessHidReport);
}
std::vector<KeyboardReport> State::keyboard_reports;
// static
void State::DefaultProcessHidReport(uint8_t, const void*, int, int) {
// TODO: Log that the report was dropped.
}
void State::ProcessHidReport(
uint8_t id, const void* data, int len, int result) {
switch (id) {
@ -72,6 +59,18 @@ void State::ProcessHidReport(
}
}
// static
std::unique_ptr<State> State::Snapshot() {
auto state = std::make_unique<State>();
// Populate state.
// TODO: Grab a copy of current instantaneous state, like:
// key states, layer stack, led states
state->keyboard_reports_ = std::move(keyboard_reports);
Clear(); // Clear global state.
return state;
}
const std::vector<KeyboardReport>& State::KeyboardReports() const {
return keyboard_reports_;
}
@ -80,13 +79,14 @@ const KeyboardReport& State::KeyboardReports(size_t i) const {
return keyboard_reports_.at(i);
}
void State::ProcessKeyboardReport(const KeyboardReport& report) {
keyboard_reports_.push_back(report);
// static
void State::Clear() {
keyboard_reports.clear();
}
void State::Snapshot() {
// TODO: Grab a copy of current instantaneous state, like:
// key states, layer stack, led states
// static
void State::ProcessKeyboardReport(const KeyboardReport& report) {
keyboard_reports.push_back(report);
}
} // namespace testing

@ -21,31 +21,30 @@
#include <vector>
#include "HID-Settings.h"
#include "HIDReportObserver.h"
#include "testing/common/KeyboardReport.h"
// Out of order due to macro conflicts.
#include "testing/common/fix-macros.h"
#include <memory>
namespace kaleidoscope {
namespace testing {
class State {
public:
~State();
static void DefaultProcessHidReport(uint8_t, const void*, int, int);
static void ProcessHidReport(
uint8_t id, const void* data, int len, int result);
void ProcessHidReport(uint8_t id, const void* data, int len, int result);
static std::unique_ptr<State> Snapshot();
const std::vector<KeyboardReport>& KeyboardReports() const;
const KeyboardReport& KeyboardReports(size_t i) const;
private:
friend class VirtualDeviceTest;
State();
void ProcessKeyboardReport(const KeyboardReport& report);
static std::vector<KeyboardReport> keyboard_reports;
void Snapshot();
static void Clear();
static void ProcessKeyboardReport(const KeyboardReport& report);
std::vector<KeyboardReport> keyboard_reports_;
};

@ -14,6 +14,10 @@
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Out of order due to macro conflicts.
#include "HIDReportObserver.h"
#include "testing/common/fix-macros.h"
#include "testing/common/VirtualDeviceTest.h"
#include <memory>
@ -21,11 +25,13 @@
namespace kaleidoscope {
namespace testing {
void VirtualDeviceTest::SetUp() {
HIDReportObserver::resetHook(&State::ProcessHidReport);
}
std::unique_ptr<State> VirtualDeviceTest::RunCycle() {
auto state = std::unique_ptr<State>(new State());
sim_.RunCycle();
state->Snapshot();
return state;
return State::Snapshot();
}
} // namespace testing

@ -21,16 +21,18 @@
#include "testing/common/SimHarness.h"
#include "testing/common/State.h"
// Out of order because `fix-macros.h` clears the preprocessor environment for
// gtest and gmock.
// Out of order due to macro conflicts.
#include "testing/common/fix-macros.h"
#include "gtest/gtest.h"
#include <memory>
namespace kaleidoscope {
namespace testing {
class VirtualDeviceTest : public ::testing::Test {
protected:
void SetUp();
std::unique_ptr<State> RunCycle();
SimHarness sim_;

@ -54,8 +54,9 @@ TEST_F(KeyboardReports, KeysActiveWhenPressed) {
state->KeyboardReports(0).ActiveKeycodes(),
IsEmpty());
state = RunCycle(); // 2 cycles later
state = RunCycle();
// 2 cycles after releasing A
EXPECT_EQ(state->KeyboardReports().size(), 0);
}

Loading…
Cancel
Save