|
| 1 | +/* |
| 2 | +
|
| 3 | + Licensed to the Apache Software Foundation (ASF) under one or more |
| 4 | + contributor license agreements. See the NOTICE file distributed with |
| 5 | + this work for additional information regarding copyright ownership. |
| 6 | + The ASF licenses this file to You under the Apache License, Version 2.0 |
| 7 | + (the "License"); you may not use this file except in compliance with |
| 8 | + the License. You may obtain a copy of the License at |
| 9 | +
|
| 10 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +
|
| 12 | + Unless required by applicable law or agreed to in writing, software |
| 13 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + See the License for the specific language governing permissions and |
| 16 | + limitations under the License. |
| 17 | +
|
| 18 | + */ |
| 19 | +package org.apache.batik.css.engine; |
| 20 | + |
| 21 | +import org.apache.batik.transcoder.ErrorHandler; |
| 22 | +import org.apache.batik.transcoder.TranscoderException; |
| 23 | +import org.apache.batik.transcoder.TranscoderInput; |
| 24 | +import org.apache.batik.transcoder.TranscoderOutput; |
| 25 | +import org.apache.batik.transcoder.image.PNGTranscoder; |
| 26 | +import org.junit.Assert; |
| 27 | +import org.junit.Test; |
| 28 | + |
| 29 | +import java.io.ByteArrayInputStream; |
| 30 | +import java.io.ByteArrayOutputStream; |
| 31 | + |
| 32 | +public class CSSEngineTestCase { |
| 33 | + @Test |
| 34 | + public void testParseErrorWithNoDataUri() throws Exception { |
| 35 | + String svgContent = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 1337 528\" width=\"1337\" height=\"528\">\n" + |
| 36 | + " <text dx=\"0\" dy=\"0\" font-family=\"Allianz_Neo\" font-size=\"25pt\" font-weight=\"bold\" " + |
| 37 | + "transform=\"translate(622.771987 374.659548)\" stroke-width=\"0\">\n" + |
| 38 | + " <tspan y=\"0\" font-weight=\"bold\" stroke-width=\"0\">H5005912</tspan>\n" + |
| 39 | + " </text>\n" + |
| 40 | + " <style>@font-face {font-family: 'Allianz_Neo';font-style: Allianz_Neo;font-weight: bold;src: " + |
| 41 | + "url(data:font/ttf;charset=utf-8;base64,xx) format('truetype');}</style>\n" + |
| 42 | + "</svg>"; |
| 43 | + PNGTranscoder transcoder = new PNGTranscoder(); |
| 44 | + TranscoderInput input = new TranscoderInput(new ByteArrayInputStream(svgContent.getBytes())); |
| 45 | + ByteArrayOutputStream ostream = new ByteArrayOutputStream(); |
| 46 | + TranscoderOutput output = new TranscoderOutput(ostream); |
| 47 | + final String[] ex = {""}; |
| 48 | + transcoder.setErrorHandler(new ErrorHandler() { |
| 49 | + public void error(TranscoderException e) { |
| 50 | + ex[0] = e.getMessage(); |
| 51 | + } |
| 52 | + public void fatalError(TranscoderException ex) { |
| 53 | + } |
| 54 | + public void warning(TranscoderException ex) { |
| 55 | + } |
| 56 | + }); |
| 57 | + try { |
| 58 | + transcoder.transcode(input, output); |
| 59 | + } catch (RuntimeException e) { |
| 60 | + //ignore |
| 61 | + } |
| 62 | + Assert.assertEquals(ex[0], "null\n" + |
| 63 | + "Enclosed Exception:\n" + |
| 64 | + "<unknown>:\n" + |
| 65 | + "The following stylesheet represents an invalid \n" + |
| 66 | + "CSS document.\n" + |
| 67 | + "@font-face {font-family: 'Allianz_Neo';font-style: Allianz_Neo;font-weight: " + |
| 68 | + "bold;src: url(data:font/ttf;charset=utf-8;base64,xx) format('truetype');}\n" + |
| 69 | + "Original message:\n" + |
| 70 | + "The \"Allianz_Neo\" identifier is not a valid value for the \"font-style\" property. "); |
| 71 | + } |
| 72 | +} |
0 commit comments