Add unit tests for printer driver, usb device and usb device factory

This commit is contained in:
2025-10-19 14:27:39 +02:00
parent d8467b8984
commit 56a3722da9
7 changed files with 466 additions and 4 deletions

View File

@@ -90,6 +90,11 @@ libusbwrap::usbId P700Printer::getUsbId() {
}
bool P700Printer::attachUsbDevice(std::shared_ptr<libusbwrap::IUsbDevice> usbHndl) {
if (!usbHndl) {
spdlog::error("Cannot attach null USB device");
return false;
}
if (!usbHndl->open()) {
spdlog::error("Unable to open USB device: {}", usbHndl->getLastErrorString());
return false;
@@ -182,6 +187,11 @@ bool P700Printer::printMonochromeData(const graphics::MonochromeData& data) {
}
bool P700Printer::printLabel(std::unique_ptr<graphics::ILabel> label) {
if (!label) {
spdlog::error("Cannot print null label");
return false;
}
// Convert label directly to MonochromeData
// getRaw() returns data in Cairo surface coordinates matching getWidth() × getHeight()
auto pixels = label->getRaw();
@@ -200,9 +210,15 @@ bool P700Printer::printLabel(std::unique_ptr<graphics::ILabel> label) {
}
bool P700Printer::print() {
send(p700::commands::LF);
send(p700::commands::FF);
send(p700::commands::EJECT);
if (!send(p700::commands::LF)) {
return false;
}
if (!send(p700::commands::FF)) {
return false;
}
if (!send(p700::commands::EJECT)) {
return false;
}
return true;
}