All checks were successful
Build ptprnt / build (push) Successful in 1m4s
71 lines
2.8 KiB
C++
71 lines
2.8 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) {
|
|
// TODO: We need to find to access the vector without the possiblity of out-of-bounds access
|
|
// Ideas: constexpr? compile time check?
|
|
GTEST_SKIP() << "Skipping this test, as ASAN will halt as this is an out-of-bounds access";
|
|
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);
|
|
} |