logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

mouse_report_util.cpp (2116B)


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