Compare commits
1 Commits
fix-logger
...
fd5713c742
Author | SHA1 | Date | |
---|---|---|---|
fd5713c742
|
@@ -5,23 +5,16 @@ jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Starting action...
|
||||
run: echo "Branch ${{ gitea.ref }} will be built for project ${{ gitea.repository }}."
|
||||
- run: echo "Branch ${{ gitea.ref }} will be built for project ${{ gitea.repository }}."
|
||||
- name: Checkout branch
|
||||
uses: actions/checkout@v3
|
||||
- name: Update package cache
|
||||
run: apt-get update
|
||||
- name: install meson
|
||||
run: apt-get -yq install meson
|
||||
run: apt-get install meson
|
||||
- name: Install build dependencies
|
||||
run: apt-get -yq install libusb-1.0-0-dev libspdlog-dev libpango1.0-dev libcairo2-dev gcovr
|
||||
run: apt-get install libusb-dev libspdlog-dev libpango1.0-dev libcairo2-dev gcovr
|
||||
- name: setup builddir
|
||||
run: meson setup builddir -Db_coverage=true
|
||||
- name: build all targets
|
||||
run: ninja -C builddir
|
||||
- name: run unit tests
|
||||
run: ninja -C builddir test
|
||||
- name: calculate coverage
|
||||
run: ninja -C builddir coverage-text
|
||||
- name: Coverage report
|
||||
run: cat ./builddir/meson-logs/coverage.txt
|
||||
|
8
.gitignore
vendored
8
.gitignore
vendored
@@ -1,13 +1,9 @@
|
||||
# Folder
|
||||
builddir/
|
||||
ptouch-print/
|
||||
subprojects/*
|
||||
.cache/
|
||||
coverageReport/
|
||||
|
||||
# Files
|
||||
!subprojects/*.wrap
|
||||
.cache/
|
||||
.vscode/*
|
||||
!.vscode/c_cpp_properties.json
|
||||
!.vscode/settings.json
|
||||
!.vscode/launch.json
|
||||
ptouch-print/
|
2
.vscode/launch.json
vendored
2
.vscode/launch.json
vendored
@@ -9,7 +9,7 @@
|
||||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"program": "${workspaceFolder}/builddir/ptprnt",
|
||||
"args": ["-t Hello"],
|
||||
"args": [],
|
||||
"stopAtEntry": false,
|
||||
"cwd": "${fileDirname}",
|
||||
"environment": [],
|
||||
|
10
README.md
10
README.md
@@ -12,16 +12,6 @@ This project requires:
|
||||
- gtest (optional, for testing, will be installed by meson)
|
||||
- gcov (optional, for coverage reports)
|
||||
|
||||
Install dependencies on Arch Linux
|
||||
``` bash
|
||||
pacman -S libusb spdlog pango cairo meson gcovr
|
||||
```
|
||||
|
||||
Install dependencies on Debian/Ubuntu
|
||||
``` bash
|
||||
apt-get install libusb-1.0-0-dev libspdlog-dev libpango1.0-dev libcairo2-dev meson gcovr
|
||||
```
|
||||
|
||||
## Build
|
||||
|
||||
Clone the repository and simply let meson do the heavy lifting.
|
||||
|
@@ -1,21 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
SCRIPT_PATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
|
||||
HTML_COV_PATH="coverageReport/html"
|
||||
HTML_START_FILE="index.html"
|
||||
|
||||
echo "Generating Coverage report for ptouch-prnt"
|
||||
|
||||
ninja -C builddir
|
||||
ninja -C builddir test
|
||||
|
||||
mkdir -p ${HTML_COV_PATH}
|
||||
gcovr --html --html-details --html-syntax-highlighting --filter src --output ${HTML_COV_PATH}/${HTML_START_FILE}
|
||||
|
||||
if [ $? ]
|
||||
then
|
||||
echo "Coverage report successful generated!"
|
||||
echo "Open: file://${SCRIPT_PATH}/${HTML_COV_PATH}/${HTML_START_FILE}"
|
||||
else
|
||||
echo "Error generating coverage report!"
|
||||
fi
|
48
meson.build
48
meson.build
@@ -8,31 +8,53 @@ usb_dep = dependency('libusb-1.0')
|
||||
log_dep = dependency('spdlog')
|
||||
pangocairo_dep = dependency('pangocairo')
|
||||
|
||||
# CLI11
|
||||
cli11_proj = subproject('cli11')
|
||||
cli11_dep = cli11_proj.get_variable('CLI11_dep')
|
||||
if not cli11_dep.found()
|
||||
error('CLI11 not found, can not proceed')
|
||||
endif
|
||||
|
||||
incdir = include_directories('src')
|
||||
|
||||
subdir('src')
|
||||
ptprnt_hpps = [
|
||||
'src/libusbwrap/interface/IUsbDeviceFactory.hpp',
|
||||
'src/libusbwrap/interface/IUsbDevice.hpp',
|
||||
'src/libusbwrap/UsbDeviceFactory.hpp',
|
||||
'src/libusbwrap/LibUsbTypes.hpp',
|
||||
'src/libusbwrap/UsbDevice.hpp',
|
||||
'src/interface/IPrinterDriver.hpp',
|
||||
'src/interface/IPrinterTypes.hpp',
|
||||
'src/P700Printer.hpp',
|
||||
'src/PtouchPrint.hpp',
|
||||
'src/graphics/Bitmap.hpp',
|
||||
'src/graphics/Image.hpp',
|
||||
'src/graphics/Monochrome.hpp'
|
||||
]
|
||||
|
||||
ptprnt_srcs = [
|
||||
'src/PtouchPrint.cpp',
|
||||
'src/P700Printer.cpp',
|
||||
'src/graphics/Image.cpp',
|
||||
'src/graphics/Bitmap.cpp',
|
||||
'src/graphics/Monochrome.cpp',
|
||||
'src/libusbwrap/UsbDeviceFactory.cpp',
|
||||
'src/libusbwrap/UsbDevice.cpp',
|
||||
]
|
||||
|
||||
ptprnt_lib = library('ptprnt',
|
||||
include_directories: incdir,
|
||||
install: true,
|
||||
dependencies: [usb_dep, log_dep, pangocairo_dep],
|
||||
sources: [ptprnt_hpps, ptprnt_srcs])
|
||||
|
||||
ptprnt_dep = declare_dependency(include_directories: incdir,
|
||||
link_with: ptprnt_lib)
|
||||
|
||||
ptprnt_exe = executable(
|
||||
'ptprnt',
|
||||
'src/main.cpp',
|
||||
install: true,
|
||||
dependencies : [usb_dep, log_dep, pangocairo_dep, cli11_dep],
|
||||
include_directories: incdir,
|
||||
sources: [ptprnt_srcs],
|
||||
dependencies : [usb_dep, log_dep, ptprnt_dep],
|
||||
cpp_args : ['-DPROJ_VERSION="'+meson.project_version()+'"'],
|
||||
)
|
||||
|
||||
|
||||
### Unit tests
|
||||
|
||||
# GTest
|
||||
#cmake = import('cmake')
|
||||
gtest_proj = subproject('gtest')
|
||||
gtest_dep = gtest_proj.get_variable('gtest_main_dep')
|
||||
if not gtest_dep.found()
|
||||
|
@@ -72,10 +72,13 @@ const PrinterStatus P700Printer::getPrinterStatus() {
|
||||
int tx = 0;
|
||||
int tries = 0;
|
||||
std::vector<uint8_t> recvBuf(32);
|
||||
while (tries++ < MAX_TRIES_GET_STATUS) {
|
||||
do {
|
||||
std::this_thread::sleep_for(100ms);
|
||||
mUsbHndl->bulkTransfer(commands["printerinfo"][0], recvBuf, &tx, 0);
|
||||
mUsbHndl->bulkTransfer(0x81, recvBuf, &tx, 0);
|
||||
if (tries++ > 10) {
|
||||
break;
|
||||
}
|
||||
} while (tx == 0);
|
||||
|
||||
return PrinterStatus{.tapeWidthMm = recvBuf[10]};
|
||||
}
|
||||
|
@@ -31,8 +31,6 @@
|
||||
|
||||
namespace ptprnt::printer {
|
||||
|
||||
constexpr uint8_t MAX_TRIES_GET_STATUS = 10;
|
||||
|
||||
class P700Printer : public ::ptprnt::IPrinterDriver {
|
||||
public:
|
||||
P700Printer() = default;
|
||||
@@ -63,7 +61,7 @@ class P700Printer : public ::ptprnt::IPrinterDriver {
|
||||
|
||||
std::shared_ptr<libusbwrap::IUsbDevice> mUsbHndl{nullptr};
|
||||
|
||||
static constexpr PrinterInfo mInfo{.driverName = "P700",
|
||||
PrinterInfo mInfo{.driverName = "P700",
|
||||
.name = "Brother P-touch P700",
|
||||
.version = "v1.0",
|
||||
.vid = 0x04f9,
|
||||
@@ -77,7 +75,7 @@ class P700Printer : public ::ptprnt::IPrinterDriver {
|
||||
{"lf", {0x5a}},
|
||||
{"ff", {0x0c}},
|
||||
{"eject", {0x1a}},
|
||||
{"printerinfo", {0x81}}};
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace ptprnt::printer
|
@@ -19,54 +19,30 @@
|
||||
|
||||
#include "PtouchPrint.hpp"
|
||||
|
||||
#include <CLI/App.hpp>
|
||||
#include <spdlog/common.h>
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include "CLI/Option.hpp"
|
||||
#include "P700Printer.hpp"
|
||||
#include "graphics/Bitmap.hpp"
|
||||
#include "libusbwrap/UsbDeviceFactory.hpp"
|
||||
|
||||
namespace ptprnt {
|
||||
PtouchPrint::PtouchPrint() {}
|
||||
|
||||
PtouchPrint::PtouchPrint(const char* versionString) : mVersionString{versionString} {}
|
||||
PtouchPrint::~PtouchPrint() {}
|
||||
|
||||
int PtouchPrint::init(int argc, char** argv) {
|
||||
setupCliParser();
|
||||
|
||||
try {
|
||||
mApp.parse(argc, argv);
|
||||
} catch (const CLI::ParseError& e) {
|
||||
mApp.exit(e);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (mVerboseFlag) {
|
||||
setupLogger(spdlog::level::trace);
|
||||
} else {
|
||||
setupLogger(spdlog::level::critical);
|
||||
}
|
||||
|
||||
if (!mUsbDeviceFactory.init()) {
|
||||
spdlog::error("Could not initialize libusb");
|
||||
return -1;
|
||||
}
|
||||
void PtouchPrint::init() {
|
||||
mUsbDeviceFactory.init();
|
||||
mCompatiblePrinters = {std::make_shared<ptprnt::printer::P700Printer>()};
|
||||
return 0;
|
||||
}
|
||||
|
||||
int PtouchPrint::run() {
|
||||
void PtouchPrint::run() {
|
||||
auto numFoundPrinters = getCompatiblePrinters();
|
||||
if (numFoundPrinters == 0) {
|
||||
spdlog::error(
|
||||
"No compatible printers found, please make sure if they are turned on and connected");
|
||||
return -1;
|
||||
return;
|
||||
} else if (numFoundPrinters > 1) {
|
||||
spdlog::warn("Found more than one compatible printer. Currently not supported.");
|
||||
return -1;
|
||||
return;
|
||||
}
|
||||
|
||||
auto printer = mCompatiblePrinters[0];
|
||||
@@ -74,20 +50,14 @@ int PtouchPrint::run() {
|
||||
if (devices.size() != 1) {
|
||||
spdlog::warn(
|
||||
"Found more than one device of the same printer on bus. Currently not supported");
|
||||
return -1;
|
||||
return;
|
||||
}
|
||||
printer->attachUsbDevice(devices[0]);
|
||||
auto status = printer->getPrinterStatus();
|
||||
spdlog::info("Detected tape width is {}mm", status.tapeWidthMm);
|
||||
auto bm = ptprnt::graphics::Bitmap<ptprnt::graphics::ALPHA8>(512, 128);
|
||||
//printer->printBitmap(bm);
|
||||
printer->printBitmap(bm);
|
||||
//printer->printText("wurst", 1);
|
||||
|
||||
for (auto& cmd : mCommands) {
|
||||
std::cout << cmd.second << std::endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned int PtouchPrint::getCompatiblePrinters() {
|
||||
@@ -111,52 +81,3 @@ unsigned int PtouchPrint::getCompatiblePrinters() {
|
||||
mCompatiblePrinters.clear();
|
||||
return mDetectedPrinters.size();
|
||||
}
|
||||
|
||||
void PtouchPrint::setupLogger(spdlog::level::level_enum lvl) {
|
||||
spdlog::set_level(lvl);
|
||||
spdlog::debug("Starting ptprnt {}", mVersionString);
|
||||
}
|
||||
|
||||
void PtouchPrint::setupCliParser() {
|
||||
auto printVersion = [this](std::size_t) {
|
||||
std::cout << "ptprnt version: " << mVersionString << std::endl;
|
||||
};
|
||||
|
||||
// General options
|
||||
mApp.add_flag("-v,--verbose", mVerboseFlag, "Enable verbose output");
|
||||
mApp.add_flag("-V,--version", printVersion, "Prints the ptprnt's version");
|
||||
|
||||
// Text printing options
|
||||
mApp.add_option("-t,--text",
|
||||
"Text to print (can be used multple times, use formatting options before to "
|
||||
"influence text layout)")
|
||||
->group("Printing")
|
||||
->multi_option_policy(CLI::MultiOptionPolicy::TakeAll)
|
||||
->trigger_on_parse()
|
||||
->each([this](std::string text) { mCommands.emplace_back(CliCmdType::Text, text); });
|
||||
mApp.add_option("-f,--font", "Font used for the following text occurences")
|
||||
->group("Text printing ")
|
||||
->multi_option_policy(CLI::MultiOptionPolicy::TakeAll)
|
||||
->trigger_on_parse()
|
||||
->each([this](std::string font) { mCommands.emplace_back(CliCmdType::Font, font); });
|
||||
mApp.add_option("-s,--fontsize", "Font size of the following text occurences")
|
||||
->group("Text printing ")
|
||||
->multi_option_policy(CLI::MultiOptionPolicy::TakeAll)
|
||||
->trigger_on_parse()
|
||||
->each([this](std::string size) { mCommands.emplace_back(CliCmdType::FontSize, size); });
|
||||
mApp.add_option("--valign", "Vertical alignment of the following text occurences")
|
||||
->group("Text printing ")
|
||||
->multi_option_policy(CLI::MultiOptionPolicy::TakeAll)
|
||||
->trigger_on_parse()
|
||||
->each([this](std::string valign) { mCommands.emplace_back(CliCmdType::VAlign, valign); });
|
||||
mApp.add_option("--halign", "Vertical alignment of the following text occurences")
|
||||
->group("Text printing ")
|
||||
->multi_option_policy(CLI::MultiOptionPolicy::TakeAll)
|
||||
->trigger_on_parse()
|
||||
->each([this](std::string halign) { mCommands.emplace_back(CliCmdType::HAlign, halign); });
|
||||
|
||||
// Image options
|
||||
mApp.add_option("-i,--image", "Image to print. Excludes all text printing ")
|
||||
->group("Image printing");
|
||||
}
|
||||
} // namespace ptprnt
|
@@ -19,47 +19,23 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <CLI/CLI.hpp>
|
||||
#include <spdlog/common.h>
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#include "constants.hpp"
|
||||
#include "interface/IPrinterDriver.hpp"
|
||||
#include "libusbwrap/UsbDeviceFactory.hpp"
|
||||
|
||||
namespace ptprnt {
|
||||
enum class CliCmdType { None = 0, Text = 1, FontSize = 2, Font = 3, VAlign = 4, HAlign = 5 };
|
||||
using CliCmd = std::pair<CliCmdType, std::string>;
|
||||
|
||||
class PtouchPrint {
|
||||
public:
|
||||
PtouchPrint(const char* versionString);
|
||||
~PtouchPrint() = default;
|
||||
PtouchPrint();
|
||||
~PtouchPrint();
|
||||
|
||||
// This is basically a singelton application class, no need to copy or move
|
||||
PtouchPrint(const PtouchPrint&) = delete;
|
||||
PtouchPrint& operator=(const PtouchPrint&) = delete;
|
||||
PtouchPrint(PtouchPrint&&) = delete;
|
||||
PtouchPrint& operator=(PtouchPrint&&) = delete;
|
||||
|
||||
int init(int argc, char** argv);
|
||||
int run();
|
||||
void init();
|
||||
void run();
|
||||
|
||||
private:
|
||||
// methods
|
||||
void setupLogger(spdlog::level::level_enum lvl);
|
||||
void setupCliParser();
|
||||
unsigned int getCompatiblePrinters();
|
||||
|
||||
// member variables
|
||||
CLI::App mApp{ptprnt::APP_DESC};
|
||||
libusbwrap::UsbDeviceFactory mUsbDeviceFactory{};
|
||||
std::vector<std::shared_ptr<ptprnt::IPrinterDriver>> mCompatiblePrinters{};
|
||||
std::vector<std::shared_ptr<ptprnt::IPrinterDriver>> mDetectedPrinters{};
|
||||
std::vector<CliCmd> mCommands{};
|
||||
std::string mVersionString = "";
|
||||
|
||||
// CLI flags
|
||||
bool mVerboseFlag = false;
|
||||
libusbwrap::UsbDeviceFactory mUsbDeviceFactory;
|
||||
std::vector<std::shared_ptr<ptprnt::IPrinterDriver>> mCompatiblePrinters;
|
||||
std::vector<std::shared_ptr<ptprnt::IPrinterDriver>> mDetectedPrinters;
|
||||
};
|
||||
} // namespace ptprnt
|
@@ -1,26 +0,0 @@
|
||||
/*
|
||||
ptrnt - print labels on linux
|
||||
Copyright (C) 2023 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
|
||||
|
||||
namespace ptprnt {
|
||||
constexpr const char* const APP_NAME = "ptprnt";
|
||||
constexpr const char* const APP_DESC =
|
||||
"ptprnt - a userspace driver for Brother P-touch label printer";
|
||||
} // namespace ptprnt
|
@@ -52,11 +52,6 @@ bool Bitmap<T>::setPixels(const std::vector<T>& pixels) {
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
std::vector<T> Bitmap<T>::getPixelsCpy() {
|
||||
return mPixels;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
std::optional<std::vector<T>> Bitmap<T>::getLine(uint16_t line) {
|
||||
if (line >= mHeight) {
|
||||
|
@@ -22,7 +22,6 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
@@ -42,7 +41,6 @@ class Bitmap {
|
||||
uint16_t getWidth();
|
||||
uint16_t getHeight();
|
||||
bool setPixels(const std::vector<T>& pixels);
|
||||
std::vector<T> getPixelsCpy();
|
||||
std::optional<std::vector<T>> getLine(uint16_t line);
|
||||
std::optional<std::vector<T>> getCol(uint16_t col);
|
||||
|
||||
|
@@ -29,12 +29,11 @@
|
||||
#include "libusbwrap/interface/IUsbDevice.hpp"
|
||||
|
||||
namespace libusbwrap {
|
||||
UsbDeviceFactory::UsbDeviceFactory() {}
|
||||
|
||||
UsbDeviceFactory::~UsbDeviceFactory() {
|
||||
if (mDeviceListInitialized) {
|
||||
libusb_free_device_list(mLibusbDeviceList, 1);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<IUsbDevice>> UsbDeviceFactory::findAllDevices() {
|
||||
refreshDeviceList();
|
||||
@@ -53,7 +52,7 @@ int UsbDeviceFactory::refreshDeviceList() {
|
||||
} else if (ret == 0) {
|
||||
spdlog::warn("No USB devices found");
|
||||
}
|
||||
mDeviceListInitialized = true;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@@ -24,14 +24,12 @@
|
||||
namespace libusbwrap {
|
||||
class UsbDeviceFactory : public IUsbDeviceFactory {
|
||||
public:
|
||||
UsbDeviceFactory() = default;
|
||||
virtual ~UsbDeviceFactory();
|
||||
UsbDeviceFactory();
|
||||
~UsbDeviceFactory();
|
||||
|
||||
// delete copy ctor and assignment
|
||||
UsbDeviceFactory(const UsbDeviceFactory&) = delete;
|
||||
UsbDeviceFactory& operator=(UsbDeviceFactory&) = delete;
|
||||
UsbDeviceFactory(UsbDeviceFactory&&) = delete;
|
||||
UsbDeviceFactory& operator=(UsbDeviceFactory&&) = delete;
|
||||
|
||||
bool init();
|
||||
/**
|
||||
@@ -58,7 +56,6 @@ class UsbDeviceFactory : public IUsbDeviceFactory {
|
||||
uint16_t pid);
|
||||
// members
|
||||
libusb_context* mLibusbCtx{nullptr};
|
||||
libusb_device** mLibusbDeviceList{};
|
||||
bool mDeviceListInitialized = false;
|
||||
libusb_device** mLibusbDeviceList;
|
||||
};
|
||||
} // namespace libusbwrap
|
21
src/main.cpp
21
src/main.cpp
@@ -16,13 +16,22 @@
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#include "PtouchPrint.hpp"
|
||||
|
||||
void setupLogger() {
|
||||
spdlog::set_level(spdlog::level::debug);
|
||||
spdlog::info("Starting ptprnt {}", PROJ_VERSION);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
ptprnt::PtouchPrint ptouchprnt(PROJ_VERSION);
|
||||
int ret = ptouchprnt.init(argc, argv);
|
||||
if (ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
return ptouchprnt.run();
|
||||
setupLogger();
|
||||
|
||||
PtouchPrint ptouchprnt;
|
||||
ptouchprnt.init();
|
||||
ptouchprnt.run();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@@ -1,24 +0,0 @@
|
||||
ptprnt_hpps = files (
|
||||
'libusbwrap/interface/IUsbDeviceFactory.hpp',
|
||||
'libusbwrap/interface/IUsbDevice.hpp',
|
||||
'libusbwrap/UsbDeviceFactory.hpp',
|
||||
'libusbwrap/LibUsbTypes.hpp',
|
||||
'libusbwrap/UsbDevice.hpp',
|
||||
'interface/IPrinterDriver.hpp',
|
||||
'interface/IPrinterTypes.hpp',
|
||||
'P700Printer.hpp',
|
||||
'PtouchPrint.hpp',
|
||||
'graphics/Bitmap.hpp',
|
||||
'graphics/Image.hpp',
|
||||
'graphics/Monochrome.hpp'
|
||||
)
|
||||
|
||||
ptprnt_srcs = files (
|
||||
'PtouchPrint.cpp',
|
||||
'P700Printer.cpp',
|
||||
'graphics/Image.cpp',
|
||||
'graphics/Bitmap.cpp',
|
||||
'graphics/Monochrome.cpp',
|
||||
'libusbwrap/UsbDeviceFactory.cpp',
|
||||
'libusbwrap/UsbDevice.cpp',
|
||||
)
|
@@ -1,9 +0,0 @@
|
||||
[wrap-file]
|
||||
directory = CLI11-2.3.2
|
||||
source_url = https://github.com/CLIUtils/CLI11/archive/refs/tags/v2.3.2.tar.gz
|
||||
source_filename = CLI11-2.3.2.tar.gz
|
||||
source_hash = aac0ab42108131ac5d3344a9db0fdf25c4db652296641955720a4fbe52334e22
|
||||
wrapdb_version = 2.3.2-1
|
||||
|
||||
[provide]
|
||||
cli11 = CLI11_dep
|
@@ -21,9 +21,7 @@
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
TEST(basic_test, Bitmap_createBitmapWithCertainSize_yieldsSpecifiedSize) {
|
||||
auto bm = ptprnt::graphics::Bitmap<ptprnt::graphics::ALPHA8>(16, 8);
|
||||
@@ -66,36 +64,3 @@ TEST(basic_test, Bitmap_getBitmapColInsideOfImage_yieldsValidColSize) {
|
||||
auto colSize = col->size();
|
||||
ASSERT_EQ(8, colSize);
|
||||
}
|
||||
|
||||
TEST(basic_test, Bitmap_setPixels_setsGivenPixels) {
|
||||
auto bm = ptprnt::graphics::Bitmap<ptprnt::graphics::ALPHA8>(16, 8);
|
||||
std::vector<uint8_t> pix(16 * 8);
|
||||
|
||||
bm.setPixels(pix);
|
||||
auto pixCpy = bm.getPixelsCpy();
|
||||
|
||||
ASSERT_EQ(pix, pixCpy);
|
||||
}
|
||||
|
||||
TEST(basic_test, Bitmap_setPixels_isSuccessfulWithValidPixels) {
|
||||
auto bm = ptprnt::graphics::Bitmap<ptprnt::graphics::ALPHA8>(16, 8);
|
||||
std::vector<uint8_t> pix(16 * 8);
|
||||
|
||||
ASSERT_TRUE(bm.setPixels(pix));
|
||||
}
|
||||
|
||||
TEST(basic_test, Bitmap_setPixels_yieldsSamePixelsBack) {
|
||||
auto bm = ptprnt::graphics::Bitmap<ptprnt::graphics::ALPHA8>(16, 8);
|
||||
std::vector<uint8_t> pix(16 * 8);
|
||||
|
||||
bm.setPixels(pix);
|
||||
auto pixCpy = bm.getPixelsCpy();
|
||||
ASSERT_EQ(pix, pixCpy);
|
||||
}
|
||||
|
||||
TEST(basic_test, Bitmap_setPixelsWithWrongSize_isFailing) {
|
||||
auto bm = ptprnt::graphics::Bitmap<ptprnt::graphics::ALPHA8>(5, 8);
|
||||
std::vector<uint8_t> pix(16 * 8);
|
||||
|
||||
ASSERT_FALSE(bm.setPixels(pix));
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
tests = [['bitmap_test', 'bitmap_test_exe', ptprnt_srcs + ['bitmap_test/bitmap_test.cpp']],
|
||||
['image_test', 'image_test_exe', ptprnt_srcs +['image_test/image_test.cpp']],
|
||||
['monochrome_test', 'monochrome_test_exe', ptprnt_srcs +['monochrome_test/monochrome_test.cpp']]
|
||||
tests = [['bitmap_test', 'bitmap_test_exe', ['bitmap_test/bitmap_test.cpp']],
|
||||
['image_test', 'image_test_exe', ['image_test/image_test.cpp']],
|
||||
['monochrome_test', 'monochrome_test_exe', ['monochrome_test/monochrome_test.cpp']]
|
||||
]
|
||||
|
||||
foreach test : tests
|
||||
@@ -8,7 +8,8 @@ foreach test : tests
|
||||
executable(test.get(1),
|
||||
sources: test.get(2),
|
||||
include_directories: incdir,
|
||||
dependencies: [gtest_dep, usb_dep, log_dep, pangocairo_dep, cli11_dep]
|
||||
link_with:[ptprnt_lib],
|
||||
dependencies: [gtest_dep, pangocairo_dep]
|
||||
)
|
||||
)
|
||||
endforeach
|
Reference in New Issue
Block a user