You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ms...@apache.org on 2015/09/28 11:41:45 UTC
svn commit: r1705636 -
/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/text/BidiTest.java
Author: msahyoun
Date: Mon Sep 28 09:41:44 2015
New Revision: 1705636
URL: http://svn.apache.org/viewvc?rev=1705636&view=rev
Log:
PDFBOX-2252: add unit test
Added:
pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/text/BidiTest.java (with props)
Added: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/text/BidiTest.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/text/BidiTest.java?rev=1705636&view=auto
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/text/BidiTest.java (added)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/text/BidiTest.java Mon Sep 28 09:41:44 2015
@@ -0,0 +1,111 @@
+/*
+ * 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.pdfbox.text;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+
+import org.apache.pdfbox.pdmodel.PDDocument;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test for the PDButton class.
+ *
+ */
+public class BidiTest
+{
+ private static final File IN_DIR = new File("src/test/resources/org/apache/pdfbox/text/");
+ private static final String NAME_OF_PDF = "BidiSample.pdf";
+ private static final String NAME_OF_TXT = "BidiSample.pdf.txt";
+ private static final String NAME_OF_TXT_SORTED = "BidiSample.pdf-sorted.txt";
+
+ private PDDocument document;
+ private PDFTextStripper stripper;
+
+ @Before
+ public void setUp() throws IOException
+ {
+ document = PDDocument.load(new File(IN_DIR, NAME_OF_PDF));
+ stripper = new PDFTextStripper();
+ stripper.setLineSeparator("\n");
+ }
+
+ @Test
+ public void testSorted() throws IOException
+ {
+ stripper.setSortByPosition(true);
+ String extractedText = stripper.getText(document);
+
+ FileReader compareTextReader = new FileReader(new File(IN_DIR, NAME_OF_TXT_SORTED));
+ BufferedReader bufferedCompareTextReader = new BufferedReader(compareTextReader);
+
+ StringBuilder compareTextBuilder = new StringBuilder();
+
+ String line = bufferedCompareTextReader.readLine();
+
+ while (line != null)
+ {
+ compareTextBuilder.append(line);
+ compareTextBuilder.append('\n');
+ line = bufferedCompareTextReader.readLine();
+ }
+
+ bufferedCompareTextReader.close();
+
+ assertEquals(extractedText, compareTextBuilder.toString());
+
+ }
+
+ @Test
+ public void testNotSorted() throws IOException
+ {
+ stripper.setSortByPosition(false);
+ String extractedText = stripper.getText(document);
+
+ FileReader compareTextReader = new FileReader(new File(IN_DIR, NAME_OF_TXT));
+ BufferedReader bufferedCompareTextReader = new BufferedReader(compareTextReader);
+
+ StringBuilder compareTextBuilder = new StringBuilder();
+ String line = bufferedCompareTextReader.readLine();
+
+ while (line != null)
+ {
+ compareTextBuilder.append(line);
+ compareTextBuilder.append('\n');
+ line = bufferedCompareTextReader.readLine();
+ }
+
+ bufferedCompareTextReader.close();
+
+ assertEquals(extractedText, compareTextBuilder.toString());
+
+ }
+
+ @After
+ public void tearDown() throws IOException
+ {
+ document.close();
+ }
+
+}
Propchange: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/text/BidiTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/text/BidiTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain