test/jdk/javax/imageio/metadata/BooleanAttributes.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 13769 jdk/test/javax/imageio/metadata/BooleanAttributes.java@ba52da5186ad
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2375
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
     1
/*
13769
ba52da5186ad 7186799: Regression tests for ImageIO metadata fail on second run
bae
parents: 5506
diff changeset
     2
 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
2375
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
     4
 *
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
13769
ba52da5186ad 7186799: Regression tests for ImageIO metadata fail on second run
bae
parents: 5506
diff changeset
     7
 * published by the Free Software Foundation.
2375
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
     8
 *
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    13
 * accompanied this code).
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    14
 *
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2375
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2375
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2375
diff changeset
    21
 * questions.
2375
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    22
 */
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    23
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    24
/**
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    25
 * @test
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    26
 * @bug 5082756
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    27
 * @summary ensure that boolean attributes follow ( "TRUE" | "FALSE" )
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    28
 *          including correct (i.e. upper) case
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    29
 *
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    30
 * @run main BooleanAttributes
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    31
 */
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    32
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    33
import java.awt.image.BufferedImage;
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    34
import java.io.ByteArrayInputStream;
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    35
import java.io.ByteArrayOutputStream;
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    36
import java.io.StringReader;
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    37
import java.util.Arrays;
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    38
import java.util.List;
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    39
import javax.imageio.IIOImage;
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    40
import javax.imageio.ImageIO;
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    41
import javax.imageio.ImageReader;
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    42
import javax.imageio.ImageTypeSpecifier;
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    43
import javax.imageio.ImageWriteParam;
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    44
import javax.imageio.ImageWriter;
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    45
import javax.imageio.metadata.IIOMetadata;
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    46
import javax.imageio.stream.ImageInputStream;
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    47
import javax.imageio.stream.ImageOutputStream;
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    48
import javax.imageio.stream.MemoryCacheImageInputStream;
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    49
import javax.imageio.stream.MemoryCacheImageOutputStream;
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    50
import javax.xml.transform.Result;
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    51
import javax.xml.transform.Source;
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    52
import javax.xml.transform.TransformerFactory;
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    53
import javax.xml.transform.dom.DOMResult;
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    54
import javax.xml.transform.stream.StreamSource;
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    55
import javax.xml.xpath.XPath;
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    56
import javax.xml.xpath.XPathConstants;
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    57
import javax.xml.xpath.XPathFactory;
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    58
import org.w3c.dom.Document;
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    59
import org.w3c.dom.Element;
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    60
import org.w3c.dom.Node;
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    61
import org.w3c.dom.NodeList;
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    62
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    63
public class BooleanAttributes {
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    64
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    65
    private static TransformerFactory transformerFactory =
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    66
        TransformerFactory.newInstance();
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    67
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    68
    private static XPath xpathEngine = XPathFactory.newInstance().newXPath();
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    69
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    70
    public static void main(String[] args) throws Exception {
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    71
        test("image/png", false, "<javax_imageio_1.0 />",
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    72
             "Chroma/BlackIsZero/@value",
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    73
             "Compression/Lossless/@value");
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    74
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    75
        test("image/png", false,
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    76
             "<javax_imageio_png_1.0>" +
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    77
             "<iTXt><iTXtEntry keyword='Comment' compressionFlag='TRUE' " +
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    78
             "compressionMethod='0' languageTag='en' " +
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    79
             "translatedKeyword='comment' text='foo'/></iTXt>" +
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    80
             "</javax_imageio_png_1.0>",
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    81
             "iTXt/iTXtEntry/@compressionFlag");
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    82
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    83
        test("image/png", false,
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    84
             "<javax_imageio_png_1.0>" +
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    85
             "<iTXt><iTXtEntry keyword='Comment' compressionFlag='FALSE' " +
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    86
             "compressionMethod='0' languageTag='en' " +
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    87
             "translatedKeyword='comment' text='foo'/></iTXt>" +
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    88
             "</javax_imageio_png_1.0>",
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    89
             "iTXt/iTXtEntry/@compressionFlag");
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    90
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    91
        test("image/gif", false, "<javax_imageio_1.0 />",
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    92
             "Chroma/BlackIsZero/@value",
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    93
             "Compression/Lossless/@value");
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    94
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    95
        test("image/gif", false,
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    96
             "<javax_imageio_gif_image_1.0>" +
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    97
             "<ImageDescriptor imageLeftPosition='0' imageTopPosition='0' " +
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    98
             "imageWidth='16' imageHeight='16' interlaceFlag='TRUE' />" +
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
    99
             "<LocalColorTable sizeOfLocalColorTable='2' " +
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   100
             "backgroundColorIndex='1' sortFlag='TRUE'>" +
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   101
             "<ColorTableEntry index='0' red='0' green='0' blue='0' />" +
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   102
             "<ColorTableEntry index='1' red='255' green='255' blue='255' />" +
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   103
             "</LocalColorTable>" +
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   104
             "<GraphicControlExtension disposalMethod='doNotDispose' " +
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   105
             "userInputFlag='FALSE' transparentColorFlag='TRUE' " +
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   106
             "delayTime='100' transparentColorIndex='1' />" +
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   107
             "</javax_imageio_gif_image_1.0>",
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   108
             "ImageDescriptor/@interlaceFlag",
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   109
             "LocalColorTable/@sortFlag",
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   110
             "GraphicControlExtension/@userInputFlag",
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   111
             "GraphicControlExtension/@transparentColorFlag");
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   112
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   113
        test("image/gif", true,
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   114
             "<javax_imageio_gif_stream_1.0>" +
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   115
             "<GlobalColorTable sizeOfGlobalColorTable='2' " +
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   116
             "backgroundColorIndex='1' sortFlag='TRUE'>" +
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   117
             "<ColorTableEntry index='0' red='0' green='0' blue='0' />" +
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   118
             "<ColorTableEntry index='1' red='255' green='255' blue='255' />" +
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   119
             "</GlobalColorTable>" +
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   120
             "</javax_imageio_gif_stream_1.0>",
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   121
             "GlobalColorTable/@sortFlag");
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   122
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   123
        test("image/jpeg", false, "<javax_imageio_1.0 />",
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   124
             "Compression/Lossless/@value");
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   125
    }
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   126
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   127
    private static void transform(Source src, Result dst)
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   128
        throws Exception
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   129
    {
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   130
        transformerFactory.newTransformer().transform(src, dst);
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   131
    }
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   132
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   133
    private static void verify(Node meta, String[] xpaths, boolean required)
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   134
        throws Exception
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   135
    {
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   136
        for (String xpath: xpaths) {
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   137
            NodeList list = (NodeList)
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   138
                xpathEngine.evaluate(xpath, meta, XPathConstants.NODESET);
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   139
            if (list.getLength() == 0 && required)
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   140
                throw new AssertionError("Missing value: " + xpath);
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   141
            for (int i = 0; i < list.getLength(); ++i) {
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   142
                String value = list.item(i).getNodeValue();
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   143
                if (!(value.equals("TRUE") || value.equals("FALSE")))
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   144
                    throw new AssertionError(xpath + " has value " + value);
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   145
            }
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   146
        }
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   147
    }
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   148
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   149
    public static void test(String mimeType, boolean useStreamMeta,
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   150
                            String metaXml, String... boolXpaths)
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   151
        throws Exception
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   152
    {
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   153
        BufferedImage img =
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   154
            new BufferedImage(16, 16, BufferedImage.TYPE_INT_RGB);
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   155
        ImageWriter iw = ImageIO.getImageWritersByMIMEType(mimeType).next();
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   156
        ByteArrayOutputStream os = new ByteArrayOutputStream();
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   157
        ImageOutputStream ios = new MemoryCacheImageOutputStream(os);
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   158
        iw.setOutput(ios);
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   159
        ImageWriteParam param = null;
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   160
        IIOMetadata streamMeta = iw.getDefaultStreamMetadata(param);
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   161
        IIOMetadata imageMeta =
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   162
            iw.getDefaultImageMetadata(new ImageTypeSpecifier(img), param);
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   163
        IIOMetadata meta = useStreamMeta ? streamMeta : imageMeta;
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   164
        Source src = new StreamSource(new StringReader(metaXml));
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   165
        DOMResult dst = new DOMResult();
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   166
        transform(src, dst);
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   167
        Document doc = (Document)dst.getNode();
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   168
        Element node = doc.getDocumentElement();
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   169
        String metaFormat = node.getNodeName();
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   170
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   171
        // Verify that the default metadata gets formatted correctly.
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   172
        verify(meta.getAsTree(metaFormat), boolXpaths, false);
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   173
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   174
        meta.mergeTree(metaFormat, node);
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   175
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   176
        // Verify that the merged metadata gets formatte correctly.
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   177
        verify(meta.getAsTree(metaFormat), boolXpaths, true);
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   178
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   179
        iw.write(streamMeta, new IIOImage(img, null, imageMeta), param);
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   180
        iw.dispose();
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   181
        ios.close();
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   182
        ImageReader ir = ImageIO.getImageReader(iw);
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   183
        byte[] bytes = os.toByteArray();
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   184
        if (bytes.length == 0)
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   185
            throw new AssertionError("Zero length image file");
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   186
        ByteArrayInputStream is = new ByteArrayInputStream(bytes);
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   187
        ImageInputStream iis = new MemoryCacheImageInputStream(is);
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   188
        ir.setInput(iis);
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   189
        if (useStreamMeta) meta = ir.getStreamMetadata();
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   190
        else meta = ir.getImageMetadata(0);
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   191
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   192
        // Verify again after writing and re-reading the image
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   193
        verify(meta.getAsTree(metaFormat), boolXpaths, true);
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   194
    }
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   195
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   196
    public static void xtest(Object... eatAnyArguments) {
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   197
        System.err.println("Disabled test! Change xtest back into test!");
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   198
    }
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   199
bb4dd76ca2c9 5082756: Image I/O plug-ins set metadata boolean attributes to "true" or "false"
bae
parents:
diff changeset
   200
}