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.

AdobeStandardEncodingTestCase.java 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. /* $Id$ */
  18. package org.apache.fop.fonts.type1;
  19. import java.io.BufferedReader;
  20. import java.io.FileNotFoundException;
  21. import java.io.IOException;
  22. import java.io.InputStream;
  23. import java.io.InputStreamReader;
  24. import org.junit.BeforeClass;
  25. import org.junit.Test;
  26. import static org.junit.Assert.assertEquals;
  27. /**
  28. * Test case for {@link AdobeStandardEncoding}.
  29. */
  30. public class AdobeStandardEncodingTestCase {
  31. private static BufferedReader adobeStandardEncoding;
  32. /**
  33. * Sets up the file reader, this file was retrieved from the url below.
  34. * http://unicode.org/Public/MAPPINGS/VENDORS/ADOBE/stdenc.txt
  35. *
  36. * @throws FileNotFoundException if the file was not found
  37. */
  38. @BeforeClass
  39. public static void setupReader() throws FileNotFoundException {
  40. InputStream inStream = AdobeStandardEncodingTestCase.class.getResourceAsStream(
  41. "AdobeStandardEncoding.txt");
  42. adobeStandardEncoding = new BufferedReader(new InputStreamReader(inStream));
  43. }
  44. /**
  45. * Probably the best way to test the encoding is by converting it back to format specified in
  46. * the file, that way we can ensure data has been migrated properly.
  47. *
  48. * @throws IOException if an I/O error occurs
  49. */
  50. @Test
  51. public void testCorrectEncoding() throws IOException {
  52. for (AdobeStandardEncoding encoding : AdobeStandardEncoding.values()) {
  53. String expectedLine = getLine();
  54. String hexUnicode = toHexString(encoding.getUnicodeIndex(), 4);
  55. String hexAdobe = toHexString(encoding.getAdobeCodePoint(), 2);
  56. String actualLine = hexUnicode + "\t"
  57. + hexAdobe + "\t# "
  58. + encoding.getUnicodeName() + "\t# "
  59. + encoding.getAdobeName();
  60. assertEquals(expectedLine, actualLine);
  61. }
  62. }
  63. private String getLine() throws IOException {
  64. String line = "# The first few lines are comments, these should be ignored";
  65. while (line.startsWith("#")) {
  66. line = adobeStandardEncoding.readLine();
  67. }
  68. return line;
  69. }
  70. private String toHexString(int number, int length) {
  71. return String.format("%0" + length + "X", number);
  72. }
  73. }