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.

TTFTableNameTestCase.java 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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.truetype;
  19. import org.junit.Test;
  20. import static org.junit.Assert.assertEquals;
  21. import static org.junit.Assert.assertFalse;
  22. import static org.junit.Assert.assertTrue;
  23. /**
  24. * This class tests the enum org.apache.fop.fonts.truetype.TTFTableName
  25. *
  26. */
  27. public class TTFTableNameTestCase {
  28. /**
  29. * Test getName() - tests that the getName() method returns the expected String as expected in
  30. * the Directory Table.
  31. * @exception IllegalAccessException error
  32. */
  33. @Test
  34. public void testGetName() throws IllegalAccessException {
  35. assertEquals("tableDirectory", TTFTableName.TABLE_DIRECTORY.getName());
  36. assertEquals("EBDT", TTFTableName.EBDT.getName());
  37. assertEquals("EBLC", TTFTableName.EBLC.getName());
  38. assertEquals("EBSC", TTFTableName.EBSC.getName());
  39. assertEquals("FFTM", TTFTableName.FFTM.getName());
  40. assertEquals("GDEF", TTFTableName.GDEF.getName());
  41. assertEquals("GPOS", TTFTableName.GPOS.getName());
  42. assertEquals("GSUB", TTFTableName.GSUB.getName());
  43. assertEquals("LTSH", TTFTableName.LTSH.getName());
  44. assertEquals("OS/2", TTFTableName.OS2.getName());
  45. assertEquals("PCLT", TTFTableName.PCLT.getName());
  46. assertEquals("VDMX", TTFTableName.VDMX.getName());
  47. assertEquals("cmap", TTFTableName.CMAP.getName());
  48. assertEquals("cvt ", TTFTableName.CVT.getName());
  49. assertEquals("fpgm", TTFTableName.FPGM.getName());
  50. assertEquals("gasp", TTFTableName.GASP.getName());
  51. assertEquals("glyf", TTFTableName.GLYF.getName());
  52. assertEquals("hdmx", TTFTableName.HDMX.getName());
  53. assertEquals("head", TTFTableName.HEAD.getName());
  54. assertEquals("hhea", TTFTableName.HHEA.getName());
  55. assertEquals("hmtx", TTFTableName.HMTX.getName());
  56. assertEquals("kern", TTFTableName.KERN.getName());
  57. assertEquals("loca", TTFTableName.LOCA.getName());
  58. assertEquals("maxp", TTFTableName.MAXP.getName());
  59. assertEquals("name", TTFTableName.NAME.getName());
  60. assertEquals("post", TTFTableName.POST.getName());
  61. assertEquals("prep", TTFTableName.PREP.getName());
  62. assertEquals("vhea", TTFTableName.VHEA.getName());
  63. assertEquals("vmtx", TTFTableName.VMTX.getName());
  64. // make sure it works with other table names
  65. TTFTableName test = TTFTableName.getValue("test");
  66. assertEquals("test", test.getName());
  67. }
  68. /**
  69. * Test getValue(String) - tests that the getValue(String) method returns the expected
  70. * TTFTableNames value when it is given a String (name of a table).
  71. * @exception IllegalAccessException error
  72. */
  73. @Test
  74. public void testGetValue() throws IllegalAccessException {
  75. assertEquals(TTFTableName.EBDT, TTFTableName.getValue("EBDT"));
  76. assertEquals(TTFTableName.EBLC, TTFTableName.getValue("EBLC"));
  77. assertEquals(TTFTableName.EBSC, TTFTableName.getValue("EBSC"));
  78. assertEquals(TTFTableName.FFTM, TTFTableName.getValue("FFTM"));
  79. assertEquals(TTFTableName.LTSH, TTFTableName.getValue("LTSH"));
  80. assertEquals(TTFTableName.OS2, TTFTableName.getValue("OS/2"));
  81. assertEquals(TTFTableName.PCLT, TTFTableName.getValue("PCLT"));
  82. assertEquals(TTFTableName.VDMX, TTFTableName.getValue("VDMX"));
  83. assertEquals(TTFTableName.CMAP, TTFTableName.getValue("cmap"));
  84. assertEquals(TTFTableName.CVT, TTFTableName.getValue("cvt "));
  85. assertEquals(TTFTableName.FPGM, TTFTableName.getValue("fpgm"));
  86. assertEquals(TTFTableName.GASP, TTFTableName.getValue("gasp"));
  87. assertEquals(TTFTableName.GLYF, TTFTableName.getValue("glyf"));
  88. assertEquals(TTFTableName.HDMX, TTFTableName.getValue("hdmx"));
  89. assertEquals(TTFTableName.HEAD, TTFTableName.getValue("head"));
  90. assertEquals(TTFTableName.HHEA, TTFTableName.getValue("hhea"));
  91. assertEquals(TTFTableName.HMTX, TTFTableName.getValue("hmtx"));
  92. assertEquals(TTFTableName.KERN, TTFTableName.getValue("kern"));
  93. assertEquals(TTFTableName.LOCA, TTFTableName.getValue("loca"));
  94. assertEquals(TTFTableName.MAXP, TTFTableName.getValue("maxp"));
  95. assertEquals(TTFTableName.NAME, TTFTableName.getValue("name"));
  96. assertEquals(TTFTableName.POST, TTFTableName.getValue("post"));
  97. assertEquals(TTFTableName.PREP, TTFTableName.getValue("prep"));
  98. assertEquals(TTFTableName.VHEA, TTFTableName.getValue("vhea"));
  99. assertEquals(TTFTableName.VMTX, TTFTableName.getValue("vmtx"));
  100. // Test that we can store a random table name and it will not fail or throw an error.
  101. TTFTableName test = TTFTableName.getValue("random");
  102. assertTrue(test instanceof TTFTableName);
  103. }
  104. /**
  105. * This class overrides hashCode() - we need to ensure it works properly by instantiating two
  106. * objects and comparing their hash-codes.
  107. * @exception IllegalAccessException error
  108. */
  109. @Test
  110. public void testHashCode() throws IllegalAccessException {
  111. TTFTableName a = TTFTableName.getValue("testObject");
  112. TTFTableName b = TTFTableName.getValue("testObject");
  113. assertTrue(a.hashCode() == b.hashCode());
  114. TTFTableName c = TTFTableName.getValue("fail");
  115. assertFalse(a.hashCode() == c.hashCode());
  116. }
  117. /**
  118. * This class overrides equals(object) - we need to test:
  119. * 1) Reflexivity
  120. * 2) Symmetry
  121. * 3) Transitivity
  122. * 4) Consistency
  123. * 5) check it fails if you put in a null value
  124. * @throws IllegalAccessException error
  125. */
  126. @Test
  127. public void testEquals() throws IllegalAccessException {
  128. // Reflexivity
  129. TTFTableName a = TTFTableName.getValue("test");
  130. assertTrue(a.equals(a));
  131. // Symmetry
  132. TTFTableName b = TTFTableName.getValue("test");
  133. assertTrue(a.equals(b));
  134. assertTrue(b.equals(a));
  135. // Transitivity (tested with symmetry)
  136. // Consistency (test that a == b is true and that a == c fails)
  137. TTFTableName c = TTFTableName.getValue("fail");
  138. for (int i = 0; i < 100; i++) {
  139. assertTrue(a.equals(b));
  140. assertFalse(a.equals(c));
  141. }
  142. // check with null value
  143. assertFalse(a.equals(null));
  144. }
  145. }