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.

PSTTFTableOutputStreamTest.java 3.4KB

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