浏览代码

Slightly expand tests, inspired by bug #50060, but ultimately show there is a deeper issue outstanding

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1026399 13f79535-47bb-0310-9956-ffa450edef68
tags/REL_3_8_BETA1
Nick Burch 13 年前
父节点
当前提交
74bfae6b2c

+ 2
- 1
src/scratchpad/src/org/apache/poi/hwpf/model/CHPBinTable.java 查看文件

@@ -199,7 +199,8 @@ public class CHPBinTable
int pageNum = docOffset/POIFSConstants.SMALLER_BIG_BLOCK_SIZE;

// get the ending fc
int endingFc = ((PropertyNode)_textRuns.get(_textRuns.size() - 1)).getEnd();
PropertyNode lastRun = (PropertyNode)_textRuns.get(_textRuns.size() - 1);
int endingFc = lastRun.getEnd();
endingFc += fcMin;



+ 136
- 95
src/scratchpad/testcases/org/apache/poi/hwpf/TestHWPFRangeParts.java 查看文件

@@ -98,108 +98,149 @@ public final class TestHWPFRangeParts extends TestCase {
docAscii = HWPFTestDataSamples.openSampleFile("ThreeColHeadFoot.doc");
}

/**
* Note - this test runs several times, to ensure that things
* don't get broken as we write out and read back in again
* TODO - Make this work with 3+ runs
*/
public void testBasics() {
// First check the start and end bits
assertEquals(
0,
docAscii._cpSplit.getMainDocumentStart()
);
assertEquals(
a_page_1.length() +
2 + // page break
a_page_2.length(),
docAscii._cpSplit.getMainDocumentEnd()
);

assertEquals(
238,
docAscii._cpSplit.getFootnoteStart()
);
assertEquals(
238,
docAscii._cpSplit.getFootnoteEnd()
);

assertEquals(
238,
docAscii._cpSplit.getHeaderStoryStart()
);
assertEquals(
238 + headerDef.length() + a_header.length() +
footerDef.length() + a_footer.length() + endHeaderFooter.length(),
docAscii._cpSplit.getHeaderStoryEnd()
);
HWPFDocument doc = docAscii;
for(int run=0; run<3; run++) {
// First check the start and end bits
assertEquals(
0,
doc._cpSplit.getMainDocumentStart()
);
assertEquals(
a_page_1.length() +
2 + // page break
a_page_2.length(),
doc._cpSplit.getMainDocumentEnd()
);
assertEquals(
238,
doc._cpSplit.getFootnoteStart()
);
assertEquals(
238,
doc._cpSplit.getFootnoteEnd()
);
assertEquals(
238,
doc._cpSplit.getHeaderStoryStart()
);
assertEquals(
238 + headerDef.length() + a_header.length() +
footerDef.length() + a_footer.length() + endHeaderFooter.length(),
doc._cpSplit.getHeaderStoryEnd()
);
// Write out and read back in again, ready for
// the next run of the test
// TODO run more than once
if(run < 1)
doc = HWPFTestDataSamples.writeOutAndReadBack(doc);
}
}

/**
* Note - this test runs several times, to ensure that things
* don't get broken as we write out and read back in again
* TODO - Make this work with 3+ runs
*/
public void testContents() {
Range r;

// Now check the real ranges
r = docAscii.getRange();
assertEquals(
a_page_1 +
page_break + "\r" +
a_page_2,
r.text()
);

r = docAscii.getHeaderStoryRange();
assertEquals(
headerDef +
a_header +
footerDef +
a_footer +
endHeaderFooter,
r.text()
);

r = docAscii.getOverallRange();
assertEquals(
a_page_1 +
page_break + "\r" +
a_page_2 +
headerDef +
a_header +
footerDef +
a_footer +
endHeaderFooter +
"\r",
r.text()
);
HWPFDocument doc = docAscii;
for(int run=0; run<3; run++) {
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()
);
// Write out and read back in again, ready for
// the next run of the test
// TODO run more than once
if(run < 1)
doc = HWPFTestDataSamples.writeOutAndReadBack(doc);
}
}

/**
* Note - this test runs several times, to ensure that things
* don't get broken as we write out and read back in again
*/
public void testBasicsUnicode() {
// First check the start and end bits
assertEquals(
0,
docUnicode._cpSplit.getMainDocumentStart()
);
assertEquals(
u_page_1.length() +
2 + // page break
u_page_2.length(),
docUnicode._cpSplit.getMainDocumentEnd()
);

assertEquals(
408,
docUnicode._cpSplit.getFootnoteStart()
);
assertEquals(
408,
docUnicode._cpSplit.getFootnoteEnd()
);

assertEquals(
408,
docUnicode._cpSplit.getHeaderStoryStart()
);
// TODO - fix this one
assertEquals(
408 + headerDef.length() + u_header.length() +
footerDef.length() + u_footer.length() + endHeaderFooter.length(),
docUnicode._cpSplit.getHeaderStoryEnd()
);
HWPFDocument doc = docUnicode;
for(int run=0; run<3; run++) {
// First check the start and end bits
assertEquals(
0,
doc._cpSplit.getMainDocumentStart()
);
assertEquals(
u_page_1.length() +
2 + // page break
u_page_2.length(),
doc._cpSplit.getMainDocumentEnd()
);
assertEquals(
408,
doc._cpSplit.getFootnoteStart()
);
assertEquals(
408,
doc._cpSplit.getFootnoteEnd()
);
assertEquals(
408,
doc._cpSplit.getHeaderStoryStart()
);
// TODO - fix this one
assertEquals(
408 + headerDef.length() + u_header.length() +
footerDef.length() + u_footer.length() + endHeaderFooter.length(),
doc._cpSplit.getHeaderStoryEnd()
);
// Write out and read back in again, ready for
// the next run of the test
// TODO run more than once
if(run < 1)
doc = HWPFTestDataSamples.writeOutAndReadBack(doc);
}
}

public void testContentsUnicode() {

正在加载...
取消
保存