01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: /* $Id$ */
19:
20: package org.apache.xmlgraphics.ps;
21:
22: import org.apache.xmlgraphics.ps.PSGenerator;
23:
24: import junit.framework.TestCase;
25:
26: /**
27: * Tests literal text string escaping.
28: */
29: public class PSEscapeTestCase extends TestCase {
30:
31: public void testBasics() throws Exception {
32: StringBuffer sb = new StringBuffer();
33:
34: PSGenerator.escapeChar('a', sb);
35: PSGenerator.escapeChar('b', sb);
36: PSGenerator.escapeChar('c', sb);
37: PSGenerator.escapeChar('!', sb);
38: assertEquals("abc!", sb.toString());
39:
40: sb.setLength(0);
41: PSGenerator.escapeChar('0', sb);
42: PSGenerator.escapeChar('\t', sb);
43: PSGenerator.escapeChar('(', sb);
44: PSGenerator.escapeChar('x', sb);
45: PSGenerator.escapeChar(')', sb);
46: PSGenerator.escapeChar('\n', sb);
47: PSGenerator.escapeChar('\u001E', sb); //<RS>
48: PSGenerator.escapeChar('\u00E4', sb); //a umlaut
49: PSGenerator.escapeChar('\u20AC', sb); //EURO Sign
50: assertEquals("0\\t\\(x\\)\\n\\036\\344?", sb.toString());
51: }
52:
53: public void testStringToDSC() throws Exception {
54: String escaped;
55: escaped = PSGenerator
56: .convertStringToDSC("0\t(x)\n\u001E\u00E4\u20AC");
57: assertEquals("0\\t\\(x\\)\\n\\036\\344?", escaped);
58: escaped = PSGenerator
59: .convertStringToDSC("0\t(x)\n\u001E\u00E4 \u20AC");
60: assertEquals("(0\\t\\(x\\)\\n\\036\\344 ?)", escaped);
61: escaped = PSGenerator.convertStringToDSC(
62: "0\t(x)\n\u001E\u00E4\u20AC", true);
63: assertEquals("(0\\t\\(x\\)\\n\\036\\344?)", escaped);
64: }
65:
66: }
|