This is an automated email from the ASF dual-hosted git repository.

kinow pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-imaging.git

commit 2b0311a56fb68119dd8f22647e56e47dfb1f3f47
Author: Bruno P. Kinoshita <[email protected]>
AuthorDate: Mon Mar 15 15:39:29 2021 +1300

    [IMAGING-168]: Add unit test
---
 .../imaging/formats/jpeg/iptc/IptcParserTest.java  |  22 +++++++++++++++++++++
 ...083453-c07f1880-851e-11eb-8b61-2757f7d934bf.jpg | Bin 0 -> 24243 bytes
 2 files changed, 22 insertions(+)

diff --git 
a/src/test/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcParserTest.java
 
b/src/test/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcParserTest.java
index a7ae28c..6fff24e 100644
--- 
a/src/test/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcParserTest.java
+++ 
b/src/test/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcParserTest.java
@@ -16,16 +16,19 @@
  */
 package org.apache.commons.imaging.formats.jpeg.iptc;
 
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 import static org.junit.jupiter.api.Assertions.fail;
 
 import java.io.File;
 import java.io.IOException;
+import java.nio.charset.StandardCharsets;
 import java.util.HashMap;
 import java.util.List;
 
 import org.apache.commons.imaging.ImageReadException;
+import 
org.apache.commons.imaging.common.GenericImageMetadata.GenericImageMetadataItem;
 import org.apache.commons.imaging.common.bytesource.ByteSourceFile;
 import org.apache.commons.imaging.formats.jpeg.JpegImageMetadata;
 import org.apache.commons.imaging.formats.jpeg.JpegImageParser;
@@ -81,4 +84,23 @@ public class IptcParserTest {
             }
         }
     }
+
+    /**
+     * Tests for IptcParser encoding support. See IMAGING-168 and pullr equest 
#124 for more.
+     * @throws IOException when reading input
+     * @throws ImageReadException when parsing file
+     */
+    @Test
+    public void testEncodingSupport() throws IOException, ImageReadException {
+        // NOTE: We use the JpegParser, so it will send only the block/segment 
that IptcParser needs for the test image
+        File file = new 
File(IptcParserTest.class.getResource("/images/jpeg/iptc/IMAGING-168/111083453-c07f1880-851e-11eb-8b61-2757f7d934bf.jpg").getFile());
+        JpegImageParser parser = new JpegImageParser();
+        JpegImageMetadata metadata = (JpegImageMetadata) 
parser.getMetadata(file);
+        JpegPhotoshopMetadata photoshopMetadata = metadata.getPhotoshop();
+        @SuppressWarnings("unchecked")
+        List<GenericImageMetadataItem> items = 
(List<GenericImageMetadataItem>) photoshopMetadata.getItems();
+        GenericImageMetadataItem thanksInMandarin = items.get(3);
+        // converted the thank-you in chinese characters to unicode for 
comparison here
+        assertArrayEquals("\u8c22\u8c22".getBytes(StandardCharsets.UTF_8), 
thanksInMandarin.getText().getBytes());
+    }
 }
diff --git 
a/src/test/resources/images/jpeg/iptc/IMAGING-168/111083453-c07f1880-851e-11eb-8b61-2757f7d934bf.jpg
 
b/src/test/resources/images/jpeg/iptc/IMAGING-168/111083453-c07f1880-851e-11eb-8b61-2757f7d934bf.jpg
new file mode 100644
index 0000000..f00deca
Binary files /dev/null and 
b/src/test/resources/images/jpeg/iptc/IMAGING-168/111083453-c07f1880-851e-11eb-8b61-2757f7d934bf.jpg
 differ

Reply via email to