1
// ***************************************************************** -*- C++ -*-
3
Abstract : ExifData assignment and copy construction unit tests
5
File : exifdata-test.cpp
7
Author(s): Andreas Huggel (ahu) <ahuggel@gmx.net>
8
History : 20-Feb-05, ahu: created
11
// *****************************************************************************
12
// included header files
20
void write(const std::string& file, Exiv2::ExifData& ed);
21
void print(const std::string& file);
23
// *****************************************************************************
25
int main(int argc, char* const argv[])
29
std::cout << "Usage: " << argv[0] << " file\n";
32
std::string file(argv[1]);
34
Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(file);
35
assert (image.get() != 0);
36
image->readMetadata();
38
Exiv2::ExifData &ed = image->exifData();
40
std::string error = file + ": No Exif data found in the file";
41
throw Exiv2::Error(1, error);
44
std::cout << "Copy construction, non-intrusive changes\n";
45
Exiv2::ExifData ed1(ed);
46
ed1["Exif.Image.DateTime"] = "Sunday, 11am";
47
ed1["Exif.Image.Orientation"] = uint16_t(2);
48
ed1["Exif.Photo.DateTimeOriginal"] = "Sunday, 11am";
49
ed1["Exif.Photo.MeteringMode"] = uint16_t(1);
50
ed1["Exif.Iop.InteroperabilityIndex"] = "123";
51
// ed1["Exif.Thumbnail.Orientation"] = uint16_t(2);
54
std::cout << "----------------------------------------------\n";
56
std::cout << "Copy construction, intrusive changes\n";
57
Exiv2::ExifData ed2(ed);
58
ed2["Exif.Image.DateTime"] = "Sunday, 11am and ten minutes";
59
ed2["Exif.Image.Orientation"] = "2 3 4 5";
60
ed2["Exif.Photo.DateTimeOriginal"] = "Sunday, 11am and ten minutes";
61
ed2["Exif.Photo.MeteringMode"] = "1 2 3 4 5 6";
62
ed2["Exif.Iop.InteroperabilityIndex"] = "1234";
63
ed2["Exif.Thumbnail.Orientation"] = "2 3 4 5 6";
66
std::cout << "----------------------------------------------\n";
68
std::cout << "Assignment, non-intrusive changes\n";
70
ed3["Exif.Iop.InteroperabilityVersion"] = "Test 6 Iop tag";
71
ed3["Exif.Thumbnail.Artist"] = "Test 6 Ifd1 tag";
73
ed3["Exif.Image.DateTime"] = "Sunday, 11am";
74
ed3["Exif.Image.Orientation"] = uint16_t(2);
75
ed3["Exif.Photo.DateTimeOriginal"] = "Sunday, 11am";
76
ed3["Exif.Photo.MeteringMode"] = uint16_t(1);
77
ed3["Exif.Iop.InteroperabilityIndex"] = "123";
78
// ed3["Exif.Thumbnail.Orientation"] = uint16_t(2);
81
std::cout << "----------------------------------------------\n";
83
std::cout << "Assignment, intrusive changes\n";
85
ed4["Exif.Iop.InteroperabilityVersion"] = "Test 6 Iop tag";
86
ed4["Exif.Thumbnail.Artist"] = "Test 6 Ifd1 tag";
88
ed4["Exif.Image.DateTime"] = "Sunday, 11am and ten minutes";
89
ed4["Exif.Image.Orientation"] = "2 3 4 5";
90
ed4["Exif.Photo.DateTimeOriginal"] = "Sunday, 11am and ten minutes";
91
ed4["Exif.Photo.MeteringMode"] = uint16_t(1);
92
ed4["Exif.Iop.InteroperabilityIndex"] = "123";
93
ed4["Exif.Thumbnail.Orientation"] = uint16_t(2);
99
catch (Exiv2::AnyError& e) {
100
std::cout << "Caught Exiv2 exception '" << e << "'\n";
105
void write(const std::string& file, Exiv2::ExifData& ed)
107
Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(file);
108
assert (image.get() != 0);
109
image->setExifData(ed);
110
image->writeMetadata();
113
void print(const std::string& file)
115
Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(file);
116
assert (image.get() != 0);
117
image->readMetadata();
119
Exiv2::ExifData &ed = image->exifData();
120
Exiv2::ExifData::const_iterator end = ed.end();
121
for (Exiv2::ExifData::const_iterator i = ed.begin(); i != end; ++i) {
122
std::cout << std::setw(45) << std::setfill(' ') << std::left
124
<< "0x" << std::setw(4) << std::setfill('0') << std::right
125
<< std::hex << i->tag() << " "
126
<< std::setw(12) << std::setfill(' ') << std::left
127
<< i->ifdName() << " "
128
<< std::setw(9) << std::setfill(' ') << std::left
129
<< i->typeName() << " "
130
<< std::dec << std::setw(3)
131
<< std::setfill(' ') << std::right
133
<< std::dec << i->value()