commit
ed09d9f017
@ -0,0 +1,116 @@
|
|||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include <exiv2/datasets.hpp>
|
||||||
|
#include <exiv2/error.hpp>
|
||||||
|
|
||||||
|
using namespace Exiv2;
|
||||||
|
|
||||||
|
TEST(IptcKey, creationWithNonValidStringFormatThrows)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
IptcKey key("Yeah");
|
||||||
|
FAIL();
|
||||||
|
} catch (const Exiv2::Error& e) {
|
||||||
|
ASSERT_EQ(kerInvalidKey, e.code());
|
||||||
|
ASSERT_STREQ("Invalid key 'Yeah'", e.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(IptcKey, creationWithNonValidRecordNameThrows)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
IptcKey key("Iptc.WrongRecordName.ModelVersion");
|
||||||
|
FAIL();
|
||||||
|
} catch (const Exiv2::Error& e) {
|
||||||
|
ASSERT_EQ(kerInvalidRecord, e.code());
|
||||||
|
ASSERT_STREQ("Invalid record name 'WrongRecordName'", e.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(IptcKey, creationWithNonValidDatasetNameThrows)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
IptcKey key("Iptc.Envelope.WrongDataset");
|
||||||
|
FAIL();
|
||||||
|
} catch (const Exiv2::Error& e) {
|
||||||
|
ASSERT_EQ(kerInvalidDataset, e.code());
|
||||||
|
ASSERT_STREQ("Invalid dataset name 'WrongDataset'", e.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(IptcKey, creationWithNonValidFamiltyNameThrows)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
IptcKey key("JOJO.Envelope.WrongDataset");
|
||||||
|
FAIL();
|
||||||
|
} catch (const Exiv2::Error& e) {
|
||||||
|
ASSERT_EQ(kerInvalidKey, e.code());
|
||||||
|
ASSERT_STREQ("Invalid key 'JOJO.Envelope.WrongDataset'", e.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(IptcKey, creationWithValidStringDoesNotThrow)
|
||||||
|
{
|
||||||
|
ASSERT_NO_THROW(IptcKey ("Iptc.Envelope.ModelVersion"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(IptcKey, copyConstructor)
|
||||||
|
{
|
||||||
|
IptcKey key ("Iptc.Envelope.ModelVersion");
|
||||||
|
IptcKey keyCopy (key);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(IptcKey, clone)
|
||||||
|
{
|
||||||
|
IptcKey key ("Iptc.Envelope.ModelVersion");
|
||||||
|
auto keyClone = key.clone();
|
||||||
|
ASSERT_EQ("Iptc.Envelope.ModelVersion", keyClone->key());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(IptcKey, keyReturnsTheFullString)
|
||||||
|
{
|
||||||
|
IptcKey key ("Iptc.Envelope.ModelVersion");
|
||||||
|
ASSERT_EQ("Iptc.Envelope.ModelVersion", key.key());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(IptcKey, familyNameReturnsTheFullString)
|
||||||
|
{
|
||||||
|
IptcKey key ("Iptc.Envelope.ModelVersion");
|
||||||
|
ASSERT_STREQ("Iptc", key.familyName());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(IptcKey, groupNameReturnsTheRecordName)
|
||||||
|
{
|
||||||
|
IptcKey key ("Iptc.Envelope.ModelVersion");
|
||||||
|
ASSERT_EQ("Envelope", key.groupName());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(IptcKey, recordNameReturnsTheRecordName)
|
||||||
|
{
|
||||||
|
IptcKey key ("Iptc.Envelope.ModelVersion");
|
||||||
|
ASSERT_EQ("Envelope", key.recordName());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(IptcKey, tagNameReturnsTheDatasetName)
|
||||||
|
{
|
||||||
|
IptcKey key ("Iptc.Envelope.ModelVersion");
|
||||||
|
ASSERT_EQ("ModelVersion", key.tagName());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(IptcKey, tagLabelReturnsTheDatasetTitle)
|
||||||
|
{
|
||||||
|
IptcKey key ("Iptc.Envelope.ModelVersion");
|
||||||
|
ASSERT_EQ("Model Version", key.tagLabel());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(IptcKey, tag)
|
||||||
|
{
|
||||||
|
IptcKey key ("Iptc.Envelope.ModelVersion");
|
||||||
|
ASSERT_EQ(IptcDataSets::ModelVersion, key.tag());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(IptcKey, record)
|
||||||
|
{
|
||||||
|
IptcKey key ("Iptc.Envelope.ModelVersion");
|
||||||
|
ASSERT_EQ(IptcDataSets::envelope, key.record());
|
||||||
|
}
|
@ -0,0 +1,196 @@
|
|||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
#include <exiv2/bmpimage.hpp>
|
||||||
|
|
||||||
|
using namespace Exiv2;
|
||||||
|
|
||||||
|
TEST(BmpImage, canBeOpenedWithEmptyMemIo)
|
||||||
|
{
|
||||||
|
auto memIo = std::make_unique<MemIo>();
|
||||||
|
ASSERT_NO_THROW(BmpImage bmp(std::move(memIo)));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(BmpImage, mimeTypeIsBmp)
|
||||||
|
{
|
||||||
|
auto memIo = std::make_unique<MemIo>();
|
||||||
|
BmpImage bmp(std::move(memIo));
|
||||||
|
|
||||||
|
ASSERT_EQ("image/x-ms-bmp", bmp.mimeType());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(BmpImage, writeMetadataIsNotImplemented)
|
||||||
|
{
|
||||||
|
auto memIo = std::make_unique<MemIo>();
|
||||||
|
BmpImage bmp(std::move(memIo));
|
||||||
|
|
||||||
|
try {
|
||||||
|
bmp.writeMetadata();
|
||||||
|
FAIL();
|
||||||
|
} catch (const Exiv2::Error& e) {
|
||||||
|
ASSERT_EQ(kerWritingImageFormatUnsupported, e.code());
|
||||||
|
ASSERT_STREQ("Writing to BMP images is not supported", e.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(BmpImage, setExitDataIsNotImplemented)
|
||||||
|
{
|
||||||
|
auto memIo = std::make_unique<MemIo>();
|
||||||
|
BmpImage bmp(std::move(memIo));
|
||||||
|
|
||||||
|
try {
|
||||||
|
ExifData data;
|
||||||
|
bmp.setExifData(data);
|
||||||
|
FAIL();
|
||||||
|
} catch (const Exiv2::Error& e) {
|
||||||
|
ASSERT_EQ(kerInvalidSettingForImage, e.code());
|
||||||
|
ASSERT_STREQ("Setting Exif metadata in BMP images is not supported", e.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(BmpImage, setIptcDataIsNotImplemented)
|
||||||
|
{
|
||||||
|
auto memIo = std::make_unique<MemIo>();
|
||||||
|
BmpImage bmp(std::move(memIo));
|
||||||
|
|
||||||
|
try {
|
||||||
|
IptcData data;
|
||||||
|
bmp.setIptcData(data);
|
||||||
|
FAIL();
|
||||||
|
} catch (const Exiv2::Error& e) {
|
||||||
|
ASSERT_EQ(kerInvalidSettingForImage, e.code());
|
||||||
|
ASSERT_STREQ("Setting IPTC metadata in BMP images is not supported", e.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(BmpImage, setCommentIsNotImplemented)
|
||||||
|
{
|
||||||
|
auto memIo = std::make_unique<MemIo>();
|
||||||
|
BmpImage bmp(std::move(memIo));
|
||||||
|
|
||||||
|
try {
|
||||||
|
bmp.setComment("random comment");
|
||||||
|
FAIL();
|
||||||
|
} catch (const Exiv2::Error& e) {
|
||||||
|
ASSERT_EQ(kerInvalidSettingForImage, e.code());
|
||||||
|
ASSERT_STREQ("Setting Image comment in BMP images is not supported", e.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(BmpImage, readMetadataReadsImageDimensionsWhenDataIsAvailable)
|
||||||
|
{
|
||||||
|
const std::array<unsigned char, 26> header{
|
||||||
|
'B', 'M', // Signature off:0 size:2
|
||||||
|
0x4E, 0x47, 0x0D, 0x0A, // Size of the BMP file in bytes off:2, size:4
|
||||||
|
0x1A, 0x0A, // Reserved off:6, size:2
|
||||||
|
0x00, 0x00, // Reserved off:8, size:2
|
||||||
|
0x00, 0x00, 0x00, 0x00, // Offset of the byte where the bitmap image data can be found off:10, size:4
|
||||||
|
0x00, 0x00, 0x00, 0x00, // Size of this header off:14, size:4
|
||||||
|
0x00, 0x05, 0x00, 0x00, // The bitmap width in pixels (unsigned 16 bit) off:18, size:4
|
||||||
|
0x20, 0x03, 0x00, 0x00, // The bitmap height in pixels (unsigned 16 bit) off:22, size:4
|
||||||
|
};
|
||||||
|
|
||||||
|
auto memIo = std::make_unique<MemIo>(header.data(), static_cast<long>(header.size()));
|
||||||
|
BmpImage bmp(std::move(memIo));
|
||||||
|
ASSERT_NO_THROW(bmp.readMetadata());
|
||||||
|
ASSERT_EQ(1280, bmp.pixelWidth());
|
||||||
|
ASSERT_EQ(800, bmp.pixelHeight());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(BmpImage, readMetadataThrowsWhenImageIsNotBMP)
|
||||||
|
{
|
||||||
|
const std::array<unsigned char, 26> header{
|
||||||
|
'B', 'A', // Signature off:0 size:2
|
||||||
|
0x4E, 0x47, 0x0D, 0x0A, // Size of the BMP file in bytes off:2, size:4
|
||||||
|
0x1A, 0x0A, // Reserved off:6, size:2
|
||||||
|
0x00, 0x00, // Reserved off:8, size:2
|
||||||
|
0x00, 0x00, 0x00, 0x00, // Offset of the byte where the bitmap image data can be found off:10, size:4
|
||||||
|
0x00, 0x00, 0x00, 0x00, // Size of this header off:14, size:4
|
||||||
|
0x00, 0x05, 0x00, 0x00, // The bitmap width in pixels (unsigned 16 bit) off:18, size:4
|
||||||
|
0x20, 0x03, 0x00, 0x00, // The bitmap height in pixels (unsigned 16 bit) off:22, size:4
|
||||||
|
};
|
||||||
|
|
||||||
|
auto memIo = std::make_unique<MemIo>(header.data(), static_cast<long>(header.size()));
|
||||||
|
BmpImage bmp(std::move(memIo));
|
||||||
|
try {
|
||||||
|
bmp.readMetadata();
|
||||||
|
FAIL();
|
||||||
|
} catch (const Exiv2::Error& e) {
|
||||||
|
ASSERT_EQ(kerNotAnImage, e.code());
|
||||||
|
ASSERT_STREQ("This does not look like a BMP image", e.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(BmpImage, readMetadataThrowsWhenThereIsNotEnoughInfoToRead)
|
||||||
|
{
|
||||||
|
const std::array<unsigned char, 1> header{'B'};
|
||||||
|
auto memIo = std::make_unique<MemIo>(header.data(), static_cast<long>(header.size()));
|
||||||
|
BmpImage bmp(std::move(memIo));
|
||||||
|
try {
|
||||||
|
bmp.readMetadata();
|
||||||
|
FAIL();
|
||||||
|
} catch (const Exiv2::Error& e) {
|
||||||
|
ASSERT_EQ(kerFailedToReadImageData, e.code());
|
||||||
|
ASSERT_STREQ("Failed to read image data", e.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TEST(BmpImage, readMetadataThrowsWhenIoCannotBeOpened)
|
||||||
|
{
|
||||||
|
auto fileIo = std::make_unique<FileIo>("NonExistingPath.png");
|
||||||
|
BmpImage bmp(std::move(fileIo));
|
||||||
|
try {
|
||||||
|
bmp.readMetadata();
|
||||||
|
FAIL();
|
||||||
|
} catch (const Exiv2::Error& e) {
|
||||||
|
ASSERT_EQ(kerDataSourceOpenFailed, e.code());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(newBmpInstance, createsValidInstace)
|
||||||
|
{
|
||||||
|
const std::array<unsigned char, 14> bitmapHeader{
|
||||||
|
'B', 'M', // Signature
|
||||||
|
0x4E, 0x47, 0x0D, 0x0A, // Size of the BMP file in bytes
|
||||||
|
0x1A, 0x0A, // Reserved
|
||||||
|
0x00, 0x00, // Reserved
|
||||||
|
0x00, 0x00, 0x00, 0x00 // Offset of the byte where the bitmap image data can be found
|
||||||
|
};
|
||||||
|
auto memIo = std::make_unique<MemIo>(bitmapHeader.data(), static_cast<long>(bitmapHeader.size()));
|
||||||
|
auto img = newBmpInstance(std::move(memIo), false);
|
||||||
|
ASSERT_TRUE(img->good());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(newBmpInstance, createsInvalidInstaceWithNonExistingFilePath)
|
||||||
|
{
|
||||||
|
auto fileIo = std::make_unique<FileIo>("NonExistingPath.png");
|
||||||
|
auto img = newBmpInstance(std::move(fileIo), false);
|
||||||
|
ASSERT_FALSE(img);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(isBmpType, withValidSignatureReturnsTrue)
|
||||||
|
{
|
||||||
|
const std::array<unsigned char, 14> bitmapHeader{
|
||||||
|
'B', 'M', // Signature
|
||||||
|
0x4E, 0x47, 0x0D, 0x0A, // Size of the BMP file in bytes
|
||||||
|
0x1A, 0x0A, // Reserved
|
||||||
|
0x00, 0x00, // Reserved
|
||||||
|
0x00, 0x00, 0x00, 0x00 // Offset of the byte where the bitmap image data can be found
|
||||||
|
};
|
||||||
|
MemIo memIo(bitmapHeader.data(), static_cast<long>(bitmapHeader.size()));
|
||||||
|
ASSERT_TRUE(isBmpType(memIo, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(isBmpType, withInvalidSignatureReturnsFalse)
|
||||||
|
{
|
||||||
|
const std::array<unsigned char, 14> bitmapHeader{
|
||||||
|
'B', 'A', // Signature
|
||||||
|
0x4E, 0x47, 0x0D, 0x0A, // Size of the BMP file in bytes
|
||||||
|
0x1A, 0x0A, // Reserved
|
||||||
|
0x00, 0x00, // Reserved
|
||||||
|
0x00, 0x00, 0x00, 0x00 // Offset of the byte where the bitmap image data can be found
|
||||||
|
};
|
||||||
|
MemIo memIo(bitmapHeader.data(), static_cast<long>(bitmapHeader.size()));
|
||||||
|
ASSERT_FALSE(isBmpType(memIo, false));
|
||||||
|
}
|
@ -0,0 +1,218 @@
|
|||||||
|
#include <gmock/gmock.h>
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include <exiv2/datasets.hpp>
|
||||||
|
#include <exiv2/error.hpp>
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
using namespace Exiv2;
|
||||||
|
using ::testing::StartsWith;
|
||||||
|
|
||||||
|
TEST(IptcDataSets, dataSetName_returnsValidNamesWhenRequestingNumbersAvailableInEnvelopeRecord)
|
||||||
|
{
|
||||||
|
ASSERT_EQ("ModelVersion", IptcDataSets::dataSetName(IptcDataSets::ModelVersion, IptcDataSets::envelope));
|
||||||
|
ASSERT_EQ("Destination", IptcDataSets::dataSetName(IptcDataSets::Destination, IptcDataSets::envelope));
|
||||||
|
ASSERT_EQ("FileFormat", IptcDataSets::dataSetName(IptcDataSets::FileFormat, IptcDataSets::envelope));
|
||||||
|
ASSERT_EQ("FileVersion", IptcDataSets::dataSetName(IptcDataSets::FileVersion, IptcDataSets::envelope));
|
||||||
|
ASSERT_EQ("ServiceId", IptcDataSets::dataSetName(IptcDataSets::ServiceId, IptcDataSets::envelope));
|
||||||
|
ASSERT_EQ("EnvelopeNumber", IptcDataSets::dataSetName(IptcDataSets::EnvelopeNumber, IptcDataSets::envelope));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(IptcDataSets, dataSetName_returnsValidNamesWhenRequestingNumbersAvailableInApplicationRecord)
|
||||||
|
{
|
||||||
|
ASSERT_EQ("ObjectType", IptcDataSets::dataSetName(IptcDataSets::ObjectType, IptcDataSets::application2));
|
||||||
|
ASSERT_EQ("ObjectAttribute", IptcDataSets::dataSetName(IptcDataSets::ObjectAttribute, IptcDataSets::application2));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(IptcDataSets, dataSetName_returnsWrongNamesWhenRequestingNumbersNotAvailableInEnvelopeRecord)
|
||||||
|
{
|
||||||
|
ASSERT_EQ("0x0003", IptcDataSets::dataSetName(IptcDataSets::ObjectType, IptcDataSets::envelope));
|
||||||
|
ASSERT_EQ("0x0004", IptcDataSets::dataSetName(IptcDataSets::ObjectAttribute, IptcDataSets::envelope));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(IptcDataSets, dataSetTitle_returnsValidTitleWhenRequestingNumbersAvailableInRecord)
|
||||||
|
{
|
||||||
|
ASSERT_STREQ("Model Version", IptcDataSets::dataSetTitle(IptcDataSets::ModelVersion, IptcDataSets::envelope));
|
||||||
|
ASSERT_STREQ("Destination", IptcDataSets::dataSetTitle(IptcDataSets::Destination, IptcDataSets::envelope));
|
||||||
|
ASSERT_STREQ("File Format", IptcDataSets::dataSetTitle(IptcDataSets::FileFormat, IptcDataSets::envelope));
|
||||||
|
|
||||||
|
ASSERT_STREQ("Object Type", IptcDataSets::dataSetTitle(IptcDataSets::ObjectType, IptcDataSets::application2));
|
||||||
|
ASSERT_STREQ("Object Attribute",
|
||||||
|
IptcDataSets::dataSetTitle(IptcDataSets::ObjectAttribute, IptcDataSets::application2));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(IptcDataSets, dataSetTitle_returnsUnknownStringWhenRequestingNumbersNotAvailableInEnvelopeRecord)
|
||||||
|
{
|
||||||
|
ASSERT_STREQ("Unknown dataset", IptcDataSets::dataSetTitle(IptcDataSets::ObjectType, IptcDataSets::envelope));
|
||||||
|
ASSERT_STREQ("Unknown dataset", IptcDataSets::dataSetTitle(IptcDataSets::ObjectAttribute, IptcDataSets::envelope));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unfortunately, some constants such as ModelVersion, Destination or FileFormat has the same values as other constants
|
||||||
|
// available for other records (RecordVersion, ObjectName & SuppCategory respectively)
|
||||||
|
|
||||||
|
// TEST(IptcDataSets, dataSetTitle_returnsUnknownStringWhenRequestingNumbersNotAvailableInApplicationRecord)
|
||||||
|
//{
|
||||||
|
// ASSERT_STREQ("Unknown dataset", IptcDataSets::dataSetTitle(IptcDataSets::ModelVersion, IptcDataSets::application2));
|
||||||
|
// ASSERT_STREQ("Unknown dataset", IptcDataSets::dataSetTitle(IptcDataSets::Destination, IptcDataSets::application2));
|
||||||
|
// ASSERT_STREQ("Unknown dataset", IptcDataSets::dataSetTitle(IptcDataSets::FileFormat, IptcDataSets::application2));
|
||||||
|
//}
|
||||||
|
|
||||||
|
TEST(IptcDataSets, dataSetTitle_returnsUnknownStringWhenRequestingNumbersNotAvailableInApplicationRecord)
|
||||||
|
{
|
||||||
|
ASSERT_STREQ("Unknown dataset", IptcDataSets::dataSetTitle(1, IptcDataSets::envelope));
|
||||||
|
ASSERT_STREQ("Unknown dataset", IptcDataSets::dataSetTitle(2, IptcDataSets::envelope));
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------
|
||||||
|
|
||||||
|
TEST(IptcDataSets, dataSetDescription_returnsValidDescriptionWhenRequestingNumbersAvailableInRecord)
|
||||||
|
{
|
||||||
|
ASSERT_THAT(IptcDataSets::dataSetDesc(IptcDataSets::ModelVersion, IptcDataSets::envelope),
|
||||||
|
StartsWith("A binary number identifying the version of the Information Interchange Model"));
|
||||||
|
ASSERT_THAT(IptcDataSets::dataSetDesc(IptcDataSets::FileFormat, IptcDataSets::envelope),
|
||||||
|
StartsWith("A binary number representing the file format. The file format must be registered with"));
|
||||||
|
|
||||||
|
ASSERT_THAT(IptcDataSets::dataSetDesc(IptcDataSets::RecordVersion, IptcDataSets::application2),
|
||||||
|
StartsWith("A binary number identifying the version of the Information Interchange Model"));
|
||||||
|
ASSERT_THAT(IptcDataSets::dataSetDesc(IptcDataSets::ObjectType, IptcDataSets::application2),
|
||||||
|
StartsWith("The Object Type is used to distinguish between different types of objects within the IIM"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(IptcDataSets, dataSetDescription_returnsUnknownStringWhenRequestingNumbersNotAvailableInRecord)
|
||||||
|
{
|
||||||
|
ASSERT_STREQ("Unknown dataset", IptcDataSets::dataSetDesc(1, IptcDataSets::envelope));
|
||||||
|
ASSERT_STREQ("Unknown dataset", IptcDataSets::dataSetDesc(2, IptcDataSets::envelope));
|
||||||
|
|
||||||
|
ASSERT_STREQ("Unknown dataset", IptcDataSets::dataSetDesc(1, IptcDataSets::application2));
|
||||||
|
ASSERT_STREQ("Unknown dataset", IptcDataSets::dataSetDesc(2, IptcDataSets::application2));
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------
|
||||||
|
|
||||||
|
TEST(IptcDataSets, dataSetPsName_returnsValidPsNameWhenRequestingNumbersAvailableInRecord)
|
||||||
|
{
|
||||||
|
ASSERT_STREQ("", IptcDataSets::dataSetPsName(IptcDataSets::FileFormat, IptcDataSets::envelope));
|
||||||
|
|
||||||
|
ASSERT_STREQ("Document Title", IptcDataSets::dataSetPsName(IptcDataSets::ObjectName, IptcDataSets::application2));
|
||||||
|
ASSERT_STREQ("Urgency", IptcDataSets::dataSetPsName(IptcDataSets::Urgency, IptcDataSets::application2));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(IptcDataSets, dataSetPsName_returnsUnknownStringWhenRequestingNumbersNotAvailableInRecord)
|
||||||
|
{
|
||||||
|
ASSERT_STREQ("Unknown dataset", IptcDataSets::dataSetPsName(1, IptcDataSets::envelope));
|
||||||
|
ASSERT_STREQ("Unknown dataset", IptcDataSets::dataSetPsName(2, IptcDataSets::envelope));
|
||||||
|
|
||||||
|
ASSERT_STREQ("Unknown dataset", IptcDataSets::dataSetPsName(1, IptcDataSets::application2));
|
||||||
|
ASSERT_STREQ("Unknown dataset", IptcDataSets::dataSetPsName(2, IptcDataSets::application2));
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------
|
||||||
|
|
||||||
|
TEST(IptcDataSets, dataSetRepeatable_returnsExpectedValueNameWhenRequestingNumbersAvailableInRecord)
|
||||||
|
{
|
||||||
|
ASSERT_TRUE(IptcDataSets::dataSetRepeatable(IptcDataSets::Destination, IptcDataSets::envelope));
|
||||||
|
ASSERT_FALSE(IptcDataSets::dataSetRepeatable(IptcDataSets::FileFormat, IptcDataSets::envelope));
|
||||||
|
|
||||||
|
ASSERT_FALSE(IptcDataSets::dataSetRepeatable(IptcDataSets::ObjectType, IptcDataSets::application2));
|
||||||
|
ASSERT_TRUE(IptcDataSets::dataSetRepeatable(IptcDataSets::ObjectAttribute, IptcDataSets::application2));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// \todo check if we want to return true in this case or throw an exception ...
|
||||||
|
TEST(IptcDataSets, dataSetRepeatable_returnsTrueWhenRequestingNumbersNotAvailableInRecord)
|
||||||
|
{
|
||||||
|
ASSERT_TRUE(IptcDataSets::dataSetRepeatable(1, IptcDataSets::envelope));
|
||||||
|
ASSERT_TRUE(IptcDataSets::dataSetRepeatable(2, IptcDataSets::envelope));
|
||||||
|
|
||||||
|
ASSERT_TRUE(IptcDataSets::dataSetRepeatable(1, IptcDataSets::application2));
|
||||||
|
ASSERT_TRUE(IptcDataSets::dataSetRepeatable(2, IptcDataSets::application2));
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------
|
||||||
|
|
||||||
|
TEST(IptcDataSets, dataSet_returnsExpectedValueWhenRequestingValidDatasetName)
|
||||||
|
{
|
||||||
|
ASSERT_EQ(IptcDataSets::ModelVersion, IptcDataSets::dataSet("ModelVersion", IptcDataSets::envelope));
|
||||||
|
ASSERT_EQ(IptcDataSets::FileFormat, IptcDataSets::dataSet("FileFormat", IptcDataSets::envelope));
|
||||||
|
|
||||||
|
ASSERT_EQ(IptcDataSets::RecordVersion, IptcDataSets::dataSet("RecordVersion", IptcDataSets::application2));
|
||||||
|
ASSERT_EQ(IptcDataSets::FixtureId, IptcDataSets::dataSet("FixtureId", IptcDataSets::application2));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(IptcDataSets, dataSet_throwWithNonExistingDatasetName)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
IptcDataSets::dataSet("NonExistingName", IptcDataSets::envelope);
|
||||||
|
FAIL();
|
||||||
|
} catch (const Exiv2::Error& e) {
|
||||||
|
ASSERT_EQ(kerInvalidDataset, e.code());
|
||||||
|
ASSERT_STREQ("Invalid dataset name 'NonExistingName'", e.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// \todo Weird error reporting here. It should indicate that the record specified does not exist
|
||||||
|
TEST(IptcDataSets, dataSet_throwWithNonExistingRecordId)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
IptcDataSets::dataSet("ModelVersion", 5);
|
||||||
|
FAIL();
|
||||||
|
} catch (const Exiv2::Error& e) {
|
||||||
|
ASSERT_EQ(kerInvalidDataset, e.code());
|
||||||
|
ASSERT_STREQ("Invalid dataset name 'ModelVersion'", e.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------
|
||||||
|
|
||||||
|
TEST(IptcDataSets, dataSetType_returnsExpectedTypeWhenRequestingValidDataset)
|
||||||
|
{
|
||||||
|
ASSERT_EQ(unsignedShort, IptcDataSets::dataSetType(IptcDataSets::ModelVersion, IptcDataSets::envelope));
|
||||||
|
ASSERT_EQ(Exiv2::string, IptcDataSets::dataSetType(IptcDataSets::Destination, IptcDataSets::envelope));
|
||||||
|
|
||||||
|
ASSERT_EQ(unsignedShort, IptcDataSets::dataSetType(IptcDataSets::RecordVersion, IptcDataSets::application2));
|
||||||
|
ASSERT_EQ(Exiv2::string, IptcDataSets::dataSetType(IptcDataSets::ObjectType, IptcDataSets::application2));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// \todo probably better to throw exception here?
|
||||||
|
TEST(IptcDataSets, dataSetType_returnsStringTypeWhenRecordIdDoesNotExist)
|
||||||
|
{
|
||||||
|
ASSERT_EQ(Exiv2::string, IptcDataSets::dataSetType(1, 5));
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------
|
||||||
|
|
||||||
|
TEST(IptcDataSets, recordName_returnsExpectedNameWhenRequestingValidRecordId)
|
||||||
|
{
|
||||||
|
ASSERT_EQ("Envelope", IptcDataSets::recordName(IptcDataSets::envelope));
|
||||||
|
ASSERT_EQ("Application2", IptcDataSets::recordName(IptcDataSets::application2));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(IptcDataSets, recordName_returnsHexStringWhenRecordIdDoesNotExist)
|
||||||
|
{
|
||||||
|
ASSERT_EQ("0x0000", IptcDataSets::recordName(0));
|
||||||
|
ASSERT_EQ("0x0003", IptcDataSets::recordName(3));
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------
|
||||||
|
|
||||||
|
TEST(IptcDataSets, recordDesc_returnsExpectedDescriptionWhenRequestingValidRecordId)
|
||||||
|
{
|
||||||
|
ASSERT_STREQ("IIM envelope record", IptcDataSets::recordDesc(IptcDataSets::envelope));
|
||||||
|
ASSERT_STREQ("IIM application record 2", IptcDataSets::recordDesc(IptcDataSets::application2));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(IptcDataSets, recordDesc_)
|
||||||
|
{
|
||||||
|
ASSERT_STREQ("Unknown dataset", IptcDataSets::recordDesc(0));
|
||||||
|
ASSERT_STREQ("Unknown dataset", IptcDataSets::recordDesc(3));
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------
|
||||||
|
|
||||||
|
TEST(IptcDataSets, dataSetLists_printDatasetsIntoOstream)
|
||||||
|
{
|
||||||
|
std::ostringstream stream;
|
||||||
|
ASSERT_NO_THROW(IptcDataSets::dataSetList(stream));
|
||||||
|
ASSERT_FALSE(stream.str().empty());
|
||||||
|
}
|
Loading…
Reference in New Issue