All checks were successful
Build ptprnt / build (push) Successful in 2m59s
Reviewed-on: #21
77 lines
3.0 KiB
C++
77 lines
3.0 KiB
C++
/*
|
|
ptrnt - print labels on linux
|
|
Copyright (C) 2025 Moritz Martinius
|
|
|
|
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 3 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 <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <gmock/gmock.h>
|
|
|
|
#include "libusbwrap/LibUsbWrapper.hpp"
|
|
|
|
namespace libusbwrap {
|
|
|
|
/**
|
|
* @brief GMock implementation of ILibUsbWrapper for unit testing
|
|
*
|
|
* This mock allows tests to verify that UsbDevice and UsbDeviceFactory
|
|
* correctly interact with the libusb API without requiring actual USB hardware.
|
|
*/
|
|
class MockLibUsbWrapper : public ILibUsbWrapper {
|
|
public:
|
|
// Context management
|
|
MOCK_METHOD(int, init, (libusb_context * *ctx), (override));
|
|
MOCK_METHOD(void, exit, (libusb_context * ctx), (override));
|
|
|
|
// Device enumeration
|
|
MOCK_METHOD(ssize_t, getDeviceList, (libusb_context * ctx, libusb_device*** list), (override));
|
|
MOCK_METHOD(void, freeDeviceList, (libusb_device * *list, int unrefDevices), (override));
|
|
MOCK_METHOD(void, refDevice, (libusb_device * dev), (override));
|
|
MOCK_METHOD(void, unrefDevice, (libusb_device * dev), (override));
|
|
|
|
// Device descriptor
|
|
MOCK_METHOD(int, getDeviceDescriptor, (libusb_device * dev, libusb_device_descriptor* desc), (override));
|
|
|
|
// Device opening/closing
|
|
MOCK_METHOD(int, open, (libusb_device * dev, libusb_device_handle** handle), (override));
|
|
MOCK_METHOD(void, close, (libusb_device_handle * handle), (override));
|
|
|
|
// Device information
|
|
MOCK_METHOD(int, getSpeed, (libusb_device * dev), (override));
|
|
MOCK_METHOD(uint8_t, getBusNumber, (libusb_device * dev), (override));
|
|
MOCK_METHOD(uint8_t, getPortNumber, (libusb_device * dev), (override));
|
|
|
|
// Kernel driver management
|
|
MOCK_METHOD(int, kernelDriverActive, (libusb_device_handle * handle, int interfaceNo), (override));
|
|
MOCK_METHOD(int, detachKernelDriver, (libusb_device_handle * handle, int interfaceNo), (override));
|
|
|
|
// Interface management
|
|
MOCK_METHOD(int, claimInterface, (libusb_device_handle * handle, int interfaceNo), (override));
|
|
MOCK_METHOD(int, releaseInterface, (libusb_device_handle * handle, int interfaceNo), (override));
|
|
|
|
// Data transfer
|
|
MOCK_METHOD(int, bulkTransfer,
|
|
(libusb_device_handle * handle, uint8_t endpoint, unsigned char* data, int length, int* transferred,
|
|
unsigned int timeout),
|
|
(override));
|
|
|
|
// Error handling
|
|
MOCK_METHOD(const char*, errorName, (int errorCode), (override));
|
|
};
|
|
|
|
} // namespace libusbwrap
|