You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GraphicsCharacterStringTestCase.java 3.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. import java.io.ByteArrayOutputStream;
  19. import java.io.IOException;
  20. import org.junit.Before;
  21. import org.junit.Test;
  22. import static org.junit.Assert.assertEquals;
  23. import org.apache.fop.afp.fonts.CharacterSet;
  24. import org.apache.fop.afp.fonts.CharacterSetBuilder;
  25. import org.apache.fop.fonts.Typeface;
  26. public class GraphicsCharacterStringTestCase {
  27. private GraphicsCharacterString gcsCp500;
  28. private GraphicsCharacterString gcsCp1146;
  29. // consider the EBCDIC code page variants Cp500 and Cp1146
  30. // the <A3> (pound sign) corresponds to byte 5B (position 91) in the CCSID 285 and CCSID 1146
  31. // the $ corresponds to byte 5B (position 91) in the CCSID 500
  32. private final String poundsText = "\u00A3\u00A3\u00A3\u00A3";
  33. private final String dollarsText = "$$$$";
  34. private final byte[] bytesToCheck = {(byte) 0x5b, (byte) 0x5b, (byte) 0x5b, (byte) 0x5b};
  35. @Before
  36. public void setUp() throws Exception {
  37. CharacterSetBuilder csb = CharacterSetBuilder.getSingleByteInstance();
  38. CharacterSet cs1146 = csb.build("C0H200B0", "T1V10500", "Cp1146",
  39. Class.forName("org.apache.fop.fonts.base14.Helvetica").asSubclass(Typeface.class)
  40. .newInstance(), null);
  41. gcsCp1146 = new GraphicsCharacterString(poundsText, 0, 0, cs1146);
  42. CharacterSet cs500 = csb.build("C0H200B0", "T1V10500", "Cp500",
  43. Class.forName("org.apache.fop.fonts.base14.Helvetica").asSubclass(Typeface.class)
  44. .newInstance(), null);
  45. gcsCp500 = new GraphicsCharacterString(dollarsText, 0, 0, cs500);
  46. }
  47. @Test
  48. public void testWriteToStream() throws IOException {
  49. // check pounds
  50. ByteArrayOutputStream baos1146 = new ByteArrayOutputStream();
  51. gcsCp1146.writeToStream(baos1146);
  52. byte[] bytes1146 = baos1146.toByteArray();
  53. for (int i = 0; i < bytesToCheck.length; i++) {
  54. assertEquals(bytesToCheck[i], bytes1146[6 + i]);
  55. }
  56. assertEquals(bytesToCheck.length + 6, bytes1146.length);
  57. // check dollars
  58. ByteArrayOutputStream baos500 = new ByteArrayOutputStream();
  59. gcsCp500.writeToStream(baos500);
  60. byte[] bytes500 = baos500.toByteArray();
  61. for (int i = 0; i < bytesToCheck.length; i++) {
  62. assertEquals(bytesToCheck[i], bytes500[6 + i]);
  63. }
  64. assertEquals(bytesToCheck.length + 6, bytes500.length);
  65. }
  66. }