-/*\r
- * Licensed to the Apache Software Foundation (ASF) under one or more\r
- * contributor license agreements. See the NOTICE file distributed with\r
- * this work for additional information regarding copyright ownership.\r
- * The ASF licenses this file to You under the Apache License, Version 2.0\r
- * (the "License"); you may not use this file except in compliance with\r
- * the License. You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.apache.fop.afp.goca;\r
-\r
-import static org.junit.Assert.assertEquals;\r
-\r
-import java.io.ByteArrayOutputStream;\r
-import java.io.IOException;\r
-\r
-import org.apache.fop.afp.fonts.CharacterSet;\r
-import org.apache.fop.afp.fonts.CharacterSetBuilder;\r
-import org.apache.fop.fonts.Typeface;\r
-import org.junit.Before;\r
-import org.junit.Test;\r
-\r
-public class GraphicsCharacterStringTestCase {\r
- private GraphicsCharacterString gcsCp500;\r
- private GraphicsCharacterString gcsCp1146;\r
- // consider the EBCDIC code page variants Cp500 and Cp1146\r
- // the £ corresponds to byte 5B (position 91) in the CCSID 285 and CCSID 1146\r
- // the $ corresponds to byte 5B (position 91) in the CCSID 500\r
- private final String poundsText = "\u00A3\u00A3\u00A3\u00A3";\r
- private final String dollarsText = "$$$$";\r
- private final byte[] bytesToCheck = {(byte) 0x5b, (byte) 0x5b, (byte) 0x5b, (byte) 0x5b};\r
-\r
- @Before\r
- public void setUp() throws Exception {\r
- CharacterSetBuilder csb = CharacterSetBuilder.getSingleByteInstance();\r
- CharacterSet cs1146 = csb.build("C0H200B0", "T1V10500", "Cp1146",\r
- Class.forName("org.apache.fop.fonts.base14.Helvetica").asSubclass(Typeface.class)\r
- .newInstance(), null);\r
- gcsCp1146 = new GraphicsCharacterString(poundsText, 0, 0, cs1146);\r
- CharacterSet cs500 = csb.build("C0H200B0", "T1V10500", "Cp500",\r
- Class.forName("org.apache.fop.fonts.base14.Helvetica").asSubclass(Typeface.class)\r
- .newInstance(), null);\r
- gcsCp500 = new GraphicsCharacterString(dollarsText, 0, 0, cs500);\r
- }\r
-\r
- @Test\r
- public void testWriteToStream() throws IOException {\r
- // check pounds\r
- ByteArrayOutputStream baos1146 = new ByteArrayOutputStream();\r
- gcsCp1146.writeToStream(baos1146);\r
- byte[] bytes1146 = baos1146.toByteArray();\r
- for (int i = 0; i < bytesToCheck.length; i++) {\r
- assertEquals(bytesToCheck[i], bytes1146[6 + i]);\r
- }\r
- assertEquals(bytesToCheck.length + 6, bytes1146.length);\r
- // check dollars\r
- ByteArrayOutputStream baos500 = new ByteArrayOutputStream();\r
- gcsCp500.writeToStream(baos500);\r
- byte[] bytes500 = baos500.toByteArray();\r
- for (int i = 0; i < bytesToCheck.length; i++) {\r
- assertEquals(bytesToCheck[i], bytes500[6 + i]);\r
- }\r
- assertEquals(bytesToCheck.length + 6, bytes500.length);\r
- }\r
-}\r
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.fop.afp.goca;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+import org.apache.fop.afp.fonts.CharacterSet;
+import org.apache.fop.afp.fonts.CharacterSetBuilder;
+import org.apache.fop.fonts.Typeface;
+import org.junit.Before;
+import org.junit.Test;
+
+public class GraphicsCharacterStringTestCase {
+ private GraphicsCharacterString gcsCp500;
+ private GraphicsCharacterString gcsCp1146;
+ // consider the EBCDIC code page variants Cp500 and Cp1146
+ // the £ corresponds to byte 5B (position 91) in the CCSID 285 and CCSID 1146
+ // the $ corresponds to byte 5B (position 91) in the CCSID 500
+ private final String poundsText = "\u00A3\u00A3\u00A3\u00A3";
+ private final String dollarsText = "$$$$";
+ private final byte[] bytesToCheck = {(byte) 0x5b, (byte) 0x5b, (byte) 0x5b, (byte) 0x5b};
+
+ @Before
+ public void setUp() throws Exception {
+ CharacterSetBuilder csb = CharacterSetBuilder.getSingleByteInstance();
+ CharacterSet cs1146 = csb.build("C0H200B0", "T1V10500", "Cp1146",
+ Class.forName("org.apache.fop.fonts.base14.Helvetica").asSubclass(Typeface.class)
+ .newInstance(), null);
+ gcsCp1146 = new GraphicsCharacterString(poundsText, 0, 0, cs1146);
+ CharacterSet cs500 = csb.build("C0H200B0", "T1V10500", "Cp500",
+ Class.forName("org.apache.fop.fonts.base14.Helvetica").asSubclass(Typeface.class)
+ .newInstance(), null);
+ gcsCp500 = new GraphicsCharacterString(dollarsText, 0, 0, cs500);
+ }
+
+ @Test
+ public void testWriteToStream() throws IOException {
+ // check pounds
+ ByteArrayOutputStream baos1146 = new ByteArrayOutputStream();
+ gcsCp1146.writeToStream(baos1146);
+ byte[] bytes1146 = baos1146.toByteArray();
+ for (int i = 0; i < bytesToCheck.length; i++) {
+ assertEquals(bytesToCheck[i], bytes1146[6 + i]);
+ }
+ assertEquals(bytesToCheck.length + 6, bytes1146.length);
+ // check dollars
+ ByteArrayOutputStream baos500 = new ByteArrayOutputStream();
+ gcsCp500.writeToStream(baos500);
+ byte[] bytes500 = baos500.toByteArray();
+ for (int i = 0; i < bytesToCheck.length; i++) {
+ assertEquals(bytesToCheck[i], bytes500[6 + i]);
+ }
+ assertEquals(bytesToCheck.length + 6, bytes500.length);
+ }
+}
-/*\r
- * Licensed to the Apache Software Foundation (ASF) under one or more\r
- * contributor license agreements. See the NOTICE file distributed with\r
- * this work for additional information regarding copyright ownership.\r
- * The ASF licenses this file to You under the Apache License, Version 2.0\r
- * (the "License"); you may not use this file except in compliance with\r
- * the License. You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-/* $Id$ */\r
-\r
-package org.apache.fop.fo.flow.table;\r
-\r
-import org.junit.runners.Suite;\r
-\r
-/**\r
- * All test to be added in FOTreeTestSuite\r
- *\r
- */\r
-@Suite.SuiteClasses({ CollapsedConditionalBorderTestCase.class, IllegalRowSpanTestCase.class,\r
- RowGroupBuilderTestCase.class, TableColumnColumnNumberTestCase.class,\r
- TooManyColumnsTestCase.class })\r
-\r
-public final class AllTests {\r
-}\r
-\r
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.fo.flow.table;
+
+import org.junit.runners.Suite;
+
+/**
+ * All test to be added in FOTreeTestSuite
+ *
+ */
+@Suite.SuiteClasses({ CollapsedConditionalBorderTestCase.class, IllegalRowSpanTestCase.class,
+ RowGroupBuilderTestCase.class, TableColumnColumnNumberTestCase.class,
+ TooManyColumnsTestCase.class })
+
+public final class AllTests {
+}
+
-/*\r
- * Licensed to the Apache Software Foundation (ASF) under one or more\r
- * contributor license agreements. See the NOTICE file distributed with\r
- * this work for additional information regarding copyright ownership.\r
- * The ASF licenses this file to You under the Apache License, Version 2.0\r
- * (the "License"); you may not use this file except in compliance with\r
- * the License. You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-/* $Id$ */\r
-\r
-package org.apache.fop.fo.pagination;\r
-\r
-import org.junit.runners.Suite;\r
-import org.junit.runner.RunWith;\r
-\r
-/**\r
- * All test to be added in FOTreeTestSuite\r
- *\r
- */\r
-@RunWith(Suite.class)\r
-@Suite.SuiteClasses({ PageSequenceMasterTestCase.class,\r
- RepeatablePageMasterAlternativesTestCase.class})\r
-\r
-public final class AllTests {\r
-\r
-}\r
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.fo.pagination;
+
+import org.junit.runners.Suite;
+import org.junit.runner.RunWith;
+
+/**
+ * All test to be added in FOTreeTestSuite
+ *
+ */
+@RunWith(Suite.class)
+@Suite.SuiteClasses({ PageSequenceMasterTestCase.class,
+ RepeatablePageMasterAlternativesTestCase.class})
+
+public final class AllTests {
+
+}
-/*\r
- * Licensed to the Apache Software Foundation (ASF) under one or more\r
- * contributor license agreements. See the NOTICE file distributed with\r
- * this work for additional information regarding copyright ownership.\r
- * The ASF licenses this file to You under the Apache License, Version 2.0\r
- * (the "License"); you may not use this file except in compliance with\r
- * the License. You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-/* $Id$ */\r
-\r
-package org.apache.fop.fo.pagination;\r
-\r
-import static org.junit.Assert.fail;\r
-\r
-import static org.mockito.Matchers.anyBoolean;\r
-import static org.mockito.Matchers.anyInt;\r
-import static org.mockito.Matchers.anyString;\r
-import static org.mockito.Mockito.mock;\r
-import static org.mockito.Mockito.when;\r
-\r
-import org.apache.fop.fo.FONode;\r
-import org.apache.fop.layoutmgr.BlockLevelEventProducer;\r
-\r
-import org.junit.Test;\r
-\r
-\r
-/**\r
- * Unit Test for PageSequenceMaster\r
- *\r
- */\r
-public class PageSequenceMasterTestCase {\r
-\r
- /**\r
- * Test that PageProductionException is thrown if the final simple-page-master\r
- * cannot handle the main-flow of the page sequence\r
- * @throws Exception exception\r
- */\r
- @Test\r
- public void testGetNextSimplePageMasterException() throws Exception {\r
-\r
- final String mainFlowRegionName = "main";\r
- final String emptyFlowRegionName = "empty";\r
- // Create stubs\r
-\r
- FONode mockParent = mock(FONode.class);\r
- Root mockRoot = mock(Root.class);\r
- LayoutMasterSet mockLayoutMasterSet = mock(LayoutMasterSet.class);\r
-\r
- // This will represent a page master that does not map to the main flow\r
- // of the page sequence\r
- SimplePageMaster mockEmptySPM = mock(SimplePageMaster.class);\r
- Region mockRegion = mock(Region.class);\r
- SinglePageMasterReference mockSinglePageMasterReference\r
- = mock(SinglePageMasterReference.class);\r
- BlockLevelEventProducer mockBlockLevelEventProducer = mock(BlockLevelEventProducer.class);\r
-\r
- //Stub behaviour\r
- when(mockParent.getRoot()).thenReturn(mockRoot);\r
- when(mockRoot.getLayoutMasterSet()).thenReturn(mockLayoutMasterSet);\r
-\r
- //The layout master set should return the empty page master\r
- when(mockLayoutMasterSet.getSimplePageMaster(anyString())).thenReturn(mockEmptySPM);\r
- when(mockEmptySPM.getRegion(anyInt())).thenReturn(mockRegion);\r
-\r
- when(mockRegion.getRegionName()).thenReturn(emptyFlowRegionName);\r
-\r
- when(mockSinglePageMasterReference.getNextPageMaster(anyBoolean(), anyBoolean(),\r
- anyBoolean(), anyBoolean()))\r
- .thenReturn(null, mockEmptySPM);\r
-\r
- PageSequenceMaster pageSequenceMaster = new PageSequenceMaster(mockParent,\r
- mockBlockLevelEventProducer);\r
- pageSequenceMaster.startOfNode();\r
- pageSequenceMaster.addSubsequenceSpecifier(mockSinglePageMasterReference);\r
-\r
- try {\r
- pageSequenceMaster.getNextSimplePageMaster(false, false, false, false,\r
- mainFlowRegionName);\r
- fail("The next simple page master does not refer to the main flow");\r
- } catch (PageProductionException ppe) {\r
- //Passed test\r
- }\r
- }\r
-\r
-}\r
-\r
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.fo.pagination;
+
+import static org.junit.Assert.fail;
+
+import static org.mockito.Matchers.anyBoolean;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import org.apache.fop.fo.FONode;
+import org.apache.fop.layoutmgr.BlockLevelEventProducer;
+
+import org.junit.Test;
+
+
+/**
+ * Unit Test for PageSequenceMaster
+ *
+ */
+public class PageSequenceMasterTestCase {
+
+ /**
+ * Test that PageProductionException is thrown if the final simple-page-master
+ * cannot handle the main-flow of the page sequence
+ * @throws Exception exception
+ */
+ @Test
+ public void testGetNextSimplePageMasterException() throws Exception {
+
+ final String mainFlowRegionName = "main";
+ final String emptyFlowRegionName = "empty";
+ // Create stubs
+
+ FONode mockParent = mock(FONode.class);
+ Root mockRoot = mock(Root.class);
+ LayoutMasterSet mockLayoutMasterSet = mock(LayoutMasterSet.class);
+
+ // This will represent a page master that does not map to the main flow
+ // of the page sequence
+ SimplePageMaster mockEmptySPM = mock(SimplePageMaster.class);
+ Region mockRegion = mock(Region.class);
+ SinglePageMasterReference mockSinglePageMasterReference
+ = mock(SinglePageMasterReference.class);
+ BlockLevelEventProducer mockBlockLevelEventProducer = mock(BlockLevelEventProducer.class);
+
+ //Stub behaviour
+ when(mockParent.getRoot()).thenReturn(mockRoot);
+ when(mockRoot.getLayoutMasterSet()).thenReturn(mockLayoutMasterSet);
+
+ //The layout master set should return the empty page master
+ when(mockLayoutMasterSet.getSimplePageMaster(anyString())).thenReturn(mockEmptySPM);
+ when(mockEmptySPM.getRegion(anyInt())).thenReturn(mockRegion);
+
+ when(mockRegion.getRegionName()).thenReturn(emptyFlowRegionName);
+
+ when(mockSinglePageMasterReference.getNextPageMaster(anyBoolean(), anyBoolean(),
+ anyBoolean(), anyBoolean()))
+ .thenReturn(null, mockEmptySPM);
+
+ PageSequenceMaster pageSequenceMaster = new PageSequenceMaster(mockParent,
+ mockBlockLevelEventProducer);
+ pageSequenceMaster.startOfNode();
+ pageSequenceMaster.addSubsequenceSpecifier(mockSinglePageMasterReference);
+
+ try {
+ pageSequenceMaster.getNextSimplePageMaster(false, false, false, false,
+ mainFlowRegionName);
+ fail("The next simple page master does not refer to the main flow");
+ } catch (PageProductionException ppe) {
+ //Passed test
+ }
+ }
+
+}
+
-/*\r
- * Licensed to the Apache Software Foundation (ASF) under one or more\r
- * contributor license agreements. See the NOTICE file distributed with\r
- * this work for additional information regarding copyright ownership.\r
- * The ASF licenses this file to You under the Apache License, Version 2.0\r
- * (the "License"); you may not use this file except in compliance with\r
- * the License. You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-/* $Id$ */\r
-\r
-package org.apache.fop.fo.pagination;\r
-\r
-import static org.junit.Assert.assertTrue;\r
-import static org.mockito.Matchers.anyBoolean;\r
-import static org.mockito.Matchers.anyInt;\r
-import static org.mockito.Mockito.mock;\r
-import static org.mockito.Mockito.when;\r
-\r
-import org.junit.Test;\r
-\r
-import org.apache.fop.fo.Constants;\r
-import org.apache.fop.fo.PropertyList;\r
-import org.apache.fop.fo.expr.NumericProperty;\r
-import org.apache.fop.fo.properties.Property;\r
-\r
-\r
-\r
-/**\r
- * Unit Test for RepeatablePageMasterAlternatives\r
- *\r
- */\r
-public class RepeatablePageMasterAlternativesTestCase\r
-implements Constants {\r
-\r
- /**\r
- *\r
- * @throws Exception exception\r
- */\r
- @Test\r
- public void testIsInfinite1() throws Exception {\r
- // Create fixture\r
- Property maximumRepeats = mock(Property.class);\r
- ConditionalPageMasterReference cpmr = createCPMR("empty");\r
-\r
- when(maximumRepeats.getEnum()).thenReturn(EN_NO_LIMIT);\r
-\r
- RepeatablePageMasterAlternatives objectUnderTest\r
- = createRepeatablePageMasterAlternatives(cpmr, maximumRepeats);\r
-\r
- assertTrue("is infinite", objectUnderTest.isInfinite());\r
- }\r
-\r
- /**\r
- *\r
- * @throws Exception exception\r
- */\r
- @Test\r
- public void testIsInfinite2() throws Exception {\r
- // Create fixture\r
- Property maximumRepeats = mock(Property.class);\r
- ConditionalPageMasterReference cpmr = createCPMR("empty");\r
-\r
- NumericProperty numericProperty = mock(NumericProperty.class);\r
-\r
- final int maxRepeatNum = 0;\r
- assertTrue(maxRepeatNum != EN_NO_LIMIT);\r
-\r
- when(maximumRepeats.getEnum()).thenReturn(maxRepeatNum);\r
- when(maximumRepeats.getNumeric()).thenReturn(numericProperty);\r
-\r
- RepeatablePageMasterAlternatives objectUnderTest\r
- = createRepeatablePageMasterAlternatives(createCPMR("empty"),\r
- maximumRepeats);\r
-\r
- assertTrue("is infinite", !objectUnderTest.isInfinite());\r
- }\r
-\r
- /**\r
- * Test that an infinite sequence of empty page masters has\r
- * willTerminiate() returning false\r
- * @throws Exception exception\r
- */\r
- @Test\r
- public void testCanProcess1() throws Exception {\r
- // Create fixture\r
- Property maximumRepeats = mock(Property.class);\r
- ConditionalPageMasterReference cpmr = createCPMR("empty");\r
-\r
- when(maximumRepeats.getEnum()).thenReturn(EN_NO_LIMIT);\r
- when(cpmr.isValid(anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean()))\r
- .thenReturn(true);\r
-\r
- RepeatablePageMasterAlternatives objectUnderTest\r
- = createRepeatablePageMasterAlternatives(cpmr, maximumRepeats);\r
-\r
- //Fixture assertion\r
- assertTrue("Should be infinite", objectUnderTest.isInfinite());\r
-\r
- //Test assertion\r
- assertTrue("Infinite sequences that do not process the main flow will "\r
- + " not terminate",\r
- !objectUnderTest.canProcess("main-flow"));\r
- }\r
- /**\r
- * Test that a finite sequence of simple page masters has\r
- * willTerminate() returning true\r
- *\r
- * @throws Exception exception\r
- */\r
- @Test\r
- public void testCanProcess2() throws Exception {\r
- // Create fixture\r
- Property maximumRepeats = mock(Property.class);\r
- NumericProperty numericProperty = mock(NumericProperty.class);\r
-\r
- final int maxRepeatNum = 0;\r
-\r
- when(maximumRepeats.getEnum()).thenReturn(maxRepeatNum);\r
- when(maximumRepeats.getNumeric()).thenReturn(numericProperty);\r
-\r
- RepeatablePageMasterAlternatives objectUnderTest\r
- = createRepeatablePageMasterAlternatives(createCPMR("empty"),\r
- maximumRepeats);\r
-\r
- //Fixture assertion\r
- assertTrue("Should be finite sequence", !objectUnderTest.isInfinite());\r
-\r
- //Test assertion\r
- assertTrue("Finite sequences will terminate",\r
- objectUnderTest.canProcess("main-flow"));\r
- }\r
-\r
- private ConditionalPageMasterReference createCPMR(String regionName) {\r
- ConditionalPageMasterReference cpmr = mock(ConditionalPageMasterReference.class);\r
- SimplePageMaster master = mock(SimplePageMaster.class);\r
- Region region = mock(Region.class);\r
- when(master.getRegion(anyInt())).thenReturn(region);\r
- when(region.getRegionName()).thenReturn(regionName);\r
- when(cpmr.getMaster()).thenReturn(master);\r
-\r
- return cpmr;\r
- }\r
-\r
- private RepeatablePageMasterAlternatives createRepeatablePageMasterAlternatives(\r
- ConditionalPageMasterReference cpmr, Property maximumRepeats) throws Exception {\r
-\r
- PropertyList pList = mock(PropertyList.class);\r
-\r
- when(pList.get(anyInt())).thenReturn(maximumRepeats);\r
-\r
- PageSequenceMaster parent = mock(PageSequenceMaster.class);\r
-\r
- RepeatablePageMasterAlternatives sut = new RepeatablePageMasterAlternatives(parent);\r
-\r
- sut.startOfNode();\r
- sut.bind(pList);\r
- sut.addConditionalPageMasterReference(cpmr);\r
- return sut;\r
- }\r
-\r
-}\r
-\r
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.fo.pagination;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Matchers.anyBoolean;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import org.junit.Test;
+
+import org.apache.fop.fo.Constants;
+import org.apache.fop.fo.PropertyList;
+import org.apache.fop.fo.expr.NumericProperty;
+import org.apache.fop.fo.properties.Property;
+
+
+
+/**
+ * Unit Test for RepeatablePageMasterAlternatives
+ *
+ */
+public class RepeatablePageMasterAlternativesTestCase
+implements Constants {
+
+ /**
+ *
+ * @throws Exception exception
+ */
+ @Test
+ public void testIsInfinite1() throws Exception {
+ // Create fixture
+ Property maximumRepeats = mock(Property.class);
+ ConditionalPageMasterReference cpmr = createCPMR("empty");
+
+ when(maximumRepeats.getEnum()).thenReturn(EN_NO_LIMIT);
+
+ RepeatablePageMasterAlternatives objectUnderTest
+ = createRepeatablePageMasterAlternatives(cpmr, maximumRepeats);
+
+ assertTrue("is infinite", objectUnderTest.isInfinite());
+ }
+
+ /**
+ *
+ * @throws Exception exception
+ */
+ @Test
+ public void testIsInfinite2() throws Exception {
+ // Create fixture
+ Property maximumRepeats = mock(Property.class);
+ ConditionalPageMasterReference cpmr = createCPMR("empty");
+
+ NumericProperty numericProperty = mock(NumericProperty.class);
+
+ final int maxRepeatNum = 0;
+ assertTrue(maxRepeatNum != EN_NO_LIMIT);
+
+ when(maximumRepeats.getEnum()).thenReturn(maxRepeatNum);
+ when(maximumRepeats.getNumeric()).thenReturn(numericProperty);
+
+ RepeatablePageMasterAlternatives objectUnderTest
+ = createRepeatablePageMasterAlternatives(createCPMR("empty"),
+ maximumRepeats);
+
+ assertTrue("is infinite", !objectUnderTest.isInfinite());
+ }
+
+ /**
+ * Test that an infinite sequence of empty page masters has
+ * willTerminiate() returning false
+ * @throws Exception exception
+ */
+ @Test
+ public void testCanProcess1() throws Exception {
+ // Create fixture
+ Property maximumRepeats = mock(Property.class);
+ ConditionalPageMasterReference cpmr = createCPMR("empty");
+
+ when(maximumRepeats.getEnum()).thenReturn(EN_NO_LIMIT);
+ when(cpmr.isValid(anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean()))
+ .thenReturn(true);
+
+ RepeatablePageMasterAlternatives objectUnderTest
+ = createRepeatablePageMasterAlternatives(cpmr, maximumRepeats);
+
+ //Fixture assertion
+ assertTrue("Should be infinite", objectUnderTest.isInfinite());
+
+ //Test assertion
+ assertTrue("Infinite sequences that do not process the main flow will "
+ + " not terminate",
+ !objectUnderTest.canProcess("main-flow"));
+ }
+ /**
+ * Test that a finite sequence of simple page masters has
+ * willTerminate() returning true
+ *
+ * @throws Exception exception
+ */
+ @Test
+ public void testCanProcess2() throws Exception {
+ // Create fixture
+ Property maximumRepeats = mock(Property.class);
+ NumericProperty numericProperty = mock(NumericProperty.class);
+
+ final int maxRepeatNum = 0;
+
+ when(maximumRepeats.getEnum()).thenReturn(maxRepeatNum);
+ when(maximumRepeats.getNumeric()).thenReturn(numericProperty);
+
+ RepeatablePageMasterAlternatives objectUnderTest
+ = createRepeatablePageMasterAlternatives(createCPMR("empty"),
+ maximumRepeats);
+
+ //Fixture assertion
+ assertTrue("Should be finite sequence", !objectUnderTest.isInfinite());
+
+ //Test assertion
+ assertTrue("Finite sequences will terminate",
+ objectUnderTest.canProcess("main-flow"));
+ }
+
+ private ConditionalPageMasterReference createCPMR(String regionName) {
+ ConditionalPageMasterReference cpmr = mock(ConditionalPageMasterReference.class);
+ SimplePageMaster master = mock(SimplePageMaster.class);
+ Region region = mock(Region.class);
+ when(master.getRegion(anyInt())).thenReturn(region);
+ when(region.getRegionName()).thenReturn(regionName);
+ when(cpmr.getMaster()).thenReturn(master);
+
+ return cpmr;
+ }
+
+ private RepeatablePageMasterAlternatives createRepeatablePageMasterAlternatives(
+ ConditionalPageMasterReference cpmr, Property maximumRepeats) throws Exception {
+
+ PropertyList pList = mock(PropertyList.class);
+
+ when(pList.get(anyInt())).thenReturn(maximumRepeats);
+
+ PageSequenceMaster parent = mock(PageSequenceMaster.class);
+
+ RepeatablePageMasterAlternatives sut = new RepeatablePageMasterAlternatives(parent);
+
+ sut.startOfNode();
+ sut.bind(pList);
+ sut.addConditionalPageMasterReference(cpmr);
+ return sut;
+ }
+
+}
+
-/*\r
- * Licensed to the Apache Software Foundation (ASF) under one or more\r
- * contributor license agreements. See the NOTICE file distributed with\r
- * this work for additional information regarding copyright ownership.\r
- * The ASF licenses this file to You under the Apache License, Version 2.0\r
- * (the "License"); you may not use this file except in compliance with\r
- * the License. You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-/* $Id$ */\r
-\r
-package org.apache.fop.pdf;\r
-\r
-import java.io.ByteArrayOutputStream;\r
-import java.io.IOException;\r
-import java.io.OutputStream;\r
-\r
-import static org.junit.Assert.assertEquals;\r
-import org.junit.Before;\r
-import org.junit.Test;\r
-\r
-/**\r
- * Test case for {@link AbstractPDFStream}.\r
- */\r
-public class AbstractPDFStreamTestCase extends PDFObjectTestCase {\r
-\r
- private AbstractPDFStream abstractStream;\r
-\r
- private String textData = "This is an arbitrary string for testing.";\r
-\r
- private static byte[] encodedBytes;\r
- static {\r
- int[] encoded = { 0x78, 0x9c, 0x0b, 0xc9, 0xc8, 0x2c, 0x56, 0x00, 0xa2, 0xc4, 0x3c, 0x85,\r
- 0xc4, 0xa2, 0xa4, 0xcc, 0x92, 0xa2, 0xc4, 0xa2, 0x4a, 0x85, 0xe2, 0x92, 0xa2, 0xcc,\r
- 0xbc, 0x74, 0x85, 0xb4, 0xfc, 0x22, 0x85, 0x92, 0xd4, 0xe2, 0x12, 0x20, 0x5b, 0x0f,\r
- 0x00, 0x2d, 0x2b, 0x0e, 0xde, 0x0a };\r
- encodedBytes = new byte[encoded.length];\r
- int i = 0;\r
- for (int in : encoded) {\r
- encodedBytes[i++] = (byte) (in & 0xff);\r
- }\r
- }\r
- private String startStream = "1 0 obj\n" +\r
- "<< /Length 5 0 R /Filter /FlateDecode >>\n" +\r
- "stream\n";\r
- private String endStream = "endstream\nendobj\n";\r
-\r
- @Before\r
- public void setUp() {\r
- abstractStream = new AbstractPDFStream() {\r
-\r
- @Override\r
- protected void outputRawStreamData(OutputStream out) throws IOException {\r
- out.write(textData.getBytes());\r
- }\r
-\r
- @Override\r
- protected int getSizeHint() throws IOException {\r
- return textData.length();\r
- }\r
- };\r
- abstractStream.setDocument(doc);\r
- abstractStream.setParent(parent);\r
-\r
- pdfObjectUnderTest = abstractStream;\r
- }\r
-\r
- /**\r
- * Tests output() - ensure that this object is correctly formatted to the output stream.\r
- * @throws IOException if an I/O error occurs\r
- */\r
- @Test\r
- public void testOutput() throws IOException {\r
- // This differs from most other objects, if the object number = 0 an exception is thrown\r
- ByteArrayOutputStream outStream = new ByteArrayOutputStream();\r
- abstractStream.setObjectNumber(1);\r
- ByteArrayOutputStream expectedStream = new ByteArrayOutputStream();\r
- expectedStream.write(startStream.getBytes());\r
- expectedStream.write(encodedBytes);\r
- expectedStream.write(endStream.getBytes());\r
- assertEquals(expectedStream.size(), abstractStream.output(outStream));\r
- assertEquals(expectedStream.toString(), outStream.toString());\r
- }\r
-}\r
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.pdf;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+import static org.junit.Assert.assertEquals;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test case for {@link AbstractPDFStream}.
+ */
+public class AbstractPDFStreamTestCase extends PDFObjectTestCase {
+
+ private AbstractPDFStream abstractStream;
+
+ private String textData = "This is an arbitrary string for testing.";
+
+ private static byte[] encodedBytes;
+ static {
+ int[] encoded = { 0x78, 0x9c, 0x0b, 0xc9, 0xc8, 0x2c, 0x56, 0x00, 0xa2, 0xc4, 0x3c, 0x85,
+ 0xc4, 0xa2, 0xa4, 0xcc, 0x92, 0xa2, 0xc4, 0xa2, 0x4a, 0x85, 0xe2, 0x92, 0xa2, 0xcc,
+ 0xbc, 0x74, 0x85, 0xb4, 0xfc, 0x22, 0x85, 0x92, 0xd4, 0xe2, 0x12, 0x20, 0x5b, 0x0f,
+ 0x00, 0x2d, 0x2b, 0x0e, 0xde, 0x0a };
+ encodedBytes = new byte[encoded.length];
+ int i = 0;
+ for (int in : encoded) {
+ encodedBytes[i++] = (byte) (in & 0xff);
+ }
+ }
+ private String startStream = "1 0 obj\n" +
+ "<< /Length 5 0 R /Filter /FlateDecode >>\n" +
+ "stream\n";
+ private String endStream = "endstream\nendobj\n";
+
+ @Before
+ public void setUp() {
+ abstractStream = new AbstractPDFStream() {
+
+ @Override
+ protected void outputRawStreamData(OutputStream out) throws IOException {
+ out.write(textData.getBytes());
+ }
+
+ @Override
+ protected int getSizeHint() throws IOException {
+ return textData.length();
+ }
+ };
+ abstractStream.setDocument(doc);
+ abstractStream.setParent(parent);
+
+ pdfObjectUnderTest = abstractStream;
+ }
+
+ /**
+ * Tests output() - ensure that this object is correctly formatted to the output stream.
+ * @throws IOException if an I/O error occurs
+ */
+ @Test
+ public void testOutput() throws IOException {
+ // This differs from most other objects, if the object number = 0 an exception is thrown
+ ByteArrayOutputStream outStream = new ByteArrayOutputStream();
+ abstractStream.setObjectNumber(1);
+ ByteArrayOutputStream expectedStream = new ByteArrayOutputStream();
+ expectedStream.write(startStream.getBytes());
+ expectedStream.write(encodedBytes);
+ expectedStream.write(endStream.getBytes());
+ assertEquals(expectedStream.size(), abstractStream.output(outStream));
+ assertEquals(expectedStream.toString(), outStream.toString());
+ }
+}
-/*\r
- * Licensed to the Apache Software Foundation (ASF) under one or more\r
- * contributor license agreements. See the NOTICE file distributed with\r
- * this work for additional information regarding copyright ownership.\r
- * The ASF licenses this file to You under the Apache License, Version 2.0\r
- * (the "License"); you may not use this file except in compliance with\r
- * the License. You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-/* $Id$ */\r
-\r
-package org.apache.fop.pdf;\r
-\r
-import static org.junit.Assert.assertFalse;\r
-import static org.junit.Assert.assertTrue;\r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.fail;\r
-\r
-import org.junit.Before;\r
-import org.junit.Test;\r
-\r
-import java.io.IOException;\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-\r
-/**\r
- * Test case for {@link PDFArray}.\r
- */\r
-public class PDFArrayTestCase extends PDFObjectTestCase {\r
- private PDFArray intArray;\r
- private String intArrayOutput;\r
- private PDFArray doubleArray;\r
- private String doubleArrayOutput;\r
- private PDFArray collectionArray;\r
- private String collectionArrayOutput;\r
- private PDFArray objArray;\r
- private String objArrayOutput;\r
-\r
- /** A PDF object used solely for testing */\r
- private PDFNumber num;\r
-\r
- @Before\r
- public void setUp() {\r
- intArray = new PDFArray(parent, new int[] {1, 2, 3, 4, 5});\r
- intArrayOutput = "[1 2 3 4 5]";\r
-\r
- doubleArray = new PDFArray(parent, new double[] {1.1, 2.2, 3.3, 4.4, 5.5});\r
- doubleArrayOutput = "[1.1 2.2 3.3 4.4 5.5]";\r
-\r
- List<Object> strList = new ArrayList<Object>();\r
- strList.add("one");\r
- strList.add("two");\r
- strList.add("three");\r
- collectionArray = new PDFArray(parent, strList);\r
- collectionArrayOutput = "[(one) (two) (three)]";\r
-\r
- // Set arbitrary values here\r
- num = new PDFNumber();\r
- num.setNumber(20);\r
- num.setObjectNumber(4);\r
- objArray = new PDFArray(parent, new Object[] {"one", 2, 3.0f, num});\r
- objArrayOutput = "[(one) 2 3 4 0 R]";\r
-\r
- // set the document\r
- intArray.setDocument(doc);\r
- doubleArray.setDocument(doc);\r
- collectionArray.setDocument(doc);\r
- objArray.setDocument(doc);\r
-\r
- // Test the progenitor in the inheritance stack\r
- objArray.setParent(parent);\r
- pdfObjectUnderTest = objArray;\r
- }\r
-\r
- private void intArrayContainsTests() {\r
- for (int i = 1; i <= 5; i++) {\r
- assertTrue(intArray.contains(i));\r
- }\r
- assertFalse(intArray.contains(6));\r
- assertFalse(intArray.contains(0));\r
- }\r
-\r
- private void doubleArrayContainsTests() {\r
- assertTrue(doubleArray.contains(1.1));\r
- assertTrue(doubleArray.contains(2.2));\r
- assertTrue(doubleArray.contains(3.3));\r
- assertTrue(doubleArray.contains(4.4));\r
- assertTrue(doubleArray.contains(5.5));\r
- assertFalse(doubleArray.contains(10.0));\r
- assertFalse(doubleArray.contains(0.0));\r
- }\r
-\r
- private void collectionArrayContainsTests() {\r
- assertTrue(collectionArray.contains("one"));\r
- assertTrue(collectionArray.contains("two"));\r
- assertTrue(collectionArray.contains("three"));\r
- assertFalse(collectionArray.contains("zero"));\r
- assertFalse(collectionArray.contains("four"));\r
- }\r
-\r
- private void objectArrayContainsTests() {\r
- assertTrue(objArray.contains("one"));\r
- assertTrue(objArray.contains(2));\r
- assertTrue(objArray.contains(3.0f));\r
- assertTrue(objArray.contains(num));\r
- assertFalse(objArray.contains("four"));\r
- assertFalse(objArray.contains(0.0));\r
- }\r
-\r
- /**\r
- * Test contains() - test whether this PDFArray contains an object.\r
- */\r
- @Test\r
- public void testContains() {\r
- // Test some arbitrary values\r
- intArrayContainsTests();\r
- doubleArrayContainsTests();\r
- collectionArrayContainsTests();\r
- objectArrayContainsTests();\r
- }\r
-\r
- /**\r
- * Test length() - tests the length of an array.\r
- */\r
- @Test\r
- public void testLength() {\r
- assertEquals(5, intArray.length());\r
- assertEquals(5, doubleArray.length());\r
- assertEquals(3, collectionArray.length());\r
- assertEquals(4, objArray.length());\r
-\r
- // Test the count is incremented when an object is added (this only\r
- // needs to be tested once)\r
- intArray.add(6);\r
- assertEquals(6, intArray.length());\r
- }\r
-\r
- /**\r
- * Test set() - tests that a particular point has been properly set.\r
- */\r
- @Test\r
- public void testSet() {\r
- PDFName name = new PDFName("zero test");\r
- objArray.set(0, name);\r
- assertEquals(name, objArray.get(0));\r
-\r
- objArray.set(1, "test");\r
- assertEquals("test", objArray.get(1));\r
- // This goes through the set(int, double) code path rather than set(int, Object)\r
- objArray.set(2, 5);\r
- assertEquals(5.0, objArray.get(2));\r
- try {\r
- objArray.set(4, 2);\r
- fail("out of bounds");\r
- } catch (IndexOutOfBoundsException e) {\r
- // Pass\r
- }\r
- }\r
-\r
- /**\r
- * Test get() - gets the object stored at a given index.\r
- */\r
- @Test\r
- public void testGet() {\r
- // Test some arbitrary values\r
- for (int i = 1; i <= 5; i++) {\r
- assertEquals(i, intArray.get(i - 1));\r
- }\r
-\r
- assertEquals(1.1, doubleArray.get(0));\r
- assertEquals(2.2, doubleArray.get(1));\r
- assertEquals(3.3, doubleArray.get(2));\r
- assertEquals(4.4, doubleArray.get(3));\r
- assertEquals(5.5, doubleArray.get(4));\r
-\r
- assertEquals("one", collectionArray.get(0));\r
- assertEquals("two", collectionArray.get(1));\r
- assertEquals("three", collectionArray.get(2));\r
-\r
- assertEquals("one", objArray.get(0));\r
- assertEquals(2, objArray.get(1));\r
- assertEquals(0, Double.compare(3.0, (Float) objArray.get(2)));\r
- assertEquals(num, objArray.get(3));\r
- }\r
-\r
- /**\r
- * Tests add() - tests that objects are appended to the end of the array as expected.\r
- */\r
- @Test\r
- public void testAdd() {\r
- intArray.add(new Integer(6));\r
- doubleArray.add(6.6);\r
- // Test some arbitrary values\r
- for (int i = 1; i <= 6; i++) {\r
- assertEquals(i, intArray.get(i - 1));\r
- }\r
-\r
- assertEquals(1.1, doubleArray.get(0));\r
- assertEquals(2.2, doubleArray.get(1));\r
- assertEquals(3.3, doubleArray.get(2));\r
- assertEquals(4.4, doubleArray.get(3));\r
- assertEquals(5.5, doubleArray.get(4));\r
- assertEquals(6.6, doubleArray.get(5));\r
-\r
- collectionArray.add(1);\r
- assertEquals("one", collectionArray.get(0));\r
- assertEquals("two", collectionArray.get(1));\r
- assertEquals("three", collectionArray.get(2));\r
- assertEquals(1.0, collectionArray.get(3));\r
-\r
- objArray.add("four");\r
- assertEquals("one", objArray.get(0));\r
- assertEquals(2, objArray.get(1));\r
- assertEquals(0, Double.compare(3.0, (Float) objArray.get(2)));\r
- assertEquals("four", objArray.get(4));\r
- }\r
-\r
- /**\r
- * Tests output() - tests that this object is properly streamed to the PDF document.\r
- * @throws IOException error caused by I/O\r
- */\r
- @Test\r
- public void testOutput() throws IOException {\r
- testOutputStreams(intArrayOutput, intArray);\r
- testOutputStreams(doubleArrayOutput, doubleArray);\r
- testOutputStreams(collectionArrayOutput, collectionArray);\r
- testOutputStreams(objArrayOutput, objArray);\r
- }\r
-}\r
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.pdf;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Test case for {@link PDFArray}.
+ */
+public class PDFArrayTestCase extends PDFObjectTestCase {
+ private PDFArray intArray;
+ private String intArrayOutput;
+ private PDFArray doubleArray;
+ private String doubleArrayOutput;
+ private PDFArray collectionArray;
+ private String collectionArrayOutput;
+ private PDFArray objArray;
+ private String objArrayOutput;
+
+ /** A PDF object used solely for testing */
+ private PDFNumber num;
+
+ @Before
+ public void setUp() {
+ intArray = new PDFArray(parent, new int[] {1, 2, 3, 4, 5});
+ intArrayOutput = "[1 2 3 4 5]";
+
+ doubleArray = new PDFArray(parent, new double[] {1.1, 2.2, 3.3, 4.4, 5.5});
+ doubleArrayOutput = "[1.1 2.2 3.3 4.4 5.5]";
+
+ List<Object> strList = new ArrayList<Object>();
+ strList.add("one");
+ strList.add("two");
+ strList.add("three");
+ collectionArray = new PDFArray(parent, strList);
+ collectionArrayOutput = "[(one) (two) (three)]";
+
+ // Set arbitrary values here
+ num = new PDFNumber();
+ num.setNumber(20);
+ num.setObjectNumber(4);
+ objArray = new PDFArray(parent, new Object[] {"one", 2, 3.0f, num});
+ objArrayOutput = "[(one) 2 3 4 0 R]";
+
+ // set the document
+ intArray.setDocument(doc);
+ doubleArray.setDocument(doc);
+ collectionArray.setDocument(doc);
+ objArray.setDocument(doc);
+
+ // Test the progenitor in the inheritance stack
+ objArray.setParent(parent);
+ pdfObjectUnderTest = objArray;
+ }
+
+ private void intArrayContainsTests() {
+ for (int i = 1; i <= 5; i++) {
+ assertTrue(intArray.contains(i));
+ }
+ assertFalse(intArray.contains(6));
+ assertFalse(intArray.contains(0));
+ }
+
+ private void doubleArrayContainsTests() {
+ assertTrue(doubleArray.contains(1.1));
+ assertTrue(doubleArray.contains(2.2));
+ assertTrue(doubleArray.contains(3.3));
+ assertTrue(doubleArray.contains(4.4));
+ assertTrue(doubleArray.contains(5.5));
+ assertFalse(doubleArray.contains(10.0));
+ assertFalse(doubleArray.contains(0.0));
+ }
+
+ private void collectionArrayContainsTests() {
+ assertTrue(collectionArray.contains("one"));
+ assertTrue(collectionArray.contains("two"));
+ assertTrue(collectionArray.contains("three"));
+ assertFalse(collectionArray.contains("zero"));
+ assertFalse(collectionArray.contains("four"));
+ }
+
+ private void objectArrayContainsTests() {
+ assertTrue(objArray.contains("one"));
+ assertTrue(objArray.contains(2));
+ assertTrue(objArray.contains(3.0f));
+ assertTrue(objArray.contains(num));
+ assertFalse(objArray.contains("four"));
+ assertFalse(objArray.contains(0.0));
+ }
+
+ /**
+ * Test contains() - test whether this PDFArray contains an object.
+ */
+ @Test
+ public void testContains() {
+ // Test some arbitrary values
+ intArrayContainsTests();
+ doubleArrayContainsTests();
+ collectionArrayContainsTests();
+ objectArrayContainsTests();
+ }
+
+ /**
+ * Test length() - tests the length of an array.
+ */
+ @Test
+ public void testLength() {
+ assertEquals(5, intArray.length());
+ assertEquals(5, doubleArray.length());
+ assertEquals(3, collectionArray.length());
+ assertEquals(4, objArray.length());
+
+ // Test the count is incremented when an object is added (this only
+ // needs to be tested once)
+ intArray.add(6);
+ assertEquals(6, intArray.length());
+ }
+
+ /**
+ * Test set() - tests that a particular point has been properly set.
+ */
+ @Test
+ public void testSet() {
+ PDFName name = new PDFName("zero test");
+ objArray.set(0, name);
+ assertEquals(name, objArray.get(0));
+
+ objArray.set(1, "test");
+ assertEquals("test", objArray.get(1));
+ // This goes through the set(int, double) code path rather than set(int, Object)
+ objArray.set(2, 5);
+ assertEquals(5.0, objArray.get(2));
+ try {
+ objArray.set(4, 2);
+ fail("out of bounds");
+ } catch (IndexOutOfBoundsException e) {
+ // Pass
+ }
+ }
+
+ /**
+ * Test get() - gets the object stored at a given index.
+ */
+ @Test
+ public void testGet() {
+ // Test some arbitrary values
+ for (int i = 1; i <= 5; i++) {
+ assertEquals(i, intArray.get(i - 1));
+ }
+
+ assertEquals(1.1, doubleArray.get(0));
+ assertEquals(2.2, doubleArray.get(1));
+ assertEquals(3.3, doubleArray.get(2));
+ assertEquals(4.4, doubleArray.get(3));
+ assertEquals(5.5, doubleArray.get(4));
+
+ assertEquals("one", collectionArray.get(0));
+ assertEquals("two", collectionArray.get(1));
+ assertEquals("three", collectionArray.get(2));
+
+ assertEquals("one", objArray.get(0));
+ assertEquals(2, objArray.get(1));
+ assertEquals(0, Double.compare(3.0, (Float) objArray.get(2)));
+ assertEquals(num, objArray.get(3));
+ }
+
+ /**
+ * Tests add() - tests that objects are appended to the end of the array as expected.
+ */
+ @Test
+ public void testAdd() {
+ intArray.add(new Integer(6));
+ doubleArray.add(6.6);
+ // Test some arbitrary values
+ for (int i = 1; i <= 6; i++) {
+ assertEquals(i, intArray.get(i - 1));
+ }
+
+ assertEquals(1.1, doubleArray.get(0));
+ assertEquals(2.2, doubleArray.get(1));
+ assertEquals(3.3, doubleArray.get(2));
+ assertEquals(4.4, doubleArray.get(3));
+ assertEquals(5.5, doubleArray.get(4));
+ assertEquals(6.6, doubleArray.get(5));
+
+ collectionArray.add(1);
+ assertEquals("one", collectionArray.get(0));
+ assertEquals("two", collectionArray.get(1));
+ assertEquals("three", collectionArray.get(2));
+ assertEquals(1.0, collectionArray.get(3));
+
+ objArray.add("four");
+ assertEquals("one", objArray.get(0));
+ assertEquals(2, objArray.get(1));
+ assertEquals(0, Double.compare(3.0, (Float) objArray.get(2)));
+ assertEquals("four", objArray.get(4));
+ }
+
+ /**
+ * Tests output() - tests that this object is properly streamed to the PDF document.
+ * @throws IOException error caused by I/O
+ */
+ @Test
+ public void testOutput() throws IOException {
+ testOutputStreams(intArrayOutput, intArray);
+ testOutputStreams(doubleArrayOutput, doubleArray);
+ testOutputStreams(collectionArrayOutput, collectionArray);
+ testOutputStreams(objArrayOutput, objArray);
+ }
+}
-/*\r
- * Licensed to the Apache Software Foundation (ASF) under one or more\r
- * contributor license agreements. See the NOTICE file distributed with\r
- * this work for additional information regarding copyright ownership.\r
- * The ASF licenses this file to You under the Apache License, Version 2.0\r
- * (the "License"); you may not use this file except in compliance with\r
- * the License. You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-/* $Id$ */\r
-\r
-package org.apache.fop.pdf;\r
-\r
-import org.junit.Before;\r
-import org.junit.Test;\r
-\r
-import java.io.IOException;\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-\r
-/**\r
- * Test case for {@link PDFDests}.\r
- */\r
-public class PDFDestsTestCase extends PDFObjectTestCase {\r
-\r
- private PDFDests dests = new PDFDests();\r
- private String expectedString = "<< /Names [(number) 10 (name) /Test#20name] >>\n";\r
-\r
- @Before\r
- public void setUp() {\r
- List<PDFDestination> destinations = new ArrayList<PDFDestination>();\r
- PDFNumber number = new PDFNumber();\r
- number.setNumber(10);\r
- PDFDestination testNumber = new PDFDestination("number", number);\r
- testNumber.setDocument(doc);\r
- destinations.add(testNumber);\r
- PDFDestination testName = new PDFDestination("name", new PDFName("Test name"));\r
- testName.setDocument(doc);\r
- destinations.add(testName);\r
-\r
- dests = new PDFDests(destinations);\r
- dests.setDocument(doc);\r
- dests.setParent(parent);\r
- pdfObjectUnderTest = dests;\r
- }\r
-\r
- /**\r
- * Populate the object with some arbitrary values and ensure they are wrapped properly.\r
- * @throws IOException if an I/O error occurs\r
- */\r
- @Test\r
- public void testConstructor() throws IOException {\r
- // Seems the only way to test this is by testing the output\r
- testOutputStreams(expectedString, dests);\r
- }\r
-}\r
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.pdf;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Test case for {@link PDFDests}.
+ */
+public class PDFDestsTestCase extends PDFObjectTestCase {
+
+ private PDFDests dests = new PDFDests();
+ private String expectedString = "<< /Names [(number) 10 (name) /Test#20name] >>\n";
+
+ @Before
+ public void setUp() {
+ List<PDFDestination> destinations = new ArrayList<PDFDestination>();
+ PDFNumber number = new PDFNumber();
+ number.setNumber(10);
+ PDFDestination testNumber = new PDFDestination("number", number);
+ testNumber.setDocument(doc);
+ destinations.add(testNumber);
+ PDFDestination testName = new PDFDestination("name", new PDFName("Test name"));
+ testName.setDocument(doc);
+ destinations.add(testName);
+
+ dests = new PDFDests(destinations);
+ dests.setDocument(doc);
+ dests.setParent(parent);
+ pdfObjectUnderTest = dests;
+ }
+
+ /**
+ * Populate the object with some arbitrary values and ensure they are wrapped properly.
+ * @throws IOException if an I/O error occurs
+ */
+ @Test
+ public void testConstructor() throws IOException {
+ // Seems the only way to test this is by testing the output
+ testOutputStreams(expectedString, dests);
+ }
+}
-/*\r
- * Licensed to the Apache Software Foundation (ASF) under one or more\r
- * contributor license agreements. See the NOTICE file distributed with\r
- * this work for additional information regarding copyright ownership.\r
- * The ASF licenses this file to You under the Apache License, Version 2.0\r
- * (the "License"); you may not use this file except in compliance with\r
- * the License. You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-/* $Id$ */\r
-\r
-package org.apache.fop.pdf;\r
-\r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.assertNull;\r
-import static org.junit.Assert.fail;\r
-\r
-import java.io.ByteArrayOutputStream;\r
-import java.io.IOException;\r
-\r
-import org.apache.commons.io.output.CountingOutputStream;\r
-import org.junit.Before;\r
-import org.junit.Test;\r
-\r
-\r
-/**\r
- * Test case for {@link PDFDictionary}.\r
- */\r
-public class PDFDictionaryTestCase extends PDFObjectTestCase {\r
- /** The test subject */\r
- private PDFDictionary pdfDictUnderTest;\r
- private PDFArray testArray;\r
- private PDFNumber testNumber;\r
- /** The order in which these objects are put into the dictionary MUST be maintained. */\r
- private String expectedOutput = "<<\n"\r
- + " /String (TestValue)\n"\r
- + " /int 10\n"\r
- + " /double 3.1\n"\r
- + " /array [1 (two) 20]\n"\r
- + " /number 20\n"\r
- + " /null null\n"\r
- + ">>\n";\r
-\r
- @Before\r
- public void setUp() {\r
- // A PDFNumber for testing, this DOES have a parent\r
- testNumber = new PDFNumber();\r
- testNumber.setParent(parent);\r
- testNumber.setNumber(20);\r
- // An array for testing, this DOES NOT have a parent\r
- testArray = new PDFArray();\r
- testArray.add(1);\r
- testArray.add("two");\r
- testArray.add(testNumber);\r
- // Populating the dictionary with a parent, document and the various objects\r
- pdfDictUnderTest = new PDFDictionary(parent);\r
- pdfDictUnderTest.setDocument(doc);\r
- pdfDictUnderTest.put("String", "TestValue");\r
- pdfDictUnderTest.put("int", 10);\r
- pdfDictUnderTest.put("double", Double.valueOf(3.1));\r
- pdfDictUnderTest.put("array", testArray);\r
- pdfDictUnderTest.put("number", testNumber);\r
- // null is a valid PDF object\r
- pdfDictUnderTest.put("null", null);\r
- // test that the interface is maintained\r
- pdfObjectUnderTest = pdfDictUnderTest;\r
- }\r
-\r
- /**\r
- * Tests put() - tests that the object is put into the dictionary and it is handled if it is a\r
- * {@link PDFObject}.\r
- */\r
- @Test\r
- public void testPut() {\r
- // The "put()" commands have already been done in setUp(), so just test them.\r
- assertEquals("TestValue", pdfDictUnderTest.get("String"));\r
- assertEquals(10, pdfDictUnderTest.get("int"));\r
- assertEquals(3.1, pdfDictUnderTest.get("double"));\r
- // With PDFObjects, if they DO NOT have a parent, the dict becomes their parent.\r
- assertEquals(testArray, pdfDictUnderTest.get("array"));\r
- assertEquals(pdfDictUnderTest, testArray.getParent());\r
- // With PDFObjects, if they DO have a parent, the dict DOES NOT change the parent object.\r
- assertEquals(testNumber, pdfDictUnderTest.get("number"));\r
- // Test it doesn't explode when we try to get a non-existent entry\r
- assertNull(pdfDictUnderTest.get("Not in dictionary"));\r
- // Tests that we can over-write objects\r
- pdfDictUnderTest.put("array", 10);\r
- assertEquals(10, pdfDictUnderTest.get("array"));\r
- // Test that nulls are handled appropriately\r
- assertNull(pdfDictUnderTest.get("null"));\r
- }\r
-\r
- /**\r
- * Tests get() - tests that objects can be properly retrieved from the dictionary.\r
- */\r
- @Test\r
- public void testGet() {\r
- // Tested fairly comprehensively in testPut().\r
- }\r
-\r
- /**\r
- * Tests writeDictionary() - tests that the dictionary is properly written to the output-stream.\r
- */\r
- @Test\r
- public void testWriteDictionary() {\r
- // Ensure that the objects stored in the dictionary are streamed in the correct format.\r
- ByteArrayOutputStream outStream = new ByteArrayOutputStream();\r
- CountingOutputStream cout = new CountingOutputStream(outStream);\r
- StringBuilder textBuffer = new StringBuilder();\r
- try {\r
- pdfDictUnderTest.writeDictionary(cout, textBuffer);\r
- PDFDocument.flushTextBuffer(textBuffer, cout);\r
- assertEquals(expectedOutput, outStream.toString());\r
- } catch (IOException e) {\r
- fail("IOException: " + e.getMessage());\r
- }\r
- }\r
-\r
- /**\r
- * Tests output() - test that this object can write itself to an output stream.\r
- * @throws IOException error caused by I/O\r
- */\r
- @Test\r
- public void testOutput() throws IOException {\r
- testOutputStreams(expectedOutput, pdfDictUnderTest);\r
- }\r
-}\r
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.pdf;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+import org.apache.commons.io.output.CountingOutputStream;
+import org.junit.Before;
+import org.junit.Test;
+
+
+/**
+ * Test case for {@link PDFDictionary}.
+ */
+public class PDFDictionaryTestCase extends PDFObjectTestCase {
+ /** The test subject */
+ private PDFDictionary pdfDictUnderTest;
+ private PDFArray testArray;
+ private PDFNumber testNumber;
+ /** The order in which these objects are put into the dictionary MUST be maintained. */
+ private String expectedOutput = "<<\n"
+ + " /String (TestValue)\n"
+ + " /int 10\n"
+ + " /double 3.1\n"
+ + " /array [1 (two) 20]\n"
+ + " /number 20\n"
+ + " /null null\n"
+ + ">>\n";
+
+ @Before
+ public void setUp() {
+ // A PDFNumber for testing, this DOES have a parent
+ testNumber = new PDFNumber();
+ testNumber.setParent(parent);
+ testNumber.setNumber(20);
+ // An array for testing, this DOES NOT have a parent
+ testArray = new PDFArray();
+ testArray.add(1);
+ testArray.add("two");
+ testArray.add(testNumber);
+ // Populating the dictionary with a parent, document and the various objects
+ pdfDictUnderTest = new PDFDictionary(parent);
+ pdfDictUnderTest.setDocument(doc);
+ pdfDictUnderTest.put("String", "TestValue");
+ pdfDictUnderTest.put("int", 10);
+ pdfDictUnderTest.put("double", Double.valueOf(3.1));
+ pdfDictUnderTest.put("array", testArray);
+ pdfDictUnderTest.put("number", testNumber);
+ // null is a valid PDF object
+ pdfDictUnderTest.put("null", null);
+ // test that the interface is maintained
+ pdfObjectUnderTest = pdfDictUnderTest;
+ }
+
+ /**
+ * Tests put() - tests that the object is put into the dictionary and it is handled if it is a
+ * {@link PDFObject}.
+ */
+ @Test
+ public void testPut() {
+ // The "put()" commands have already been done in setUp(), so just test them.
+ assertEquals("TestValue", pdfDictUnderTest.get("String"));
+ assertEquals(10, pdfDictUnderTest.get("int"));
+ assertEquals(3.1, pdfDictUnderTest.get("double"));
+ // With PDFObjects, if they DO NOT have a parent, the dict becomes their parent.
+ assertEquals(testArray, pdfDictUnderTest.get("array"));
+ assertEquals(pdfDictUnderTest, testArray.getParent());
+ // With PDFObjects, if they DO have a parent, the dict DOES NOT change the parent object.
+ assertEquals(testNumber, pdfDictUnderTest.get("number"));
+ // Test it doesn't explode when we try to get a non-existent entry
+ assertNull(pdfDictUnderTest.get("Not in dictionary"));
+ // Tests that we can over-write objects
+ pdfDictUnderTest.put("array", 10);
+ assertEquals(10, pdfDictUnderTest.get("array"));
+ // Test that nulls are handled appropriately
+ assertNull(pdfDictUnderTest.get("null"));
+ }
+
+ /**
+ * Tests get() - tests that objects can be properly retrieved from the dictionary.
+ */
+ @Test
+ public void testGet() {
+ // Tested fairly comprehensively in testPut().
+ }
+
+ /**
+ * Tests writeDictionary() - tests that the dictionary is properly written to the output-stream.
+ */
+ @Test
+ public void testWriteDictionary() {
+ // Ensure that the objects stored in the dictionary are streamed in the correct format.
+ ByteArrayOutputStream outStream = new ByteArrayOutputStream();
+ CountingOutputStream cout = new CountingOutputStream(outStream);
+ StringBuilder textBuffer = new StringBuilder();
+ try {
+ pdfDictUnderTest.writeDictionary(cout, textBuffer);
+ PDFDocument.flushTextBuffer(textBuffer, cout);
+ assertEquals(expectedOutput, outStream.toString());
+ } catch (IOException e) {
+ fail("IOException: " + e.getMessage());
+ }
+ }
+
+ /**
+ * Tests output() - test that this object can write itself to an output stream.
+ * @throws IOException error caused by I/O
+ */
+ @Test
+ public void testOutput() throws IOException {
+ testOutputStreams(expectedOutput, pdfDictUnderTest);
+ }
+}
-/*\r
- * Licensed to the Apache Software Foundation (ASF) under one or more\r
- * contributor license agreements. See the NOTICE file distributed with\r
- * this work for additional information regarding copyright ownership.\r
- * The ASF licenses this file to You under the Apache License, Version 2.0\r
- * (the "License"); you may not use this file except in compliance with\r
- * the License. You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-/* $Id$ */\r
-\r
-package org.apache.fop.pdf;\r
-\r
-import static org.junit.Assert.assertEquals;\r
-\r
-import org.junit.Test;\r
-\r
-import java.io.ByteArrayOutputStream;\r
-import java.io.IOException;\r
-\r
-/**\r
- * Test case for {@link PDFDocument}\r
- */\r
-public class PDFDocumentTestCase {\r
-\r
- /**\r
- * Test flushTextBuffer() - ensure that the text given will stream to the PDF document as\r
- * expected.\r
- * @throws IOException when an I/O error occurs\r
- */\r
- @Test\r
- public void testFlushTextBuffer() throws IOException {\r
- ByteArrayOutputStream out = new ByteArrayOutputStream();\r
- StringBuilder textBuffer = new StringBuilder();\r
- String testString = "This is a test string, just some arbitrary data.";\r
- textBuffer.append(testString);\r
- \r
- PDFDocument.flushTextBuffer(textBuffer, out);\r
- assertEquals(testString, out.toString());\r
- \r
- // Should reset the textBuffer\r
- assertEquals(0, textBuffer.length());\r
- assertEquals("", textBuffer.toString());\r
- out.reset();\r
-\r
- String[] strArray = { "Try ", "with ", "multiple ", "strings." };\r
- for (String str : strArray) {\r
- textBuffer.append(str);\r
- }\r
- String fullString = textBuffer.toString();\r
- PDFDocument.flushTextBuffer(textBuffer, out);\r
- assertEquals(fullString, out.toString());\r
- }\r
-}\r
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.pdf;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+/**
+ * Test case for {@link PDFDocument}
+ */
+public class PDFDocumentTestCase {
+
+ /**
+ * Test flushTextBuffer() - ensure that the text given will stream to the PDF document as
+ * expected.
+ * @throws IOException when an I/O error occurs
+ */
+ @Test
+ public void testFlushTextBuffer() throws IOException {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ StringBuilder textBuffer = new StringBuilder();
+ String testString = "This is a test string, just some arbitrary data.";
+ textBuffer.append(testString);
+
+ PDFDocument.flushTextBuffer(textBuffer, out);
+ assertEquals(testString, out.toString());
+
+ // Should reset the textBuffer
+ assertEquals(0, textBuffer.length());
+ assertEquals("", textBuffer.toString());
+ out.reset();
+
+ String[] strArray = { "Try ", "with ", "multiple ", "strings." };
+ for (String str : strArray) {
+ textBuffer.append(str);
+ }
+ String fullString = textBuffer.toString();
+ PDFDocument.flushTextBuffer(textBuffer, out);
+ assertEquals(fullString, out.toString());
+ }
+}
-/*\r
- * Licensed to the Apache Software Foundation (ASF) under one or more\r
- * contributor license agreements. See the NOTICE file distributed with\r
- * this work for additional information regarding copyright ownership.\r
- * The ASF licenses this file to You under the Apache License, Version 2.0\r
- * (the "License"); you may not use this file except in compliance with\r
- * the License. You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-/* $Id$ */\r
-\r
-package org.apache.fop.pdf;\r
-\r
-import junit.framework.Test;\r
-import junit.framework.TestSuite;\r
-\r
-\r
-/**\r
- * Test suite for FOP's utility classes.\r
- */\r
-public class PDFLibraryTestSuite {\r
-\r
- /**\r
- * Builds the test suite\r
- * @return the test suite\r
- */\r
- public static Test suite() {\r
- TestSuite suite = new TestSuite(\r
- "Test suite for FOP's utility classes");\r
- //$JUnit-BEGIN$\r
- suite.addTest(new TestSuite(PDFArrayTestCase.class));\r
- suite.addTest(new TestSuite(PDFDictionaryTestCase.class));\r
- suite.addTest(new TestSuite(PDFNumberTestCase.class));\r
- suite.addTest(new TestSuite(PDFObjectTestCase.class));\r
- suite.addTest(new TestSuite(PDFNameTestCase.class));\r
- suite.addTest(new TestSuite(AbstractPDFStreamTestCase.class));\r
- suite.addTest(new TestSuite(PDFDestsTestCase.class));\r
- suite.addTest(new TestSuite(PDFDocumentTestCase.class));\r
- suite.addTest(new TestSuite(PDFNullTestCase.class));\r
- suite.addTest(new TestSuite(PDFNumsArrayTestCase.class));\r
- suite.addTest(new TestSuite(PDFRectangleTestCase.class));\r
- suite.addTest(new TestSuite(PDFReferenceTestCase.class));\r
- //$JUnit-END$\r
- return suite;\r
- }\r
-}\r
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.pdf;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+
+/**
+ * Test suite for FOP's utility classes.
+ */
+public class PDFLibraryTestSuite {
+
+ /**
+ * Builds the test suite
+ * @return the test suite
+ */
+ public static Test suite() {
+ TestSuite suite = new TestSuite(
+ "Test suite for FOP's utility classes");
+ //$JUnit-BEGIN$
+ suite.addTest(new TestSuite(PDFArrayTestCase.class));
+ suite.addTest(new TestSuite(PDFDictionaryTestCase.class));
+ suite.addTest(new TestSuite(PDFNumberTestCase.class));
+ suite.addTest(new TestSuite(PDFObjectTestCase.class));
+ suite.addTest(new TestSuite(PDFNameTestCase.class));
+ suite.addTest(new TestSuite(AbstractPDFStreamTestCase.class));
+ suite.addTest(new TestSuite(PDFDestsTestCase.class));
+ suite.addTest(new TestSuite(PDFDocumentTestCase.class));
+ suite.addTest(new TestSuite(PDFNullTestCase.class));
+ suite.addTest(new TestSuite(PDFNumsArrayTestCase.class));
+ suite.addTest(new TestSuite(PDFRectangleTestCase.class));
+ suite.addTest(new TestSuite(PDFReferenceTestCase.class));
+ //$JUnit-END$
+ return suite;
+ }
+}
-/*\r
- * Licensed to the Apache Software Foundation (ASF) under one or more\r
- * contributor license agreements. See the NOTICE file distributed with\r
- * this work for additional information regarding copyright ownership.\r
- * The ASF licenses this file to You under the Apache License, Version 2.0\r
- * (the "License"); you may not use this file except in compliance with\r
- * the License. You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-/* $Id$ */\r
-\r
-package org.apache.fop.pdf;\r
-\r
-import java.io.ByteArrayOutputStream;\r
-import java.io.IOException;\r
-\r
-import org.apache.commons.io.output.CountingOutputStream;\r
-import org.junit.Before;\r
-import org.junit.Test;\r
-import static org.junit.Assert.fail;\r
-import static org.junit.Assert.assertEquals;\r
-\r
-/**\r
- * Test class for {@link PDFName}.\r
- */\r
-public class PDFNameTestCase extends PDFObjectTestCase {\r
- private PDFName pdfName;\r
-\r
- /**\r
- * Sets up the local variables\r
- */\r
- @Before\r
- public void setUp() {\r
- pdfName = new PDFName("TestName");\r
- pdfName.setParent(parent);\r
- pdfName.setDocument(doc);\r
-\r
- pdfObjectUnderTest = pdfName;\r
- }\r
-\r
- /**\r
- * Tests escapeName() - tests that this method escapes the necessary characters.\r
- */\r
- @Test\r
- public void testEscapeName() {\r
- try {\r
- // Test for null, this is a programming error thus the NPE\r
- PDFName.escapeName(null);\r
- fail("NPE not thrown when null object given to escapeName()");\r
- } catch (NullPointerException e) {\r
- // PASS\r
- }\r
- // All names are prefixed by "/", check the PDF spec for further details.\r
- assertEquals("/Test", PDFName.escapeName("Test"));\r
- // Check that if the name is already prefixed with "/" it doens't do it twice\r
- assertEquals("/Test", PDFName.escapeName("/Test"));\r
- // Test with a space in the middle\r
- assertEquals("/Test#20test", PDFName.escapeName("Test test"));\r
- // Test that all chars apart from ASCII '!' --> '~' are escaped\r
- nonEscapedCharactersTests();\r
- escapedCharactersTests();\r
- }\r
-\r
- private void escapedCharactersTests() {\r
- for (char i = 0; i < '!'; i++) {\r
- String str = Integer.toHexString(i >>> 4 & 0x0f).toUpperCase();\r
- str += Integer.toHexString(i & 0x0f).toUpperCase();\r
- assertEquals("/#" + str, PDFName.escapeName(String.valueOf(i)));\r
- }\r
- for (char i = '~' + 1; i < 256; i++) {\r
- String str = Integer.toHexString(i >>> 4 & 0x0f).toUpperCase();\r
- str += Integer.toHexString(i & 0x0f).toUpperCase();\r
- assertEquals("/#" + str, PDFName.escapeName(String.valueOf(i)));\r
- }\r
- checkCharacterIsEscaped('#');\r
- checkCharacterIsEscaped('%');\r
- checkCharacterIsEscaped('(');\r
- checkCharacterIsEscaped(')');\r
- checkCharacterIsEscaped('<');\r
- checkCharacterIsEscaped('>');\r
- checkCharacterIsEscaped('[');\r
- checkCharacterIsEscaped(']');\r
- checkCharacterIsEscaped('>');\r
- }\r
-\r
- private void checkCharacterIsEscaped(char c) {\r
- String str = Integer.toHexString(c >>> 4 & 0x0f).toUpperCase();\r
- str += Integer.toHexString(c & 0x0f).toUpperCase();\r
- assertEquals("/#" + str, PDFName.escapeName(String.valueOf(c)));\r
- }\r
-\r
- private void nonEscapedCharactersTests() {\r
- charactersNotEscapedBetween('!', '"');\r
- charactersNotEscapedBetween('*', ';');\r
- charactersNotEscapedBetween('?', 'Z');\r
- charactersNotEscapedBetween('^', '~');\r
- }\r
-\r
- private void charactersNotEscapedBetween(char c1, char c2) {\r
- for (char i = c1; i <= c2; i++) {\r
- String str = String.valueOf(i);\r
- String expected = !str.equals("/") ? "/" + str : str;\r
- assertEquals(expected, PDFName.escapeName(str));\r
- }\r
- }\r
-\r
- /**\r
- * Tests toString() - this has been overridden to return the String that PDFName wraps.\r
- */\r
- @Test\r
- public void testToString() {\r
- // The escape characters have already been tested in testEscapeName() so this doesn't need\r
- // to be done twice.\r
- PDFName test1 = new PDFName("test1");\r
- assertEquals("/test1", test1.toString());\r
- PDFName test2 = new PDFName("another test");\r
- assertEquals("/another#20test", test2.toString());\r
- try {\r
- new PDFName(null);\r
- fail("NPE not thrown when null passed to constructor");\r
- } catch (NullPointerException e) {\r
- // PASS\r
- }\r
- }\r
-\r
- /**\r
- * Tests output() - check that this object can stream itself in the correct format.\r
- * @throws IOException error caused by I/O\r
- */\r
- @Test\r
- public void testOutput() throws IOException {\r
- testOutputStreams("/TestName", pdfName);\r
- testOutputStreams("/test#20test", new PDFName("test test"));\r
- }\r
-\r
- /**\r
- * Test outputInline() - this writes the object reference if it is a direct object (has an\r
- * object number), or writes the String representation if there is no object number.\r
- */\r
- @Test\r
- public void testOutputInline() {\r
- ByteArrayOutputStream outStream = new ByteArrayOutputStream();\r
- CountingOutputStream cout = new CountingOutputStream(outStream);\r
- StringBuilder textBuffer = new StringBuilder();\r
- try {\r
- // test with no object number set.\r
- pdfName.outputInline(outStream, textBuffer);\r
- PDFDocument.flushTextBuffer(textBuffer, cout);\r
- assertEquals("/TestName", outStream.toString());\r
-\r
- outStream.reset();\r
- // test with object number set\r
- pdfName.setObjectNumber(1);\r
- pdfName.outputInline(outStream, textBuffer);\r
- PDFDocument.flushTextBuffer(textBuffer, cout);\r
- assertEquals("1 0 R", outStream.toString());\r
- } catch (IOException e) {\r
- fail("IOException: " + e.getMessage());\r
- }\r
- }\r
-}\r
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.pdf;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+import org.apache.commons.io.output.CountingOutputStream;
+import org.junit.Before;
+import org.junit.Test;
+import static org.junit.Assert.fail;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Test class for {@link PDFName}.
+ */
+public class PDFNameTestCase extends PDFObjectTestCase {
+ private PDFName pdfName;
+
+ /**
+ * Sets up the local variables
+ */
+ @Before
+ public void setUp() {
+ pdfName = new PDFName("TestName");
+ pdfName.setParent(parent);
+ pdfName.setDocument(doc);
+
+ pdfObjectUnderTest = pdfName;
+ }
+
+ /**
+ * Tests escapeName() - tests that this method escapes the necessary characters.
+ */
+ @Test
+ public void testEscapeName() {
+ try {
+ // Test for null, this is a programming error thus the NPE
+ PDFName.escapeName(null);
+ fail("NPE not thrown when null object given to escapeName()");
+ } catch (NullPointerException e) {
+ // PASS
+ }
+ // All names are prefixed by "/", check the PDF spec for further details.
+ assertEquals("/Test", PDFName.escapeName("Test"));
+ // Check that if the name is already prefixed with "/" it doens't do it twice
+ assertEquals("/Test", PDFName.escapeName("/Test"));
+ // Test with a space in the middle
+ assertEquals("/Test#20test", PDFName.escapeName("Test test"));
+ // Test that all chars apart from ASCII '!' --> '~' are escaped
+ nonEscapedCharactersTests();
+ escapedCharactersTests();
+ }
+
+ private void escapedCharactersTests() {
+ for (char i = 0; i < '!'; i++) {
+ String str = Integer.toHexString(i >>> 4 & 0x0f).toUpperCase();
+ str += Integer.toHexString(i & 0x0f).toUpperCase();
+ assertEquals("/#" + str, PDFName.escapeName(String.valueOf(i)));
+ }
+ for (char i = '~' + 1; i < 256; i++) {
+ String str = Integer.toHexString(i >>> 4 & 0x0f).toUpperCase();
+ str += Integer.toHexString(i & 0x0f).toUpperCase();
+ assertEquals("/#" + str, PDFName.escapeName(String.valueOf(i)));
+ }
+ checkCharacterIsEscaped('#');
+ checkCharacterIsEscaped('%');
+ checkCharacterIsEscaped('(');
+ checkCharacterIsEscaped(')');
+ checkCharacterIsEscaped('<');
+ checkCharacterIsEscaped('>');
+ checkCharacterIsEscaped('[');
+ checkCharacterIsEscaped(']');
+ checkCharacterIsEscaped('>');
+ }
+
+ private void checkCharacterIsEscaped(char c) {
+ String str = Integer.toHexString(c >>> 4 & 0x0f).toUpperCase();
+ str += Integer.toHexString(c & 0x0f).toUpperCase();
+ assertEquals("/#" + str, PDFName.escapeName(String.valueOf(c)));
+ }
+
+ private void nonEscapedCharactersTests() {
+ charactersNotEscapedBetween('!', '"');
+ charactersNotEscapedBetween('*', ';');
+ charactersNotEscapedBetween('?', 'Z');
+ charactersNotEscapedBetween('^', '~');
+ }
+
+ private void charactersNotEscapedBetween(char c1, char c2) {
+ for (char i = c1; i <= c2; i++) {
+ String str = String.valueOf(i);
+ String expected = !str.equals("/") ? "/" + str : str;
+ assertEquals(expected, PDFName.escapeName(str));
+ }
+ }
+
+ /**
+ * Tests toString() - this has been overridden to return the String that PDFName wraps.
+ */
+ @Test
+ public void testToString() {
+ // The escape characters have already been tested in testEscapeName() so this doesn't need
+ // to be done twice.
+ PDFName test1 = new PDFName("test1");
+ assertEquals("/test1", test1.toString());
+ PDFName test2 = new PDFName("another test");
+ assertEquals("/another#20test", test2.toString());
+ try {
+ new PDFName(null);
+ fail("NPE not thrown when null passed to constructor");
+ } catch (NullPointerException e) {
+ // PASS
+ }
+ }
+
+ /**
+ * Tests output() - check that this object can stream itself in the correct format.
+ * @throws IOException error caused by I/O
+ */
+ @Test
+ public void testOutput() throws IOException {
+ testOutputStreams("/TestName", pdfName);
+ testOutputStreams("/test#20test", new PDFName("test test"));
+ }
+
+ /**
+ * Test outputInline() - this writes the object reference if it is a direct object (has an
+ * object number), or writes the String representation if there is no object number.
+ */
+ @Test
+ public void testOutputInline() {
+ ByteArrayOutputStream outStream = new ByteArrayOutputStream();
+ CountingOutputStream cout = new CountingOutputStream(outStream);
+ StringBuilder textBuffer = new StringBuilder();
+ try {
+ // test with no object number set.
+ pdfName.outputInline(outStream, textBuffer);
+ PDFDocument.flushTextBuffer(textBuffer, cout);
+ assertEquals("/TestName", outStream.toString());
+
+ outStream.reset();
+ // test with object number set
+ pdfName.setObjectNumber(1);
+ pdfName.outputInline(outStream, textBuffer);
+ PDFDocument.flushTextBuffer(textBuffer, cout);
+ assertEquals("1 0 R", outStream.toString());
+ } catch (IOException e) {
+ fail("IOException: " + e.getMessage());
+ }
+ }
+}
-/*\r
- * Licensed to the Apache Software Foundation (ASF) under one or more\r
- * contributor license agreements. See the NOTICE file distributed with\r
- * this work for additional information regarding copyright ownership.\r
- * The ASF licenses this file to You under the Apache License, Version 2.0\r
- * (the "License"); you may not use this file except in compliance with\r
- * the License. You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-/* $Id$ */\r
-\r
-package org.apache.fop.pdf;\r
-\r
-import static org.junit.Assert.assertEquals;\r
-\r
-import org.junit.Test;\r
-\r
-import java.io.ByteArrayOutputStream;\r
-import java.io.IOException;\r
-\r
-/**\r
- * Test case for {@link PDFNull}.\r
- */\r
-public class PDFNullTestCase extends PDFObjectTestCase {\r
-\r
- /**\r
- * Test outputInline() - test that "null" is printed to the output stream.\r
- */\r
- @Test\r
- public void testOutputInline() throws IOException {\r
- PDFNull obj = PDFNull.INSTANCE;\r
- ByteArrayOutputStream out = new ByteArrayOutputStream();\r
- StringBuilder text = new StringBuilder();\r
- obj.outputInline(out, text);\r
- assertEquals("null", text.toString());\r
-\r
- // Ensure previously written text is not discarded\r
- obj.outputInline(out, text);\r
- assertEquals("nullnull", text.toString());\r
- }\r
-}\r
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.pdf;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+/**
+ * Test case for {@link PDFNull}.
+ */
+public class PDFNullTestCase extends PDFObjectTestCase {
+
+ /**
+ * Test outputInline() - test that "null" is printed to the output stream.
+ */
+ @Test
+ public void testOutputInline() throws IOException {
+ PDFNull obj = PDFNull.INSTANCE;
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ StringBuilder text = new StringBuilder();
+ obj.outputInline(out, text);
+ assertEquals("null", text.toString());
+
+ // Ensure previously written text is not discarded
+ obj.outputInline(out, text);
+ assertEquals("nullnull", text.toString());
+ }
+}
-/*\r
- * Licensed to the Apache Software Foundation (ASF) under one or more\r
- * contributor license agreements. See the NOTICE file distributed with\r
- * this work for additional information regarding copyright ownership.\r
- * The ASF licenses this file to You under the Apache License, Version 2.0\r
- * (the "License"); you may not use this file except in compliance with\r
- * the License. You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-/* $Id$ */\r
-\r
-package org.apache.fop.pdf;\r
-\r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.fail;\r
-\r
-import org.junit.Before;\r
-import org.junit.Test;\r
-\r
-import java.io.IOException;\r
-\r
-/**\r
- * This test tests PDFNumber's doubleOut() methods.\r
- */\r
-public class PDFNumberTestCase extends PDFObjectTestCase {\r
- /**\r
- * Sets up the local variables, most of these are inherited from PDFObjectTestCase\r
- */\r
- @Before\r
- public void setUp() {\r
- pdfObjectUnderTest = new PDFNumber();\r
- pdfObjectUnderTest.setParent(parent);\r
- pdfObjectUnderTest.setDocument(doc);\r
- }\r
-\r
- /**\r
- * Tests PDFNumber.doubleOut().\r
- * @throws Exception if the test fails\r
- */\r
- @Test\r
- public void testDoubleOut1() throws Exception {\r
- //Default is 6 decimal digits\r
- assertEquals("0", PDFNumber.doubleOut(0.0f));\r
- assertEquals("0", PDFNumber.doubleOut(0.0000000000000000000123f));\r
- assertEquals("0.1", PDFNumber.doubleOut(0.1f));\r
- assertEquals("100", PDFNumber.doubleOut(100.0f));\r
- assertEquals("100", PDFNumber.doubleOut(99.99999999999999999999999f));\r
-\r
- //You'd expect 100.123456 here but DecimalFormat uses the BigDecimal.ROUND_HALF_EVEN\r
- //strategy. I don't know if that's a problem. The strange thing testDoubleOut2\r
- //seems to return the normally expected value. Weird.\r
- assertEquals("100.123459", PDFNumber.doubleOut(100.12345611111111f));\r
- assertEquals("-100.123459", PDFNumber.doubleOut(-100.12345611111111f));\r
- }\r
-\r
- /**\r
- * Tests PDFNumber.doubleOut().\r
- * @throws Exception if the test fails\r
- */\r
- public void testDoubleOut2() throws Exception {\r
- //4 decimal digits in this case\r
- assertEquals("0", PDFNumber.doubleOut(0.0f, 4));\r
- assertEquals("0", PDFNumber.doubleOut(0.0000000000000000000123f, 4));\r
- assertEquals("0.1", PDFNumber.doubleOut(0.1f, 4));\r
- assertEquals("100", PDFNumber.doubleOut(100.0f, 4));\r
- assertEquals("100", PDFNumber.doubleOut(99.99999999999999999999999f, 4));\r
- assertEquals("100.1234", PDFNumber.doubleOut(100.12341111111111f, 4));\r
- assertEquals("-100.1234", PDFNumber.doubleOut(-100.12341111111111f, 4));\r
- }\r
-\r
- /**\r
- * Tests PDFNumber.doubleOut().\r
- * @throws Exception if the test fails\r
- */\r
- public void testDoubleOut3() throws Exception {\r
- //0 decimal digits in this case\r
- assertEquals("0", PDFNumber.doubleOut(0.0f, 0));\r
- assertEquals("0", PDFNumber.doubleOut(0.1f, 0));\r
- assertEquals("1", PDFNumber.doubleOut(0.6f, 0));\r
- assertEquals("100", PDFNumber.doubleOut(100.1234f, 0));\r
- assertEquals("-100", PDFNumber.doubleOut(-100.1234f, 0));\r
- }\r
-\r
- /**\r
- * Tests PDFNumber.doubleOut(). Special cases (former bugs).\r
- * @throws Exception if the test fails\r
- */\r
- public void testDoubleOut4() throws Exception {\r
- double d = Double.parseDouble("5.7220458984375E-6");\r
- assertEquals("0.000006", PDFNumber.doubleOut(d));\r
- assertEquals("0", PDFNumber.doubleOut(d, 4));\r
- assertEquals("0.00000572", PDFNumber.doubleOut(d, 8));\r
- }\r
-\r
- /**\r
- * Tests PDFNumber.doubleOut(). Tests for wrong parameters.\r
- * @throws Exception if the test fails\r
- */\r
- public void testDoubleOutWrongParameters() throws Exception {\r
- try {\r
- PDFNumber.doubleOut(0.1f, -1);\r
- fail("IllegalArgument expected!");\r
- } catch (IllegalArgumentException iae) {\r
- //we want that\r
- }\r
- try {\r
- PDFNumber.doubleOut(0.1f, 17); //We support max 16 decimal digits\r
- fail("IllegalArgument expected!");\r
- } catch (IllegalArgumentException iae) {\r
- //we want that\r
- }\r
- try {\r
- PDFNumber.doubleOut(0.1f, 98274659);\r
- fail("IllegalArgument expected!");\r
- } catch (IllegalArgumentException iae) {\r
- //we want that\r
- }\r
- try {\r
- PDFNumber.doubleOut(null);\r
- fail("NullPointer expected!");\r
- } catch (NullPointerException e) {\r
- // PASS\r
- }\r
- }\r
-\r
- /**\r
- * Tests both getNumber() and setNumber() - basic getter/setter methods... Why there isn't a\r
- * constructor is beyond me...\r
- */\r
- public void testGetSetNumber() {\r
- PDFNumber pdfNum = new PDFNumber();\r
- // Check with a floating point number\r
- pdfNum.setNumber(1.111f);\r
- assertEquals(1.111f, pdfNum.getNumber());\r
- // try with an int\r
- pdfNum.setNumber(2);\r
- assertEquals(2, pdfNum.getNumber());\r
- // See what happens with a null... make sure it doesn't explode\r
- pdfNum.setNumber(null);\r
- assertEquals(null, pdfNum.getNumber());\r
- }\r
-\r
- /**\r
- * Tests toPDFString() - this serializes PDFNumber to PDF format.\r
- * @throws IOException error caused by I/O\r
- */\r
- public void testToPDFString() throws IOException {\r
- PDFNumber testSubject = new PDFNumber();\r
- testSubject.setNumber(1.0001);\r
- testOutputStreams("1.0001", testSubject);\r
- testSubject.setNumber(999);\r
- testOutputStreams("999", testSubject);\r
- }\r
-}\r
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.pdf;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.IOException;
+
+/**
+ * This test tests PDFNumber's doubleOut() methods.
+ */
+public class PDFNumberTestCase extends PDFObjectTestCase {
+ /**
+ * Sets up the local variables, most of these are inherited from PDFObjectTestCase
+ */
+ @Before
+ public void setUp() {
+ pdfObjectUnderTest = new PDFNumber();
+ pdfObjectUnderTest.setParent(parent);
+ pdfObjectUnderTest.setDocument(doc);
+ }
+
+ /**
+ * Tests PDFNumber.doubleOut().
+ * @throws Exception if the test fails
+ */
+ @Test
+ public void testDoubleOut1() throws Exception {
+ //Default is 6 decimal digits
+ assertEquals("0", PDFNumber.doubleOut(0.0f));
+ assertEquals("0", PDFNumber.doubleOut(0.0000000000000000000123f));
+ assertEquals("0.1", PDFNumber.doubleOut(0.1f));
+ assertEquals("100", PDFNumber.doubleOut(100.0f));
+ assertEquals("100", PDFNumber.doubleOut(99.99999999999999999999999f));
+
+ //You'd expect 100.123456 here but DecimalFormat uses the BigDecimal.ROUND_HALF_EVEN
+ //strategy. I don't know if that's a problem. The strange thing testDoubleOut2
+ //seems to return the normally expected value. Weird.
+ assertEquals("100.123459", PDFNumber.doubleOut(100.12345611111111f));
+ assertEquals("-100.123459", PDFNumber.doubleOut(-100.12345611111111f));
+ }
+
+ /**
+ * Tests PDFNumber.doubleOut().
+ * @throws Exception if the test fails
+ */
+ public void testDoubleOut2() throws Exception {
+ //4 decimal digits in this case
+ assertEquals("0", PDFNumber.doubleOut(0.0f, 4));
+ assertEquals("0", PDFNumber.doubleOut(0.0000000000000000000123f, 4));
+ assertEquals("0.1", PDFNumber.doubleOut(0.1f, 4));
+ assertEquals("100", PDFNumber.doubleOut(100.0f, 4));
+ assertEquals("100", PDFNumber.doubleOut(99.99999999999999999999999f, 4));
+ assertEquals("100.1234", PDFNumber.doubleOut(100.12341111111111f, 4));
+ assertEquals("-100.1234", PDFNumber.doubleOut(-100.12341111111111f, 4));
+ }
+
+ /**
+ * Tests PDFNumber.doubleOut().
+ * @throws Exception if the test fails
+ */
+ public void testDoubleOut3() throws Exception {
+ //0 decimal digits in this case
+ assertEquals("0", PDFNumber.doubleOut(0.0f, 0));
+ assertEquals("0", PDFNumber.doubleOut(0.1f, 0));
+ assertEquals("1", PDFNumber.doubleOut(0.6f, 0));
+ assertEquals("100", PDFNumber.doubleOut(100.1234f, 0));
+ assertEquals("-100", PDFNumber.doubleOut(-100.1234f, 0));
+ }
+
+ /**
+ * Tests PDFNumber.doubleOut(). Special cases (former bugs).
+ * @throws Exception if the test fails
+ */
+ public void testDoubleOut4() throws Exception {
+ double d = Double.parseDouble("5.7220458984375E-6");
+ assertEquals("0.000006", PDFNumber.doubleOut(d));
+ assertEquals("0", PDFNumber.doubleOut(d, 4));
+ assertEquals("0.00000572", PDFNumber.doubleOut(d, 8));
+ }
+
+ /**
+ * Tests PDFNumber.doubleOut(). Tests for wrong parameters.
+ * @throws Exception if the test fails
+ */
+ public void testDoubleOutWrongParameters() throws Exception {
+ try {
+ PDFNumber.doubleOut(0.1f, -1);
+ fail("IllegalArgument expected!");
+ } catch (IllegalArgumentException iae) {
+ //we want that
+ }
+ try {
+ PDFNumber.doubleOut(0.1f, 17); //We support max 16 decimal digits
+ fail("IllegalArgument expected!");
+ } catch (IllegalArgumentException iae) {
+ //we want that
+ }
+ try {
+ PDFNumber.doubleOut(0.1f, 98274659);
+ fail("IllegalArgument expected!");
+ } catch (IllegalArgumentException iae) {
+ //we want that
+ }
+ try {
+ PDFNumber.doubleOut(null);
+ fail("NullPointer expected!");
+ } catch (NullPointerException e) {
+ // PASS
+ }
+ }
+
+ /**
+ * Tests both getNumber() and setNumber() - basic getter/setter methods... Why there isn't a
+ * constructor is beyond me...
+ */
+ public void testGetSetNumber() {
+ PDFNumber pdfNum = new PDFNumber();
+ // Check with a floating point number
+ pdfNum.setNumber(1.111f);
+ assertEquals(1.111f, pdfNum.getNumber());
+ // try with an int
+ pdfNum.setNumber(2);
+ assertEquals(2, pdfNum.getNumber());
+ // See what happens with a null... make sure it doesn't explode
+ pdfNum.setNumber(null);
+ assertEquals(null, pdfNum.getNumber());
+ }
+
+ /**
+ * Tests toPDFString() - this serializes PDFNumber to PDF format.
+ * @throws IOException error caused by I/O
+ */
+ public void testToPDFString() throws IOException {
+ PDFNumber testSubject = new PDFNumber();
+ testSubject.setNumber(1.0001);
+ testOutputStreams("1.0001", testSubject);
+ testSubject.setNumber(999);
+ testOutputStreams("999", testSubject);
+ }
+}
-/*\r
- * Licensed to the Apache Software Foundation (ASF) under one or more\r
- * contributor license agreements. See the NOTICE file distributed with\r
- * this work for additional information regarding copyright ownership.\r
- * The ASF licenses this file to You under the Apache License, Version 2.0\r
- * (the "License"); you may not use this file except in compliance with\r
- * the License. You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-/* $Id$ */\r
-\r
-package org.apache.fop.pdf;\r
-\r
-import org.junit.Before;\r
-import org.junit.Test;\r
-\r
-import java.io.IOException;\r
-\r
-/**\r
- * Test case for {@link PDFNumsArray}.\r
- */\r
-public class PDFNumsArrayTestCase extends PDFObjectTestCase {\r
- private PDFNumsArray numsArray;\r
- private String expectedString = "[0 /Test#20name 1 10]";\r
-\r
- @Before\r
- public void setUp() {\r
- numsArray = new PDFNumsArray(parent);\r
- numsArray.put(0, new PDFName("Test name"));\r
- PDFNumber num = new PDFNumber();\r
- num.setNumber(10);\r
- numsArray.put(1, num);\r
- numsArray.setDocument(doc);\r
-\r
- pdfObjectUnderTest = numsArray;\r
- }\r
-\r
- /**\r
- * Test output() - ensure that this object is properly outputted to the PDF document.\r
- * @throws IOException if an I/O error occurs\r
- */\r
- @Test\r
- public void testOutput() throws IOException {\r
- testOutputStreams(expectedString, numsArray);\r
- }\r
-}\r
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.pdf;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.IOException;
+
+/**
+ * Test case for {@link PDFNumsArray}.
+ */
+public class PDFNumsArrayTestCase extends PDFObjectTestCase {
+ private PDFNumsArray numsArray;
+ private String expectedString = "[0 /Test#20name 1 10]";
+
+ @Before
+ public void setUp() {
+ numsArray = new PDFNumsArray(parent);
+ numsArray.put(0, new PDFName("Test name"));
+ PDFNumber num = new PDFNumber();
+ num.setNumber(10);
+ numsArray.put(1, num);
+ numsArray.setDocument(doc);
+
+ pdfObjectUnderTest = numsArray;
+ }
+
+ /**
+ * Test output() - ensure that this object is properly outputted to the PDF document.
+ * @throws IOException if an I/O error occurs
+ */
+ @Test
+ public void testOutput() throws IOException {
+ testOutputStreams(expectedString, numsArray);
+ }
+}
-/*\r
- * Licensed to the Apache Software Foundation (ASF) under one or more\r
- * contributor license agreements. See the NOTICE file distributed with\r
- * this work for additional information regarding copyright ownership.\r
- * The ASF licenses this file to You under the Apache License, Version 2.0\r
- * (the "License"); you may not use this file except in compliance with\r
- * the License. You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-/* $Id$ */\r
-\r
-package org.apache.fop.pdf;\r
-\r
-import static org.junit.Assert.assertEquals;\r
-\r
-import org.junit.Test;\r
-\r
-import java.io.ByteArrayOutputStream;\r
-import java.io.IOException;\r
-import java.io.OutputStream;\r
-\r
-/**\r
- * Test case for {@link PDFRectangle}.\r
- */\r
-public class PDFRectangleTestCase {\r
-\r
- /**\r
- * Test outputInline() - ensure properly formatted co-ords are printed to the output stream.\r
- * @throws IOException if an I/O error occurs\r
- */\r
- @Test\r
- public void testOutputInline() throws IOException {\r
- OutputStream out = new ByteArrayOutputStream();\r
- // These are arbitrary values thus have no meaning\r
- PDFRectangle rect = new PDFRectangle(1, 2, 3, 4);\r
-\r
- StringBuilder textBuffer = new StringBuilder();\r
- // Ensure text before the outputInline() is maintained\r
- textBuffer.append("Test ");\r
-\r
- rect.outputInline(out, textBuffer);\r
- assertEquals("Test [1 2 3 4]", textBuffer.toString());\r
- }\r
-}\r
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.pdf;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+/**
+ * Test case for {@link PDFRectangle}.
+ */
+public class PDFRectangleTestCase {
+
+ /**
+ * Test outputInline() - ensure properly formatted co-ords are printed to the output stream.
+ * @throws IOException if an I/O error occurs
+ */
+ @Test
+ public void testOutputInline() throws IOException {
+ OutputStream out = new ByteArrayOutputStream();
+ // These are arbitrary values thus have no meaning
+ PDFRectangle rect = new PDFRectangle(1, 2, 3, 4);
+
+ StringBuilder textBuffer = new StringBuilder();
+ // Ensure text before the outputInline() is maintained
+ textBuffer.append("Test ");
+
+ rect.outputInline(out, textBuffer);
+ assertEquals("Test [1 2 3 4]", textBuffer.toString());
+ }
+}
-/*\r
- * Licensed to the Apache Software Foundation (ASF) under one or more\r
- * contributor license agreements. See the NOTICE file distributed with\r
- * this work for additional information regarding copyright ownership.\r
- * The ASF licenses this file to You under the Apache License, Version 2.0\r
- * (the "License"); you may not use this file except in compliance with\r
- * the License. You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-/* $Id$ */\r
-\r
-package org.apache.fop.pdf;\r
-\r
-import static org.junit.Assert.assertEquals;\r
-\r
-import org.junit.Test;\r
-\r
-import java.io.ByteArrayOutputStream;\r
-import java.io.IOException;\r
-\r
-/**\r
- * Test case for {@link PDFReference}.\r
- */\r
-public class PDFReferenceTestCase {\r
-\r
- /**\r
- * Tests outputInline() - ensure that this object is properly formatted when printed to the\r
- * output stream.\r
- * @throws IOException if an I/O error occurs\r
- */\r
- @Test\r
- public void testOutputInline() throws IOException {\r
- PDFName name = new PDFName("Test name");\r
- name.setObjectNumber(2);\r
- PDFReference pdfRef = new PDFReference(name);\r
-\r
- ByteArrayOutputStream out = new ByteArrayOutputStream();\r
- StringBuilder textBuffer = new StringBuilder();\r
- // Ensure that text before outputInline() is kept\r
- textBuffer.append("Text ");\r
-\r
- pdfRef.outputInline(out, textBuffer);\r
- assertEquals("Text 2 0 R", textBuffer.toString());\r
- }\r
-\r
- /**\r
- * Tests toString() - since this is used quite a lot, we have to ensure the format is correct.\r
- */\r
- @Test\r
- public void testToString() {\r
- PDFName name = new PDFName("arbitrary");\r
- name.setObjectNumber(10);\r
- PDFReference ref = new PDFReference(name);\r
- assertEquals("10 0 R", ref.toString());\r
- }\r
-}\r
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.pdf;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+/**
+ * Test case for {@link PDFReference}.
+ */
+public class PDFReferenceTestCase {
+
+ /**
+ * Tests outputInline() - ensure that this object is properly formatted when printed to the
+ * output stream.
+ * @throws IOException if an I/O error occurs
+ */
+ @Test
+ public void testOutputInline() throws IOException {
+ PDFName name = new PDFName("Test name");
+ name.setObjectNumber(2);
+ PDFReference pdfRef = new PDFReference(name);
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ StringBuilder textBuffer = new StringBuilder();
+ // Ensure that text before outputInline() is kept
+ textBuffer.append("Text ");
+
+ pdfRef.outputInline(out, textBuffer);
+ assertEquals("Text 2 0 R", textBuffer.toString());
+ }
+
+ /**
+ * Tests toString() - since this is used quite a lot, we have to ensure the format is correct.
+ */
+ @Test
+ public void testToString() {
+ PDFName name = new PDFName("arbitrary");
+ name.setObjectNumber(10);
+ PDFReference ref = new PDFReference(name);
+ assertEquals("10 0 R", ref.toString());
+ }
+}