diff options
| author | Dasky <32983009+daskygit@users.noreply.github.com> | 2024-11-23 16:34:32 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-11-23 16:34:32 +0000 |
| commit | 1f7d10902a7e603a47b9291664fcb9ab0b21f690 (patch) | |
| tree | 55202d0ac9edd5bf977e5b0c95bdcf3b3f859c88 /tests/test_common/mouse_report_util.cpp | |
| parent | d189de24a0797ea32d00b652fe798f5315566ab3 (diff) | |
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 @@ | |||
| 1 | /* Copyright 2017 Fred Sundvik | ||
| 2 | * | ||
| 3 | * This program is free software: you can redistribute it and/or modify | ||
| 4 | * it under the terms of the GNU General Public License as published by | ||
| 5 | * the Free Software Foundation, either version 2 of the License, or | ||
| 6 | * (at your option) any later version. | ||
| 7 | * | ||
| 8 | * This program is distributed in the hope that it will be useful, | ||
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 11 | * GNU General Public License for more details. | ||
| 12 | * | ||
| 13 | * You should have received a copy of the GNU General Public License | ||
| 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 15 | */ | ||
| 16 | |||
| 17 | #include "mouse_report_util.hpp" | ||
| 18 | #include <cstdint> | ||
| 19 | #include <vector> | ||
| 20 | #include <algorithm> | ||
| 21 | |||
| 22 | using namespace testing; | ||
| 23 | |||
| 24 | bool operator==(const report_mouse_t& lhs, const report_mouse_t& rhs) { | ||
| 25 | return lhs.x == rhs.x && lhs.y == rhs.y && lhs.h == rhs.h && lhs.v == rhs.v && lhs.buttons == rhs.buttons; | ||
| 26 | } | ||
| 27 | |||
| 28 | std::ostream& operator<<(std::ostream& os, const report_mouse_t& report) { | ||
| 29 | os << std::setw(10) << std::left << "mouse report: "; | ||
| 30 | |||
| 31 | if (report.x == 0 && report.y == 0 && report.h == 0 && report.v == 0 && report.buttons == 0) { | ||
| 32 | return os << "empty" << std::endl; | ||
| 33 | } | ||
| 34 | |||
| 35 | os << "(X:" << (int)report.x << ", Y:" << (int)report.y << ", H:" << (int)report.h << ", V:" << (int)report.v << ", B:" << (int)report.buttons << ")"; | ||
| 36 | return os << std::endl; | ||
| 37 | } | ||
| 38 | |||
| 39 | MouseReportMatcher::MouseReportMatcher(int16_t x, int16_t y, int8_t h, int8_t v, uint8_t button_mask) { | ||
| 40 | memset(&m_report, 0, sizeof(report_mouse_t)); | ||
| 41 | m_report.x = x; | ||
| 42 | m_report.y = y; | ||
| 43 | m_report.h = h; | ||
| 44 | m_report.v = v; | ||
| 45 | m_report.buttons = button_mask; | ||
| 46 | } | ||
| 47 | |||
| 48 | bool MouseReportMatcher::MatchAndExplain(report_mouse_t& report, MatchResultListener* listener) const { | ||
| 49 | return m_report == report; | ||
| 50 | } | ||
| 51 | |||
| 52 | void MouseReportMatcher::DescribeTo(::std::ostream* os) const { | ||
| 53 | *os << "is equal to " << m_report; | ||
| 54 | } | ||
| 55 | |||
| 56 | void MouseReportMatcher::DescribeNegationTo(::std::ostream* os) const { | ||
| 57 | *os << "is not equal to " << m_report; | ||
| 58 | } | ||
