Files
ptouch-prnt/tests/monochrome_test/monochrome_test.cpp

68 lines
2.6 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/Monochrome.hpp"
#include <gtest/gtest.h>
TEST(basic_test, Monochrome_convertGrayscale_yieldsMonochrome) {
const std::vector<uint8_t> pixels({0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00,
0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00});
const std::vector<uint8_t> expected({0b10101010, 0b10101010});
auto mono = ptprnt::graphics::Monochrome(pixels);
auto out = mono.get();
EXPECT_EQ(out, expected);
}
TEST(basic_test, Monochrome_convertInvertedGrayscale_yieldsInvertedMonochrome) {
const std::vector<uint8_t> pixels({0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00,
0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00});
const std::vector<uint8_t> expected({0b01010101, 0b01010101});
auto mono = ptprnt::graphics::Monochrome(pixels);
mono.invert(true);
auto out = mono.get();
EXPECT_EQ(out, expected);
}
TEST(basic_test, Monochrome_convertWithCustomThreshhold_yieldsMonochromeRespectingThreshhold) {
const std::vector<uint8_t> pixels({0x0F, 0x11, 0x0F, 0x11, 0x0F, 0x11, 0x0F, 0x11, 0x0F, 0x11,
0x0F, 0x11, 0x0F, 0x11, 0x0F, 0x11});
const std::vector<uint8_t> expected({0b01010101, 0b01010101});
auto mono = ptprnt::graphics::Monochrome(pixels);
mono.setThreshold(16);
auto out = mono.get();
EXPECT_EQ(out, expected);
}
TEST(basic_test, Monochrome_convertNonAlignedPixels_spillsOverIntoNewByte) {
const std::vector<uint8_t> pixels({0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00,
0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF});
const std::vector<uint8_t> expected({0b10101010, 0b10101010, 0b10000000});
auto mono = ptprnt::graphics::Monochrome(pixels);
auto out = mono.get();
EXPECT_EQ(out, expected);
}