diff --git a/include/exiv2/bmpimage.hpp b/include/exiv2/bmpimage.hpp index 2dd03010..abd0ccf5 100644 --- a/include/exiv2/bmpimage.hpp +++ b/include/exiv2/bmpimage.hpp @@ -84,20 +84,11 @@ namespace Exiv2 { yet(?) implemented. Calling it will throw an Error(kerWritingImageFormatUnsupported). */ void writeMetadata() override; - /*! - @brief Todo: Not supported yet(?). Calling this function will throw - an instance of Error(kerInvalidSettingForImage). - */ + void setExifData(const ExifData& exifData) override; - /*! - @brief Todo: Not supported yet(?). Calling this function will throw - an instance of Error(kerInvalidSettingForImage). - */ + void setIptcData(const IptcData& iptcData) override; - /*! - @brief Not supported. Calling this function will throw an instance - of Error(kerInvalidSettingForImage). - */ + void setComment(const std::string& comment) override; //@} diff --git a/src/bmpimage.cpp b/src/bmpimage.cpp index 8c2f5f09..1aff6991 100644 --- a/src/bmpimage.cpp +++ b/src/bmpimage.cpp @@ -47,24 +47,22 @@ namespace Exiv2 std::string BmpImage::mimeType() const { - return "image/x-ms-bmp"; + // "image/bmp" is a Generic Bitmap + return "image/x-ms-bmp"; // Microsoft Bitmap } void BmpImage::setExifData(const ExifData& /*exifData*/) { - // Todo: implement me! throw(Error(kerInvalidSettingForImage, "Exif metadata", "BMP")); } void BmpImage::setIptcData(const IptcData& /*iptcData*/) { - // Todo: implement me! throw(Error(kerInvalidSettingForImage, "IPTC metadata", "BMP")); } void BmpImage::setComment(const std::string& /*comment*/) { - // not supported throw(Error(kerInvalidSettingForImage, "Image comment", "BMP")); } @@ -77,9 +75,11 @@ namespace Exiv2 throw Error(kerDataSourceOpenFailed, io_->path(), strError()); } IoCloser closer(*io_); + // Ensure that this is the correct image type if (!isBmpType(*io_, false)) { - if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData); + if (io_->error() || io_->eof()) + throw Error(kerFailedToReadImageData); throw Error(kerNotAnImage, "BMP"); } clearMetadata(); diff --git a/unitTests/CMakeLists.txt b/unitTests/CMakeLists.txt index 1933c922..375f9820 100644 --- a/unitTests/CMakeLists.txt +++ b/unitTests/CMakeLists.txt @@ -2,6 +2,7 @@ find_package(GTest REQUIRED) add_executable(unit_tests mainTestRunner.cpp + test_bmpimage.cpp test_DateValue.cpp test_TimeValue.cpp test_XmpKey.cpp diff --git a/unitTests/test_bmpimage.cpp b/unitTests/test_bmpimage.cpp new file mode 100644 index 00000000..92865de6 --- /dev/null +++ b/unitTests/test_bmpimage.cpp @@ -0,0 +1,21 @@ +#include + +#include + +#include + +using namespace Exiv2; + +TEST(BmpImage, canBeOpenedWithEmptyMemIo) +{ + auto memIo = std::make_unique(); + ASSERT_NO_THROW(BmpImage bmp(std::move(memIo))); +} + +TEST(BmpImage, mimeTypeIsBmp) +{ + auto memIo = std::make_unique(); + BmpImage bmp(std::move(memIo)); + + ASSERT_EQ("image/x-ms-bmp", bmp.mimeType()); +} diff --git a/unitTests/test_pngimage.cpp b/unitTests/test_pngimage.cpp index ccdbb893..51b7c61f 100644 --- a/unitTests/test_pngimage.cpp +++ b/unitTests/test_pngimage.cpp @@ -158,6 +158,14 @@ TEST(PngImage, cannotWriteMetadataToEmptyIo) } } +TEST(PngImage, canWriteMetadataFromCreatedPngImage) +{ + auto memIo = std::make_unique(); + const bool create {true}; + PngImage png(std::move(memIo), create); + ASSERT_NO_THROW(png.writeMetadata()); +} + TEST(PngImage, cannotWriteMetadataToIoWhichCannotBeOpened) { auto memIo = std::make_unique("NonExistingPath.png");