Skip to content

Commit 5847a6d

Browse files
author
Christian Feldmann
committed
Fix another test with the new pixelFormat iteration function and fix test.
1 parent 0066d86 commit 5847a6d

1 file changed

Lines changed: 45 additions & 27 deletions

File tree

YUViewUnitTest/video/rgb/GetPixelValueTest.cpp

Lines changed: 45 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -58,43 +58,61 @@ void testGetPixelValueFromBuffer(const QByteArray &sourceBuffer,
5858
const auto actualValue =
5959
getPixelValueFromBuffer(sourceBuffer, srcPixelFormat, TEST_FRAME_SIZE, pixelPos);
6060

61-
const auto testValue = TEST_VALUES_12BIT[testValueIndex++];
62-
auto expectedValue = convertBitness(testValue, 12, bitDepth);
63-
if (!srcPixelFormat.hasAlpha())
64-
expectedValue.a = 0;
61+
const auto testValue = TEST_VALUES_12BIT[testValueIndex++];
62+
rgba_t expectedValue{};
63+
if (srcPixelFormat.getPredefinedPixelFormat() == PredefinedPixelFormat::RGB565)
64+
{
65+
expectedValue.r = convertBitness(testValue.r, 12, 5);
66+
expectedValue.g = convertBitness(testValue.g, 12, 6);
67+
expectedValue.b = convertBitness(testValue.b, 12, 5);
68+
expectedValue.a = 255;
69+
}
70+
else if (srcPixelFormat.getPredefinedPixelFormat())
71+
throw std::runtime_error("Unsupported predefined pixel format");
72+
else
73+
{
74+
expectedValue = convertBitness(testValue, 12, bitDepth);
75+
if (!srcPixelFormat.hasAlpha())
76+
expectedValue.a = 0;
77+
}
6578

6679
if (actualValue != expectedValue)
6780
throw std::runtime_error("Error checking pixel [" + std::to_string(x) + "," +
68-
std::to_string(y) + " format " + *srcPixelFormat.getName());
81+
std::to_string(y) + "] expected " + to_string(expectedValue) +
82+
" but got " + to_string(actualValue));
6983
}
7084
}
7185
}
7286

7387
} // namespace
7488

75-
TEST(GetPixelValueTest, TestGetPixelValueFromBuffer)
89+
class GetPixelValueTest : public TestWithParam<PixelFormatRGB>
7690
{
77-
for (const auto endianness : EndianessMapper.getValues())
78-
{
79-
for (auto bitDepth : {8, 10, 12, 16, 32})
80-
{
81-
for (const auto &alphaMode : AlphaModeMapper.getValues())
82-
{
83-
for (const auto &dataLayout : DataLayoutMapper.getValues())
84-
{
85-
for (const auto &channelOrder : ChannelOrderMapper.getValues())
86-
{
87-
const PixelFormatRGB pixelFormat(
88-
bitDepth, dataLayout, channelOrder, alphaMode, endianness);
89-
const auto data = createRawRGBData(pixelFormat, TEST_VALUES_12BIT, 12);
90-
91-
EXPECT_NO_THROW(testGetPixelValueFromBuffer(data, pixelFormat))
92-
<< "Failed for pixel format " << *pixelFormat.getName();
93-
}
94-
}
95-
}
96-
}
97-
}
91+
};
92+
93+
TEST_P(GetPixelValueTest, TestGetPixelValueFromBuffer)
94+
{
95+
const auto &pixelFormat = GetParam();
96+
97+
QByteArray data;
98+
if (pixelFormat.getPredefinedPixelFormat())
99+
data = createRawRGBData(
100+
*pixelFormat.getPredefinedPixelFormat(), pixelFormat.getEndianess(), TEST_VALUES_12BIT, 12);
101+
else
102+
data = createRawRGBData(pixelFormat, TEST_VALUES_12BIT, 12);
103+
104+
EXPECT_NO_THROW(testGetPixelValueFromBuffer(data, pixelFormat))
105+
<< "Failed for pixel format " << *pixelFormat.getName();
98106
}
99107

108+
std::string getName(const testing::TestParamInfo<GetPixelValueTest::ParamType> &info)
109+
{
110+
return yuviewTest::replaceNonSupportedCharacters(*info.param.getName());
111+
}
112+
113+
INSTANTIATE_TEST_SUITE_P(VideoRGBTest,
114+
GetPixelValueTest,
115+
ValuesIn(createTestSetOfPixelFormatRGB()),
116+
getName);
117+
100118
} // namespace video::rgb::test

0 commit comments

Comments
 (0)