Skip to content

Commit e72d27e

Browse files
Add some first conversion tests
1 parent 0af71d7 commit e72d27e

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

YUViewLib/src/video/rgb/ConversionFunctions.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ DataPointers<T> calculatePointersToStartOfComponents(QByteArray &rawFr
5959
const Size &frameSize,
6060
const PixelFormatRGB &pixelFormat)
6161
{
62+
if (!pixelFormat.isValid())
63+
throw std::invalid_argument("Pixel format must be valid");
64+
if (!frameSize)
65+
throw std::invalid_argument("Frame size must be valid");
66+
if (rawFrameData.size() < pixelFormat.getBytesPerFrame(frameSize))
67+
throw std::invalid_argument("Raw frame data too small");
68+
6269
const auto posR = pixelFormat.getChannelPosition(Channel::Red);
6370
const auto posG = pixelFormat.getChannelPosition(Channel::Green);
6471
const auto posB = pixelFormat.getChannelPosition(Channel::Blue);
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/* This file is part of YUView - The YUV player with advanced analytics toolset
2+
* <https://github.com/IENT/YUView>
3+
* Copyright (C) 2015 Institut für Nachrichtentechnik, RWTH Aachen University, GERMANY
4+
*
5+
* This program is free software; you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation; either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* In addition, as a special exception, the copyright holders give
11+
* permission to link the code of portions of this program with the
12+
* OpenSSL library under certain conditions as described in each
13+
* individual source file, and distribute linked combinations including
14+
* the two.
15+
*
16+
* You must obey the GNU General Public License in all respects for all
17+
* of the code used other than OpenSSL. If you modify file(s) with this
18+
* exception, you may extend this exception to your version of the
19+
* file(s), but you are not obligated to do so. If you do not wish to do
20+
* so, delete this exception statement from your version. If you delete
21+
* this exception statement from all source files in the program, then
22+
* also delete it here.
23+
*
24+
* This program is distributed in the hope that it will be useful,
25+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
26+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27+
* GNU General Public License for more details.
28+
*
29+
* You should have received a copy of the GNU General Public License
30+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
31+
*/
32+
33+
#include <common/Testing.h>
34+
35+
#include <video/rgb/ConversionFunctions.h>
36+
37+
#include "CreateTestData.h"
38+
39+
namespace video::rgb::test
40+
{
41+
42+
TEST(ConversionFunctionsTest,
43+
TestCalculatePointersToStartOfComponents_InvalidPixelFormat_ShouldThrow)
44+
{
45+
const auto pixelFormat = PixelFormatRGB(8, DataLayout::Packed, ChannelOrder::RGB);
46+
auto data = createRawRGBData(pixelFormat);
47+
EXPECT_THROW(calculatePointersToStartOfComponents<uint8_t>(data, {128, 128}, {}),
48+
std::invalid_argument);
49+
}
50+
51+
TEST(ConversionFunctionsTest, TestCalculatePointersToStartOfComponents_InvalidFrameSize_ShouldThrow)
52+
{
53+
const auto pixelFormat = PixelFormatRGB(8, DataLayout::Packed, ChannelOrder::RGB);
54+
auto data = createRawRGBData(pixelFormat);
55+
EXPECT_THROW(calculatePointersToStartOfComponents<uint8_t>(data, {128, 0}, pixelFormat),
56+
std::invalid_argument);
57+
}
58+
59+
TEST(ConversionFunctionsTest, TestCalculatePointersToStartOfComponents_NotEnoughData_ShouldThrow)
60+
{
61+
QByteArray data;
62+
EXPECT_THROW(calculatePointersToStartOfComponents<uint8_t>(
63+
data, TEST_FRAME_SIZE, PixelFormatRGB(8, DataLayout::Packed, ChannelOrder::RGB)),
64+
std::invalid_argument);
65+
}
66+
67+
TEST(ConversionFunctionsTest, TestCalculatePointersToStartOfComponents_OffsetForPacked8Bit)
68+
{
69+
const auto pixelFormat = PixelFormatRGB(8, DataLayout::Packed, ChannelOrder::RGB);
70+
auto data = createRawRGBData(pixelFormat);
71+
72+
const auto offsets =
73+
calculatePointersToStartOfComponents<uint8_t>(data, TEST_FRAME_SIZE, pixelFormat);
74+
75+
const auto rawDataPointer = reinterpret_cast<uint8_t *>(data.data());
76+
EXPECT_EQ(offsets.r, rawDataPointer + 0);
77+
EXPECT_EQ(offsets.g, rawDataPointer + 1);
78+
EXPECT_EQ(offsets.b, rawDataPointer + 2);
79+
}
80+
81+
// More tests
82+
83+
} // namespace video::rgb::test

0 commit comments

Comments
 (0)