From ce1d4cfc754f077400e1a28e61e3a742ae9d5114 Mon Sep 17 00:00:00 2001 From: Robin Mills Date: Mon, 20 Apr 2015 18:07:25 +0000 Subject: [PATCH] #1058. Calming the test suite. LangAltValue comparator causes harmless changes in order of lang reporting. --- src/value.cpp | 24 +++++++++++++++--------- src/xmp.cpp | 29 ++++++++++++----------------- test/data/conversions.out | 2 +- test/data/xmpparser-test.out | 10 +++++----- 4 files changed, 33 insertions(+), 32 deletions(-) diff --git a/src/value.cpp b/src/value.cpp index eb0bac8e..5ac34573 100644 --- a/src/value.cpp +++ b/src/value.cpp @@ -847,27 +847,33 @@ namespace Exiv2 { return static_cast(value_.size()); } + static const std::string x_default = "x-default"; + std::ostream& LangAltValue::write(std::ostream& os) const { - bool first = true; + bool first = true; + // Write the default entry first - ValueType::const_iterator i = value_.find("x-default"); + ValueType::const_iterator i = value_.find(x_default); if (i != value_.end()) { os << "lang=\"" << i->first << "\" " << i->second; first = false; } + + // Write the others for (i = value_.begin(); i != value_.end(); ++i) { - if (i->first == "x-default") continue; - if (!first) os << ", "; - os << "lang=\"" << i->first << "\" " << i->second; - first = false; + if (i->first != x_default ) { + if (!first) os << ", "; + os << "lang=\"" << i->first << "\" " << i->second; + first = false; + } } return os; } std::string LangAltValue::toString(long /*n*/) const { - return toString("x-default"); + return toString(x_default); } std::string LangAltValue::toString(const std::string& qualifier) const @@ -1009,8 +1015,8 @@ namespace Exiv2 { os << date_.year << '-' << std::right << std::setw(2) << std::setfill('0') << date_.month << '-' << std::setw(2) << std::setfill('0') << date_.day; - os.flags(f); - return os; + os.flags(f); + return os; } long DateValue::toLong(long /*n*/) const diff --git a/src/xmp.cpp b/src/xmp.cpp index baa006eb..7075667e 100644 --- a/src/xmp.cpp +++ b/src/xmp.cpp @@ -403,9 +403,9 @@ namespace Exiv2 { xmpLockFct_ = xmpLockFct; pLockData_ = pLockData; initialized_ = SXMPMeta::Initialize(); - SXMPMeta::RegisterNamespace("http://ns.adobe.com/lightroom/1.0/", "lr"); - SXMPMeta::RegisterNamespace("http://rs.tdwg.org/dwc/index.htm", "dwc"); - SXMPMeta::RegisterNamespace("http://purl.org/dc/terms/", "dcterms"); + SXMPMeta::RegisterNamespace("http://ns.adobe.com/lightroom/1.0/", "lr"); + SXMPMeta::RegisterNamespace("http://rs.tdwg.org/dwc/index.htm", "dwc"); + SXMPMeta::RegisterNamespace("http://purl.org/dc/terms/", "dcterms"); SXMPMeta::RegisterNamespace("http://www.digikam.org/ns/1.0/", "digiKam"); SXMPMeta::RegisterNamespace("http://www.digikam.org/ns/kipi/1.0/", "kipi"); SXMPMeta::RegisterNamespace("http://ns.microsoft.com/photo/1.0/", "MicrosoftPhoto"); @@ -417,9 +417,9 @@ namespace Exiv2 { SXMPMeta::RegisterNamespace("http://ns.microsoft.com/photo/1.2/t/RegionInfo#", "MPRI"); SXMPMeta::RegisterNamespace("http://ns.microsoft.com/photo/1.2/t/Region#", "MPReg"); SXMPMeta::RegisterNamespace("http://www.metadataworkinggroup.com/schemas/regions/", "mwg-rs"); - SXMPMeta::RegisterNamespace("http://www.metadataworkinggroup.com/schemas/keywords/", "mwg-kw"); + SXMPMeta::RegisterNamespace("http://www.metadataworkinggroup.com/schemas/keywords/", "mwg-kw"); SXMPMeta::RegisterNamespace("http://ns.adobe.com/xmp/sType/Area#", "stArea"); - + #else initialized_ = true; #endif @@ -659,22 +659,16 @@ namespace Exiv2 { XMP_OptionBits options = 0; if (i->typeId() == langAlt) { + // Encode Lang Alt property const LangAltValue* la = dynamic_cast(&i->value()); if (la == 0) throw Error(43, i->key()); + int idx = 1; - // write the default first - LangAltValue::ValueType::const_iterator k = la->value_.find("x-default"); - if (k != la->value_.end()) { -#ifdef DEBUG - printNode(ns, i->tagName(), k->second, 0); -#endif - meta.AppendArrayItem(ns.c_str(), i->tagName().c_str(), kXMP_PropArrayIsAlternate, k->second.c_str()); - const std::string item = i->tagName() + "[" + toString(idx++) + "]"; - meta.SetQualifier(ns.c_str(), item.c_str(), kXMP_NS_XML, "lang", k->first.c_str()); - } - for (k = la->value_.begin(); k != la->value_.end(); ++k) { - if (k->first == "x-default") continue; + for ( LangAltValue::ValueType::const_iterator k = la->value_.begin() + ; k != la->value_.end() + ; ++k + ) { #ifdef DEBUG printNode(ns, i->tagName(), k->second, 0); #endif @@ -684,6 +678,7 @@ namespace Exiv2 { } continue; } + // Todo: Xmpdatum should have an XmpValue, not a Value const XmpValue* val = dynamic_cast(&i->value()); if (val == 0) throw Error(52, i->key(), i->typeName()); diff --git a/test/data/conversions.out b/test/data/conversions.out index f4041c05..1fe627d8 100644 --- a/test/data/conversions.out +++ b/test/data/conversions.out @@ -23,7 +23,7 @@ Testcase 4 ========== Warning: Failed to convert Xmp.dc.description to Iptc.Application2.Caption Warning: Failed to convert Xmp.dc.description to Exif.Image.ImageDescription -Xmp.dc.description LangAlt 2 lang="de-DE" The Exif image description, lang="it-IT" Ciao bella +Xmp.dc.description LangAlt 2 lang="it-IT" Ciao bella, lang="de-DE" The Exif image description File 1/1: k.jpg k.jpg: (No Exif data found in the file) File 1/1: k.jpg diff --git a/test/data/xmpparser-test.out b/test/data/xmpparser-test.out index 3816d315..de9b06f5 100644 --- a/test/data/xmpparser-test.out +++ b/test/data/xmpparser-test.out @@ -32,10 +32,10 @@ Xmp.exif.NativeDigest XmpText 414 36864,40960,40961,37 < --- > -35d34 -< Blue Square Test File - .jpg -37a37 -> Blue Square Test File - .jpg +34a35 +> Blaues Quadrat Test Datei - .jpg +37d37 +< Blaues Quadrat Test Datei - .jpg -----> Decoding XMP data read from StaffPhotographer-Example.xmp <----- Xmp.iptc.IntellectualGenre XmpText 7 Profile Xmp.iptc.Location XmpText 17 Moore family farm @@ -372,8 +372,8 @@ Xmp.iptc.CreatorContactInfo/Iptc4xmpCore:CiUrlWork XmpText 20 http://www.exi - TIFF image description TIFF Bildbeschreibung + TIFF image description