XMP.t 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. # Before "make install", this script should be runnable with "make test".
  2. # After "make install" it should work as "perl t/XMP.t".
  3. BEGIN { $| = 1; print "1..45\n"; $Image::ExifTool::noConfig = 1; }
  4. END {print "not ok 1\n" unless $loaded;}
  5. # definitions for user-defined tag test (#26)
  6. %Image::ExifTool::UserDefined = (
  7. 'Image::ExifTool::XMP::Main' => {
  8. myXMPns => {
  9. SubDirectory => {
  10. TagTable => 'Image::ExifTool::UserDefined::myXMPns',
  11. # (see the definition of this table below)
  12. },
  13. },
  14. },
  15. );
  16. use vars %Image::ExifTool::UserDefined::myXMPns; # avoid "typo" warning
  17. %Image::ExifTool::UserDefined::myXMPns = (
  18. GROUPS => { 0 => 'XMP', 1 => 'XMP-myXMPns'},
  19. NAMESPACE => { 'myXMPns' => 'http://ns.exiftool.ca/t/XMP.t' },
  20. WRITABLE => 'string',
  21. ATestTag => { List => 'Bag', Resource => 1 },
  22. BTestTag => {
  23. Struct => {
  24. TYPE => 'myXMPns:SomeFunnyType',
  25. Field1 => { Writable => 'lang-alt', List => 'Bag' },
  26. }
  27. },
  28. BTestTagField1 => { Name => 'Renamed', Flat => 1 },
  29. );
  30. # test 1: Load the module(s)
  31. use Image::ExifTool 'ImageInfo';
  32. use Image::ExifTool::XMP;
  33. $loaded = 1;
  34. print "ok 1\n";
  35. use t::TestLib;
  36. my $testname = 'XMP';
  37. my $testnum = 1;
  38. # test 2: Extract information from XMP.jpg
  39. {
  40. ++$testnum;
  41. my $exifTool = new Image::ExifTool;
  42. my $info = $exifTool->ImageInfo('t/images/XMP.jpg', {Duplicates => 1});
  43. print 'not ' unless check($exifTool, $info, $testname, $testnum);
  44. print "ok $testnum\n";
  45. }
  46. # test 3: Test rewriting everything with slightly different values
  47. {
  48. ++$testnum;
  49. my $exifTool = new Image::ExifTool;
  50. $exifTool->Options(Duplicates => 1, Binary => 1, List => 1);
  51. my $info = $exifTool->ImageInfo('t/images/XMP.jpg');
  52. my $tag;
  53. foreach $tag (keys %$info) {
  54. my $group = $exifTool->GetGroup($tag);
  55. my $val = $$info{$tag};
  56. if (ref $val eq 'ARRAY') {
  57. push @$val, 'v2';
  58. } elsif (ref $val eq 'SCALAR') {
  59. $val = 'v2';
  60. } elsif ($val =~ /^\d+(\.\d*)?$/) {
  61. # (add extra .001 to avoid problem with aperture of 4.85
  62. # getting rounded to 4.8 or 4.9 and causing failed tests)
  63. $val += ($val / 10) + 1.001;
  64. $1 or $val = int($val);
  65. } else {
  66. $val .= '-v2';
  67. }
  68. # eat return values so warning don't get printed
  69. my @x = $exifTool->SetNewValue($tag, $val, Group=>$group, Replace=>1);
  70. }
  71. # also try writing a few specific tags
  72. $exifTool->SetNewValue(CreatorCountry => 'Canada');
  73. $exifTool->SetNewValue(CodedCharacterSet => 'UTF8', Protected => 1);
  74. undef $info;
  75. my $image;
  76. my $ok = writeInfo($exifTool,'t/images/XMP.jpg',\$image);
  77. # this is effectively what the RHEL 3 UTF8 LANG problem does:
  78. # $image = pack("U*", unpack("C*", $image));
  79. my $exifTool2 = new Image::ExifTool;
  80. $exifTool2->Options(Duplicates => 1);
  81. $info = $exifTool2->ImageInfo(\$image);
  82. my $testfile = "t/${testname}_${testnum}_failed.jpg";
  83. if (check($exifTool2, $info, $testname, $testnum) and $ok) {
  84. unlink $testfile;
  85. } else {
  86. # save bad file
  87. open(TESTFILE,">$testfile");
  88. binmode(TESTFILE);
  89. print TESTFILE $image;
  90. close(TESTFILE);
  91. print 'not ';
  92. }
  93. print "ok $testnum\n";
  94. }
  95. # tests 4/5: Test extracting then reading XMP data as a block
  96. {
  97. ++$testnum;
  98. my $exifTool = new Image::ExifTool;
  99. my $info = $exifTool->ImageInfo('t/images/XMP.jpg','XMP');
  100. print 'not ' unless $$info{XMP};
  101. print "ok $testnum\n";
  102. ++$testnum;
  103. my $pass;
  104. if ($$info{XMP}) {
  105. $info = $exifTool->ImageInfo($$info{XMP});
  106. $pass = check($exifTool, $info, $testname, $testnum);
  107. }
  108. print 'not ' unless $pass;
  109. print "ok $testnum\n";
  110. }
  111. # test 6: Test copying information to a new XMP data file
  112. {
  113. ++$testnum;
  114. my $exifTool = new Image::ExifTool;
  115. $exifTool->SetNewValuesFromFile('t/images/XMP.jpg');
  116. my $testfile = "t/${testname}_${testnum}_failed.xmp";
  117. unlink $testfile;
  118. my $ok = writeInfo($exifTool,undef,$testfile);
  119. my $info = $exifTool->ImageInfo($testfile);
  120. if (check($exifTool, $info, $testname, $testnum) and $ok) {
  121. unlink $testfile;
  122. } else {
  123. print 'not ';
  124. }
  125. print "ok $testnum\n";
  126. }
  127. # test 7: Test rewriting CS2 XMP information
  128. {
  129. ++$testnum;
  130. my $exifTool = new Image::ExifTool;
  131. my $testfile = "t/${testname}_${testnum}_failed.xmp";
  132. unlink $testfile;
  133. $exifTool->SetNewValue(Label => 'Blue');
  134. $exifTool->SetNewValue(Rating => 3);
  135. $exifTool->SetNewValue(Subject => q{char test: & > < ' "}, AddValue => 1);
  136. $exifTool->SetNewValue('Rights' => "\xc2\xa9 Copyright Someone Else");
  137. my $ok = writeInfo($exifTool,'t/images/XMP.xmp',$testfile);
  138. print 'not ' unless testCompare("t/XMP_$testnum.out",$testfile,$testnum) and $ok;
  139. print "ok $testnum\n";
  140. }
  141. # test 8-11: Test reading/writing XMP with blank nodes and some problems that need correcting
  142. {
  143. my $file;
  144. foreach $file ('XMP2.xmp', 'XMP3.xmp') {
  145. ++$testnum;
  146. my $exifTool = new Image::ExifTool;
  147. my $info = $exifTool->ImageInfo("t/images/$file", {Duplicates => 1});
  148. print 'not ' unless check($exifTool, $info, $testname, $testnum);
  149. print "ok $testnum\n";
  150. ++$testnum;
  151. my $testfile = "t/${testname}_${testnum}_failed.xmp";
  152. unlink $testfile;
  153. $exifTool->SetNewValue('XMP:Creator' => 'Phil', AddValue => 1);
  154. $exifTool->SetNewValue('manifestplacedXResolution' => 1);
  155. $exifTool->SetNewValue('attributionname' => 'something else');
  156. $exifTool->WriteInfo("t/images/$file", $testfile);
  157. my $err = $exifTool->GetValue('Error');
  158. warn "\n $err\n" if $err;
  159. print 'not ' unless testCompare("t/XMP_$testnum.out",$testfile,$testnum);
  160. print "ok $testnum\n";
  161. }
  162. }
  163. # tests 12-17: Test writing/deleting XMP alternate languages
  164. {
  165. my @writeList = (
  166. [ ['Rights-x-default' => "\xc2\xa9 Copyright Another One"] ], # should overwrite x-default only
  167. [ ['Rights-de-DE' => "\xc2\xa9 Urheberrecht Phil Harvey"] ], # should create de-DE only
  168. [ ['Rights-x-default' => undef] ], # should delete x-default only
  169. [ ['Rights-fr' => undef] ], # should delete fr only
  170. [ ['Title-fr' => 'Test fr title'] ],# should not create x-default
  171. [ ['Title-fr' => 'Test fr title'],
  172. ['Title-x-default' => 'dTitle'] ],# should create x-default before fr
  173. );
  174. my $writeListRef;
  175. foreach $writeListRef (@writeList) {
  176. ++$testnum;
  177. my $exifTool = new Image::ExifTool;
  178. my $testfile = "t/${testname}_${testnum}_failed.xmp";
  179. unlink $testfile;
  180. print 'not ' unless writeCheck($writeListRef, $testname, $testnum,
  181. 't/images/XMP.xmp', ['XMP-dc:*']);
  182. print "ok $testnum\n";
  183. }
  184. }
  185. # test 18: Delete some family 1 XMP groups
  186. {
  187. ++$testnum;
  188. my @writeInfo = (
  189. [ 'xmp-xmpmm:all' => undef ],
  190. [ 'XMP-PHOTOSHOP:all' => undef ],
  191. );
  192. print 'not ' unless writeCheck(\@writeInfo, $testname, $testnum,
  193. 't/images/XMP.jpg', ['XMP:all']);
  194. print "ok $testnum\n";
  195. }
  196. # test 19-20: Copy from XMP to EXIF with and without PrintConv enabled
  197. {
  198. my $exifTool = new Image::ExifTool;
  199. while ($testnum < 20) {
  200. ++$testnum;
  201. my $testfile = "t/${testname}_${testnum}_failed.jpg";
  202. unlink $testfile;
  203. $exifTool->SetNewValue();
  204. $exifTool->SetNewValuesFromFile('t/images/XMP.xmp', 'XMP:all>EXIF:all');
  205. my $ok = writeInfo($exifTool, "t/images/Writer.jpg", $testfile);
  206. my $info = $exifTool->ImageInfo($testfile, 'EXIF:all');
  207. if (check($exifTool, $info, $testname, $testnum) and $ok) {
  208. unlink $testfile;
  209. } else {
  210. print 'not ';
  211. }
  212. print "ok $testnum\n";
  213. $exifTool->Options(PrintConv => 0);
  214. }
  215. }
  216. # test 21-22: Copy from EXIF to XMP with and without PrintConv enabled
  217. {
  218. my $exifTool = new Image::ExifTool;
  219. while ($testnum < 22) {
  220. ++$testnum;
  221. my $testfile = "t/${testname}_${testnum}_failed.xmp";
  222. unlink $testfile;
  223. $exifTool->SetNewValue();
  224. $exifTool->SetNewValuesFromFile('t/images/Canon.jpg', 'EXIF:* > XMP:*');
  225. my $ok = writeInfo($exifTool, undef, $testfile);
  226. my $info = $exifTool->ImageInfo($testfile, 'XMP:*');
  227. if (check($exifTool, $info, $testname, $testnum) and $ok) {
  228. unlink $testfile;
  229. } else {
  230. print 'not ';
  231. }
  232. print "ok $testnum\n";
  233. $exifTool->Options(PrintConv => 0);
  234. }
  235. }
  236. # test 23: Delete all tags except two specific XMP family 1 groups
  237. {
  238. ++$testnum;
  239. my @writeInfo = (
  240. [ 'all' => undef ],
  241. [ 'xmp-dc:all' => undef, Replace => 2 ],
  242. [ 'xmp-xmprights:all' => undef, Replace => 2 ],
  243. );
  244. print 'not ' unless writeCheck(\@writeInfo, $testname, $testnum,
  245. 't/images/XMP.jpg', ['XMP:all']);
  246. print "ok $testnum\n";
  247. }
  248. # test 24: Delete all tags except XMP
  249. {
  250. ++$testnum;
  251. my @writeInfo = (
  252. [ 'all' => undef ],
  253. [ 'xmp:all' => undef, Replace => 2 ],
  254. );
  255. print 'not ' unless writeCheck(\@writeInfo, $testname, $testnum,
  256. 't/images/XMP.jpg', ['-file:all']);
  257. print "ok $testnum\n";
  258. }
  259. # test 25: Extract information from SVG image
  260. {
  261. ++$testnum;
  262. my $exifTool = new Image::ExifTool;
  263. my $info = $exifTool->ImageInfo('t/images/XMP.svg', {Duplicates => 1});
  264. print 'not ' unless check($exifTool, $info, $testname, $testnum);
  265. print "ok $testnum\n";
  266. }
  267. # test 26: Test creating a variety of XMP information
  268. # (including x:xmptk, rdf:about and rdf:resource attributes)
  269. {
  270. ++$testnum;
  271. my $exifTool = new Image::ExifTool;
  272. my $testfile = "t/${testname}_${testnum}_failed.xmp";
  273. unlink $testfile;
  274. my @writeInfo = (
  275. [ 'XMP-x:XMPToolkit' => "What's this?", Protected => 1 ],
  276. [ 'XMP-rdf:About' => "http://www.exiftool.ca/t/$testname.t#$testnum", Protected => 1 ],
  277. [ 'XMP:ImageType' => 'Video' ],
  278. [ 'LicenseeImageNotes-en' => 'english notes' ],
  279. [ 'LicenseeImageNotes-de' => 'deutsche anmerkungen' ],
  280. [ 'LicenseeImageNotes' => 'default notes' ],
  281. [ 'LicenseeName' => 'Phil' ],
  282. [ 'CopyrightStatus' => 'public' ],
  283. [ 'Custom1-en' => 'a' ],
  284. [ 'Custom1-en' => 'b' ],
  285. [ 'ATestTag' => "http://www.exiftool.ca/t/$testname.t#$testnum-one" ],
  286. [ 'ATestTag' => "http://www.exiftool.ca/t/$testname.t#$testnum-two" ],
  287. );
  288. $exifTool->SetNewValue(@$_) foreach @writeInfo;
  289. my $ok = writeInfo($exifTool, undef, $testfile);
  290. print 'not ' unless testCompare("t/XMP_$testnum.out",$testfile,$testnum) and $ok;
  291. print "ok $testnum\n";
  292. }
  293. # test 27: Extract information from exiftool RDF/XML output file
  294. {
  295. ++$testnum;
  296. my $exifTool = new Image::ExifTool;
  297. my $info = $exifTool->ImageInfo('t/images/XMP.xml', {Duplicates => 1});
  298. print 'not ' unless check($exifTool, $info, $testname, $testnum);
  299. print "ok $testnum\n";
  300. }
  301. # test 28: Write information to exiftool RDF/XML output file
  302. {
  303. ++$testnum;
  304. my @writeInfo = (
  305. [ 'all' => undef ],
  306. [ 'ifd0:all' => undef, Replace => 2 ],
  307. [ 'XML-file:all' => undef, Replace => 2 ],
  308. [ 'author' => 'Phil' ],
  309. );
  310. print 'not ' unless writeCheck(\@writeInfo, $testname, $testnum, 't/images/XMP.xml');
  311. print "ok $testnum\n";
  312. }
  313. # test 29: Rewrite extended XMP segment
  314. {
  315. ++$testnum;
  316. my @writeInfo = ( [ 'author' => 'Test' ] );
  317. print 'not ' unless writeCheck(\@writeInfo, $testname, $testnum, 't/images/ExtendedXMP.jpg');
  318. print "ok $testnum\n";
  319. }
  320. # test 30: Test mass copy with deletion of specific XMP family 1 groups
  321. {
  322. ++$testnum;
  323. my $exifTool = new Image::ExifTool;
  324. my $testfile = "t/${testname}_${testnum}_failed.out";
  325. unlink $testfile;
  326. $exifTool->SetNewValuesFromFile('t/images/XMP.jpg');
  327. $exifTool->SetNewValue('xmp-exif:all');
  328. $exifTool->SetNewValue('XMP-TIFF:*');
  329. $exifTool->WriteInfo(undef,$testfile,'XMP'); #(also test output file type option)
  330. print 'not ' unless testCompare("t/XMP_$testnum.out",$testfile,$testnum);
  331. print "ok $testnum\n";
  332. }
  333. # test 31: Extract structured information
  334. {
  335. ++$testnum;
  336. my $exifTool = new Image::ExifTool;
  337. my $info = $exifTool->ImageInfo('t/images/XMP4.xmp', {Struct => 1});
  338. print 'not ' unless check($exifTool, $info, $testname, $testnum);
  339. print "ok $testnum\n";
  340. }
  341. # tests 32-34: Conditionally add XMP lang-alt tag
  342. {
  343. # write title only if it doesn't exist
  344. ++$testnum;
  345. my $exifTool = new Image::ExifTool;
  346. my $testfile = "t/${testname}_${testnum}_failed.jpg";
  347. unlink $testfile;
  348. $exifTool->SetNewValue('XMP-dc:Title-de' => '', DelValue => 1);
  349. $exifTool->SetNewValue('XMP-dc:Title-de' => 'A');
  350. my $ok = writeInfo($exifTool,'t/images/Writer.jpg',$testfile);
  351. my $info = $exifTool->ImageInfo($testfile,'XMP:*');
  352. print 'not ' unless check($exifTool, $info, $testname, $testnum) and $ok;
  353. print "ok $testnum\n";
  354. # try again when title already exists
  355. ++$testnum;
  356. my $testfile2 = "t/${testname}_${testnum}_failed.jpg";
  357. unlink $testfile2;
  358. $exifTool->SetNewValue('XMP-dc:Title-de' => 'B');
  359. $exifTool->WriteInfo($testfile,$testfile2);
  360. $info = $exifTool->ImageInfo($testfile2,'XMP:*');
  361. if (check($exifTool, $info, $testname, $testnum, 32)) {
  362. unlink $testfile2
  363. } else {
  364. print 'not ';
  365. }
  366. print "ok $testnum\n";
  367. # one final time replacing an existing title
  368. ++$testnum;
  369. $testfile2 = "t/${testname}_${testnum}_failed.jpg";
  370. unlink $testfile2;
  371. $exifTool->SetNewValue('XMP-dc:Title-de' => 'A', DelValue => 1);
  372. $exifTool->SetNewValue('XMP-dc:Title-de' => 'C');
  373. $ok = writeInfo($exifTool,$testfile,$testfile2);
  374. $info = $exifTool->ImageInfo($testfile2,'XMP:*');
  375. if (check($exifTool, $info, $testname, $testnum) and $ok) {
  376. unlink $testfile;
  377. unlink $testfile2
  378. } else {
  379. print 'not ';
  380. }
  381. print "ok $testnum\n";
  382. }
  383. # test 35: Test various features of writing structured information
  384. {
  385. ++$testnum;
  386. my $exifTool = new Image::ExifTool;
  387. my $testfile = "t/${testname}_${testnum}_failed.xmp";
  388. unlink $testfile;
  389. my @writeInfo = (
  390. # write as flattened string
  391. [ HierarchicalKeywords => '{keyWORD=A-1,childREN={keyword=A-2}}' ],
  392. # write as HASH reference
  393. [ HierarchicalKeywords => [{kEyWoRd=>'B-1', cHiLdReN=>{keyword=>'B-2'}},{keyword=>'C-1'}] ],
  394. # write a type'd structure
  395. [ licensee => {licenseename=>'Phil'} ],
  396. # write a region, including a 'seeAlso' resource
  397. [ 'RegionList', {
  398. Area => {X=>0,Y=>0,W=>8,H=>8},
  399. Name => 'Region 1',
  400. type => 'Face',
  401. seeAlso => 'plus:Licensee',
  402. }],
  403. # write alternate language structure elements
  404. [ ArtworkOrObject => "{AOTitle=test,aotitle-de=pr\xc3\xbcfung,AOTitle_FR=\xc3\xa9preuve}" ],
  405. # disable print conversion for a single structure element
  406. [ 'XMP:Flash' => '{Return=no,mode#=2}' ],
  407. # write a complex user-defined lang-alt structure
  408. [ BTestTag => "{Field1-en-CA=[eh?],Field1-en-US=[huh?,groovy],Field1-fr=[,ing\xc3\xa9nieux]}" ],
  409. # write some dynamic structure elements
  410. [ RegionList => { Extensions => {
  411. # may mix-and-match flattened and structured tags when writing!...
  412. 'XMP-exif:FlashReturn' => 'not', # flattened tag with group name
  413. Flash => { 'Mode#' => 1 }, # structured tag with disabled conversion
  414. 'UsageTerms-fr' => 'libre', # lang-alt tag
  415. 'ArtworkTitle-de' => "verf\xc3\xa4nglich", # renamed lang-alt tag in a list
  416. Renamed => 'this is wild', # user-defined renamed flattened tag with TYPE
  417. }}],
  418. );
  419. $exifTool->SetNewValue(@$_) foreach @writeInfo;
  420. my $ok = writeInfo($exifTool,undef,$testfile);
  421. print 'not ' unless testCompare("t/images/XMP5.xmp",$testfile,$testnum) and $ok;
  422. print "ok $testnum\n";
  423. }
  424. # tests 36-37: Test reading structures with and without the Struct option
  425. {
  426. my $i;
  427. for ($i=0; $i<2; ++$i) {
  428. ++$testnum;
  429. my $exifTool = new Image::ExifTool;
  430. $exifTool->Options(Struct => 1 - $i);
  431. $exifTool->Options(Escape => 'HTML'); # test escaping of structure fields too
  432. my $info = $exifTool->ImageInfo("t/images/XMP5.xmp");
  433. print 'not ' unless check($exifTool, $info, $testname, $testnum);
  434. print "ok $testnum\n";
  435. }
  436. }
  437. # test 38: Copy complex structured information
  438. {
  439. ++$testnum;
  440. my $exifTool = new Image::ExifTool;
  441. my $testfile = "t/${testname}_${testnum}_failed.xmp";
  442. unlink $testfile;
  443. $exifTool->SetNewValuesFromFile('t/images/XMP5.xmp', 'xmp:all');
  444. my $ok = writeInfo($exifTool,undef,$testfile);
  445. print 'not ' unless testCompare("t/images/XMP5.xmp",$testfile,$testnum) and $ok;
  446. print "ok $testnum\n";
  447. }
  448. # test 39: Extract information from an INX file
  449. {
  450. ++$testnum;
  451. my $exifTool = new Image::ExifTool;
  452. my $info = $exifTool->ImageInfo('t/images/XMP.inx', {Duplicates => 1});
  453. print 'not ' unless check($exifTool, $info, $testname, $testnum);
  454. print "ok $testnum\n";
  455. }
  456. # test 40: Copy by flattened tag name and structure at the same time
  457. {
  458. ++$testnum;
  459. my $exifTool = new Image::ExifTool;
  460. my $testfile = "t/${testname}_${testnum}_failed.xmp";
  461. unlink $testfile;
  462. $exifTool->SetNewValuesFromFile('t/images/XMP5.xmp', 'HierarchicalKeywords1', 'Licensee');
  463. my $ok = writeInfo($exifTool,undef,$testfile);
  464. my $info = $exifTool->ImageInfo($testfile, 'XMP:*');
  465. if (check($exifTool, $info, $testname, $testnum) and $ok) {
  466. unlink $testfile;
  467. } else {
  468. print 'not ';
  469. }
  470. print "ok $testnum\n";
  471. }
  472. # test 41: Rest writing/reading all DarwinCore tags
  473. {
  474. ++$testnum;
  475. my $exifTool = new Image::ExifTool;
  476. my $testfile = "t/${testname}_${testnum}_failed.xmp";
  477. unlink $testfile;
  478. $exifTool->SetNewValue('xmp-dwc:*' => 2013);
  479. my $ok = writeInfo($exifTool, undef, $testfile);
  480. my $info = $exifTool->ImageInfo($testfile, {Duplicates => 1});
  481. if (check($exifTool, $info, $testname, $testnum) and $ok) {
  482. unlink $testfile;
  483. } else {
  484. print 'not ';
  485. }
  486. print "ok $testnum\n";
  487. }
  488. # test 42: Read extended XMP
  489. {
  490. ++$testnum;
  491. my $exifTool = new Image::ExifTool;
  492. my $info = $exifTool->ImageInfo('t/images/ExtendedXMP.jpg', 'xmp:all');
  493. print 'not ' unless check($exifTool, $info, $testname, $testnum);
  494. print "ok $testnum\n";
  495. }
  496. # test 43: Read XMP with unusual namespace prefixes
  497. {
  498. ++$testnum;
  499. my $exifTool = new Image::ExifTool;
  500. my $info = $exifTool->ImageInfo('t/images/XMP6.xmp', 'xmp:all');
  501. print 'not ' unless check($exifTool, $info, $testname, $testnum);
  502. print "ok $testnum\n";
  503. }
  504. # test 44: Write XMP with unusual namespace prefixes
  505. {
  506. ++$testnum;
  507. my $exifTool = new Image::ExifTool;
  508. my $testfile = "t/${testname}_${testnum}_failed.xmp";
  509. unlink $testfile;
  510. $exifTool->SetNewValue('xmp-dc:subject' => 'changed');
  511. $exifTool->WriteInfo("t/images/XMP6.xmp", $testfile);
  512. my $err = $exifTool->GetValue('Error');
  513. warn "\n $err\n" if $err;
  514. print 'not ' unless testCompare("t/XMP_$testnum.out",$testfile,$testnum);
  515. print "ok $testnum\n";
  516. }
  517. # test 45: Write empty structures
  518. {
  519. ++$testnum;
  520. my $exifTool = new Image::ExifTool;
  521. my $testfile = "t/${testname}_${testnum}_failed.xmp";
  522. unlink $testfile;
  523. $exifTool->SetNewValue('regioninfo' => '{RegionList=[,]}');
  524. $exifTool->SetNewValue('xmp:flash' => '{}');
  525. $exifTool->WriteInfo(undef, $testfile);
  526. print 'not ' unless testCompare("t/XMP_$testnum.out",$testfile,$testnum);
  527. print "ok $testnum\n";
  528. }
  529. # end