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.
This commit is contained in:
Luis Diaz 2022-04-05 09:46:00 +02:00 committed by Luis Díaz Más
parent a698c3fc08
commit 7366a64d44
2 changed files with 32 additions and 0 deletions

View File

@ -18,6 +18,7 @@ add_executable(unit_tests
test_jp2image_int.cpp
test_IptcKey.cpp
test_LangAltValueRead.cpp
test_Photoshop.cpp
test_pngimage.cpp
test_safe_op.cpp
test_slice.cpp

View File

@ -0,0 +1,31 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#include <exiv2/jpgimage.hpp>
#include <gtest/gtest.h>
using namespace Exiv2;
namespace {
constexpr std::array validMarkers{"8BIM", "AgHg", "DCSR", "PHUT"};
}
TEST(Photoshop_isIrb, returnsTrueWithValidMarkers) {
for (const auto& marker : validMarkers) {
ASSERT_TRUE(Photoshop::isIrb(reinterpret_cast<const byte*>(marker), 4));
}
}
TEST(Photoshop_isIrb, returnsFalseWithInvalidMarkers) {
ASSERT_FALSE(Photoshop::isIrb(reinterpret_cast<const byte *>("7BIM"), 4));
ASSERT_FALSE(Photoshop::isIrb(reinterpret_cast<const byte *>("AGHg"), 4));
ASSERT_FALSE(Photoshop::isIrb(reinterpret_cast<const byte *>("dcsr"), 4));
ASSERT_FALSE(Photoshop::isIrb(reinterpret_cast<const byte *>("LUIS"), 4));
}
TEST(Photoshop_isIrb, returnsFalseWithInvalidSize) {
ASSERT_FALSE(Photoshop::isIrb(reinterpret_cast<const byte *>("8BIM"), 3));
ASSERT_FALSE(Photoshop::isIrb(reinterpret_cast<const byte *>("8BIM"), 0));
ASSERT_FALSE(Photoshop::isIrb(reinterpret_cast<const byte *>("8BIM"), 5));
}