Fix the inconsistent indents in the test file

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1575600 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2014-03-08 20:03:40 +00:00
parent 09adb72510
commit 434f05058e

View File

@ -28,17 +28,16 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText;
public final class TestXWPFHeader extends TestCase { public final class TestXWPFHeader extends TestCase {
public void testSimpleHeader() throws IOException {
XWPFDocument sampleDoc = XWPFTestDataSamples.openSampleDocument("headerFooter.docx");
public void testSimpleHeader() throws IOException { XWPFHeaderFooterPolicy policy = sampleDoc.getHeaderFooterPolicy();
XWPFDocument sampleDoc = XWPFTestDataSamples.openSampleDocument("headerFooter.docx");
XWPFHeaderFooterPolicy policy = sampleDoc.getHeaderFooterPolicy(); XWPFHeader header = policy.getDefaultHeader();
XWPFFooter footer = policy.getDefaultFooter();
XWPFHeader header = policy.getDefaultHeader(); assertNotNull(header);
XWPFFooter footer = policy.getDefaultFooter(); assertNotNull(footer);
assertNotNull(header); }
assertNotNull(footer);
}
public void testImageInHeader() throws IOException { public void testImageInHeader() throws IOException {
XWPFDocument sampleDoc = XWPFTestDataSamples.openSampleDocument("headerPic.docx"); XWPFDocument sampleDoc = XWPFTestDataSamples.openSampleDocument("headerPic.docx");
@ -51,92 +50,92 @@ public final class TestXWPFHeader extends TestCase {
assertEquals(1, header.getRelations().size()); assertEquals(1, header.getRelations().size());
} }
public void testSetHeader() throws IOException { public void testSetHeader() throws IOException {
XWPFDocument sampleDoc = XWPFTestDataSamples.openSampleDocument("SampleDoc.docx"); XWPFDocument sampleDoc = XWPFTestDataSamples.openSampleDocument("SampleDoc.docx");
// no header is set (yet) // no header is set (yet)
XWPFHeaderFooterPolicy policy = sampleDoc.getHeaderFooterPolicy(); XWPFHeaderFooterPolicy policy = sampleDoc.getHeaderFooterPolicy();
assertNull(policy.getDefaultHeader()); assertNull(policy.getDefaultHeader());
assertNull(policy.getFirstPageHeader()); assertNull(policy.getFirstPageHeader());
assertNull(policy.getDefaultFooter()); assertNull(policy.getDefaultFooter());
CTP ctP1 = CTP.Factory.newInstance(); CTP ctP1 = CTP.Factory.newInstance();
CTR ctR1 = ctP1.addNewR(); CTR ctR1 = ctP1.addNewR();
CTText t = ctR1.addNewT(); CTText t = ctR1.addNewT();
String tText = "Paragraph in header"; String tText = "Paragraph in header";
t.setStringValue(tText); t.setStringValue(tText);
// Commented MB 23 May 2010 // Commented MB 23 May 2010
//CTP ctP2 = CTP.Factory.newInstance(); //CTP ctP2 = CTP.Factory.newInstance();
//CTR ctR2 = ctP2.addNewR(); //CTR ctR2 = ctP2.addNewR();
//CTText t2 = ctR2.addNewT(); //CTText t2 = ctR2.addNewT();
//t2.setStringValue("Second paragraph.. for footer"); //t2.setStringValue("Second paragraph.. for footer");
// Create two paragraphs for insertion into the footer.
// Previously only one was inserted MB 23 May 2010
CTP ctP2 = CTP.Factory.newInstance();
CTR ctR2 = ctP2.addNewR();
CTText t2 = ctR2.addNewT();
t2.setStringValue("First paragraph for the footer");
CTP ctP3 = CTP.Factory.newInstance();
CTR ctR3 = ctP3.addNewR();
CTText t3 = ctR3.addNewT();
t3.setStringValue("Second paragraph for the footer");
XWPFParagraph p1 = new XWPFParagraph(ctP1, sampleDoc); // Create two paragraphs for insertion into the footer.
XWPFParagraph[] pars = new XWPFParagraph[1]; // Previously only one was inserted MB 23 May 2010
pars[0] = p1; CTP ctP2 = CTP.Factory.newInstance();
CTR ctR2 = ctP2.addNewR();
CTText t2 = ctR2.addNewT();
t2.setStringValue("First paragraph for the footer");
XWPFParagraph p2 = new XWPFParagraph(ctP2, sampleDoc); CTP ctP3 = CTP.Factory.newInstance();
XWPFParagraph p3 = new XWPFParagraph(ctP3, sampleDoc); CTR ctR3 = ctP3.addNewR();
XWPFParagraph[] pars2 = new XWPFParagraph[2]; CTText t3 = ctR3.addNewT();
pars2[0] = p2; t3.setStringValue("Second paragraph for the footer");
pars2[1] = p3;
// Set headers XWPFParagraph p1 = new XWPFParagraph(ctP1, sampleDoc);
XWPFHeader headerD = policy.createHeader(policy.DEFAULT, pars); XWPFParagraph[] pars = new XWPFParagraph[1];
XWPFHeader headerF = policy.createHeader(policy.FIRST); pars[0] = p1;
// Set a default footer and capture the returned XWPFFooter object.
XWPFFooter footer = policy.createFooter(policy.DEFAULT, pars2);
// Ensure the headers and footer were set correctly.... XWPFParagraph p2 = new XWPFParagraph(ctP2, sampleDoc);
assertNotNull(policy.getDefaultHeader()); XWPFParagraph p3 = new XWPFParagraph(ctP3, sampleDoc);
assertNotNull(policy.getFirstPageHeader()); XWPFParagraph[] pars2 = new XWPFParagraph[2];
assertNotNull(policy.getDefaultFooter()); pars2[0] = p2;
// ....and that the footer object captured above contains two pars2[1] = p3;
// paragraphs of text.
assertEquals(2, footer.getParagraphs().size()); // Set headers
XWPFHeader headerD = policy.createHeader(policy.DEFAULT, pars);
// Check the header created with the paragraph got them, and the one XWPFHeader headerF = policy.createHeader(policy.FIRST);
// created without got an empty one // Set a default footer and capture the returned XWPFFooter object.
assertEquals(1, headerD.getParagraphs().size()); XWPFFooter footer = policy.createFooter(policy.DEFAULT, pars2);
// Ensure the headers and footer were set correctly....
assertNotNull(policy.getDefaultHeader());
assertNotNull(policy.getFirstPageHeader());
assertNotNull(policy.getDefaultFooter());
// ....and that the footer object captured above contains two
// paragraphs of text.
assertEquals(2, footer.getParagraphs().size());
// Check the header created with the paragraph got them, and the one
// created without got an empty one
assertEquals(1, headerD.getParagraphs().size());
assertEquals(1, headerF.getParagraphs().size()); assertEquals(1, headerF.getParagraphs().size());
assertEquals(tText, headerD.getParagraphs().get(0).getText()); assertEquals(tText, headerD.getParagraphs().get(0).getText());
assertEquals("", headerF.getParagraphs().get(0).getText()); assertEquals("", headerF.getParagraphs().get(0).getText());
// As an additional check, recover the defauls footer and // As an additional check, recover the defauls footer and
// make sure that it contains two paragraphs of text and that // make sure that it contains two paragraphs of text and that
// both do hold what is expected. // both do hold what is expected.
footer = policy.getDefaultFooter(); footer = policy.getDefaultFooter();
XWPFParagraph[] paras = footer.getParagraphs().toArray(new XWPFParagraph[0]); XWPFParagraph[] paras = footer.getParagraphs().toArray(new XWPFParagraph[0]);
assertEquals(2, paras.length); assertEquals(2, paras.length);
assertEquals("First paragraph for the footer", paras[0].getText()); assertEquals("First paragraph for the footer", paras[0].getText());
assertEquals("Second paragraph for the footer", paras[1].getText()); assertEquals("Second paragraph for the footer", paras[1].getText());
// Add some text to the empty header // Add some text to the empty header
String fText1 = "New Text!"; String fText1 = "New Text!";
headerF.getParagraphs().get(0).insertNewRun(0).setText(fText1); headerF.getParagraphs().get(0).insertNewRun(0).setText(fText1);
// TODO Add another paragraph and check // TODO Add another paragraph and check
// Check it // Check it
assertEquals(tText, headerD.getParagraphs().get(0).getText()); assertEquals(tText, headerD.getParagraphs().get(0).getText());
assertEquals(fText1, headerF.getParagraphs().get(0).getText()); assertEquals(fText1, headerF.getParagraphs().get(0).getText());
// Save, re-open, ensure it's all still there // Save, re-open, ensure it's all still there
XWPFDocument reopened = XWPFTestDataSamples.writeOutAndReadBack(sampleDoc); XWPFDocument reopened = XWPFTestDataSamples.writeOutAndReadBack(sampleDoc);
policy = reopened.getHeaderFooterPolicy(); policy = reopened.getHeaderFooterPolicy();
assertNotNull(policy.getDefaultHeader()); assertNotNull(policy.getDefaultHeader());
@ -145,50 +144,59 @@ public final class TestXWPFHeader extends TestCase {
assertNotNull(policy.getDefaultFooter()); assertNotNull(policy.getDefaultFooter());
assertNull(policy.getFirstPageFooter()); assertNull(policy.getFirstPageFooter());
assertNull(policy.getEvenPageFooter()); assertNull(policy.getEvenPageFooter());
// Check the new headers still have their text // Check the new headers still have their text
headerD = policy.getDefaultHeader(); headerD = policy.getDefaultHeader();
headerF = policy.getFirstPageHeader(); headerF = policy.getFirstPageHeader();
assertEquals(tText, headerD.getParagraphs().get(0).getText()); assertEquals(tText, headerD.getParagraphs().get(0).getText());
assertEquals(fText1, headerF.getParagraphs().get(0).getText()); assertEquals(fText1, headerF.getParagraphs().get(0).getText());
// Check the new footers have their new text too // Check the new footers have their new text too
footer = policy.getDefaultFooter(); footer = policy.getDefaultFooter();
paras = footer.getParagraphs().toArray(new XWPFParagraph[0]); paras = footer.getParagraphs().toArray(new XWPFParagraph[0]);
assertEquals(2, paras.length); assertEquals(2, paras.length);
assertEquals("First paragraph for the footer", paras[0].getText()); assertEquals("First paragraph for the footer", paras[0].getText());
assertEquals("Second paragraph for the footer", paras[1].getText()); assertEquals("Second paragraph for the footer", paras[1].getText());
} }
public void testSetWatermark() throws IOException { public void testSetWatermark() throws IOException {
XWPFDocument sampleDoc = XWPFTestDataSamples.openSampleDocument("SampleDoc.docx"); XWPFDocument sampleDoc = XWPFTestDataSamples.openSampleDocument("SampleDoc.docx");
// no header is set (yet)
XWPFHeaderFooterPolicy policy = sampleDoc.getHeaderFooterPolicy(); // No header is set (yet)
assertNull(policy.getDefaultHeader()); XWPFHeaderFooterPolicy policy = sampleDoc.getHeaderFooterPolicy();
assertNull(policy.getFirstPageHeader()); assertNull(policy.getDefaultHeader());
assertNull(policy.getDefaultFooter()); assertNull(policy.getFirstPageHeader());
assertNull(policy.getDefaultFooter());
policy.createWatermark("DRAFT"); policy.createWatermark("DRAFT");
assertNotNull(policy.getDefaultHeader()); assertNotNull(policy.getDefaultHeader());
assertNotNull(policy.getFirstPageHeader()); assertNotNull(policy.getFirstPageHeader());
assertNotNull(policy.getEvenPageHeader()); assertNotNull(policy.getEvenPageHeader());
}
// Re-open, and check
public void testAddPictureData() { XWPFDocument reopened = XWPFTestDataSamples.writeOutAndReadBack(sampleDoc);
policy = reopened.getHeaderFooterPolicy();
}
assertNotNull(policy.getDefaultHeader());
public void testGetAllPictures() { assertNotNull(policy.getFirstPageHeader());
assertNotNull(policy.getEvenPageHeader());
} }
public void testGetAllPackagePictures() { public void testAddPictureData() {
// TODO
} }
public void testGetPictureDataById() { public void testGetAllPictures() {
// TODO
} }
public void testGetAllPackagePictures() {
// TODO
}
public void testGetPictureDataById() {
// TODO
}
} }