diff options
author | Dasky <[email protected]> | 2024-11-23 16:34:32 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2024-11-23 16:34:32 +0000 |
commit | 1f7d10902a7e603a47b9291664fcb9ab0b21f690 (patch) | |
tree | 55202d0ac9edd5bf977e5b0c95bdcf3b3f859c88 /tests/test_common/mouse_report_util.cpp | |
parent | d189de24a0797ea32d00b652fe798f5315566ab3 (diff) | |
download | qmk_firmware-1f7d10902a7e603a47b9291664fcb9ab0b21f690.tar.gz qmk_firmware-1f7d10902a7e603a47b9291664fcb9ab0b21f690.zip |
Add pointing tests (#24513)
Diffstat (limited to 'tests/test_common/mouse_report_util.cpp')
-rw-r--r-- | tests/test_common/mouse_report_util.cpp | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/test_common/mouse_report_util.cpp b/tests/test_common/mouse_report_util.cpp new file mode 100644 index 0000000000..60cdeced24 --- /dev/null +++ b/tests/test_common/mouse_report_util.cpp @@ -0,0 +1,58 @@ +/* Copyright 2017 Fred Sundvik + * + * 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, either version 2 of the License, or + * (at your option) any later version. + * + * 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 "mouse_report_util.hpp" +#include <cstdint> +#include <vector> +#include <algorithm> + +using namespace testing; + +bool operator==(const report_mouse_t& lhs, const report_mouse_t& rhs) { + return lhs.x == rhs.x && lhs.y == rhs.y && lhs.h == rhs.h && lhs.v == rhs.v && lhs.buttons == rhs.buttons; +} + +std::ostream& operator<<(std::ostream& os, const report_mouse_t& report) { + os << std::setw(10) << std::left << "mouse report: "; + + if (report.x == 0 && report.y == 0 && report.h == 0 && report.v == 0 && report.buttons == 0) { + return os << "empty" << std::endl; + } + + os << "(X:" << (int)report.x << ", Y:" << (int)report.y << ", H:" << (int)report.h << ", V:" << (int)report.v << ", B:" << (int)report.buttons << ")"; + return os << std::endl; +} + +MouseReportMatcher::MouseReportMatcher(int16_t x, int16_t y, int8_t h, int8_t v, uint8_t button_mask) { + memset(&m_report, 0, sizeof(report_mouse_t)); + m_report.x = x; + m_report.y = y; + m_report.h = h; + m_report.v = v; + m_report.buttons = button_mask; +} + +bool MouseReportMatcher::MatchAndExplain(report_mouse_t& report, MatchResultListener* listener) const { + return m_report == report; +} + +void MouseReportMatcher::DescribeTo(::std::ostream* os) const { + *os << "is equal to " << m_report; +} + +void MouseReportMatcher::DescribeNegationTo(::std::ostream* os) const { + *os << "is not equal to " << m_report; +} |