Line 0
Link Here
|
|
|
1 |
/* |
2 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
3 |
* contributor license agreements. See the NOTICE file distributed with |
4 |
* this work for additional information regarding copyright ownership. |
5 |
* The ASF licenses this file to You under the Apache License, Version 2.0 |
6 |
* (the "License"); you may not use this file except in compliance with |
7 |
* the License. You may obtain a copy of the License at |
8 |
* |
9 |
* 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 |
package org.apache.fop.afp.goca; |
18 |
|
19 |
import static org.junit.Assert.assertEquals; |
20 |
|
21 |
import java.io.ByteArrayOutputStream; |
22 |
import java.io.IOException; |
23 |
|
24 |
import org.apache.fop.afp.fonts.CharacterSet; |
25 |
import org.apache.fop.afp.fonts.CharacterSetBuilder; |
26 |
import org.apache.fop.fonts.Typeface; |
27 |
import org.junit.Before; |
28 |
import org.junit.Test; |
29 |
|
30 |
public class GraphicsCharacterStringTestCase { |
31 |
private GraphicsCharacterString gcsCp500; |
32 |
private GraphicsCharacterString gcsCp1146; |
33 |
// consider the EBCDIC code page variants Cp500 and Cp1146 |
34 |
// the £ corresponds to byte 5B (position 91) in the CCSID 285 and CCSID 1146 |
35 |
// the $ corresponds to byte 5B (position 91) in the CCSID 500 |
36 |
private final String poundsText = "££££"; |
37 |
private final String dollarsText = "$$$$"; |
38 |
private final byte[] bytesToCheck = {(byte) 0x5b, (byte) 0x5b, (byte) 0x5b, (byte) 0x5b}; |
39 |
|
40 |
@Before |
41 |
public void setUp() throws Exception { |
42 |
CharacterSetBuilder csb = CharacterSetBuilder.getSingleByteInstance(); |
43 |
CharacterSet cs1146 = csb.build("C0H200B0", "T1V10500", "Cp1146", |
44 |
Class.forName("org.apache.fop.fonts.base14.Helvetica").asSubclass(Typeface.class) |
45 |
.newInstance(), null); |
46 |
gcsCp1146 = new GraphicsCharacterString(poundsText, 0, 0, cs1146); |
47 |
CharacterSet cs500 = csb.build("C0H200B0", "T1V10500", "Cp500", |
48 |
Class.forName("org.apache.fop.fonts.base14.Helvetica").asSubclass(Typeface.class) |
49 |
.newInstance(), null); |
50 |
gcsCp500 = new GraphicsCharacterString(dollarsText, 0, 0, cs500); |
51 |
} |
52 |
|
53 |
@Test |
54 |
public void testWriteToStream() throws IOException { |
55 |
// check pounds |
56 |
ByteArrayOutputStream baos1146 = new ByteArrayOutputStream(); |
57 |
gcsCp1146.writeToStream(baos1146); |
58 |
byte[] bytes1146 = baos1146.toByteArray(); |
59 |
for (int i = 0; i < bytesToCheck.length; i++) { |
60 |
assertEquals(bytesToCheck[i], bytes1146[6 + i]); |
61 |
} |
62 |
assertEquals(bytesToCheck.length + 6, bytes1146.length); |
63 |
// check dollars |
64 |
ByteArrayOutputStream baos500 = new ByteArrayOutputStream(); |
65 |
gcsCp500.writeToStream(baos500); |
66 |
byte[] bytes500 = baos500.toByteArray(); |
67 |
for (int i = 0; i < bytesToCheck.length; i++) { |
68 |
assertEquals(bytesToCheck[i], bytes500[6 + i]); |
69 |
} |
70 |
assertEquals(bytesToCheck.length + 6, bytes500.length); |
71 |
} |
72 |
} |