You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by fa...@apache.org on 2021/05/22 21:37:10 UTC
svn commit: r1890122 [15/16] - in /poi/trunk/poi-scratchpad/src:
main/java/org/apache/poi/hdgf/ main/java/org/apache/poi/hdgf/chunks/
main/java/org/apache/poi/hdgf/dev/ main/java/org/apache/poi/hdgf/exceptions/
main/java/org/apache/poi/hdgf/extractor/ ...
Modified: poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/usermodel/TestSlideOrdering.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/usermodel/TestSlideOrdering.java?rev=1890122&r1=1890121&r2=1890122&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/usermodel/TestSlideOrdering.java (original)
+++ poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/usermodel/TestSlideOrdering.java Sat May 22 21:37:08 2021
@@ -31,104 +31,104 @@ import org.junit.jupiter.api.Test;
* Tests that SlideShow returns Sheets in the right order
*/
public final class TestSlideOrdering {
- // Simple slideshow, record order matches slide order
- private HSLFSlideShow ssA;
- // Complex slideshow, record order doesn't match slide order
- private HSLFSlideShow ssB;
-
- @BeforeEach
- void init() throws IOException {
- ssA = HSLFTestDataSamples.getSlideShow("basic_test_ppt_file.ppt");
- ssB = HSLFTestDataSamples.getSlideShow("incorrect_slide_order.ppt");
- }
-
- @AfterEach
- void tearDown() throws IOException {
- ssA.close();
- ssB.close();
- }
-
- /**
- * Test the simple case - record order matches slide order
- */
- @Test
- void testSimpleCase() {
- assertEquals(2, ssA.getSlides().size());
-
- HSLFSlide s1 = ssA.getSlides().get(0);
- HSLFSlide s2 = ssA.getSlides().get(1);
-
- String[] firstTRs = new String[] { "This is a test title", "This is the title on page 2" };
-
- assertEquals(firstTRs[0], HSLFTextParagraph.getRawText(s1.getTextParagraphs().get(0)));
- assertEquals(firstTRs[1], HSLFTextParagraph.getRawText(s2.getTextParagraphs().get(0)));
- }
-
- /**
- * Test the complex case - record order differs from slide order
- */
+ // Simple slideshow, record order matches slide order
+ private HSLFSlideShow ssA;
+ // Complex slideshow, record order doesn't match slide order
+ private HSLFSlideShow ssB;
+
+ @BeforeEach
+ void init() throws IOException {
+ ssA = HSLFTestDataSamples.getSlideShow("basic_test_ppt_file.ppt");
+ ssB = HSLFTestDataSamples.getSlideShow("incorrect_slide_order.ppt");
+ }
+
+ @AfterEach
+ void tearDown() throws IOException {
+ ssA.close();
+ ssB.close();
+ }
+
+ /**
+ * Test the simple case - record order matches slide order
+ */
@Test
- void testComplexCase() {
- assertEquals(3, ssB.getSlides().size());
- int i=1;
- for (HSLFSlide s : ssB.getSlides()) {
- assertEquals("Slide "+(i++), HSLFTextParagraph.getRawText(s.getTextParagraphs().get(0)));
- }
- }
-
- /**
- * Assert that the order of slides is correct.
- *
- * @param filename
- * file name of the slide show to assert
- * @param titles
- * array of reference slide titles
- */
- protected void assertSlideOrdering(String filename, String[] titles) throws IOException {
+ void testSimpleCase() {
+ assertEquals(2, ssA.getSlides().size());
+
+ HSLFSlide s1 = ssA.getSlides().get(0);
+ HSLFSlide s2 = ssA.getSlides().get(1);
+
+ String[] firstTRs = new String[] { "This is a test title", "This is the title on page 2" };
+
+ assertEquals(firstTRs[0], HSLFTextParagraph.getRawText(s1.getTextParagraphs().get(0)));
+ assertEquals(firstTRs[1], HSLFTextParagraph.getRawText(s2.getTextParagraphs().get(0)));
+ }
+
+ /**
+ * Test the complex case - record order differs from slide order
+ */
+ @Test
+ void testComplexCase() {
+ assertEquals(3, ssB.getSlides().size());
+ int i=1;
+ for (HSLFSlide s : ssB.getSlides()) {
+ assertEquals("Slide "+(i++), HSLFTextParagraph.getRawText(s.getTextParagraphs().get(0)));
+ }
+ }
+
+ /**
+ * Assert that the order of slides is correct.
+ *
+ * @param filename
+ * file name of the slide show to assert
+ * @param titles
+ * array of reference slide titles
+ */
+ protected void assertSlideOrdering(String filename, String[] titles) throws IOException {
HSLFSlideShow ppt = HSLFTestDataSamples.getSlideShow(filename);
- List<HSLFSlide> slide = ppt.getSlides();
+ List<HSLFSlide> slide = ppt.getSlides();
- assertEquals(titles.length, slide.size());
- for (int i = 0; i < slide.size(); i++) {
- String title = slide.get(i).getTitle();
- assertEquals(titles[i], title, "Wrong slide title in " + filename);
- }
- ppt.close();
- }
+ assertEquals(titles.length, slide.size());
+ for (int i = 0; i < slide.size(); i++) {
+ String title = slide.get(i).getTitle();
+ assertEquals(titles[i], title, "Wrong slide title in " + filename);
+ }
+ ppt.close();
+ }
@Test
- void testTitles() throws Exception {
- assertSlideOrdering("basic_test_ppt_file.ppt", new String[] {
- "This is a test title", "This is the title on page 2" });
-
- assertSlideOrdering("incorrect_slide_order.ppt", new String[] { "Slide 1",
- "Slide 2", "Slide 3" });
-
- assertSlideOrdering("next_test_ppt_file.ppt", new String[] {
- "This is a test title", "This is the title on page 2" });
-
- assertSlideOrdering("Single_Coloured_Page.ppt",
- new String[] { "This is a title, it" + (char) 0x2019 + "s in black" });
-
- assertSlideOrdering("Single_Coloured_Page_With_Fonts_and_Alignments.ppt",
- new String[] { "This is a title, it" + (char) 0x2019 + "s in black" });
-
- assertSlideOrdering(
- "ParagraphStylesShorterThanCharStyles.ppt",
- new String[] {
- "ROMANCE: AN ANALYSIS",
- "AGENDA",
- "You are an important supplier of various items that I need",
- '\n' + "Although The Psycho set back my relationship process, recovery is luckily enough under way",
- "Since the time that we seriously go out together, you rank highly among existing relationships",
- "Although our personal interests are mostly compatible, the greatest gap exists in Sex and Shopping",
- "Your physical characteristics are strong when compared with your competition",
- "The combination of your high physical appearance and personality rank you highly, although your sister is also a top prospect",
- "When people found out that we were going out, their responses have been mixed",
- "The benchmark of relationship lifecycles, suggests that we are on schedule",
- "In summary we can say that we are on the right track, but we must remain aware of possible roadblocks ",
- "THE ANSWER",
- "Unfortunately a huge disconnect exists between my needs and your existing service",
- "SUMMARY", });
- }
+ void testTitles() throws Exception {
+ assertSlideOrdering("basic_test_ppt_file.ppt", new String[] {
+ "This is a test title", "This is the title on page 2" });
+
+ assertSlideOrdering("incorrect_slide_order.ppt", new String[] { "Slide 1",
+ "Slide 2", "Slide 3" });
+
+ assertSlideOrdering("next_test_ppt_file.ppt", new String[] {
+ "This is a test title", "This is the title on page 2" });
+
+ assertSlideOrdering("Single_Coloured_Page.ppt",
+ new String[] { "This is a title, it" + (char) 0x2019 + "s in black" });
+
+ assertSlideOrdering("Single_Coloured_Page_With_Fonts_and_Alignments.ppt",
+ new String[] { "This is a title, it" + (char) 0x2019 + "s in black" });
+
+ assertSlideOrdering(
+ "ParagraphStylesShorterThanCharStyles.ppt",
+ new String[] {
+ "ROMANCE: AN ANALYSIS",
+ "AGENDA",
+ "You are an important supplier of various items that I need",
+ '\n' + "Although The Psycho set back my relationship process, recovery is luckily enough under way",
+ "Since the time that we seriously go out together, you rank highly among existing relationships",
+ "Although our personal interests are mostly compatible, the greatest gap exists in Sex and Shopping",
+ "Your physical characteristics are strong when compared with your competition",
+ "The combination of your high physical appearance and personality rank you highly, although your sister is also a top prospect",
+ "When people found out that we were going out, their responses have been mixed",
+ "The benchmark of relationship lifecycles, suggests that we are on schedule",
+ "In summary we can say that we are on the right track, but we must remain aware of possible roadblocks ",
+ "THE ANSWER",
+ "Unfortunately a huge disconnect exists between my needs and your existing service",
+ "SUMMARY", });
+ }
}
Modified: poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/usermodel/TestTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/usermodel/TestTable.java?rev=1890122&r1=1890121&r2=1890122&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/usermodel/TestTable.java (original)
+++ poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/usermodel/TestTable.java Sat May 22 21:37:08 2021
@@ -68,42 +68,42 @@ public class TestTable {
@Test
void testTable() throws IOException {
- try (HSLFSlideShow ppt = HSLFTestDataSamples.getSlideShow("54111.ppt")) {
+ try (HSLFSlideShow ppt = HSLFTestDataSamples.getSlideShow("54111.ppt")) {
List<HSLFSlide> slides = ppt.getSlides();
assertEquals(1, slides.size());
checkSlide(slides.get(0));
}
- }
+ }
- private void checkSlide(final HSLFSlide s) {
- List<List<HSLFTextParagraph>> textRuns = s.getTextParagraphs();
- assertEquals(2, textRuns.size());
-
- HSLFTextRun textRun = textRuns.get(0).get(0).getTextRuns().get(0);
- assertEquals("Table sample", textRun.getRawText().trim());
- assertEquals(1, textRuns.get(0).get(0).getTextRuns().size());
- assertFalse(textRun.getTextParagraph().isBullet());
-
- assertEquals("Dummy text", HSLFTextParagraph.getRawText(textRuns.get(1)));
-
- List<HSLFShape> shapes = s.getShapes();
- assertNotNull(shapes);
- assertEquals(3, shapes.size());
- assertTrue(shapes.get(2) instanceof HSLFTable);
- final HSLFTable table = (HSLFTable) shapes.get(2);
- assertEquals(4, table.getNumberOfColumns());
- assertEquals(6, table.getNumberOfRows());
- for (int x = 0; x < 4; x ++) {
+ private void checkSlide(final HSLFSlide s) {
+ List<List<HSLFTextParagraph>> textRuns = s.getTextParagraphs();
+ assertEquals(2, textRuns.size());
+
+ HSLFTextRun textRun = textRuns.get(0).get(0).getTextRuns().get(0);
+ assertEquals("Table sample", textRun.getRawText().trim());
+ assertEquals(1, textRuns.get(0).get(0).getTextRuns().size());
+ assertFalse(textRun.getTextParagraph().isBullet());
+
+ assertEquals("Dummy text", HSLFTextParagraph.getRawText(textRuns.get(1)));
+
+ List<HSLFShape> shapes = s.getShapes();
+ assertNotNull(shapes);
+ assertEquals(3, shapes.size());
+ assertTrue(shapes.get(2) instanceof HSLFTable);
+ final HSLFTable table = (HSLFTable) shapes.get(2);
+ assertEquals(4, table.getNumberOfColumns());
+ assertEquals(6, table.getNumberOfRows());
+ for (int x = 0; x < 4; x ++) {
HSLFTableCell c = table.getCell(0, x);
assertNotNull(c);
- assertEquals("TH Cell " + (x + 1), HSLFTextParagraph.getRawText(c.getTextParagraphs()));
- for (int y = 1; y < 6; y++) {
- c = table.getCell(y, x);
- assertNotNull(c);
- assertEquals("Row " + y + ", Cell " + (x + 1), c.getText());
- }
- }
- }
+ assertEquals("TH Cell " + (x + 1), HSLFTextParagraph.getRawText(c.getTextParagraphs()));
+ for (int y = 1; y < 6; y++) {
+ c = table.getCell(y, x);
+ assertNotNull(c);
+ assertEquals("Row " + y + ", Cell " + (x + 1), c.getText());
+ }
+ }
+ }
@Test
void testAddText() throws IOException {
Modified: poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/usermodel/TestTextRun.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/usermodel/TestTextRun.java?rev=1890122&r1=1890121&r2=1890122&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/usermodel/TestTextRun.java (original)
+++ poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/usermodel/TestTextRun.java Sat May 22 21:37:08 2021
@@ -43,124 +43,124 @@ import org.junit.jupiter.api.Test;
*/
@SuppressWarnings("UnusedAssignment")
public final class TestTextRun {
- // SlideShow primed on the test data
- private HSLFSlideShow ss;
- private HSLFSlideShow ssRich;
-
- @BeforeEach
- void setUp() throws IOException {
- // Basic (non rich) test file
- ss = HSLFTestDataSamples.getSlideShow("basic_test_ppt_file.ppt");
-
- // Rich test file
- ssRich = HSLFTestDataSamples.getSlideShow("Single_Coloured_Page.ppt");
- }
-
- @AfterEach
- void tearDown() throws IOException {
- ssRich.close();
- ss.close();
- }
-
- /**
- * Test to ensure that getting the text works correctly
- */
- @Test
- void testGetText() {
- HSLFSlide slideOne = ss.getSlides().get(0);
- List<List<HSLFTextParagraph>> textParas = slideOne.getTextParagraphs();
-
- assertEquals(2, textParas.size());
-
- // Get text works with \n
- assertEquals("This is a test title", HSLFTextParagraph.getText(textParas.get(0)));
- assertEquals("This is a test subtitle\nThis is on page 1", HSLFTextParagraph.getText(textParas.get(1)));
-
- // Raw text has \r instead
- assertEquals("This is a test title", HSLFTextParagraph.getRawText(textParas.get(0)));
- assertEquals("This is a test subtitle\rThis is on page 1", HSLFTextParagraph.getRawText(textParas.get(1)));
-
-
- // Now check on a rich text run
- HSLFSlide slideOneR = ssRich.getSlides().get(0);
- textParas = slideOneR.getTextParagraphs();
-
- assertEquals(2, textParas.size());
- assertEquals("This is a title, it\u2019s in black", HSLFTextParagraph.getText(textParas.get(0)));
- assertEquals("This is the subtitle, in bold\nThis bit is blue and italic\nThis bit is red (normal)", HSLFTextParagraph.getText(textParas.get(1)));
- assertEquals("This is a title, it\u2019s in black", HSLFTextParagraph.getRawText(textParas.get(0)));
- assertEquals("This is the subtitle, in bold\rThis bit is blue and italic\rThis bit is red (normal)", HSLFTextParagraph.getRawText(textParas.get(1)));
- }
-
- /**
- * Test to ensure changing non rich text bytes->bytes works correctly
- */
- @Test
- void testSetText() {
- HSLFSlide slideOne = ss.getSlides().get(0);
- List<List<HSLFTextParagraph>> textRuns = slideOne.getTextParagraphs();
- HSLFTextParagraph run = textRuns.get(0).get(0);
- HSLFTextRun tr = run.getTextRuns().get(0);
-
- // Check current text
- assertEquals("This is a test title", tr.getRawText());
-
- // Change
- String changeTo = "New test title";
- tr.setText(changeTo);
- assertEquals(changeTo, tr.getRawText());
-
- // Ensure trailing \n's are NOT stripped, it is legal to set a text with a trailing '\r'
- tr.setText(changeTo + "\n");
- assertEquals(changeTo + "\r", tr.getRawText());
- }
-
- /**
- * Test to ensure that changing non rich text between bytes and
- * chars works correctly
- */
- @SuppressWarnings("unused")
- @Test
- void testAdvancedSetText() {
- HSLFSlide slideOne = ss.getSlides().get(0);
- List<HSLFTextParagraph> paras = slideOne.getTextParagraphs().get(0);
- HSLFTextParagraph para = paras.get(0);
+ // SlideShow primed on the test data
+ private HSLFSlideShow ss;
+ private HSLFSlideShow ssRich;
+
+ @BeforeEach
+ void setUp() throws IOException {
+ // Basic (non rich) test file
+ ss = HSLFTestDataSamples.getSlideShow("basic_test_ppt_file.ppt");
+
+ // Rich test file
+ ssRich = HSLFTestDataSamples.getSlideShow("Single_Coloured_Page.ppt");
+ }
+
+ @AfterEach
+ void tearDown() throws IOException {
+ ssRich.close();
+ ss.close();
+ }
+
+ /**
+ * Test to ensure that getting the text works correctly
+ */
+ @Test
+ void testGetText() {
+ HSLFSlide slideOne = ss.getSlides().get(0);
+ List<List<HSLFTextParagraph>> textParas = slideOne.getTextParagraphs();
+
+ assertEquals(2, textParas.size());
+
+ // Get text works with \n
+ assertEquals("This is a test title", HSLFTextParagraph.getText(textParas.get(0)));
+ assertEquals("This is a test subtitle\nThis is on page 1", HSLFTextParagraph.getText(textParas.get(1)));
+
+ // Raw text has \r instead
+ assertEquals("This is a test title", HSLFTextParagraph.getRawText(textParas.get(0)));
+ assertEquals("This is a test subtitle\rThis is on page 1", HSLFTextParagraph.getRawText(textParas.get(1)));
+
+
+ // Now check on a rich text run
+ HSLFSlide slideOneR = ssRich.getSlides().get(0);
+ textParas = slideOneR.getTextParagraphs();
+
+ assertEquals(2, textParas.size());
+ assertEquals("This is a title, it\u2019s in black", HSLFTextParagraph.getText(textParas.get(0)));
+ assertEquals("This is the subtitle, in bold\nThis bit is blue and italic\nThis bit is red (normal)", HSLFTextParagraph.getText(textParas.get(1)));
+ assertEquals("This is a title, it\u2019s in black", HSLFTextParagraph.getRawText(textParas.get(0)));
+ assertEquals("This is the subtitle, in bold\rThis bit is blue and italic\rThis bit is red (normal)", HSLFTextParagraph.getRawText(textParas.get(1)));
+ }
+
+ /**
+ * Test to ensure changing non rich text bytes->bytes works correctly
+ */
+ @Test
+ void testSetText() {
+ HSLFSlide slideOne = ss.getSlides().get(0);
+ List<List<HSLFTextParagraph>> textRuns = slideOne.getTextParagraphs();
+ HSLFTextParagraph run = textRuns.get(0).get(0);
+ HSLFTextRun tr = run.getTextRuns().get(0);
+
+ // Check current text
+ assertEquals("This is a test title", tr.getRawText());
+
+ // Change
+ String changeTo = "New test title";
+ tr.setText(changeTo);
+ assertEquals(changeTo, tr.getRawText());
+
+ // Ensure trailing \n's are NOT stripped, it is legal to set a text with a trailing '\r'
+ tr.setText(changeTo + "\n");
+ assertEquals(changeTo + "\r", tr.getRawText());
+ }
+
+ /**
+ * Test to ensure that changing non rich text between bytes and
+ * chars works correctly
+ */
+ @SuppressWarnings("unused")
+ @Test
+ void testAdvancedSetText() {
+ HSLFSlide slideOne = ss.getSlides().get(0);
+ List<HSLFTextParagraph> paras = slideOne.getTextParagraphs().get(0);
+ HSLFTextParagraph para = paras.get(0);
TextHeaderAtom tha = null;
TextBytesAtom tba = null;
TextCharsAtom tca = null;
- for ( org.apache.poi.hslf.record.Record r : para.getRecords()) {
- if (r instanceof TextHeaderAtom) tha = (TextHeaderAtom)r;
- else if (r instanceof TextBytesAtom) tba = (TextBytesAtom)r;
- else if (r instanceof TextCharsAtom) tca = (TextCharsAtom)r;
- }
-
- // Bytes -> Bytes
- assertNull(tca);
- assertNotNull(tba);
- // assertFalse(run._isUnicode);
- assertEquals("This is a test title", para.getTextRuns().get(0).getRawText());
-
- String changeBytesOnly = "New Test Title";
- HSLFTextParagraph.setText(paras, changeBytesOnly);
- para = paras.get(0);
- tha = null; tba = null; tca = null;
for ( org.apache.poi.hslf.record.Record r : para.getRecords()) {
if (r instanceof TextHeaderAtom) tha = (TextHeaderAtom)r;
else if (r instanceof TextBytesAtom) tba = (TextBytesAtom)r;
else if (r instanceof TextCharsAtom) tca = (TextCharsAtom)r;
}
- assertEquals(changeBytesOnly, HSLFTextParagraph.getRawText(paras));
- assertNull(tca);
- assertNotNull(tba);
-
- // Bytes -> Chars
- assertEquals(changeBytesOnly, HSLFTextParagraph.getRawText(paras));
-
- String changeByteChar = "This is a test title with a '\u0121' g with a dot";
- HSLFTextParagraph.setText(paras, changeByteChar);
- para = paras.get(0);
+ // Bytes -> Bytes
+ assertNull(tca);
+ assertNotNull(tba);
+ // assertFalse(run._isUnicode);
+ assertEquals("This is a test title", para.getTextRuns().get(0).getRawText());
+
+ String changeBytesOnly = "New Test Title";
+ HSLFTextParagraph.setText(paras, changeBytesOnly);
+ para = paras.get(0);
+ tha = null; tba = null; tca = null;
+ for ( org.apache.poi.hslf.record.Record r : para.getRecords()) {
+ if (r instanceof TextHeaderAtom) tha = (TextHeaderAtom)r;
+ else if (r instanceof TextBytesAtom) tba = (TextBytesAtom)r;
+ else if (r instanceof TextCharsAtom) tca = (TextCharsAtom)r;
+ }
+
+ assertEquals(changeBytesOnly, HSLFTextParagraph.getRawText(paras));
+ assertNull(tca);
+ assertNotNull(tba);
+
+ // Bytes -> Chars
+ assertEquals(changeBytesOnly, HSLFTextParagraph.getRawText(paras));
+
+ String changeByteChar = "This is a test title with a '\u0121' g with a dot";
+ HSLFTextParagraph.setText(paras, changeByteChar);
+ para = paras.get(0);
tha = null; tba = null; tca = null;
for ( org.apache.poi.hslf.record.Record r : para.getRecords()) {
if (r instanceof TextHeaderAtom) tha = (TextHeaderAtom)r;
@@ -168,16 +168,16 @@ public final class TestTextRun {
else if (r instanceof TextCharsAtom) tca = (TextCharsAtom)r;
}
- assertEquals(changeByteChar, HSLFTextParagraph.getRawText(paras));
- assertNotNull(tca);
- assertNull(tba);
-
- // Chars -> Chars
- assertNotNull(tca);
- assertEquals(changeByteChar, HSLFTextParagraph.getRawText(paras));
+ assertEquals(changeByteChar, HSLFTextParagraph.getRawText(paras));
+ assertNotNull(tca);
+ assertNull(tba);
+
+ // Chars -> Chars
+ assertNotNull(tca);
+ assertEquals(changeByteChar, HSLFTextParagraph.getRawText(paras));
- String changeCharChar = "This is a test title with a '\u0147' N with a hat";
- HSLFTextParagraph.setText(paras, changeCharChar);
+ String changeCharChar = "This is a test title with a '\u0147' N with a hat";
+ HSLFTextParagraph.setText(paras, changeCharChar);
para = paras.get(0);
tha = null; tba = null; tca = null;
for ( org.apache.poi.hslf.record.Record r : para.getRecords()) {
@@ -186,334 +186,334 @@ public final class TestTextRun {
else if (r instanceof TextCharsAtom) tca = (TextCharsAtom)r;
}
- assertEquals(changeCharChar, HSLFTextParagraph.getRawText(paras));
- assertNotNull(tca);
- assertNull(tba);
- }
-
- /**
- * Tests to ensure that non rich text has the right default rich text run
- * set up for it
- */
- @Test
- void testGetRichTextNonRich() {
- HSLFSlide slideOne = ss.getSlides().get(0);
- List<List<HSLFTextParagraph>> textParass = slideOne.getTextParagraphs();
-
- assertEquals(2, textParass.size());
-
- List<HSLFTextParagraph> trA = textParass.get(0);
- List<HSLFTextParagraph> trB = textParass.get(1);
-
- assertEquals(1, trA.size());
- assertEquals(2, trB.size());
-
- HSLFTextRun rtrA = trA.get(0).getTextRuns().get(0);
- HSLFTextRun rtrB = trB.get(0).getTextRuns().get(0);
-
- assertEquals(HSLFTextParagraph.getRawText(trA), rtrA.getRawText());
- assertEquals(HSLFTextParagraph.getRawText(trB.subList(0, 1)), rtrB.getRawText());
- }
-
- /**
- * Tests to ensure that the rich text runs are built up correctly
- */
- @Test
- void testGetRichText() {
- HSLFSlide slideOne = ssRich.getSlides().get(0);
- List<List<HSLFTextParagraph>> textParass = slideOne.getTextParagraphs();
-
- assertEquals(2, textParass.size());
-
- List<HSLFTextParagraph> trA = textParass.get(0);
- List<HSLFTextParagraph> trB = textParass.get(1);
-
- assertEquals(1, trA.size());
- assertEquals(3, trB.size());
-
- HSLFTextRun rtrA = trA.get(0).getTextRuns().get(0);
- HSLFTextRun rtrB = trB.get(0).getTextRuns().get(0);
- HSLFTextRun rtrC = trB.get(1).getTextRuns().get(0);
- HSLFTextRun rtrD = trB.get(2).getTextRuns().get(0);
-
- assertEquals(HSLFTextParagraph.getRawText(trA), rtrA.getRawText());
-
- String trBstr = HSLFTextParagraph.getRawText(trB);
- assertEquals(trBstr.substring(0, 30), rtrB.getRawText());
- assertEquals(trBstr.substring(30,58), rtrC.getRawText());
- assertEquals(trBstr.substring(58,82), rtrD.getRawText());
-
- // Same paragraph styles
- assertEquals(trB.get(0).getParagraphStyle(), trB.get(1).getParagraphStyle());
- assertEquals(trB.get(0).getParagraphStyle(), trB.get(2).getParagraphStyle());
+ assertEquals(changeCharChar, HSLFTextParagraph.getRawText(paras));
+ assertNotNull(tca);
+ assertNull(tba);
+ }
+
+ /**
+ * Tests to ensure that non rich text has the right default rich text run
+ * set up for it
+ */
+ @Test
+ void testGetRichTextNonRich() {
+ HSLFSlide slideOne = ss.getSlides().get(0);
+ List<List<HSLFTextParagraph>> textParass = slideOne.getTextParagraphs();
+
+ assertEquals(2, textParass.size());
+
+ List<HSLFTextParagraph> trA = textParass.get(0);
+ List<HSLFTextParagraph> trB = textParass.get(1);
+
+ assertEquals(1, trA.size());
+ assertEquals(2, trB.size());
+
+ HSLFTextRun rtrA = trA.get(0).getTextRuns().get(0);
+ HSLFTextRun rtrB = trB.get(0).getTextRuns().get(0);
+
+ assertEquals(HSLFTextParagraph.getRawText(trA), rtrA.getRawText());
+ assertEquals(HSLFTextParagraph.getRawText(trB.subList(0, 1)), rtrB.getRawText());
+ }
+
+ /**
+ * Tests to ensure that the rich text runs are built up correctly
+ */
+ @Test
+ void testGetRichText() {
+ HSLFSlide slideOne = ssRich.getSlides().get(0);
+ List<List<HSLFTextParagraph>> textParass = slideOne.getTextParagraphs();
+
+ assertEquals(2, textParass.size());
+
+ List<HSLFTextParagraph> trA = textParass.get(0);
+ List<HSLFTextParagraph> trB = textParass.get(1);
+
+ assertEquals(1, trA.size());
+ assertEquals(3, trB.size());
- // Different char styles
- assertNotEquals(rtrB.getCharacterStyle(), rtrC.getCharacterStyle());
+ HSLFTextRun rtrA = trA.get(0).getTextRuns().get(0);
+ HSLFTextRun rtrB = trB.get(0).getTextRuns().get(0);
+ HSLFTextRun rtrC = trB.get(1).getTextRuns().get(0);
+ HSLFTextRun rtrD = trB.get(2).getTextRuns().get(0);
+
+ assertEquals(HSLFTextParagraph.getRawText(trA), rtrA.getRawText());
+
+ String trBstr = HSLFTextParagraph.getRawText(trB);
+ assertEquals(trBstr.substring(0, 30), rtrB.getRawText());
+ assertEquals(trBstr.substring(30,58), rtrC.getRawText());
+ assertEquals(trBstr.substring(58,82), rtrD.getRawText());
+
+ // Same paragraph styles
+ assertEquals(trB.get(0).getParagraphStyle(), trB.get(1).getParagraphStyle());
+ assertEquals(trB.get(0).getParagraphStyle(), trB.get(2).getParagraphStyle());
+
+ // Different char styles
+ assertNotEquals(rtrB.getCharacterStyle(), rtrC.getCharacterStyle());
assertNotEquals(rtrB.getCharacterStyle(), rtrD.getCharacterStyle());
assertNotEquals(rtrC.getCharacterStyle(), rtrD.getCharacterStyle());
- }
+ }
- /**
- * Tests to ensure that setting the text where the text isn't rich,
- * ensuring that everything stays with the same default styling
- */
- @Test
- void testSetTextWhereNotRich() {
- HSLFSlide slideOne = ss.getSlides().get(0);
- List<List<HSLFTextParagraph>> textParass = slideOne.getTextParagraphs();
- List<HSLFTextParagraph> trB = textParass.get(0);
- assertEquals(1, trB.size());
-
- HSLFTextRun rtrB = trB.get(0).getTextRuns().get(0);
- assertEquals(HSLFTextParagraph.getText(trB), rtrB.getRawText());
-
- // Change text via normal
- HSLFTextParagraph.setText(trB, "Test Foo Test");
- rtrB = trB.get(0).getTextRuns().get(0);
- assertEquals("Test Foo Test", HSLFTextParagraph.getRawText(trB));
- assertEquals("Test Foo Test", rtrB.getRawText());
- }
-
- /**
- * Tests to ensure that setting the text where the text is rich
- * sets everything to the same styling
- */
- @Test
- void testSetTextWhereRich() {
- HSLFSlide slideOne = ssRich.getSlides().get(0);
- List<List<HSLFTextParagraph>> textParass = slideOne.getTextParagraphs();
- List<HSLFTextParagraph> trB = textParass.get(1);
- assertEquals(3, trB.size());
-
- HSLFTextRun rtrB = trB.get(0).getTextRuns().get(0);
- HSLFTextRun rtrC = trB.get(1).getTextRuns().get(0);
- HSLFTextRun rtrD = trB.get(2).getTextRuns().get(0);
- TextPropCollection tpBP = rtrB.getTextParagraph().getParagraphStyle();
- TextPropCollection tpBC = rtrB.getCharacterStyle();
- TextPropCollection tpCP = rtrC.getTextParagraph().getParagraphStyle();
- TextPropCollection tpCC = rtrC.getCharacterStyle();
- TextPropCollection tpDP = rtrD.getTextParagraph().getParagraphStyle();
- TextPropCollection tpDC = rtrD.getCharacterStyle();
-
-// assertEquals(trB.getRawText().substring(0, 30), rtrB.getRawText());
- assertNotNull(tpBP);
- assertNotNull(tpBC);
- assertNotNull(tpCP);
- assertNotNull(tpCC);
- assertNotNull(tpDP);
- assertNotNull(tpDC);
- assertEquals(tpBP,tpCP);
- assertEquals(tpBP,tpDP);
- assertEquals(tpCP,tpDP);
- assertNotEquals(tpBC,tpCC);
- assertNotEquals(tpBC,tpDC);
- assertNotEquals(tpCC,tpDC);
-
- // Change text via normal
- HSLFTextParagraph.setText(trB, "Test Foo Test");
-
- // Ensure now have first style
- assertEquals(1, trB.get(0).getTextRuns().size());
- rtrB = trB.get(0).getTextRuns().get(0);
- assertEquals("Test Foo Test", HSLFTextParagraph.getRawText(trB));
- assertEquals("Test Foo Test", rtrB.getRawText());
- assertNotNull(rtrB.getCharacterStyle());
- assertNotNull(rtrB.getTextParagraph().getParagraphStyle());
- assertEquals( tpBP, rtrB.getTextParagraph().getParagraphStyle() );
- assertEquals( tpBC, rtrB.getCharacterStyle() );
- }
-
- /**
- * Test to ensure the right stuff happens if we change the text
- * in a rich text run, that doesn't happen to actually be rich
- */
- @Test
- void testChangeTextInRichTextRunNonRich() {
- HSLFSlide slideOne = ss.getSlides().get(0);
- List<List<HSLFTextParagraph>> textRuns = slideOne.getTextParagraphs();
- List<HSLFTextParagraph> trB = textRuns.get(1);
- assertEquals(1, trB.get(0).getTextRuns().size());
-
- HSLFTextRun rtrB = trB.get(0).getTextRuns().get(0);
- assertEquals(HSLFTextParagraph.getRawText(trB.subList(0, 1)), rtrB.getRawText());
- assertNotNull(rtrB.getCharacterStyle());
- assertNotNull(rtrB.getTextParagraph().getParagraphStyle());
-
- // Change text via rich
- rtrB.setText("Test Test Test");
- assertEquals("Test Test Test", HSLFTextParagraph.getRawText(trB.subList(0, 1)));
- assertEquals("Test Test Test", rtrB.getRawText());
+ /**
+ * Tests to ensure that setting the text where the text isn't rich,
+ * ensuring that everything stays with the same default styling
+ */
+ @Test
+ void testSetTextWhereNotRich() {
+ HSLFSlide slideOne = ss.getSlides().get(0);
+ List<List<HSLFTextParagraph>> textParass = slideOne.getTextParagraphs();
+ List<HSLFTextParagraph> trB = textParass.get(0);
+ assertEquals(1, trB.size());
+
+ HSLFTextRun rtrB = trB.get(0).getTextRuns().get(0);
+ assertEquals(HSLFTextParagraph.getText(trB), rtrB.getRawText());
+
+ // Change text via normal
+ HSLFTextParagraph.setText(trB, "Test Foo Test");
+ rtrB = trB.get(0).getTextRuns().get(0);
+ assertEquals("Test Foo Test", HSLFTextParagraph.getRawText(trB));
+ assertEquals("Test Foo Test", rtrB.getRawText());
+ }
- // Will now have dummy props
+ /**
+ * Tests to ensure that setting the text where the text is rich
+ * sets everything to the same styling
+ */
+ @Test
+ void testSetTextWhereRich() {
+ HSLFSlide slideOne = ssRich.getSlides().get(0);
+ List<List<HSLFTextParagraph>> textParass = slideOne.getTextParagraphs();
+ List<HSLFTextParagraph> trB = textParass.get(1);
+ assertEquals(3, trB.size());
+
+ HSLFTextRun rtrB = trB.get(0).getTextRuns().get(0);
+ HSLFTextRun rtrC = trB.get(1).getTextRuns().get(0);
+ HSLFTextRun rtrD = trB.get(2).getTextRuns().get(0);
+ TextPropCollection tpBP = rtrB.getTextParagraph().getParagraphStyle();
+ TextPropCollection tpBC = rtrB.getCharacterStyle();
+ TextPropCollection tpCP = rtrC.getTextParagraph().getParagraphStyle();
+ TextPropCollection tpCC = rtrC.getCharacterStyle();
+ TextPropCollection tpDP = rtrD.getTextParagraph().getParagraphStyle();
+ TextPropCollection tpDC = rtrD.getCharacterStyle();
+
+// assertEquals(trB.getRawText().substring(0, 30), rtrB.getRawText());
+ assertNotNull(tpBP);
+ assertNotNull(tpBC);
+ assertNotNull(tpCP);
+ assertNotNull(tpCC);
+ assertNotNull(tpDP);
+ assertNotNull(tpDC);
+ assertEquals(tpBP,tpCP);
+ assertEquals(tpBP,tpDP);
+ assertEquals(tpCP,tpDP);
+ assertNotEquals(tpBC,tpCC);
+ assertNotEquals(tpBC,tpDC);
+ assertNotEquals(tpCC,tpDC);
+
+ // Change text via normal
+ HSLFTextParagraph.setText(trB, "Test Foo Test");
+
+ // Ensure now have first style
+ assertEquals(1, trB.get(0).getTextRuns().size());
+ rtrB = trB.get(0).getTextRuns().get(0);
+ assertEquals("Test Foo Test", HSLFTextParagraph.getRawText(trB));
+ assertEquals("Test Foo Test", rtrB.getRawText());
assertNotNull(rtrB.getCharacterStyle());
assertNotNull(rtrB.getTextParagraph().getParagraphStyle());
- }
+ assertEquals( tpBP, rtrB.getTextParagraph().getParagraphStyle() );
+ assertEquals( tpBC, rtrB.getCharacterStyle() );
+ }
- /**
- * Tests to ensure changing the text within rich text runs works
- * correctly
- */
- @Test
- void testChangeTextInRichTextRun() {
- HSLFSlide slideOne = ssRich.getSlides().get(0);
- List<List<HSLFTextParagraph>> textParass = slideOne.getTextParagraphs();
- List<HSLFTextParagraph> trB = textParass.get(1);
- assertEquals(3, trB.size());
-
- // We start with 3 text runs, each with their own set of styles,
- // but all sharing the same paragraph styles
- HSLFTextRun rtrB = trB.get(0).getTextRuns().get(0);
- HSLFTextRun rtrC = trB.get(1).getTextRuns().get(0);
- HSLFTextRun rtrD = trB.get(2).getTextRuns().get(0);
- TextPropCollection tpBP = rtrB.getTextParagraph().getParagraphStyle();
- TextPropCollection tpBC = rtrB.getCharacterStyle();
- TextPropCollection tpCP = rtrC.getTextParagraph().getParagraphStyle();
- TextPropCollection tpCC = rtrC.getCharacterStyle();
- TextPropCollection tpDP = rtrD.getTextParagraph().getParagraphStyle();
- TextPropCollection tpDC = rtrD.getCharacterStyle();
-
- // Check text and stylings
- assertEquals(HSLFTextParagraph.getRawText(trB).substring(0, 30), rtrB.getRawText());
- assertNotNull(tpBP);
- assertNotNull(tpBC);
- assertNotNull(tpCP);
- assertNotNull(tpCC);
- assertNotNull(tpDP);
- assertNotNull(tpDC);
- assertEquals(tpBP, tpCP);
- assertEquals(tpBP, tpDP);
- assertEquals(tpCP, tpDP);
- assertNotEquals(tpBC, tpCC);
- assertNotEquals(tpBC, tpDC);
- assertNotEquals(tpCC, tpDC);
-
- // Check text in the rich runs
- assertEquals("This is the subtitle, in bold\r", rtrB.getRawText());
- assertEquals("This bit is blue and italic\r", rtrC.getRawText());
- assertEquals("This bit is red (normal)", rtrD.getRawText());
-
- String newBText = "New Subtitle, will still be bold\n";
- String newCText = "New blue and italic text\n";
- String newDText = "Funky new normal red text";
- rtrB.setText(newBText);
- rtrC.setText(newCText);
- rtrD.setText(newDText);
- HSLFTextParagraph.storeText(trB);
-
- assertEquals(newBText.replace('\n','\r'), rtrB.getRawText());
- assertEquals(newCText.replace('\n','\r'), rtrC.getRawText());
- assertEquals(newDText.replace('\n','\r'), rtrD.getRawText());
-
- assertEquals(newBText.replace('\n','\r') + newCText.replace('\n','\r') + newDText.replace('\n','\r'), HSLFTextParagraph.getRawText(trB));
-
- // The styles should have been updated for the new sizes
- assertEquals(newBText.length(), tpBC.getCharactersCovered());
- assertEquals(newCText.length(), tpCC.getCharactersCovered());
- assertEquals(newDText.length()+1, tpDC.getCharactersCovered()); // Last one is always one larger
+ /**
+ * Test to ensure the right stuff happens if we change the text
+ * in a rich text run, that doesn't happen to actually be rich
+ */
+ @Test
+ void testChangeTextInRichTextRunNonRich() {
+ HSLFSlide slideOne = ss.getSlides().get(0);
+ List<List<HSLFTextParagraph>> textRuns = slideOne.getTextParagraphs();
+ List<HSLFTextParagraph> trB = textRuns.get(1);
+ assertEquals(1, trB.get(0).getTextRuns().size());
+
+ HSLFTextRun rtrB = trB.get(0).getTextRuns().get(0);
+ assertEquals(HSLFTextParagraph.getRawText(trB.subList(0, 1)), rtrB.getRawText());
+ assertNotNull(rtrB.getCharacterStyle());
+ assertNotNull(rtrB.getTextParagraph().getParagraphStyle());
+
+ // Change text via rich
+ rtrB.setText("Test Test Test");
+ assertEquals("Test Test Test", HSLFTextParagraph.getRawText(trB.subList(0, 1)));
+ assertEquals("Test Test Test", rtrB.getRawText());
+
+ // Will now have dummy props
+ assertNotNull(rtrB.getCharacterStyle());
+ assertNotNull(rtrB.getTextParagraph().getParagraphStyle());
+ }
+
+ /**
+ * Tests to ensure changing the text within rich text runs works
+ * correctly
+ */
+ @Test
+ void testChangeTextInRichTextRun() {
+ HSLFSlide slideOne = ssRich.getSlides().get(0);
+ List<List<HSLFTextParagraph>> textParass = slideOne.getTextParagraphs();
+ List<HSLFTextParagraph> trB = textParass.get(1);
+ assertEquals(3, trB.size());
+
+ // We start with 3 text runs, each with their own set of styles,
+ // but all sharing the same paragraph styles
+ HSLFTextRun rtrB = trB.get(0).getTextRuns().get(0);
+ HSLFTextRun rtrC = trB.get(1).getTextRuns().get(0);
+ HSLFTextRun rtrD = trB.get(2).getTextRuns().get(0);
+ TextPropCollection tpBP = rtrB.getTextParagraph().getParagraphStyle();
+ TextPropCollection tpBC = rtrB.getCharacterStyle();
+ TextPropCollection tpCP = rtrC.getTextParagraph().getParagraphStyle();
+ TextPropCollection tpCC = rtrC.getCharacterStyle();
+ TextPropCollection tpDP = rtrD.getTextParagraph().getParagraphStyle();
+ TextPropCollection tpDC = rtrD.getCharacterStyle();
+
+ // Check text and stylings
+ assertEquals(HSLFTextParagraph.getRawText(trB).substring(0, 30), rtrB.getRawText());
+ assertNotNull(tpBP);
+ assertNotNull(tpBC);
+ assertNotNull(tpCP);
+ assertNotNull(tpCC);
+ assertNotNull(tpDP);
+ assertNotNull(tpDC);
+ assertEquals(tpBP, tpCP);
+ assertEquals(tpBP, tpDP);
+ assertEquals(tpCP, tpDP);
+ assertNotEquals(tpBC, tpCC);
+ assertNotEquals(tpBC, tpDC);
+ assertNotEquals(tpCC, tpDC);
+
+ // Check text in the rich runs
+ assertEquals("This is the subtitle, in bold\r", rtrB.getRawText());
+ assertEquals("This bit is blue and italic\r", rtrC.getRawText());
+ assertEquals("This bit is red (normal)", rtrD.getRawText());
+
+ String newBText = "New Subtitle, will still be bold\n";
+ String newCText = "New blue and italic text\n";
+ String newDText = "Funky new normal red text";
+ rtrB.setText(newBText);
+ rtrC.setText(newCText);
+ rtrD.setText(newDText);
+ HSLFTextParagraph.storeText(trB);
+
+ assertEquals(newBText.replace('\n','\r'), rtrB.getRawText());
+ assertEquals(newCText.replace('\n','\r'), rtrC.getRawText());
+ assertEquals(newDText.replace('\n','\r'), rtrD.getRawText());
+
+ assertEquals(newBText.replace('\n','\r') + newCText.replace('\n','\r') + newDText.replace('\n','\r'), HSLFTextParagraph.getRawText(trB));
+
+ // The styles should have been updated for the new sizes
+ assertEquals(newBText.length(), tpBC.getCharactersCovered());
+ assertEquals(newCText.length(), tpCC.getCharactersCovered());
+ assertEquals(newDText.length()+1, tpDC.getCharactersCovered()); // Last one is always one larger
// Paragraph style should be sum of text length
- assertEquals(
- newBText.length() + newCText.length() + newDText.length() +1,
- tpBP.getCharactersCovered() + tpCP.getCharactersCovered() + tpDP.getCharactersCovered()
- );
-
- // Check stylings still as expected
- TextPropCollection ntpBC = rtrB.getCharacterStyle();
- TextPropCollection ntpCC = rtrC.getCharacterStyle();
- TextPropCollection ntpDC = rtrD.getCharacterStyle();
- assertEquals(tpBC.getTextPropList(), ntpBC.getTextPropList());
- assertEquals(tpCC.getTextPropList(), ntpCC.getTextPropList());
- assertEquals(tpDC.getTextPropList(), ntpDC.getTextPropList());
- }
-
-
- /**
- * Test case for Bug 41015.
- *
- * In some cases RichTextRun.getText() threw StringIndexOutOfBoundsException because
- * of the wrong list of potential paragraph properties defined in StyleTextPropAtom.
- *
- */
- @Test
- void testBug41015() throws IOException {
- List<HSLFTextRun> rt;
+ assertEquals(
+ newBText.length() + newCText.length() + newDText.length() +1,
+ tpBP.getCharactersCovered() + tpCP.getCharactersCovered() + tpDP.getCharactersCovered()
+ );
+
+ // Check stylings still as expected
+ TextPropCollection ntpBC = rtrB.getCharacterStyle();
+ TextPropCollection ntpCC = rtrC.getCharacterStyle();
+ TextPropCollection ntpDC = rtrD.getCharacterStyle();
+ assertEquals(tpBC.getTextPropList(), ntpBC.getTextPropList());
+ assertEquals(tpCC.getTextPropList(), ntpCC.getTextPropList());
+ assertEquals(tpDC.getTextPropList(), ntpDC.getTextPropList());
+ }
+
+
+ /**
+ * Test case for Bug 41015.
+ *
+ * In some cases RichTextRun.getText() threw StringIndexOutOfBoundsException because
+ * of the wrong list of potential paragraph properties defined in StyleTextPropAtom.
+ *
+ */
+ @Test
+ void testBug41015() throws IOException {
+ List<HSLFTextRun> rt;
- HSLFSlideShow ppt = HSLFTestDataSamples.getSlideShow("bug-41015.ppt");
- HSLFSlide sl = ppt.getSlides().get(0);
+ HSLFSlideShow ppt = HSLFTestDataSamples.getSlideShow("bug-41015.ppt");
+ HSLFSlide sl = ppt.getSlides().get(0);
List<List<HSLFTextParagraph>> textParass = sl.getTextParagraphs();
- assertEquals(2, textParass.size());
+ assertEquals(2, textParass.size());
- List<HSLFTextParagraph> textParas = textParass.get(0);
- rt = textParass.get(0).get(0).getTextRuns();
- assertEquals(1, rt.size());
- assertEquals(0, textParass.get(0).get(0).getIndentLevel());
- assertEquals("sdfsdfsdf", rt.get(0).getRawText());
+ List<HSLFTextParagraph> textParas = textParass.get(0);
+ rt = textParass.get(0).get(0).getTextRuns();
+ assertEquals(1, rt.size());
+ assertEquals(0, textParass.get(0).get(0).getIndentLevel());
+ assertEquals("sdfsdfsdf", rt.get(0).getRawText());
- textParas = textParass.get(1);
+ textParas = textParass.get(1);
String[] texts = {"Sdfsdfsdf\r", "Dfgdfg\r", "Dfgdfgdfg\r", "Sdfsdfs\r", "Sdfsdf\r"};
int[] indents = {0, 0, 0, 1, 1};
- int i=0;
- for (HSLFTextParagraph p : textParas) {
- assertEquals(texts[i], p.getTextRuns().get(0).getRawText());
- assertEquals(indents[i], p.getIndentLevel());
- i++;
- }
- ppt.close();
- }
-
- /**
- * Test creation of TextRun objects.
- */
- @Test
- void testAddTextRun() throws IOException {
- HSLFSlideShow ppt = new HSLFSlideShow();
- HSLFSlide slide = ppt.createSlide();
-
- assertEquals(0, slide.getTextParagraphs().size());
-
- HSLFTextBox shape1 = new HSLFTextBox();
- List<HSLFTextParagraph> run1 = shape1.getTextParagraphs();
- shape1.setText("Text 1");
- slide.addShape(shape1);
-
- //The array of Slide's text runs must be updated when new text shapes are added.
- List<List<HSLFTextParagraph>> runs = slide.getTextParagraphs();
- assertNotNull(runs);
- assertSame(run1, runs.get(0));
-
- HSLFTextBox shape2 = new HSLFTextBox();
- List<HSLFTextParagraph> run2 = shape2.getTextParagraphs();
- shape2.setText("Text 2");
- slide.addShape(shape2);
-
- runs = slide.getTextParagraphs();
- assertEquals(2, runs.size());
-
- assertSame(run1, runs.get(0));
- assertSame(run2, runs.get(1));
-
- // as getShapes()
- List<HSLFShape> sh = slide.getShapes();
- assertEquals(2, sh.size());
- assertTrue(sh.get(0) instanceof HSLFTextBox);
- HSLFTextBox box1 = (HSLFTextBox)sh.get(0);
- assertSame(run1, box1.getTextParagraphs());
- HSLFTextBox box2 = (HSLFTextBox)sh.get(1);
- assertSame(run2, box2.getTextParagraphs());
-
- // test Table - a complex group of shapes containing text objects
- HSLFSlide slide2 = ppt.createSlide();
- assertTrue(slide2.getTextParagraphs().isEmpty());
- HSLFTable table = new HSLFTable(2, 2);
- slide2.addShape(table);
- runs = slide2.getTextParagraphs();
- assertNotNull(runs);
- assertEquals(4, runs.size());
- ppt.close();
- }
+ int i=0;
+ for (HSLFTextParagraph p : textParas) {
+ assertEquals(texts[i], p.getTextRuns().get(0).getRawText());
+ assertEquals(indents[i], p.getIndentLevel());
+ i++;
+ }
+ ppt.close();
+ }
- @Test
- void test48916() throws IOException {
+ /**
+ * Test creation of TextRun objects.
+ */
+ @Test
+ void testAddTextRun() throws IOException {
+ HSLFSlideShow ppt = new HSLFSlideShow();
+ HSLFSlide slide = ppt.createSlide();
+
+ assertEquals(0, slide.getTextParagraphs().size());
+
+ HSLFTextBox shape1 = new HSLFTextBox();
+ List<HSLFTextParagraph> run1 = shape1.getTextParagraphs();
+ shape1.setText("Text 1");
+ slide.addShape(shape1);
+
+ //The array of Slide's text runs must be updated when new text shapes are added.
+ List<List<HSLFTextParagraph>> runs = slide.getTextParagraphs();
+ assertNotNull(runs);
+ assertSame(run1, runs.get(0));
+
+ HSLFTextBox shape2 = new HSLFTextBox();
+ List<HSLFTextParagraph> run2 = shape2.getTextParagraphs();
+ shape2.setText("Text 2");
+ slide.addShape(shape2);
+
+ runs = slide.getTextParagraphs();
+ assertEquals(2, runs.size());
+
+ assertSame(run1, runs.get(0));
+ assertSame(run2, runs.get(1));
+
+ // as getShapes()
+ List<HSLFShape> sh = slide.getShapes();
+ assertEquals(2, sh.size());
+ assertTrue(sh.get(0) instanceof HSLFTextBox);
+ HSLFTextBox box1 = (HSLFTextBox)sh.get(0);
+ assertSame(run1, box1.getTextParagraphs());
+ HSLFTextBox box2 = (HSLFTextBox)sh.get(1);
+ assertSame(run2, box2.getTextParagraphs());
+
+ // test Table - a complex group of shapes containing text objects
+ HSLFSlide slide2 = ppt.createSlide();
+ assertTrue(slide2.getTextParagraphs().isEmpty());
+ HSLFTable table = new HSLFTable(2, 2);
+ slide2.addShape(table);
+ runs = slide2.getTextParagraphs();
+ assertNotNull(runs);
+ assertEquals(4, runs.size());
+ ppt.close();
+ }
+
+ @Test
+ void test48916() throws IOException {
HSLFSlideShow ppt1 = HSLFTestDataSamples.getSlideShow("SampleShow.ppt");
List<HSLFSlide> slides = ppt1.getSlides();
for(HSLFSlide slide : slides){
@@ -555,8 +555,8 @@ public final class TestTextRun {
ppt1.close();
}
- @Test
- void test52244() throws IOException {
+ @Test
+ void test52244() throws IOException {
HSLFSlideShow ppt = HSLFTestDataSamples.getSlideShow("52244.ppt");
HSLFSlide slide = ppt.getSlides().get(0);
@@ -564,7 +564,7 @@ public final class TestTextRun {
int i=0;
for (List<HSLFTextParagraph> textParas : slide.getTextParagraphs()) {
- HSLFTextRun first = textParas.get(0).getTextRuns().get(0);
+ HSLFTextRun first = textParas.get(0).getTextRuns().get(0);
assertEquals("Arial", first.getFontFamily());
assertNotNull(first.getFontSize());
assertEquals(sizes[i++], first.getFontSize().intValue());
@@ -572,15 +572,15 @@ public final class TestTextRun {
ppt.close();
}
- @Test
- void testAppendEmpty() throws IOException {
+ @Test
+ void testAppendEmpty() throws IOException {
try (HSLFSlideShow ppt = new HSLFSlideShow()) {
- HSLFSlide s = ppt.createSlide();
- HSLFTextBox title = s.addTitle();
- title.setText("");
- title.appendText("\n", true);
- title.appendText("para", true);
- assertEquals("\npara", title.getText());
- }
- }
+ HSLFSlide s = ppt.createSlide();
+ HSLFTextBox title = s.addTitle();
+ title.setText("");
+ title.appendText("\n", true);
+ title.appendText("para", true);
+ assertEquals("\npara", title.getText());
+ }
+ }
}
Modified: poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/util/TestSystemTimeUtils.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/util/TestSystemTimeUtils.java?rev=1890122&r1=1890121&r2=1890122&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/util/TestSystemTimeUtils.java (original)
+++ poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/util/TestSystemTimeUtils.java Sat May 22 21:37:08 2021
@@ -32,19 +32,19 @@ import org.junit.jupiter.api.Test;
* Tests that SystemTimeUtils works properly.
*/
public final class TestSystemTimeUtils {
- // From real files
- private final byte[] data_a = new byte[] {
- 0xD6-256, 07, 01, 00,
- 02, 00, 0x18, 00, 0x0A, 00, 0x1A, 00,
- 0x0F, 00, 0xCD-256, 00
- };
- private final byte[] data_b = new byte[] {
- 00, 00, 0xE1-256, 0x2E, 0x1C, 00, 00, 00,
- 01, 00, 00, 00, 0xD6-256, 0x07, 01, 00,
- 02, 00, 0x18, 00, 0x15, 00, 0x19, 00, 03,
- 00, 0xD5-256, 02, 0x0A, 00, 00, 00,
- 0x0A, 00, 00, 00
- };
+ // From real files
+ private final byte[] data_a = new byte[] {
+ 0xD6-256, 07, 01, 00,
+ 02, 00, 0x18, 00, 0x0A, 00, 0x1A, 00,
+ 0x0F, 00, 0xCD-256, 00
+ };
+ private final byte[] data_b = new byte[] {
+ 00, 00, 0xE1-256, 0x2E, 0x1C, 00, 00, 00,
+ 01, 00, 00, 00, 0xD6-256, 0x07, 01, 00,
+ 02, 00, 0x18, 00, 0x15, 00, 0x19, 00, 03,
+ 00, 0xD5-256, 02, 0x0A, 00, 00, 00,
+ 0x0A, 00, 00, 00
+ };
private static SimpleDateFormat sdf;
@@ -54,49 +54,49 @@ public final class TestSystemTimeUtils {
sdf.setTimeZone(LocaleUtil.getUserTimeZone());
}
- @Test
+ @Test
void testGetDateA() throws Exception {
- Date date = SystemTimeUtils.getDate(data_a);
+ Date date = SystemTimeUtils.getDate(data_a);
- // Is 2006-01-24 (2nd day of week) 10:26:15.205
- Date exp = sdf.parse("2006-01-24 10:26:15.205");
- assertEquals(exp.getTime(), date.getTime());
- assertEquals(exp, date);
- }
-
- @Test
- void testGetDateB() throws Exception {
- Date date = SystemTimeUtils.getDate(data_b, 8+4);
-
- // Is 2006-01-24 (2nd day of week) 21:25:03.725
- Date exp = sdf.parse("2006-01-24 21:25:03.725");
- assertEquals(exp.getTime(), date.getTime());
- assertEquals(exp, date);
- }
-
- @Test
- void testWriteDateA() throws Exception {
- byte[] out_a = new byte[data_a.length];
- Date date = sdf.parse("2006-01-24 10:26:15.205");
- SystemTimeUtils.storeDate(date, out_a);
-
- for(int i=0; i<out_a.length; i++) {
- assertEquals(data_a[i], out_a[i]);
- }
- }
-
- @Test
- void testWriteDateB() throws Exception {
- byte[] out_b = new byte[data_b.length];
- // Copy over start and end, ignoring the 16 byte date field in the middle
- System.arraycopy(data_b, 0, out_b, 0, 12);
- System.arraycopy(data_b, 12+16, out_b, 12+16, data_b.length-12-16);
-
- Date date = sdf.parse("2006-01-24 21:25:03.725");
- SystemTimeUtils.storeDate(date, out_b, 12);
-
- for(int i=0; i<out_b.length; i++) {
- assertEquals(data_b[i], out_b[i]);
- }
- }
+ // Is 2006-01-24 (2nd day of week) 10:26:15.205
+ Date exp = sdf.parse("2006-01-24 10:26:15.205");
+ assertEquals(exp.getTime(), date.getTime());
+ assertEquals(exp, date);
+ }
+
+ @Test
+ void testGetDateB() throws Exception {
+ Date date = SystemTimeUtils.getDate(data_b, 8+4);
+
+ // Is 2006-01-24 (2nd day of week) 21:25:03.725
+ Date exp = sdf.parse("2006-01-24 21:25:03.725");
+ assertEquals(exp.getTime(), date.getTime());
+ assertEquals(exp, date);
+ }
+
+ @Test
+ void testWriteDateA() throws Exception {
+ byte[] out_a = new byte[data_a.length];
+ Date date = sdf.parse("2006-01-24 10:26:15.205");
+ SystemTimeUtils.storeDate(date, out_a);
+
+ for(int i=0; i<out_a.length; i++) {
+ assertEquals(data_a[i], out_a[i]);
+ }
+ }
+
+ @Test
+ void testWriteDateB() throws Exception {
+ byte[] out_b = new byte[data_b.length];
+ // Copy over start and end, ignoring the 16 byte date field in the middle
+ System.arraycopy(data_b, 0, out_b, 0, 12);
+ System.arraycopy(data_b, 12+16, out_b, 12+16, data_b.length-12-16);
+
+ Date date = sdf.parse("2006-01-24 21:25:03.725");
+ SystemTimeUtils.storeDate(date, out_b, 12);
+
+ for(int i=0; i<out_b.length; i++) {
+ assertEquals(data_b[i], out_b[i]);
+ }
+ }
}
Modified: poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hsmf/TestBasics.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hsmf/TestBasics.java?rev=1890122&r1=1890121&r2=1890122&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hsmf/TestBasics.java (original)
+++ poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hsmf/TestBasics.java Sat May 22 21:37:08 2021
@@ -74,10 +74,10 @@ public final class TestBasics {
// This one has lots...
assertEquals(18, outlook30.getRecipientEmailAddressList().length);
assertEquals("shawn.bohn@pnl.gov; gus.calapristi@pnl.gov; Richard.Carter@pnl.gov; " +
- "barb.cheney@pnl.gov; nick.cramer@pnl.gov; vern.crow@pnl.gov; Laura.Curtis@pnl.gov; " +
- "julie.dunkle@pnl.gov; david.gillen@pnl.gov; michelle@pnl.gov; Jereme.Haack@pnl.gov; " +
- "Michelle.Hart@pnl.gov; ranata.johnson@pnl.gov; grant.nakamura@pnl.gov; " +
- "debbie.payne@pnl.gov; stuart.rose@pnl.gov; randall.scarberry@pnl.gov; Leigh.Williams@pnl.gov",
+ "barb.cheney@pnl.gov; nick.cramer@pnl.gov; vern.crow@pnl.gov; Laura.Curtis@pnl.gov; " +
+ "julie.dunkle@pnl.gov; david.gillen@pnl.gov; michelle@pnl.gov; Jereme.Haack@pnl.gov; " +
+ "Michelle.Hart@pnl.gov; ranata.johnson@pnl.gov; grant.nakamura@pnl.gov; " +
+ "debbie.payne@pnl.gov; stuart.rose@pnl.gov; randall.scarberry@pnl.gov; Leigh.Williams@pnl.gov",
outlook30.getRecipientEmailAddress()
);
}
Modified: poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hsmf/datatypes/TestChunkData.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hsmf/datatypes/TestChunkData.java?rev=1890122&r1=1890121&r2=1890122&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hsmf/datatypes/TestChunkData.java (original)
+++ poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hsmf/datatypes/TestChunkData.java Sat May 22 21:37:08 2021
@@ -26,14 +26,14 @@ import org.junit.jupiter.api.Test;
* that will break the library.
*/
public final class TestChunkData {
- @Test
- void testChunkCreate() {
- Chunk chunk;
-
- chunk = new StringChunk(0x0200, Types.createCustom(0x001E));
- assertEquals("__substg1.0_0200001E", chunk.getEntryName());
- assertEquals(0x0200, chunk.getChunkId());
- assertEquals(0x001E, chunk.getType().getId());
+ @Test
+ void testChunkCreate() {
+ Chunk chunk;
+
+ chunk = new StringChunk(0x0200, Types.createCustom(0x001E));
+ assertEquals("__substg1.0_0200001E", chunk.getEntryName());
+ assertEquals(0x0200, chunk.getChunkId());
+ assertEquals(0x001E, chunk.getType().getId());
chunk = new StringChunk("__substg1.0_", 0x0200, Types.createCustom(0x001E));
assertEquals("__substg1.0_0200001E", chunk.getEntryName());
@@ -45,46 +45,46 @@ public final class TestChunkData {
assertEquals(0x0200, chunk.getChunkId());
assertEquals(0x001E, chunk.getType().getId());
- /* test the lower and upper limits of the chunk ids */
- chunk = new StringChunk(0x0000, Types.createCustom(0x001E));
- assertEquals("__substg1.0_0000001E", chunk.getEntryName());
-
- chunk = new StringChunk(0xFFFF, Types.createCustom(0x001E));
- assertEquals("__substg1.0_FFFF001E", chunk.getEntryName());
-
- chunk = new StringChunk(0xFFFF, Types.createCustom(0x001F));
- assertEquals("__substg1.0_FFFF001F", chunk.getEntryName());
- }
-
- @Test
- void testTextBodyChunk() {
- StringChunk chunk = new StringChunk(0x1000, Types.UNICODE_STRING);
- assertEquals(chunk.getChunkId(), MAPIProperty.BODY.id);
- }
-
- @Test
- void testDisplayToChunk() {
- StringChunk chunk = new StringChunk(0x0E04, Types.UNICODE_STRING);
+ /* test the lower and upper limits of the chunk ids */
+ chunk = new StringChunk(0x0000, Types.createCustom(0x001E));
+ assertEquals("__substg1.0_0000001E", chunk.getEntryName());
+
+ chunk = new StringChunk(0xFFFF, Types.createCustom(0x001E));
+ assertEquals("__substg1.0_FFFF001E", chunk.getEntryName());
+
+ chunk = new StringChunk(0xFFFF, Types.createCustom(0x001F));
+ assertEquals("__substg1.0_FFFF001F", chunk.getEntryName());
+ }
+
+ @Test
+ void testTextBodyChunk() {
+ StringChunk chunk = new StringChunk(0x1000, Types.UNICODE_STRING);
+ assertEquals(chunk.getChunkId(), MAPIProperty.BODY.id);
+ }
+
+ @Test
+ void testDisplayToChunk() {
+ StringChunk chunk = new StringChunk(0x0E04, Types.UNICODE_STRING);
assertEquals(chunk.getChunkId(), MAPIProperty.DISPLAY_TO.id);
- }
+ }
- @Test
- void testDisplayCCChunk() {
- StringChunk chunk = new StringChunk(0x0E03, Types.UNICODE_STRING);
+ @Test
+ void testDisplayCCChunk() {
+ StringChunk chunk = new StringChunk(0x0E03, Types.UNICODE_STRING);
assertEquals(chunk.getChunkId(), MAPIProperty.DISPLAY_CC.id);
- }
+ }
- @Test
- void testDisplayBCCChunk() {
- StringChunk chunk = new StringChunk(0x0E02, Types.UNICODE_STRING);
+ @Test
+ void testDisplayBCCChunk() {
+ StringChunk chunk = new StringChunk(0x0E02, Types.UNICODE_STRING);
assertEquals(chunk.getChunkId(), MAPIProperty.DISPLAY_BCC.id);
- }
+ }
- @Test
- void testSubjectChunk() {
- Chunk chunk = new StringChunk(0x0037, Types.UNICODE_STRING);
+ @Test
+ void testSubjectChunk() {
+ Chunk chunk = new StringChunk(0x0037, Types.UNICODE_STRING);
assertEquals(chunk.getChunkId(), MAPIProperty.SUBJECT.id);
- }
+ }
}
Modified: poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hsmf/parsers/TestPOIFSChunkParser.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hsmf/parsers/TestPOIFSChunkParser.java?rev=1890122&r1=1890121&r2=1890122&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hsmf/parsers/TestPOIFSChunkParser.java (original)
+++ poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hsmf/parsers/TestPOIFSChunkParser.java Sat May 22 21:37:08 2021
@@ -252,7 +252,7 @@ public final class TestPOIFSChunkParser
@Test
void testFindsAttachments() throws IOException, ChunkNotFoundException {
- POIFSFileSystem with = new POIFSFileSystem(samples.getFile("attachment_test_msg.msg"), true);
+ POIFSFileSystem with = new POIFSFileSystem(samples.getFile("attachment_test_msg.msg"), true);
POIFSFileSystem without = new POIFSFileSystem(samples.getFile("quick.msg"), true);
AttachmentChunks attachment;
@@ -285,7 +285,7 @@ public final class TestPOIFSChunkParser
assertFalse(without.getRoot().hasEntry("__attach_version1.0_#00000000"));
assertFalse(without.getRoot().hasEntry("__attach_version1.0_#00000001"));
- // One with, from the top
+ // One with, from the top
MAPIMessage msgWith = new MAPIMessage(with);
assertEquals(2, msgWith.getAttachmentFiles().length);
@@ -304,7 +304,7 @@ public final class TestPOIFSChunkParser
assertEquals("Nicolas1 23456", msgWith.getDisplayFrom());
assertEquals("test pi\u00e8ce jointe 1", msgWith.getSubject());
- // One without, from the top
+ // One without, from the top
MAPIMessage msgWithout = new MAPIMessage(without);
// No attachments
Modified: poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/TestHWPFPictures.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/TestHWPFPictures.java?rev=1890122&r1=1890121&r2=1890122&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/TestHWPFPictures.java (original)
+++ poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/TestHWPFPictures.java Sat May 22 21:37:08 2021
@@ -39,85 +39,85 @@ import org.junit.jupiter.api.Test;
* Test picture support in HWPF
*/
public final class TestHWPFPictures {
- @BeforeAll
+ @BeforeAll
static void setUp() {
- // we use ImageIO in one of the tests here so we should ensure that the temporary directory is created correctly
- File tempDir = new File(System.getProperty("java.io.tmpdir"));
- assertTrue( tempDir.exists() || tempDir.mkdirs(), "Could not create temporary directory " + tempDir.getAbsolutePath() + ": " + tempDir.exists() + "/" + tempDir.isDirectory() );
- }
-
- /**
- * Test that we have the right numbers of images in each file
- */
- @Test
- void testImageCount() {
- HWPFDocument docA = HWPFTestDataSamples.openSampleFile("testPictures.doc");
- HWPFDocument docB = HWPFTestDataSamples.openSampleFile("two_images.doc");
-
- assertNotNull(docA.getPicturesTable());
- assertNotNull(docB.getPicturesTable());
-
- PicturesTable picA = docA.getPicturesTable();
- PicturesTable picB = docB.getPicturesTable();
-
- List<Picture> picturesA = picA.getAllPictures();
- List<Picture> picturesB = picB.getAllPictures();
-
- assertEquals(7, picturesA.size());
- assertEquals(2, picturesB.size());
- }
-
- /**
- * Test that we have the right images in at least one file
- */
- @Test
- void testImageData() {
- HWPFDocument docB = HWPFTestDataSamples.openSampleFile("two_images.doc");
- PicturesTable picB = docB.getPicturesTable();
- List<Picture> picturesB = picB.getAllPictures();
-
- assertEquals(2, picturesB.size());
-
- Picture pic1 = picturesB.get(0);
- Picture pic2 = picturesB.get(1);
-
- assertNotNull(pic1);
- assertNotNull(pic2);
-
- // Check the same
- byte[] pic1B = readFile("simple_image.jpg");
- byte[] pic2B = readFile("simple_image.png");
-
- assertArrayEquals(pic1B, pic1.getContent());
- assertArrayEquals(pic2B, pic2.getContent());
- }
-
- /**
- * Test that compressed image data is correctly returned.
- */
- @Test
- void testCompressedImageData() {
- HWPFDocument docC = HWPFTestDataSamples.openSampleFile("vector_image.doc");
- PicturesTable picC = docC.getPicturesTable();
- List<Picture> picturesC = picC.getAllPictures();
-
- assertEquals(1, picturesC.size());
-
- Picture pic = picturesC.get(0);
- assertNotNull(pic);
-
- // Check the same
- byte[] picBytes = readFile("vector_image.emf");
- assertArrayEquals(picBytes, pic.getContent());
- }
+ // we use ImageIO in one of the tests here so we should ensure that the temporary directory is created correctly
+ File tempDir = new File(System.getProperty("java.io.tmpdir"));
+ assertTrue( tempDir.exists() || tempDir.mkdirs(), "Could not create temporary directory " + tempDir.getAbsolutePath() + ": " + tempDir.exists() + "/" + tempDir.isDirectory() );
+ }
+
+ /**
+ * Test that we have the right numbers of images in each file
+ */
+ @Test
+ void testImageCount() {
+ HWPFDocument docA = HWPFTestDataSamples.openSampleFile("testPictures.doc");
+ HWPFDocument docB = HWPFTestDataSamples.openSampleFile("two_images.doc");
+
+ assertNotNull(docA.getPicturesTable());
+ assertNotNull(docB.getPicturesTable());
+
+ PicturesTable picA = docA.getPicturesTable();
+ PicturesTable picB = docB.getPicturesTable();
+
+ List<Picture> picturesA = picA.getAllPictures();
+ List<Picture> picturesB = picB.getAllPictures();
+
+ assertEquals(7, picturesA.size());
+ assertEquals(2, picturesB.size());
+ }
+
+ /**
+ * Test that we have the right images in at least one file
+ */
+ @Test
+ void testImageData() {
+ HWPFDocument docB = HWPFTestDataSamples.openSampleFile("two_images.doc");
+ PicturesTable picB = docB.getPicturesTable();
+ List<Picture> picturesB = picB.getAllPictures();
+
+ assertEquals(2, picturesB.size());
+
+ Picture pic1 = picturesB.get(0);
+ Picture pic2 = picturesB.get(1);
+
+ assertNotNull(pic1);
+ assertNotNull(pic2);
+
+ // Check the same
+ byte[] pic1B = readFile("simple_image.jpg");
+ byte[] pic2B = readFile("simple_image.png");
+
+ assertArrayEquals(pic1B, pic1.getContent());
+ assertArrayEquals(pic2B, pic2.getContent());
+ }
+
+ /**
+ * Test that compressed image data is correctly returned.
+ */
+ @Test
+ void testCompressedImageData() {
+ HWPFDocument docC = HWPFTestDataSamples.openSampleFile("vector_image.doc");
+ PicturesTable picC = docC.getPicturesTable();
+ List<Picture> picturesC = picC.getAllPictures();
+
+ assertEquals(1, picturesC.size());
+
+ Picture pic = picturesC.get(0);
+ assertNotNull(pic);
+
+ // Check the same
+ byte[] picBytes = readFile("vector_image.emf");
+ assertArrayEquals(picBytes, pic.getContent());
+ }
- @Test
- void testMacImages() throws Exception {
+ @Test
+ void testMacImages() throws Exception {
HWPFDocument docC = HWPFTestDataSamples.openSampleFile("53446.doc");
- PicturesTable picturesTable = docC.getPicturesTable();
- List<Picture> pictures = picturesTable.getAllPictures();
+ PicturesTable picturesTable = docC.getPicturesTable();
+ List<Picture> pictures = picturesTable.getAllPictures();
- assertEquals(4, pictures.size());
+ assertEquals(4, pictures.size());
int[][] expectedSizes = {
{ 185, 42 }, // PNG
@@ -134,29 +134,29 @@ public final class TestHWPFPictures {
assertEquals(dimensions[0], image.getWidth());
assertEquals(dimensions[1], image.getHeight());
}
- }
+ }
- /**
- * Pending the missing files being uploaded to
- * bug #44937
- */
- @Test
- void testEscherDrawing() {
- HWPFDocument docD = HWPFTestDataSamples.openSampleFile("GaiaTest.doc");
- List<Picture> allPictures = docD.getPicturesTable().getAllPictures();
-
- assertEquals(1, allPictures.size());
-
- Picture pic = allPictures.get(0);
- assertNotNull(pic);
- byte[] picD = readFile("GaiaTestImg.png");
-
- assertEquals(picD.length, pic.getContent().length);
-
- assertArrayEquals(picD, pic.getContent());
- }
-
- private static byte[] readFile(String file) {
- return POIDataSamples.getDocumentInstance().readFile(file);
- }
+ /**
+ * Pending the missing files being uploaded to
+ * bug #44937
+ */
+ @Test
+ void testEscherDrawing() {
+ HWPFDocument docD = HWPFTestDataSamples.openSampleFile("GaiaTest.doc");
+ List<Picture> allPictures = docD.getPicturesTable().getAllPictures();
+
+ assertEquals(1, allPictures.size());
+
+ Picture pic = allPictures.get(0);
+ assertNotNull(pic);
+ byte[] picD = readFile("GaiaTestImg.png");
+
+ assertEquals(picD.length, pic.getContent().length);
+
+ assertArrayEquals(picD, pic.getContent());
+ }
+
+ private static byte[] readFile(String file) {
+ return POIDataSamples.getDocumentInstance().readFile(file);
+ }
}
Modified: poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/TestHWPFRangeParts.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/TestHWPFRangeParts.java?rev=1890122&r1=1890121&r2=1890122&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/TestHWPFRangeParts.java (original)
+++ poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/TestHWPFRangeParts.java Sat May 22 21:37:08 2021
@@ -27,78 +27,78 @@ import org.junit.jupiter.api.Test;
* Test that we pull out the right bits of a file into the different ranges
*/
public final class TestHWPFRangeParts {
- private static final char page_break = (char)12;
- private static final String headerDef =
- "\u0003\r\r" +
- "\u0004\r\r" +
- "\u0003\r\r" +
- "\u0004\r\r"
- ;
- private static final String footerDef = "\r";
- private static final String endHeaderFooter = "\r\r";
-
-
- private static final String a_page_1 =
- "This is a sample word document. It has two pages. It has a three column heading, and a three column footer\r" +
- "\r" +
- "HEADING TEXT\r" +
- "\r" +
- "More on page one\r" +
- "\r\r" +
- "End of page 1\r"
- ;
- private static final String a_page_2 =
- "This is page two. It also has a three column heading, and a three column footer.\r"
- ;
-
- private static final String a_header =
- "First header column!\tMid header Right header!\r"
- ;
- private static final String a_footer =
- "Footer Left\tFooter Middle Footer Right\r"
- ;
-
-
- private static final String u_page_1 =
- "This is a fairly simple word document, over two pages, with headers and footers.\r" +
- "The trick with this one is that it contains some Unicode based strings in it.\r" +
- "Firstly, some currency symbols:\r" +
- "\tGBP - \u00a3\r" +
- "\tEUR - \u20ac\r" +
- "Now, we\u2019ll have some French text, in bold and big:\r" +
- "\tMoli\u00e8re\r" +
- "And some normal French text:\r" +
- "\tL'Avare ou l'\u00c9cole du mensonge\r" +
- "That\u2019s it for page one\r"
- ;
- private static final String u_page_2 =
- "This is page two. Les Pr\u00e9cieuses ridicules. The end.\r"
- ;
-
- private static final String u_header =
- "\r\r" +
- "This is a simple header, with a \u20ac euro symbol in it.\r"
- ;
- private static final String u_footer =
- "\r\r\r" +
- "The footer, with Moli\u00e8re, has Unicode in it.\r" +
- "\r\r\r\r"
- ;
-
- /**
- * A document made up only of basic ASCII text
- */
- private HWPFDocument docAscii;
- /**
- * A document with some unicode in it too
- */
- private HWPFDocument docUnicode;
+ private static final char page_break = (char)12;
+ private static final String headerDef =
+ "\u0003\r\r" +
+ "\u0004\r\r" +
+ "\u0003\r\r" +
+ "\u0004\r\r"
+ ;
+ private static final String footerDef = "\r";
+ private static final String endHeaderFooter = "\r\r";
+
+
+ private static final String a_page_1 =
+ "This is a sample word document. It has two pages. It has a three column heading, and a three column footer\r" +
+ "\r" +
+ "HEADING TEXT\r" +
+ "\r" +
+ "More on page one\r" +
+ "\r\r" +
+ "End of page 1\r"
+ ;
+ private static final String a_page_2 =
+ "This is page two. It also has a three column heading, and a three column footer.\r"
+ ;
+
+ private static final String a_header =
+ "First header column!\tMid header Right header!\r"
+ ;
+ private static final String a_footer =
+ "Footer Left\tFooter Middle Footer Right\r"
+ ;
+
+
+ private static final String u_page_1 =
+ "This is a fairly simple word document, over two pages, with headers and footers.\r" +
+ "The trick with this one is that it contains some Unicode based strings in it.\r" +
+ "Firstly, some currency symbols:\r" +
+ "\tGBP - \u00a3\r" +
+ "\tEUR - \u20ac\r" +
+ "Now, we\u2019ll have some French text, in bold and big:\r" +
+ "\tMoli\u00e8re\r" +
+ "And some normal French text:\r" +
+ "\tL'Avare ou l'\u00c9cole du mensonge\r" +
+ "That\u2019s it for page one\r"
+ ;
+ private static final String u_page_2 =
+ "This is page two. Les Pr\u00e9cieuses ridicules. The end.\r"
+ ;
+
+ private static final String u_header =
+ "\r\r" +
+ "This is a simple header, with a \u20ac euro symbol in it.\r"
+ ;
+ private static final String u_footer =
+ "\r\r\r" +
+ "The footer, with Moli\u00e8re, has Unicode in it.\r" +
+ "\r\r\r\r"
+ ;
+
+ /**
+ * A document made up only of basic ASCII text
+ */
+ private HWPFDocument docAscii;
+ /**
+ * A document with some unicode in it too
+ */
+ private HWPFDocument docUnicode;
- @BeforeEach
+ @BeforeEach
void setUp() {
- docUnicode = HWPFTestDataSamples.openSampleFile("HeaderFooterUnicode.doc");
- docAscii = HWPFTestDataSamples.openSampleFile("ThreeColHeadFoot.doc");
- }
+ docUnicode = HWPFTestDataSamples.openSampleFile("HeaderFooterUnicode.doc");
+ docAscii = HWPFTestDataSamples.openSampleFile("ThreeColHeadFoot.doc");
+ }
/**
* Note - this test runs several times, to ensure that things
@@ -106,43 +106,43 @@ public final class TestHWPFRangeParts {
* TODO - Make this work with 3+ runs
*/
@Test
- void testContents() {
+ void testContents() {
HWPFDocument doc = docAscii;
for(int run=0; run<3; run++) {
- Range r;
+ Range r;
- // Now check the real ranges
- r = doc.getRange();
- assertEquals(
- a_page_1 +
- page_break + "\r" +
- a_page_2,
- r.text()
- );
-
- r = doc.getHeaderStoryRange();
- assertEquals(
- headerDef +
- a_header +
- footerDef +
- a_footer +
- endHeaderFooter,
- r.text()
- );
-
- r = doc.getOverallRange();
- assertEquals(
- a_page_1 +
- page_break + "\r" +
- a_page_2 +
- headerDef +
- a_header +
- footerDef +
- a_footer +
- endHeaderFooter +
- "\r",
- r.text()
- );
+ // Now check the real ranges
+ r = doc.getRange();
+ assertEquals(
+ a_page_1 +
+ page_break + "\r" +
+ a_page_2,
+ r.text()
+ );
+
+ r = doc.getHeaderStoryRange();
+ assertEquals(
+ headerDef +
+ a_header +
+ footerDef +
+ a_footer +
+ endHeaderFooter,
+ r.text()
+ );
+
+ r = doc.getOverallRange();
+ assertEquals(
+ a_page_1 +
+ page_break + "\r" +
+ a_page_2 +
+ headerDef +
+ a_header +
+ footerDef +
+ a_footer +
+ endHeaderFooter +
+ "\r",
+ r.text()
+ );
// Write out and read back in again, ready for
// the next run of the test
@@ -150,43 +150,43 @@ public final class TestHWPFRangeParts {
if(run < 1)
doc = HWPFTestDataSamples.writeOutAndReadBack(doc);
}
- }
+ }
- @Test
- void testContentsUnicode() {
- Range r;
-
- // Now check the real ranges
- r = docUnicode.getRange();
- assertEquals(
- u_page_1 +
- page_break + "\r" +
- u_page_2,
- r.text()
- );
-
- r = docUnicode.getHeaderStoryRange();
- assertEquals(
- headerDef +
- u_header +
- footerDef +
- u_footer +
- endHeaderFooter,
- r.text()
- );
-
- r = docUnicode.getOverallRange();
- assertEquals(
- u_page_1 +
- page_break + "\r" +
- u_page_2 +
- headerDef +
- u_header +
- footerDef +
- u_footer +
- endHeaderFooter +
- "\r",
- r.text()
- );
- }
+ @Test
+ void testContentsUnicode() {
+ Range r;
+
+ // Now check the real ranges
+ r = docUnicode.getRange();
+ assertEquals(
+ u_page_1 +
+ page_break + "\r" +
+ u_page_2,
+ r.text()
+ );
+
+ r = docUnicode.getHeaderStoryRange();
+ assertEquals(
+ headerDef +
+ u_header +
+ footerDef +
+ u_footer +
+ endHeaderFooter,
+ r.text()
+ );
+
+ r = docUnicode.getOverallRange();
+ assertEquals(
+ u_page_1 +
+ page_break + "\r" +
+ u_page_2 +
+ headerDef +
+ u_header +
+ footerDef +
+ u_footer +
+ endHeaderFooter +
+ "\r",
+ r.text()
+ );
+ }
}
Modified: poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/extractor/TestDifferentRoutes.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/extractor/TestDifferentRoutes.java?rev=1890122&r1=1890121&r2=1890122&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/extractor/TestDifferentRoutes.java (original)
+++ poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/extractor/TestDifferentRoutes.java Sat May 22 21:37:08 2021
@@ -35,57 +35,57 @@ import org.junit.jupiter.api.Test;
* Test the different routes to extracting text
*/
public final class TestDifferentRoutes {
- private static final String[] p_text = new String[] {
- "This is a simple word document\r",
- "\r",
- "It has a number of paragraphs in it\r",
- "\r",
- "Some of them even feature bold, italic and underlined text\r",
- "\r",
- "\r",
- "This bit is in a different font and size\r",
- "\r",
- "\r",
- "This bit features some red text.\r",
- "\r",
- "\r",
- "It is otherwise very very boring.\r"
- };
-
- private HWPFDocument doc;
-
- @BeforeEach
- void setUp() {
- doc = HWPFTestDataSamples.openSampleFile("test2.doc");
- }
-
- @AfterEach
- void tearDown() throws IOException {
- doc.close();
- }
-
- /**
- * Test model based extraction
- */
- @Test
- void testExtractFromModel() {
- Range r = doc.getRange();
-
- String[] text = new String[r.numParagraphs()];
- for (int i = 0; i < r.numParagraphs(); i++) {
- Paragraph p = r.getParagraph(i);
- text[i] = p.text();
- }
-
- assertArrayEquals(p_text, text);
- }
-
- /**
- * Test textPieces based extraction
- */
- @Test
- void testExtractFromTextPieces() throws Exception {
- String expected = StringUtil.join(p_text, "");
- assertEquals(expected, doc.getDocumentText());
- }
+ private static final String[] p_text = new String[] {
+ "This is a simple word document\r",
+ "\r",
+ "It has a number of paragraphs in it\r",
+ "\r",
+ "Some of them even feature bold, italic and underlined text\r",
+ "\r",
+ "\r",
+ "This bit is in a different font and size\r",
+ "\r",
+ "\r",
+ "This bit features some red text.\r",
+ "\r",
+ "\r",
+ "It is otherwise very very boring.\r"
+ };
+
+ private HWPFDocument doc;
+
+ @BeforeEach
+ void setUp() {
+ doc = HWPFTestDataSamples.openSampleFile("test2.doc");
+ }
+
+ @AfterEach
+ void tearDown() throws IOException {
+ doc.close();
+ }
+
+ /**
+ * Test model based extraction
+ */
+ @Test
+ void testExtractFromModel() {
+ Range r = doc.getRange();
+
+ String[] text = new String[r.numParagraphs()];
+ for (int i = 0; i < r.numParagraphs(); i++) {
+ Paragraph p = r.getParagraph(i);
+ text[i] = p.text();
+ }
+
+ assertArrayEquals(p_text, text);
+ }
+
+ /**
+ * Test textPieces based extraction
+ */
+ @Test
+ void testExtractFromTextPieces() throws Exception {
+ String expected = StringUtil.join(p_text, "");
+ assertEquals(expected, doc.getDocumentText());
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org