diff --git a/src/Makefile b/src/Makefile index 17580827..1b2cd54f 100644 --- a/src/Makefile +++ b/src/Makefile @@ -20,7 +20,7 @@ # 02111-1307, USA. # # File: Makefile -# Version: $Name: $ $Revision: 1.26 $ +# Version: $Name: $ $Revision: 1.27 $ # Author(s): Andreas Huggel (ahu) # History: 10-Dec-03, ahu: created # @@ -56,7 +56,7 @@ CCSRC = canonmn.cpp exif.cpp fujimn.cpp ifd.cpp image.cpp makernote.cpp \ # Add source files of simple applications to this list BINSRC = addmoddel.cpp exifcomment.cpp exifprint.cpp ifd-test.cpp \ - makernote-test.cpp taglist.cpp write-test.cpp + makernote-test.cpp taglist.cpp write-test.cpp write2-test.cpp # State the main source file of the Exiv2 application here EXIV2MAIN = exiv2.cpp diff --git a/src/write2-test.cpp b/src/write2-test.cpp new file mode 100644 index 00000000..2d51639c --- /dev/null +++ b/src/write2-test.cpp @@ -0,0 +1,117 @@ +// ***************************************************************** -*- C++ -*- +/* + Abstract : ExifData write unit tests for Exif data created from scratch + + File : write2-test.cpp + Version : $Name: $ $Revision: 1.1 $ + Author(s): Andreas Huggel (ahu) + History : 26-Jun-04, ahu: created + + */ +// ***************************************************************************** +// included header files +#include "exif.hpp" +#include +#include +#include + +void write(const std::string& file, Exiv2::ExifData& ed); +void print(const std::string& file); + +// ***************************************************************************** +// Main +int main(int argc, char* const argv[]) +{ +try { + if (argc != 2) { + std::cout << "Usage: " << argv[0] << " file\n"; + return 1; + } + std::string file(argv[1]); + + std::cout <<"----- One IFD0 tag\n"; + Exiv2::ExifData ed1; + Exiv2::Metadatum md1("Image.OtherTags.Model"); + md1.setValue("Test 1"); + ed1.add(md1); + write(file, ed1); + print(file); + + std::cout <<"\n----- One Exif tag\n"; + Exiv2::ExifData ed2; + Exiv2::Metadatum md2("Image.DateTime.DateTimeOriginal"); + md2.setValue("Test 2"); + ed2.add(md2); + write(file, ed2); + print(file); + + // Todo: One Makernote tag for each Makernote + + std::cout <<"\n----- One IOP tag\n"; + Exiv2::ExifData ed3; + Exiv2::Metadatum md3("Image.Interoperability.InteroperabilityVersion"); + md3.setValue("Test 3"); + ed3.add(md3); + write(file, ed3); + print(file); + + std::cout <<"\n----- One GPS tag\n"; + Exiv2::ExifData ed4; + Exiv2::Metadatum md4("Image.GPS.GPSVersionID"); + md4.setValue("Test 4"); + ed4.add(md4); + write(file, ed4); + print(file); + + // Todo: Fix this + std::cout <<"\n----- One IFD1 tag\n"; + Exiv2::ExifData ed5; + Exiv2::Metadatum md5("Thumbnail.OtherTags.Artist"); + md5.setValue("Test 5"); + ed5.add(md5); + + Exiv2::Metadatum md6("Image.OtherTags.Model"); + md6.setValue("Test 1"); + ed5.add(md6); + + write(file, ed5); + print(file); + + return 0; +} +catch (Exiv2::Error& e) { + std::cout << "Caught Exiv2 exception '" << e << "'\n"; + return -1; +} +} + +void write(const std::string& file, Exiv2::ExifData& ed) +{ + int rc = ed.write(file); + if (rc) { + std::string error = Exiv2::ExifData::strError(rc, file); + throw Exiv2::Error(error); + } +} + +void print(const std::string& file) +{ + Exiv2::ExifData ed; + int rc = ed.read(file); + if (rc) { + std::string error = Exiv2::ExifData::strError(rc, file); + throw Exiv2::Error(error); + } + + Exiv2::ExifData::const_iterator end = ed.end(); + for (Exiv2::ExifData::const_iterator i = ed.begin(); i != end; ++i) { + std::cout << std::setw(53) << std::setfill(' ') << std::left + << i->key() << " " + << std::setw(12) << std::setfill(' ') << std::left + << i->ifdName() << " " + << "0x" << std::setw(4) << std::setfill('0') << std::right + << std::hex << i->tag() << " " + << std::dec << i->value() + << "\n"; + } +}