ICNSParserTest.java

/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.tika.parser.image;


import org.junit.jupiter.api.Test;
import org.xml.sax.helpers.DefaultHandler;

import org.apache.tika.TikaTest;
import org.apache.tika.io.TikaInputStream;
import org.apache.tika.metadata.Metadata;
import org.apache.tika.parser.ParseContext;
import org.apache.tika.parser.Parser;

/**
 * Test class for the ICNSParser
 */
public class ICNSParserTest extends TikaTest {

    private final Parser parser = new ICNSParser();

    /**
     * Tests a very basic icns file, with one icon and no masks
     */
    @Test
    public void testICNS_basic() throws Exception {
        Metadata metadata = new Metadata();
        metadata.set(Metadata.CONTENT_TYPE, "image/icns");
        metadata.set("Icons count", "1");
        metadata.set("Icons details", "512x512 (JPEG 2000 or PNG format)");


        try (TikaInputStream tis = getResourceAsStream("/test-documents/testICNS_basic.icns")) {
            parser.parse(tis, new DefaultHandler(), metadata, new ParseContext());
        }
    }

    /**
     * Tests a file with multiple icons and masks
     */
    @Test
    public void testICNS() throws Exception {
        Metadata metadata = new Metadata();
        metadata.set(Metadata.CONTENT_TYPE, "image/icns");
        metadata.set("Icons count", "2");
        metadata.set("Icons details", "16x16 (24 bpp), 32x32 (24 bpp)");
        metadata.set("Masked icon count", "2");
        metadata.set("Masked icon details", "16x16 (8 bpp), 32x32 (8 bpp)");


        try (TikaInputStream tis = getResourceAsStream("/test-documents/testICNS.icns")) {
            parser.parse(tis, new DefaultHandler(), metadata, new ParseContext());
        }
    }
}