mouse_report_util.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. #include "mouse_report_util.hpp"
  17. #include <cstdint>
  18. #include <vector>
  19. #include <algorithm>
  20. #include <iomanip>
  21. using namespace testing;
  22. bool operator==(const report_mouse_t& lhs, const report_mouse_t& rhs) {
  23. return lhs.x == rhs.x && lhs.y == rhs.y && lhs.h == rhs.h && lhs.v == rhs.v && lhs.buttons == rhs.buttons;
  24. }
  25. std::ostream& operator<<(std::ostream& os, const report_mouse_t& report) {
  26. os << std::setw(10) << std::left << "mouse report: ";
  27. if (report.x == 0 && report.y == 0 && report.h == 0 && report.v == 0 && report.buttons == 0) {
  28. return os << "empty" << std::endl;
  29. }
  30. os << "(X:" << (int)report.x << ", Y:" << (int)report.y << ", H:" << (int)report.h << ", V:" << (int)report.v << ", B:" << (int)report.buttons << ")";
  31. return os << std::endl;
  32. }
  33. MouseReportMatcher::MouseReportMatcher(int16_t x, int16_t y, int8_t h, int8_t v, uint8_t button_mask) {
  34. memset(&m_report, 0, sizeof(report_mouse_t));
  35. m_report.x = x;
  36. m_report.y = y;
  37. m_report.h = h;
  38. m_report.v = v;
  39. m_report.buttons = button_mask;
  40. }
  41. bool MouseReportMatcher::MatchAndExplain(report_mouse_t& report, MatchResultListener* listener) const {
  42. return m_report == report;
  43. }
  44. void MouseReportMatcher::DescribeTo(::std::ostream* os) const {
  45. *os << "is equal to " << m_report;
  46. }
  47. void MouseReportMatcher::DescribeNegationTo(::std::ostream* os) const {
  48. *os << "is not equal to " << m_report;
  49. }