Files
ptouch-prnt/tests/bitmap_test/bitmap_test.cpp
2025-09-11 10:02:43 +02:00

95 lines
3.0 KiB
C++

/*
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/>.
*/
#include "graphics/Bitmap.hpp"
#include <gtest/gtest.h>
#include <cstdint>
#include <vector>
TEST(basic_test, Bitmap_createBitmapWithCertainSize_yieldsSpecifiedSize) {
auto bm = ptprnt::graphics::Bitmap<ptprnt::graphics::ALPHA8>(16, 8);
auto width = bm.getWidth();
auto height = bm.getHeight();
ASSERT_EQ(width, 16);
ASSERT_EQ(height, 8);
}
TEST(basic_test, Bitmap_getBitmapLineOutsideOfImage_yieldsNullopt) {
auto bm = ptprnt::graphics::Bitmap<ptprnt::graphics::ALPHA8>(16, 8);
// line 8 is out of bounds, count begins with 0
EXPECT_ANY_THROW(auto outOfBoundsLine = bm.getLine(8));
}
TEST(basic_test, Bitmap_getBitmapLineInsideOfImage_yieldsValidLineSize) {
auto bm = ptprnt::graphics::Bitmap<ptprnt::graphics::ALPHA8>(16, 8);
auto line = bm.getLine(7);
auto lineSize = line.size();
ASSERT_EQ(16, lineSize);
}
TEST(basic_test, Bitmap_getBitmapColOutsideOfImage_yieldsNullopt) {
auto bm = ptprnt::graphics::Bitmap<ptprnt::graphics::ALPHA8>(16, 8);
// col 16 is out of bounds, count begins with 0
EXPECT_ANY_THROW(auto outOfBoundsCol = bm.getCol(16));
}
TEST(basic_test, Bitmap_getBitmapColInsideOfImage_yieldsValidColSize) {
auto bm = ptprnt::graphics::Bitmap<ptprnt::graphics::ALPHA8>(16, 8);
auto col = bm.getCol(15);
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));
}