@@ -0,0 +1,3349 @@
+/*%0A * Licensed to the Apache Software Foundation (ASF) under one or more%0A * contributor license agreements.  See the NOTICE file distributed with%0A * this work for additional information regarding copyright ownership.%0A * The ASF licenses this file to You under the Apache License, Version 2.0%0A * (the %22License%22); you may not use this file except in compliance with%0A * the License.  You may obtain a copy of the License at%0A *%0A *      http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage org.apache.commons.imaging.formats.png.chunks;%0A%0Aimport static org.junit.Assert.assertArrayEquals;%0A%0Aimport java.io.ByteArrayOutputStream;%0Aimport java.io.IOException;%0Aimport java.nio.charset.StandardCharsets;%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0Aimport java.util.stream.IntStream;%0Aimport java.util.zip.Deflater;%0Aimport java.util.zip.DeflaterOutputStream;%0A%0Aimport org.apache.commons.imaging.ImageReadException;%0Aimport org.junit.Test;%0A%0A/**%0A * Tests for %7B@link PngChunkIccp%7D.%0A */%0Apublic class PngChunkIccpTest %7B%0A%0A    private static final int chunkType = 1766015824;%0A%0A    @Test(expected = ImageReadException.class)%0A    public void testErrorOnNoProfileName() throws ImageReadException, IOException %7B%0A        final byte%5B%5D data = new byte%5B0%5D;%0A        new PngChunkIccp(0, chunkType, 0, data);%0A    %7D%0A%0A    @Test%0A    public void testParsingIccpChunk() throws ImageReadException, IOException %7B%0A        final List%3CByte%3E bytes = new ArrayList%3C%3E();%0A        final String profileName = %22my-profile-01%22;%0A        for (byte b : profileName.getBytes(StandardCharsets.ISO_8859_1)) %7B%0A            bytes.add(new Byte(b));%0A        %7D%0A        bytes.add(new Byte((byte) 0)); // null%0A        bytes.add(new Byte((byte) 0)); // 0=deflate compression method%0A        %0A        // generate some 100 bytes of dummy data%0A        byte%5B%5D uncompressedData = new byte%5B100%5D;%0A        IntStream.range(0, 100).forEach((i) -%3E %7B%0A            uncompressedData%5Bi%5D = (byte) (i + 1); // dummy data%0A        %7D);%0A        try (ByteArrayOutputStream baos = new ByteArrayOutputStream(100)) %7B%0A            // compress the dummy data with deflate%0A            Deflater def = new Deflater();%0A            try (DeflaterOutputStream ios = new DeflaterOutputStream(baos, def)) %7B%0A                ios.write(uncompressedData);%0A            %7D%0A            baos.flush();%0A            byte%5B%5D compressedData = baos.toByteArray();%0A            final byte%5B%5D data = new byte%5Bbytes.size() + compressedData.length%5D;%0A            // gather everything, except for the compressed data%0A            for (int i = 0; i %3C bytes.size(); ++i) %7B%0A                data%5Bi%5D = bytes.get(i).byteValue();%0A            %7D%0A            // gather the compressed data%0A            IntStream.range(0, compressedData.length).forEach((i) -%3E %7B%0A                data%5Bbytes.size() + i%5D = compressedData%5Bi%5D;%0A            %7D);%0A            // create the chunk%0A            final PngChunkIccp chunk = new PngChunkIccp(data.length, chunkType, 0, data);%0A            assertArrayEquals(uncompressedData, chunk.getUncompressedProfile());%0A        %7D%0A    %7D%0A%7D%0A

Add unit test for PngChunkIccp