diff options
author | Chris Bowditch <cbowditch@apache.org> | 2012-01-20 10:39:42 +0000 |
---|---|---|
committer | Chris Bowditch <cbowditch@apache.org> | 2012-01-20 10:39:42 +0000 |
commit | 70182e47ba2efd7f475ba266b1f3d29ff2051bd4 (patch) | |
tree | cb8ad28175c285dd1e7308e900c6e3c74c79bf2b /test/java/org | |
parent | cb5ef63bdccfc497e5e52b1770c508260f34535c (diff) | |
download | xmlgraphics-fop-70182e47ba2efd7f475ba266b1f3d29ff2051bd4.tar.gz xmlgraphics-fop-70182e47ba2efd7f475ba266b1f3d29ff2051bd4.zip |
added svn:eol-style=native property to recently added new files
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1233854 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test/java/org')
17 files changed, 1601 insertions, 1601 deletions
diff --git a/test/java/org/apache/fop/afp/goca/GraphicsCharacterStringTestCase.java b/test/java/org/apache/fop/afp/goca/GraphicsCharacterStringTestCase.java index 48803e69c..801f1c4d4 100644 --- a/test/java/org/apache/fop/afp/goca/GraphicsCharacterStringTestCase.java +++ b/test/java/org/apache/fop/afp/goca/GraphicsCharacterStringTestCase.java @@ -1,72 +1,72 @@ -/*
- * 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);
- }
-}
+/* + * 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); + } +} diff --git a/test/java/org/apache/fop/fo/flow/table/AllTests.java b/test/java/org/apache/fop/fo/flow/table/AllTests.java index 5b5c32a18..7adca8f3a 100644 --- a/test/java/org/apache/fop/fo/flow/table/AllTests.java +++ b/test/java/org/apache/fop/fo/flow/table/AllTests.java @@ -1,34 +1,34 @@ -/*
- * 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 {
-}
-
+/* + * 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 { +} + diff --git a/test/java/org/apache/fop/fo/pagination/AllTests.java b/test/java/org/apache/fop/fo/pagination/AllTests.java index a91203251..664214195 100644 --- a/test/java/org/apache/fop/fo/pagination/AllTests.java +++ b/test/java/org/apache/fop/fo/pagination/AllTests.java @@ -1,35 +1,35 @@ -/*
- * 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 {
-
-}
+/* + * 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 { + +} diff --git a/test/java/org/apache/fop/fo/pagination/PageSequenceMasterTestCase.java b/test/java/org/apache/fop/fo/pagination/PageSequenceMasterTestCase.java index 23c0522e6..d23ff3c57 100644 --- a/test/java/org/apache/fop/fo/pagination/PageSequenceMasterTestCase.java +++ b/test/java/org/apache/fop/fo/pagination/PageSequenceMasterTestCase.java @@ -1,95 +1,95 @@ -/*
- * 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
- }
- }
-
-}
-
+/* + * 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 + } + } + +} + diff --git a/test/java/org/apache/fop/fo/pagination/RepeatablePageMasterAlternativesTestCase.java b/test/java/org/apache/fop/fo/pagination/RepeatablePageMasterAlternativesTestCase.java index d2c5b3f13..29810c472 100644 --- a/test/java/org/apache/fop/fo/pagination/RepeatablePageMasterAlternativesTestCase.java +++ b/test/java/org/apache/fop/fo/pagination/RepeatablePageMasterAlternativesTestCase.java @@ -1,171 +1,171 @@ -/*
- * 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;
- }
-
-}
-
+/* + * 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; + } + +} + diff --git a/test/java/org/apache/fop/pdf/AbstractPDFStreamTestCase.java b/test/java/org/apache/fop/pdf/AbstractPDFStreamTestCase.java index 59b3452ec..b930a8b6d 100644 --- a/test/java/org/apache/fop/pdf/AbstractPDFStreamTestCase.java +++ b/test/java/org/apache/fop/pdf/AbstractPDFStreamTestCase.java @@ -1,92 +1,92 @@ -/*
- * 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());
- }
-}
+/* + * 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()); + } +} diff --git a/test/java/org/apache/fop/pdf/PDFArrayTestCase.java b/test/java/org/apache/fop/pdf/PDFArrayTestCase.java index 73fda56d1..418b2f1a9 100644 --- a/test/java/org/apache/fop/pdf/PDFArrayTestCase.java +++ b/test/java/org/apache/fop/pdf/PDFArrayTestCase.java @@ -1,237 +1,237 @@ -/*
- * 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);
- }
-}
+/* + * 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); + } +} diff --git a/test/java/org/apache/fop/pdf/PDFDestsTestCase.java b/test/java/org/apache/fop/pdf/PDFDestsTestCase.java index be2dfe4e5..08d841ede 100644 --- a/test/java/org/apache/fop/pdf/PDFDestsTestCase.java +++ b/test/java/org/apache/fop/pdf/PDFDestsTestCase.java @@ -1,64 +1,64 @@ -/*
- * 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);
- }
-}
+/* + * 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); + } +} diff --git a/test/java/org/apache/fop/pdf/PDFDictionaryTestCase.java b/test/java/org/apache/fop/pdf/PDFDictionaryTestCase.java index 0ef5171aa..3f84fac2e 100644 --- a/test/java/org/apache/fop/pdf/PDFDictionaryTestCase.java +++ b/test/java/org/apache/fop/pdf/PDFDictionaryTestCase.java @@ -1,135 +1,135 @@ -/*
- * 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);
- }
-}
+/* + * 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); + } +} diff --git a/test/java/org/apache/fop/pdf/PDFDocumentTestCase.java b/test/java/org/apache/fop/pdf/PDFDocumentTestCase.java index dc3a05e2f..f65d73872 100644 --- a/test/java/org/apache/fop/pdf/PDFDocumentTestCase.java +++ b/test/java/org/apache/fop/pdf/PDFDocumentTestCase.java @@ -1,62 +1,62 @@ -/*
- * 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());
- }
-}
+/* + * 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()); + } +} diff --git a/test/java/org/apache/fop/pdf/PDFLibraryTestSuite.java b/test/java/org/apache/fop/pdf/PDFLibraryTestSuite.java index 0332ec768..4df325969 100644 --- a/test/java/org/apache/fop/pdf/PDFLibraryTestSuite.java +++ b/test/java/org/apache/fop/pdf/PDFLibraryTestSuite.java @@ -1,54 +1,54 @@ -/*
- * 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;
- }
-}
+/* + * 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; + } +} diff --git a/test/java/org/apache/fop/pdf/PDFNameTestCase.java b/test/java/org/apache/fop/pdf/PDFNameTestCase.java index 189f2e61f..80917f416 100644 --- a/test/java/org/apache/fop/pdf/PDFNameTestCase.java +++ b/test/java/org/apache/fop/pdf/PDFNameTestCase.java @@ -1,169 +1,169 @@ -/*
- * 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());
- }
- }
-}
+/* + * 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()); + } + } +} diff --git a/test/java/org/apache/fop/pdf/PDFNullTestCase.java b/test/java/org/apache/fop/pdf/PDFNullTestCase.java index 51d3de4ea..98427cd20 100644 --- a/test/java/org/apache/fop/pdf/PDFNullTestCase.java +++ b/test/java/org/apache/fop/pdf/PDFNullTestCase.java @@ -1,49 +1,49 @@ -/*
- * 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());
- }
-}
+/* + * 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()); + } +} diff --git a/test/java/org/apache/fop/pdf/PDFNumberTestCase.java b/test/java/org/apache/fop/pdf/PDFNumberTestCase.java index 61d7b0297..ed660af8d 100644 --- a/test/java/org/apache/fop/pdf/PDFNumberTestCase.java +++ b/test/java/org/apache/fop/pdf/PDFNumberTestCase.java @@ -1,162 +1,162 @@ -/*
- * 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);
- }
-}
+/* + * 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); + } +} diff --git a/test/java/org/apache/fop/pdf/PDFNumsArrayTestCase.java b/test/java/org/apache/fop/pdf/PDFNumsArrayTestCase.java index 3268fc977..e0dca33bf 100644 --- a/test/java/org/apache/fop/pdf/PDFNumsArrayTestCase.java +++ b/test/java/org/apache/fop/pdf/PDFNumsArrayTestCase.java @@ -1,54 +1,54 @@ -/*
- * 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);
- }
-}
+/* + * 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); + } +} diff --git a/test/java/org/apache/fop/pdf/PDFRectangleTestCase.java b/test/java/org/apache/fop/pdf/PDFRectangleTestCase.java index 023a91f65..24b6a1c71 100644 --- a/test/java/org/apache/fop/pdf/PDFRectangleTestCase.java +++ b/test/java/org/apache/fop/pdf/PDFRectangleTestCase.java @@ -1,52 +1,52 @@ -/*
- * 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());
- }
-}
+/* + * 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()); + } +} diff --git a/test/java/org/apache/fop/pdf/PDFReferenceTestCase.java b/test/java/org/apache/fop/pdf/PDFReferenceTestCase.java index 1691698b3..a2c6193cf 100644 --- a/test/java/org/apache/fop/pdf/PDFReferenceTestCase.java +++ b/test/java/org/apache/fop/pdf/PDFReferenceTestCase.java @@ -1,64 +1,64 @@ -/*
- * 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());
- }
-}
+/* + * 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()); + } +} |