Signed-off-by: Eric Paniagua <epaniagua@google.com>
epan/testing/readable
Eric Paniagua 4 years ago
parent 5356514a22
commit 5c8a438cc6

@ -1,2 +0,0 @@
#pragma once
// Fake file to trick arduino-builder into working.

@ -0,0 +1,33 @@
/* -*- mode: c++ -*-
* Copyright (C) 2020 Eric Paniagua (epaniagua@google.com)
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Fake file to trick arduino-builder into working.
#pragma once
#undef min
#undef max
#undef T
#undef U
#include "gtest/gtest.h"
#define SETUP_GOOGLETEST() \
void executeTestFunction() { \
setup(); /* setup Kaleidoscope */ \
testing::InitGoogleTest(); \
RUN_ALL_TESTS(); \
}

@ -0,0 +1,23 @@
/* kailedoscope::sim - Simulator for Unit Testing Kaleidoscope
* Copyright (C) 2020 epan <epaniagua@google.com>
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "kaleidoscope/sim/Sim.h"
namespace kaleidoscope {
namespace sim {
} // namespace sim
} // namespace kaleidoscope

@ -0,0 +1,32 @@
/* kailedoscope::sim - Simulator for Unit Testing Kaleidoscope
* Copyright (C) 2020 epan <epaniagua@google.com>
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef KALEIDOSCOPE_VIRTUAL_BUILD
#pragma once
namespace kaleidoscope {
namespace sim {
class Sim {
public:
};
} // namespace sim
} // namespace kaleidoscope
#endif // KALEIDOSCOPE_VIRTUAL_BUILD

@ -0,0 +1,78 @@
/* -*- mode: c++ -*-
* Copyright (C) 2020 Eric Paniagua (epaniagua@google.com)
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef KALEIDOSCOPE_VIRTUAL_BUILD
#pragma once
#include "./Logging.h"
#include "HID-Settings.h"
namespace kaleidoscope {
namespace testing {
class VirtualDeviceTest : public ::testing::Test {
protected:
void SetUp() {
HIDReportObserver
}
void Press(uint8_t row, uint8_t, col) {
Kaleidoscope.device().keyScanner().setKeystate(
KeyAddr{row, col},
Kaleidoscope::Device::Props::keyScanner::KeyState::Pressed);
}
private:
template <class R>
void ProcessReport(const R& report) {
observer_RecordReport(report);
}
template <class R>
void RecordReport(const R& report);
template <>
void RecordReport<MouseReport>(const MouseReport& report) {
mouse_reports_.push_back(report);
}
template <>
void RecordReport<BootKeyboardReport>(const BootKeyboardReport& report) {
boot_keyboard_reports_.push_back(report);
}
template <>
void RecordReport<AbsoluteMouseReport>(const AbsoluteMouseReport& report) {
absolute_mouse_reports_.push_back(report);
}
template <>
void RecordReport<KeyboardReport>(const KeyboardReport& report) {
keyboard_reports_.push_back(report);
}
std::vector<MouseReport> mouse_reports_;
std::vector<BootKeyboardReport> boot_keyboard_reports_;
std::vector<AbsoluteMouseReport> absolute_mouse_reports_;
std::vector<KeyboardReport> keyboard_reports_;
};
} // namespace testing
} // namespace kaleidoscope
#endif // KALEIDOSCOPE_VIRTUAL_BUILD

@ -0,0 +1,90 @@
/* -*- mode: c++ -*-
* Copyright (C) 2020 Eric Paniagua (epaniagua@google.com)
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef KALEIDOSCOPE_VIRTUAL_BUILD
#pragma once
#include "./Logging.h"
#include "HID-Settings.h"
namespace kaleidoscope {
namespace testing {
class Observer {
public:
void ProcessHidReport(uint8_t id, const void* data, int len, int result) {
switch (id) {
case HID_REPORTID_MOUSE: {
ProcessReport(MouseReport{data});
break;
}
case HID_REPORTID_KEYBOARD: {
ProcessReport(BootKeyboardReport{data});
break;
}
case HID_REPORTID_GAMEPAD:
case HID_REPORTID_CONSUMERCONTROL:
case HID_REPORTID_SYSTEMCONTROL: {
// TODO: React appropriately to these.
LOG(INFO) << "Ignoring HID report with id = " << id;
break;
}
case HID_REPORTID_MOUSE_ABSOLUTE: {
ProcessReport(AbsoluteMouseReport{data});
break;
}
case HID_REPORTID_NKRO_KEYBOARD: {
ProcessReport(KeyboardReport{data});
break;
}
default:
LOG(ERROR) << "Encountered unknown HID report with id = " << id;
}
}
template <class R>
void RecordReport(const R& report);
template <>
void RecordReport<MouseReport>(const MouseReport& report) {
mouse_reports_.push_back(report);
}
template <>
void RecordReport<BootKeyboardReport>(const BootKeyboardReport& report) {
boot_keyboard_reports_.push_back(report);
}
template <>
void RecordReport<AbsoluteMouseReport>(const AbsoluteMouseReport& report) {
absolute_mouse_reports_.push_back(report);
}
template <>
void RecordReport<KeyboardReport>(const KeyboardReport& report) {
keyboard_reports_.push_back(report);
}
std::vector<MouseReport> mouse_reports_;
std::vector<BootKeyboardReport> boot_keyboard_reports_;
std::vector<AbsoluteMouseReport> absolute_mouse_reports_;
std::vector<KeyboardReport> keyboard_reports_;
};
} // namespace testing
} // namespace kaleidoscope

@ -0,0 +1,21 @@
/* -*- mode: c++ -*-
* Copyright (C) 2020 Eric Paniagua (epaniagua@google.com)
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef KALEIDOSCOPE_VIRTUAL_BUILD
#pragma once
#endif // KALEIDOSCOPE_VIRTUAL_BUILD

@ -23,16 +23,11 @@
#undef T #undef T
#undef U #undef U
#include "fake-gtest.h" #include "setup-googletest.h"
#include "gtest/gtest.h"
#include "Kaleidoscope-Simulator.h" #include "Kaleidoscope-Simulator.h"
void executeTestFunction() { SETUP_GOOGLETEST();
setup(); /* setup Kaleidoscope */
testing::InitGoogleTest();
RUN_ALL_TESTS();
}
namespace kaleidoscope { namespace kaleidoscope {
namespace simulator { namespace simulator {

@ -0,0 +1,39 @@
/* -*- mode: c++ -*-
* Copyright (C) 2020 Eric Paniagua (epaniagua@google.com)
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef KALEIDOSCOPE_VIRTUAL_BUILD
#pragma once
#include "setup-googletest.h"
SETUP_GOOGLETEST();
namespace kaleidoscope {
namespace testing {
namespace {
class KeyboardReports : public VirtualDeviceTest {};
TEST_F(KeyboardReports, KeysActiveWhenPressed) {
Press(2, 1); // A
}
} // namespace
} // namespace testing
} // namespace kaleidoscope
#endif // KALEIDOSCOPE_VIRTUAL_BUILD

@ -0,0 +1 @@
#include "./kaleidoscope_test.h"
Loading…
Cancel
Save