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.

PSTTFTableOutputStreamTestCase.java 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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.render.ps.fonts;
  19. import java.io.IOException;
  20. import org.junit.Before;
  21. import org.junit.Test;
  22. import org.mockito.InOrder;
  23. import static org.mockito.Mockito.inOrder;
  24. import static org.mockito.Mockito.mock;
  25. /**
  26. * Test class for unit testing PSTTFTableOutputStream
  27. */
  28. public class PSTTFTableOutputStreamTestCase {
  29. private PSTTFGenerator mockGen;
  30. private PSTTFTableOutputStream tableOut;
  31. @Before
  32. public void setUp() {
  33. mockGen = mock(PSTTFGenerator.class);
  34. tableOut = new PSTTFTableOutputStream(mockGen);
  35. }
  36. /**
  37. * Test streamTable() - several paths to test (2. and 3. test corner cases):
  38. * 1) that a table of length < PSTTFGenerator.MAX_BUFFER_SIZE invokes the correct methods in
  39. * PSTTFGenerator.
  40. * 2) that a table of length > PSTTFGenerator.MAX_BUFFER_SIZE and
  41. * length == n * PSTTFGenerator.MAX_BUFFER_SIZE is split up and the methods in PSTTFGenerator
  42. * are invoked.
  43. * 3) that a table of length > PSTTFGenerator.MAX_BUFFER_SIZE but
  44. * length != n * PSTTFGenerator.MAX_BUFFER_SIZE is split up and the methods in PSTTFGenerator
  45. * are invoked.
  46. * @throws IOException file write error.
  47. */
  48. @Test
  49. public void testStreamTable() throws IOException {
  50. byte[] byteArray = new byte[PSTTFGenerator.MAX_BUFFER_SIZE * 3];
  51. tableOut.streamTable(byteArray, 0, 10);
  52. InOrder inOrder = inOrder(mockGen);
  53. inOrder.verify(mockGen).startString();
  54. inOrder.verify(mockGen).streamBytes(byteArray, 0, 10);
  55. inOrder.verify(mockGen).endString();
  56. setUp(); // reset all all the method calls
  57. /* We're going to run this 3 times to ensure the proper method calls are invoked and all
  58. * the bytes are streamed */
  59. tableOut.streamTable(byteArray, 0, byteArray.length);
  60. inOrder = inOrder(mockGen);
  61. for (int i = 0; i < 3; i++) {
  62. int offset = PSTTFGenerator.MAX_BUFFER_SIZE * i;
  63. inOrder.verify(mockGen).startString();
  64. inOrder.verify(mockGen).streamBytes(byteArray, offset, PSTTFGenerator.MAX_BUFFER_SIZE);
  65. inOrder.verify(mockGen).endString();
  66. }
  67. setUp(); // reset all the method calls
  68. tableOut.streamTable(byteArray, 0, PSTTFGenerator.MAX_BUFFER_SIZE + 1);
  69. inOrder = inOrder(mockGen);
  70. inOrder.verify(mockGen).startString();
  71. inOrder.verify(mockGen).streamBytes(byteArray, 0, PSTTFGenerator.MAX_BUFFER_SIZE);
  72. inOrder.verify(mockGen).endString();
  73. inOrder.verify(mockGen).startString();
  74. inOrder.verify(mockGen).streamBytes(byteArray, PSTTFGenerator.MAX_BUFFER_SIZE, 1);
  75. inOrder.verify(mockGen).endString();
  76. }
  77. }