Multilabel support & Label refactoring (#17)
All checks were successful
Build ptprnt / build (push) Successful in 3m47s
All checks were successful
Build ptprnt / build (push) Successful in 3m47s
Reviewed-on: moritz/ptouch-prnt#17
This commit was merged in pull request #17.
This commit is contained in:
84
tests/mocks/MockCairoWrapper.hpp
Normal file
84
tests/mocks/MockCairoWrapper.hpp
Normal file
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
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 "graphics/interface/ICairoWrapper.hpp"
|
||||
|
||||
namespace ptprnt::graphics {
|
||||
|
||||
/**
|
||||
* @brief GMock implementation of ICairoWrapper for unit testing
|
||||
*
|
||||
* This mock allows tests to verify that the Label class correctly interacts
|
||||
* with the Cairo/Pango API without requiring actual graphics rendering.
|
||||
*/
|
||||
class MockCairoWrapper : public ICairoWrapper {
|
||||
public:
|
||||
// Cairo image surface functions
|
||||
MOCK_METHOD(cairo_surface_t*, cairo_image_surface_create, (cairo_format_t format, int width, int height),
|
||||
(override));
|
||||
MOCK_METHOD(void, cairo_surface_destroy, (cairo_surface_t * surface), (override));
|
||||
MOCK_METHOD(void, cairo_surface_flush, (cairo_surface_t * surface), (override));
|
||||
MOCK_METHOD(void, cairo_surface_mark_dirty, (cairo_surface_t * surface), (override));
|
||||
MOCK_METHOD(cairo_status_t, cairo_surface_status, (cairo_surface_t * surface), (override));
|
||||
MOCK_METHOD(cairo_format_t, cairo_image_surface_get_format, (cairo_surface_t * surface), (override));
|
||||
MOCK_METHOD(int, cairo_image_surface_get_width, (cairo_surface_t * surface), (override));
|
||||
MOCK_METHOD(int, cairo_image_surface_get_height, (cairo_surface_t * surface), (override));
|
||||
MOCK_METHOD(int, cairo_image_surface_get_stride, (cairo_surface_t * surface), (override));
|
||||
MOCK_METHOD(unsigned char*, cairo_image_surface_get_data, (cairo_surface_t * surface), (override));
|
||||
MOCK_METHOD(cairo_status_t, cairo_surface_write_to_png, (cairo_surface_t * surface, const char* filename),
|
||||
(override));
|
||||
|
||||
// Cairo context functions
|
||||
MOCK_METHOD(cairo_t*, cairo_create, (cairo_surface_t * surface), (override));
|
||||
MOCK_METHOD(void, cairo_destroy, (cairo_t * cr), (override));
|
||||
MOCK_METHOD(void, cairo_move_to, (cairo_t * cr, double x, double y), (override));
|
||||
MOCK_METHOD(void, cairo_set_source_rgb, (cairo_t * cr, double red, double green, double blue), (override));
|
||||
|
||||
// Pango-Cairo functions
|
||||
MOCK_METHOD(PangoFontMap*, pango_cairo_font_map_new, (), (override));
|
||||
MOCK_METHOD(PangoContext*, pango_cairo_create_context, (cairo_t * cr), (override));
|
||||
MOCK_METHOD(void, pango_cairo_show_layout, (cairo_t * cr, PangoLayout* layout), (override));
|
||||
|
||||
// Pango layout functions
|
||||
MOCK_METHOD(PangoLayout*, pango_layout_new, (PangoContext * context), (override));
|
||||
MOCK_METHOD(void, pango_layout_set_font_description, (PangoLayout * layout, const PangoFontDescription* desc),
|
||||
(override));
|
||||
MOCK_METHOD(void, pango_layout_set_text, (PangoLayout * layout, const char* text, int length), (override));
|
||||
MOCK_METHOD(void, pango_layout_set_height, (PangoLayout * layout, int height), (override));
|
||||
MOCK_METHOD(void, pango_layout_set_alignment, (PangoLayout * layout, PangoAlignment alignment), (override));
|
||||
MOCK_METHOD(void, pango_layout_set_justify, (PangoLayout * layout, gboolean justify), (override));
|
||||
#if PANGO_VERSION_MAJOR >= 1 && PANGO_VERSION_MINOR >= 50
|
||||
MOCK_METHOD(void, pango_layout_set_justify_last_line, (PangoLayout * layout, gboolean justify), (override));
|
||||
#endif
|
||||
MOCK_METHOD(void, pango_layout_get_size, (PangoLayout * layout, int* width, int* height), (override));
|
||||
|
||||
// Pango font description functions
|
||||
MOCK_METHOD(PangoFontDescription*, pango_font_description_new, (), (override));
|
||||
MOCK_METHOD(void, pango_font_description_set_size, (PangoFontDescription * desc, gint size), (override));
|
||||
MOCK_METHOD(void, pango_font_description_set_family, (PangoFontDescription * desc, const char* family),
|
||||
(override));
|
||||
|
||||
// GObject reference counting
|
||||
MOCK_METHOD(void, g_object_unref, (gpointer object), (override));
|
||||
};
|
||||
|
||||
} // namespace ptprnt::graphics
|
||||
Reference in New Issue
Block a user