at master 58 lines 2.1 kB view raw
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 22using namespace testing; 23 24bool 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 28std::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 39MouseReportMatcher::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 48bool MouseReportMatcher::MatchAndExplain(report_mouse_t& report, MatchResultListener* listener) const { 49 return m_report == report; 50} 51 52void MouseReportMatcher::DescribeTo(::std::ostream* os) const { 53 *os << "is equal to " << m_report; 54} 55 56void MouseReportMatcher::DescribeNegationTo(::std::ostream* os) const { 57 *os << "is not equal to " << m_report; 58}