|
| 1 | +/* |
| 2 | + * Copyright (C) 2004-2022 Exiv2 authors |
| 3 | + * This program is part of the Exiv2 distribution. |
| 4 | + * |
| 5 | + * This program is free software; you can redistribute it and/or |
| 6 | + * modify it under the terms of the GNU General Public License |
| 7 | + * as published by the Free Software Foundation; either version 2 |
| 8 | + * of the License, or (at your option) any later version. |
| 9 | + * |
| 10 | + * This program is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | + * GNU General Public License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License |
| 16 | + * along with this program; if not, write to the Free Software |
| 17 | + * Foundation, Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301 USA. |
| 18 | + */ |
| 19 | + |
| 20 | +#include <exiv2/pngimage.hpp> |
| 21 | +#include "pngchunk_int.hpp" // This is not part of the public API |
| 22 | + |
| 23 | +#include <gtest/gtest.h> |
| 24 | + |
| 25 | +#include <array> |
| 26 | +#include <algorithm> |
| 27 | + |
| 28 | +using namespace Exiv2; |
| 29 | + |
| 30 | +TEST(PngChunk, keyTxtChunkExtractsKeywordCorrectlyInPresenceOfNullChar) |
| 31 | +{ |
| 32 | + // The following data is: '\0\0"AzTXtRaw profile type exif\0\0x' |
| 33 | + std::array<std::uint8_t, 32> data{0x00, 0x00, 0x22, 0x41, 0x7a, 0x54, 0x58, 0x74, |
| 34 | + 0x52, 0x61, 0x77, 0x20, 0x70, 0x72, 0x6f, 0x66, |
| 35 | + 0x69, 0x6c, 0x65, 0x20, 0x74, 0x79, 0x70, 0x65, |
| 36 | + 0x20, 0x65, 0x78, 0x69, 0x66, 0x00, 0x00, 0x78}; |
| 37 | + |
| 38 | + DataBuf chunkBuf(data.data(), static_cast<long>(data.size())); |
| 39 | + DataBuf key = Internal::PngChunk::keyTXTChunk(chunkBuf, true); |
| 40 | + ASSERT_EQ(21, key.size()); |
| 41 | + |
| 42 | + ASSERT_TRUE(std::equal(key.data(), key.data()+key.size(), data.data()+8, data.data()+8+key.size())); |
| 43 | +} |
| 44 | + |
| 45 | + |
| 46 | +TEST(PngChunk, keyTxtChunkThrowsExceptionWhenThereIsNoNullChar) |
| 47 | +{ |
| 48 | + // The following data is: '\0\0"AzTXtRaw profile type exifx' |
| 49 | + std::array<std::uint8_t, 30> data{0x00, 0x00, 0x22, 0x41, 0x7a, 0x54, 0x58, 0x74, |
| 50 | + 0x52, 0x61, 0x77, 0x20, 0x70, 0x72, 0x6f, 0x66, |
| 51 | + 0x69, 0x6c, 0x65, 0x20, 0x74, 0x79, 0x70, 0x65, |
| 52 | + 0x20, 0x65, 0x78, 0x69, 0x66, 0x78}; |
| 53 | + |
| 54 | + DataBuf chunkBuf(data.data(), static_cast<long>(data.size())); |
| 55 | + ASSERT_THROW(Internal::PngChunk::keyTXTChunk(chunkBuf, true), Exiv2::Error); |
| 56 | +} |
0 commit comments