IRSOL
C++ code implementing socket server for interacting with Baumer camera.
test_pixel_format.cpp
Go to the documentation of this file.
2
3#include <catch2/catch_all.hpp>
4#include <vector>
5
6TEST_CASE("Pixel<T>::max())", "[PixelFormat]")
7{
11}
12
22
23TEST_CASE("PixelByteSwapper<true>-swaps-bytes-for-16-bit-data", "[PixelFormat]")
24{
25
26 SECTION("Empty range does nothing")
27 {
28 std::vector<irsol::types::byte_t> v;
29 irsol::camera::PixelByteSwapper<true>()(v.begin(), v.end());
30 CHECK(v.empty());
31 }
32
33 SECTION("Begin after end raises an assertion")
34 {
35 std::vector<irsol::types::byte_t> v = {irsol::types::byte_t{0x01}, irsol::types::byte_t{0x02}};
38 }
39
40 SECTION("Even number of bytes swaps pairs")
41 {
42 std::vector<irsol::types::byte_t> v = {irsol::types::byte_t{0x01},
46 irsol::camera::PixelByteSwapper<true>()(v.begin(), v.end());
47 CHECK(
48 v == std::vector<irsol::types::byte_t>{irsol::types::byte_t{0x02},
52 }
53
54 SECTION("Odd number of bytes swaps pairs, last byte untouched")
55 {
56 std::vector<irsol::types::byte_t> v = {
58 irsol::camera::PixelByteSwapper<true>()(v.begin(), v.end());
59 CHECK(
60 v == std::vector<irsol::types::byte_t>{
62 }
63
64 SECTION("Single byte does nothing")
65 {
66 std::vector<irsol::types::byte_t> v = {irsol::types::byte_t{0xAA}};
67 irsol::camera::PixelByteSwapper<true>()(v.begin(), v.end());
68 CHECK(v == std::vector<irsol::types::byte_t>{irsol::types::byte_t{0xAA}});
69 }
70
71 SECTION("Longer vector swaps all pairs correctly")
72 {
73 std::vector<irsol::types::byte_t> v = {irsol::types::byte_t{0x01},
85 irsol::camera::PixelByteSwapper<true>()(v.begin(), v.end());
86 CHECK(
87 v == std::vector<irsol::types::byte_t>{irsol::types::byte_t{0x02},
99 }
100}
101
102TEST_CASE("PixelByteSwapper<false>-is-no-op", "[PixelFormat]")
103{
104
105 SECTION("No-op on empty vector")
106 {
107 std::vector<irsol::types::byte_t> v;
108 irsol::camera::PixelByteSwapper<false>()(v.begin(), v.end());
109 CHECK(v.empty());
110 }
111
112 SECTION("No-op on non-empty vector")
113 {
114 std::vector<irsol::types::byte_t> v = {irsol::types::byte_t{0x01},
118 irsol::camera::PixelByteSwapper<false>()(v.begin(), v.end());
119 CHECK(
120 v == std::vector<irsol::types::byte_t>{irsol::types::byte_t{0x01},
123 irsol::types::byte_t{0x04}});
124 }
125}
std::byte byte_t
Alias for a single byte used in serialization or binary data handling.
Definition types.hpp:165
ppk::assert::AssertionException AssertionException
Definition assert.hpp:149
Utilities for managing and transforming pixel formats between each other.
Utility for swapping pixel bytes in a buffer.
Helper to convert pixel values from one bit depth to another with scaling.
Represents a pixel with a given bit depth.
CHECK(m.identifier==identifier)
CHECK_THROWS_AS(irsol::protocol::Assignment(identifier, value), std::invalid_argument)
STATIC_CHECK(m.DIM==1)
TEST_CASE("Pixel<T>::max())", "[PixelFormat]")