12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- #include "keyboard_report_util.hpp"
- #include <vector>
- #include <algorithm>
- using namespace testing;
- namespace
- {
- std::vector<uint8_t> get_keys(const report_keyboard_t& report) {
- std::vector<uint8_t> result;
- #if defined(NKRO_ENABLE)
- #error NKRO support not implemented yet
- #elif defined(USB_6KRO_ENABLE)
- #error 6KRO support not implemented yet
- #else
- for(size_t i=0; i<KEYBOARD_REPORT_KEYS; i++) {
- if (report.keys[i]) {
- result.emplace_back(report.keys[i]);
- }
- }
- #endif
- std::sort(result.begin(), result.end());
- return result;
- }
- }
- bool operator==(const report_keyboard_t& lhs, const report_keyboard_t& rhs) {
- auto lhskeys = get_keys(lhs);
- auto rhskeys = get_keys(rhs);
- return lhs.mods == rhs.mods && lhskeys == rhskeys;
- }
- std::ostream& operator<<(std::ostream& stream, const report_keyboard_t& value) {
- stream << "Keyboard report:" << std::endl;
- stream << "Mods: " << (uint32_t)value.mods << std::endl;
- stream << "Keys: ";
-
- for (uint32_t k: get_keys(value)) {
- stream << k << " ";
- }
- stream << std::endl;
- return stream;
- }
- KeyboardReportMatcher::KeyboardReportMatcher(const std::vector<uint8_t>& keys) {
- memset(m_report.raw, 0, sizeof(m_report.raw));
- for (auto k: keys) {
- if (IS_MOD(k)) {
- m_report.mods |= MOD_BIT(k);
- }
- else {
- add_key_to_report(&m_report, k);
- }
- }
- }
- bool KeyboardReportMatcher::MatchAndExplain(report_keyboard_t& report, MatchResultListener* listener) const {
- return m_report == report;
- }
- void KeyboardReportMatcher::DescribeTo(::std::ostream* os) const {
- *os << "is equal to " << m_report;
- }
- void KeyboardReportMatcher::DescribeNegationTo(::std::ostream* os) const {
- *os << "is not equal to " << m_report;
- }
|