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.

DataStreamTestCase.java 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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;
  19. import java.awt.Color;
  20. import java.awt.Point;
  21. import java.io.ByteArrayInputStream;
  22. import java.io.ByteArrayOutputStream;
  23. import org.junit.Assert;
  24. import org.junit.Before;
  25. import org.junit.Test;
  26. import static org.mockito.Mockito.mock;
  27. import static org.mockito.Mockito.when;
  28. import org.apache.fop.afp.fonts.CharacterSet;
  29. import org.apache.fop.afp.fonts.CharacterSetBuilder;
  30. import org.apache.fop.afp.modca.InterchangeSet;
  31. import org.apache.fop.afp.modca.InvokeMediumMap;
  32. import org.apache.fop.afp.modca.PageGroup;
  33. import org.apache.fop.fonts.Font;
  34. import org.apache.fop.fonts.Typeface;
  35. import org.apache.fop.util.CharUtilities;
  36. public class DataStreamTestCase {
  37. private DataStream ds;
  38. private ByteArrayOutputStream outStream = new ByteArrayOutputStream();
  39. private AFPTextDataInfo textInfo = new AFPTextDataInfo();
  40. private CharacterSet cs1146;
  41. private AFPPaintingState paintState = mock(AFPPaintingState.class);
  42. @Before
  43. public void setUp() throws Exception {
  44. when(paintState.getRotation()).thenReturn(90);
  45. when(paintState.getPoint(50, 50)).thenReturn(new Point(50, 50));
  46. AFPUnitConverter unitConv = new AFPUnitConverter(paintState);
  47. when(paintState.getUnitConverter()).thenReturn(unitConv);
  48. ds = new DataStream(new Factory(), paintState, outStream);
  49. textInfo.setEncoding("WinAnsiEncoding");
  50. textInfo.setRotation(0);
  51. char ch = '\u3000';
  52. textInfo.setString("Test String" + CharUtilities.NBSPACE + "blah" + ch + "hello" + '\u2000'
  53. + "end.");
  54. textInfo.setX(50);
  55. textInfo.setY(50);
  56. textInfo.setColor(Color.black);
  57. CharacterSetBuilder csb = CharacterSetBuilder.getSingleByteInstance();
  58. cs1146 = csb.build("C0H200B0", "T1V10500", "Cp1146",
  59. Class.forName("org.apache.fop.fonts.base14.Helvetica").asSubclass(Typeface.class)
  60. .getDeclaredConstructor().newInstance(), null);
  61. ds.startPage(1000, 1000, 0, 300, 300);
  62. }
  63. @Test
  64. public void testCreateText() throws Exception {
  65. Font font = mock(Font.class);
  66. ds.createText(textInfo, 100, 300, font, cs1146);
  67. ds.createShading(10, 10, 300, 300, Color.white);
  68. ds.createIncludePageOverlay("testings", 10, 10);
  69. ds.startDocument();
  70. ds.startPageGroup();
  71. ds.createInvokeMediumMap("test");
  72. ds.createIncludePageSegment("test", 10, 10, 300, 300);
  73. ds.createTagLogicalElement("test", "test", 0);
  74. PageGroup pg = ds.getCurrentPageGroup();
  75. InterchangeSet is = ds.getInterchangeSet();
  76. ds.getResourceGroup(AFPResourceLevel.valueOf(AFPResourceLevel.ResourceType.DOCUMENT.name()));
  77. }
  78. @Test
  79. public void testMediumMapOnPage() throws Exception {
  80. ds.createInvokeMediumMap("test");
  81. ByteArrayOutputStream bos = new ByteArrayOutputStream();
  82. ds.getCurrentPage().writeToStream(bos);
  83. ByteArrayInputStream data = new ByteArrayInputStream(bos.toByteArray());
  84. data.skip(21);
  85. Assert.assertEquals((byte)data.read(), InvokeMediumMap.Type.MAP);
  86. Assert.assertEquals((byte)data.read(), InvokeMediumMap.Category.MEDIUM_MAP);
  87. }
  88. @Test
  89. public void testMediumMapOnDocument() throws Exception {
  90. ds = new DataStream(new Factory(), paintState, outStream);
  91. ds.startDocument();
  92. ds.createInvokeMediumMap("test");
  93. ds.endDocument();
  94. ByteArrayInputStream data = new ByteArrayInputStream(outStream.toByteArray());
  95. data.skip(21);
  96. Assert.assertEquals((byte)data.read(), InvokeMediumMap.Type.MAP);
  97. Assert.assertEquals((byte)data.read(), InvokeMediumMap.Category.MEDIUM_MAP);
  98. }
  99. @Test
  100. public void testMediumMapBeforePageGroupOnDocument() throws Exception {
  101. ds = new DataStream(new Factory(), paintState, outStream);
  102. ds.startDocument();
  103. ds.createInvokeMediumMap("test");
  104. ds.startPageGroup();
  105. ds.startPage(1, 1, 0, 1, 1);
  106. ds.endPage();
  107. ds.endPageGroup();
  108. ds.endDocument();
  109. ByteArrayInputStream data = new ByteArrayInputStream(outStream.toByteArray());
  110. data.skip(21);
  111. Assert.assertEquals((byte)data.read(), InvokeMediumMap.Type.MAP);
  112. Assert.assertEquals((byte)data.read(), InvokeMediumMap.Category.MEDIUM_MAP);
  113. }
  114. }