001: /**
002: * Copyright (c) 2005, www.pdfbox.org
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions are met:
007: *
008: * 1. Redistributions of source code must retain the above copyright notice,
009: * this list of conditions and the following disclaimer.
010: * 2. Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: * 3. Neither the name of pdfbox; nor the names of its
014: * contributors may be used to endorse or promote products derived from this
015: * software without specific prior written permission.
016: *
017: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
018: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
019: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
020: * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
021: * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
022: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
023: * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
024: * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
025: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
026: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
027: *
028: * http://www.pdfbox.org
029: *
030: */package test.pdfbox.pdfparser;
031:
032: import java.io.ByteArrayInputStream;
033: import java.io.IOException;
034: import java.io.InputStream;
035:
036: import junit.framework.Test;
037: import junit.framework.TestCase;
038: import junit.framework.TestSuite;
039:
040: import org.pdfbox.cos.COSName;
041:
042: import org.pdfbox.pdfparser.BaseParser;
043:
044: /**
045: * This will test the PDF parsing in PDFBox.
046: *
047: * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
048: * @version $Revision: 1.2 $
049: */
050: public class TestPDFParser extends TestCase {
051: //private static Logger log = Logger.getLogger(TestFDF.class);
052:
053: /**
054: * Constructor.
055: *
056: * @param name The name of the test to run.
057: */
058: public TestPDFParser(String name) {
059: super (name);
060: }
061:
062: /**
063: * This will get the suite of test that this class holds.
064: *
065: * @return All of the tests that this class holds.
066: */
067: public static Test suite() {
068: return new TestSuite(TestPDFParser.class);
069: }
070:
071: /**
072: * infamous main method.
073: *
074: * @param args The command line arguments.
075: */
076: public static void main(String[] args) {
077: String[] arg = { TestPDFParser.class.getName() };
078: junit.textui.TestRunner.main(arg);
079: }
080:
081: /**
082: * This will test some cos name parsing.
083: *
084: * @throws Exception If there is an exception while parsing.
085: */
086: public void testCOSName() throws Exception {
087: TestParser parser = new TestParser(new ByteArrayInputStream(
088: "/PANTONE#20116#20CV".getBytes()));
089: COSName name = parser.parseCOSName();
090: assertTrue("Failed to parse COSName", name.getName().equals(
091: "PANTONE 116 CV"));
092:
093: }
094:
095: /**
096: * A simple class used to test parsing of the cos name.
097: */
098: private class TestParser extends BaseParser {
099: /**
100: * Constructor.
101: * @param input The input stream.
102: * @throws IOException If there is an error during parsing.
103: */
104: public TestParser(InputStream input) throws IOException {
105: super (input);
106: }
107:
108: /**
109: * Expose the parseCOSName as public.
110: *
111: * @return The parsed cos name.
112: * @throws IOException If there is an error parsing the COSName.
113: */
114: public COSName parseCOSName() throws IOException {
115: return super.parseCOSName();
116: }
117: }
118: }
|