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.

TransparentDataControlSequenceTestCase.java 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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.afp.ptoca;
  19. import java.io.IOException;
  20. import java.io.OutputStream;
  21. import org.junit.Test;
  22. import static org.mockito.Mockito.mock;
  23. import static org.mockito.Mockito.times;
  24. import static org.mockito.Mockito.verify;
  25. import static org.mockito.Mockito.when;
  26. import org.apache.fop.afp.fonts.CharactersetEncoder.EncodedChars;
  27. import org.apache.fop.afp.ptoca.TransparentDataControlSequence.TransparentData;
  28. import static org.apache.fop.afp.ptoca.PtocaConstants.TRANSPARENT_DATA_MAX_SIZE;
  29. public class TransparentDataControlSequenceTestCase {
  30. private EncodedChars encodedChars;
  31. private final OutputStream outStream = mock(OutputStream.class);
  32. @Test
  33. public void testSingleByteCharacterSet() throws IOException {
  34. testTRNs(false);
  35. }
  36. @Test
  37. public void testDoubleByteCharacterSets() throws IOException {
  38. testTRNs(true);
  39. }
  40. public void testTRNs(boolean isDBCS) throws IOException {
  41. for (int length = 100; length < 10000; length += 1000) {
  42. createTRNControlSequence(isDBCS, length);
  43. int maxTRNSize = TRANSPARENT_DATA_MAX_SIZE - (isDBCS ? 1 : 0);
  44. int numberOfTRNs = length / maxTRNSize;
  45. for (int i = 0; i < numberOfTRNs; i++) {
  46. verify(encodedChars, times(1)).writeTo(outStream, i * maxTRNSize, maxTRNSize);
  47. }
  48. int lastOffset = numberOfTRNs * maxTRNSize;
  49. verify(encodedChars, times(1)).writeTo(outStream, numberOfTRNs * maxTRNSize,
  50. length - lastOffset);
  51. }
  52. }
  53. private void createTRNControlSequence(boolean isDBCS, int length) throws IOException {
  54. encodedChars = mock(EncodedChars.class);
  55. when(encodedChars.isDBCS()).thenReturn(isDBCS);
  56. when(encodedChars.getLength()).thenReturn(length);
  57. for (TransparentData trn : new TransparentDataControlSequence(encodedChars)) {
  58. trn.writeTo(outStream);
  59. }
  60. }
  61. }