Skip to content

Commit 7366a64

Browse files
committed
Add unit tests for Photoshop::isIrb().
It has been detected that we need to always pass the size==4 in the call to isIrb. Probably it is better to remove that parameter and document that it is assumed for the buffer to have a length of 4 bytes.
1 parent a698c3f commit 7366a64

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

unitTests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ add_executable(unit_tests
1818
test_jp2image_int.cpp
1919
test_IptcKey.cpp
2020
test_LangAltValueRead.cpp
21+
test_Photoshop.cpp
2122
test_pngimage.cpp
2223
test_safe_op.cpp
2324
test_slice.cpp

unitTests/test_Photoshop.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
3+
#include <exiv2/jpgimage.hpp>
4+
5+
#include <gtest/gtest.h>
6+
7+
using namespace Exiv2;
8+
9+
namespace {
10+
constexpr std::array validMarkers{"8BIM", "AgHg", "DCSR", "PHUT"};
11+
}
12+
13+
TEST(Photoshop_isIrb, returnsTrueWithValidMarkers) {
14+
for (const auto& marker : validMarkers) {
15+
ASSERT_TRUE(Photoshop::isIrb(reinterpret_cast<const byte*>(marker), 4));
16+
}
17+
}
18+
19+
20+
TEST(Photoshop_isIrb, returnsFalseWithInvalidMarkers) {
21+
ASSERT_FALSE(Photoshop::isIrb(reinterpret_cast<const byte *>("7BIM"), 4));
22+
ASSERT_FALSE(Photoshop::isIrb(reinterpret_cast<const byte *>("AGHg"), 4));
23+
ASSERT_FALSE(Photoshop::isIrb(reinterpret_cast<const byte *>("dcsr"), 4));
24+
ASSERT_FALSE(Photoshop::isIrb(reinterpret_cast<const byte *>("LUIS"), 4));
25+
}
26+
27+
TEST(Photoshop_isIrb, returnsFalseWithInvalidSize) {
28+
ASSERT_FALSE(Photoshop::isIrb(reinterpret_cast<const byte *>("8BIM"), 3));
29+
ASSERT_FALSE(Photoshop::isIrb(reinterpret_cast<const byte *>("8BIM"), 0));
30+
ASSERT_FALSE(Photoshop::isIrb(reinterpret_cast<const byte *>("8BIM"), 5));
31+
}

0 commit comments

Comments
 (0)