1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
#include <QtTest>
#include <video/rgb/PixelFormatRGB.h>
using namespace video;
using namespace video::rgb;
class PixelFormatRGBTest : public QObject
{
Q_OBJECT
public:
PixelFormatRGBTest(){};
~PixelFormatRGBTest(){};
private slots:
void testFormatFromToString();
void testInvalidFormats();
};
QList<PixelFormatRGB> getAllFormats()
{
QList<PixelFormatRGB> allFormats;
for (int bitsPerPixel = 8; bitsPerPixel <= 16; bitsPerPixel++)
for (auto dataLayout : {video::DataLayout::Packed, video::DataLayout::Planar})
for (auto channelOrder : ChannelOrderMapper.getEnums())
for (auto alphaMode : {AlphaMode::None, AlphaMode::First, AlphaMode::Last})
for (auto endianness : {Endianness::Little, Endianness::Big})
allFormats.append(
PixelFormatRGB(bitsPerPixel, dataLayout, channelOrder, alphaMode, endianness));
return allFormats;
}
void PixelFormatRGBTest::testFormatFromToString()
{
for (auto fmt : getAllFormats())
{
QVERIFY(fmt.isValid());
auto name = fmt.getName();
if (name.empty())
{
QFAIL("Name empty");
}
auto fmtNew = PixelFormatRGB(name);
if (fmt != fmtNew)
{
auto errorStr = "Comparison failed. Names: " + name;
QFAIL(errorStr.c_str());
}
if (fmt.getChannelPosition(Channel::Red) != fmtNew.getChannelPosition(Channel::Red) ||
fmt.getChannelPosition(Channel::Green) != fmtNew.getChannelPosition(Channel::Green) ||
fmt.getChannelPosition(Channel::Blue) != fmtNew.getChannelPosition(Channel::Blue) ||
fmt.getChannelPosition(Channel::Alpha) != fmtNew.getChannelPosition(Channel::Alpha) ||
fmt.getBitsPerSample() != fmtNew.getBitsPerSample() ||
fmt.getDataLayout() != fmtNew.getDataLayout())
{
auto errorStr = "Comparison of parameters failed. Names: " + name;
QFAIL(errorStr.c_str());
}
if (fmt.hasAlpha() && (fmt.nrChannels() != 4 || !fmt.hasAlpha()))
{
auto errorStr = "Alpha channel indicated wrong - " + name;
QFAIL(errorStr.c_str());
}
if (!fmt.hasAlpha() && (fmt.nrChannels() != 3 || fmt.hasAlpha()))
{
auto errorStr = "Alpha channel indicated wrong - %1" + name;
QFAIL(errorStr.c_str());
}
}
}
void PixelFormatRGBTest::testInvalidFormats()
{
QList<PixelFormatRGB> invalidFormats;
invalidFormats.append(PixelFormatRGB(0, video::DataLayout::Packed, ChannelOrder::RGB));
invalidFormats.append(PixelFormatRGB(1, video::DataLayout::Packed, ChannelOrder::RGB));
invalidFormats.append(PixelFormatRGB(7, video::DataLayout::Packed, ChannelOrder::RGB));
invalidFormats.append(PixelFormatRGB(17, video::DataLayout::Packed, ChannelOrder::RGB));
invalidFormats.append(PixelFormatRGB(200, video::DataLayout::Packed, ChannelOrder::RGB));
for (auto fmt : invalidFormats)
QVERIFY(!fmt.isValid());
}
QTEST_MAIN(PixelFormatRGBTest)
#include "PixelFormatRGBTest.moc"
|