Tidy up HSLF extractor tests, and add a bit more for bug #51803

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1173753 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2011-09-21 16:46:43 +00:00
parent 2c9a15dc3b
commit 59204cbc38

View File

@ -46,7 +46,6 @@ public final class TestExtractor extends TestCase {
private PowerPointExtractor ppe2;
private static final String expectText2 = "Hello, World!!!\nI am just a poor boy\nThis is Times New Roman\nPlain Text \n";
/** Where our embeded files live */
//private String pdirname;
private static POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
@ -57,6 +56,16 @@ public final class TestExtractor extends TestCase {
ppe2 = new PowerPointExtractor(slTests.openResourceAsStream("with_textbox.ppt"));
}
private static void assertContains(String haystack, String needle) {
assertContains(
"Unable to find expected text '" + needle + "' in text:\n" + haystack,
haystack, needle
);
}
private static void assertContains(String reason, String haystack, String needle) {
assertTrue(reason, haystack.contains(needle));
}
public void testReadSheetText() {
// Basic 2 page example
String sheetText = ppe.getText();
@ -202,24 +211,24 @@ public final class TestExtractor extends TestCase {
ppe = new PowerPointExtractor(slTests.openResourceAsStream("WithComments.ppt"));
String text = ppe.getText();
assertFalse("Comments not in by default", contains(text, "This is a test comment"));
assertFalse("Comments not in by default", text.contains("This is a test comment"));
ppe.setCommentsByDefault(true);
text = ppe.getText();
assertTrue("Unable to find expected word in text\n" + text, contains(text, "This is a test comment"));
assertContains(text, "This is a test comment");
// And another file
ppe = new PowerPointExtractor(slTests.openResourceAsStream("45543.ppt"));
text = ppe.getText();
assertFalse("Comments not in by default", contains(text, "testdoc"));
assertFalse("Comments not in by default", text.contains("testdoc"));
ppe.setCommentsByDefault(true);
text = ppe.getText();
assertTrue("Unable to find expected word in text\n" + text, contains(text, "testdoc"));
assertContains(text, "testdoc");
}
/**
@ -237,13 +246,13 @@ public final class TestExtractor extends TestCase {
ppe = new PowerPointExtractor(hslf);
text = ppe.getText();
assertFalse("Unable to find expected word in text\n" + text, contains(text, "testdoc"));
assertFalse("Unable to find expected word in text\n" + text, contains(text, "test phrase"));
assertFalse("Header shouldn't be there by default\n" + text, text.contains("testdoc"));
assertFalse("Header shouldn't be there by default\n" + text, text.contains("test phrase"));
ppe.setNotesByDefault(true);
text = ppe.getText();
assertTrue("Unable to find expected word in text\n" + text, contains(text, "testdoc"));
assertTrue("Unable to find expected word in text\n" + text, contains(text, "test phrase"));
assertContains(text, "testdoc");
assertContains(text, "test phrase");
// And with a footer, also on notes
@ -255,25 +264,49 @@ public final class TestExtractor extends TestCase {
ppe = new PowerPointExtractor(slTests.openResourceAsStream("45537_Footer.ppt"));
text = ppe.getText();
assertFalse("Unable to find expected word in text\n" + text, contains(text, "testdoc"));
assertFalse("Unable to find expected word in text\n" + text, contains(text, "test phrase"));
assertFalse("Header shouldn't be there by default\n" + text, text.contains("testdoc"));
assertFalse("Header shouldn't be there by default\n" + text, text.contains("test phrase"));
ppe.setNotesByDefault(true);
text = ppe.getText();
assertTrue("Unable to find expected word in text\n" + text, contains(text, "testdoc"));
assertTrue("Unable to find expected word in text\n" + text, contains(text, "test phrase"));
assertContains(text, "testdoc");
assertContains(text, "test phrase");
}
private static boolean contains(String text, String searchString) {
return text.indexOf(searchString) >=0;
public void testSlideMasterText() throws Exception {
String masterText = "Master footer is here";
HSLFSlideShow hslf = new HSLFSlideShow(slTests.openResourceAsStream("WithMaster.ppt"));
ppe = new PowerPointExtractor(hslf);
String text = ppe.getText();
assertContains(text, "Master");
assertContains(text, masterText);
}
public void testMasterText() throws Exception {
ppe = new PowerPointExtractor(slTests.openResourceAsStream("master_text.ppt"));
ppe.setMasterByDefault(true);
// Initially not there
String text = ppe.getText();
assertFalse(text.contains("Master Header Text"));
// Enable, shows up
ppe.setMasterByDefault(true);
text = ppe.getText();
assertTrue(text.contains("Master Header Text"));
// Now with another file only containing master text
// Will always show up
String masterText = "Master footer is here";
HSLFSlideShow hslf = new HSLFSlideShow(slTests.openResourceAsStream("WithMaster.ppt"));
ppe = new PowerPointExtractor(hslf);
text = ppe.getText();
assertContains(text, "Master");
assertContains(text, masterText);
}