forked from mirrors/qmk_userspace
[Test] Reset timer for every unit test and provide timestamps for log messages (#17028)
This commit is contained in:
parent
e2ab98f960
commit
962e4c0e18
20 changed files with 1011 additions and 41 deletions
|
@ -15,11 +15,16 @@
|
|||
*/
|
||||
|
||||
#include "keyboard_report_util.hpp"
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace testing;
|
||||
|
||||
extern std::map<uint16_t, std::string> KEYCODE_ID_TABLE;
|
||||
|
||||
namespace {
|
||||
|
||||
std::vector<uint8_t> get_keys(const report_keyboard_t& report) {
|
||||
std::vector<uint8_t> result;
|
||||
#if defined(NKRO_ENABLE)
|
||||
|
@ -36,6 +41,19 @@ std::vector<uint8_t> get_keys(const report_keyboard_t& report) {
|
|||
std::sort(result.begin(), result.end());
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> get_mods(const report_keyboard_t& report) {
|
||||
std::vector<uint8_t> result;
|
||||
for (size_t i = 0; i < 8; i++) {
|
||||
if (report.mods & (1 << i)) {
|
||||
uint8_t code = KC_LEFT_CTRL + i;
|
||||
result.emplace_back(code);
|
||||
}
|
||||
}
|
||||
std::sort(result.begin(), result.end());
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
bool operator==(const report_keyboard_t& lhs, const report_keyboard_t& rhs) {
|
||||
|
@ -44,21 +62,36 @@ bool operator==(const report_keyboard_t& lhs, const report_keyboard_t& rhs) {
|
|||
return lhs.mods == rhs.mods && lhskeys == rhskeys;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& stream, const report_keyboard_t& report) {
|
||||
std::ostream& operator<<(std::ostream& os, const report_keyboard_t& report) {
|
||||
auto keys = get_keys(report);
|
||||
auto mods = get_mods(report);
|
||||
|
||||
// TODO: This should probably print friendly names for the keys
|
||||
stream << "Keyboard Report: Mods (" << (uint32_t)report.mods << ") Keys (";
|
||||
os << std::setw(10) << std::left << "report: ";
|
||||
|
||||
if (!keys.size() && !mods.size()) {
|
||||
return os << "empty" << std::endl;
|
||||
}
|
||||
|
||||
os << "(";
|
||||
for (auto key = keys.cbegin(); key != keys.cend();) {
|
||||
stream << +(*key);
|
||||
os << KEYCODE_ID_TABLE.at(*key);
|
||||
key++;
|
||||
if (key != keys.cend()) {
|
||||
stream << ",";
|
||||
os << ", ";
|
||||
}
|
||||
}
|
||||
|
||||
return stream << ")" << std::endl;
|
||||
os << ") [";
|
||||
|
||||
for (auto mod = mods.cbegin(); mod != mods.cend();) {
|
||||
os << KEYCODE_ID_TABLE.at(*mod);
|
||||
mod++;
|
||||
if (mod != mods.cend()) {
|
||||
os << ", ";
|
||||
}
|
||||
}
|
||||
|
||||
return os << "]" << std::endl;
|
||||
}
|
||||
|
||||
KeyboardReportMatcher::KeyboardReportMatcher(const std::vector<uint8_t>& keys) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue