ASF Bugzilla – Attachment 32419 Details for
Bug 57495
[PATCH] getTableArray method can not get 0 pos table
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
updated patch with some tests
patch.txt (text/plain), 6.66 KB, created by
lordscales91
on 2015-01-31 12:31:22 UTC
(
hide
)
Description:
updated patch with some tests
Filename:
MIME Type:
Creator:
lordscales91
Created:
2015-01-31 12:31:22 UTC
Size:
6.66 KB
patch
obsolete
>Index: src/java/org/apache/poi/util/Units.java >=================================================================== >--- src/java/org/apache/poi/util/Units.java (revisi¢n: 1655973) >+++ src/java/org/apache/poi/util/Units.java (copia de trabajo) >@@ -26,11 +26,20 @@ > /** > * Converts points to EMUs > * @param points points >- * @return emus >+ * @return EMUs > */ > public static int toEMU(double points){ > return (int)Math.round(EMU_PER_POINT*points); > } >+ >+ /** >+ * Converts pixels to EMUs >+ * @param pixels pixels >+ * @return EMUs >+ */ >+ public static int pixelToEMU(int pixels) { >+ return pixels*EMU_PER_PIXEL; >+ } > > /** > * Converts EMUs to points >Index: src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java >=================================================================== >--- src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java (revisi¢n: 1655973) >+++ src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java (copia de trabajo) >@@ -330,7 +330,7 @@ > */ > @Override > public XWPFTable getTableArray(int pos) { >- if (pos > 0 && pos < tables.size()){ >+ if (pos >= 0 && pos < tables.size()){ > return tables.get(pos); > } > return null; >@@ -345,7 +345,10 @@ > } > > public XWPFFooter getFooterArray(int pos){ >- return footers.get(pos); >+ if(pos >=0 && pos < footers.size()) { >+ return footers.get(pos); >+ } >+ return null; > } > > /** >@@ -357,7 +360,10 @@ > } > > public XWPFHeader getHeaderArray(int pos){ >- return headers.get(pos); >+ if(pos >=0 && pos < headers.size()) { >+ return headers.get(pos); >+ } >+ return null; > } > > public String getTblStyle(XWPFTable table){ >Index: src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFootnote.java >=================================================================== >--- src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFootnote.java (revisi¢n: 1655973) >+++ src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFootnote.java (copia de trabajo) >@@ -111,7 +111,7 @@ > * @see org.apache.poi.xwpf.usermodel.IBody#getTableArray(int) > */ > public XWPFTable getTableArray(int pos) { >- if(pos > 0 && pos < tables.size()){ >+ if(pos >= 0 && pos < tables.size()){ > return tables.get(pos); > } > return null; >@@ -177,8 +177,10 @@ > * @see org.apache.poi.xwpf.usermodel.IBody#getParagraphArray(int pos) > */ > public XWPFParagraph getParagraphArray(int pos) { >- >- return paragraphs.get(pos); >+ if(pos >=0 && pos < paragraphs.size()) { >+ return paragraphs.get(pos); >+ } >+ return null; > } > > /** >@@ -206,7 +208,7 @@ > return null; > } > XWPFTableRow tableRow = table.getRow(row); >- if(row == null){ >+ if(tableRow == null){ > return null; > } > return tableRow.getTableCell(cell); >Index: src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHeaderFooter.java >=================================================================== >--- src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHeaderFooter.java (revisi¢n: 1655973) >+++ src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHeaderFooter.java (copia de trabajo) >@@ -203,8 +203,10 @@ > * the text of the header or footer. > */ > public XWPFParagraph getParagraphArray(int pos) { >- >- return paragraphs.get(pos); >+ if(pos >= 0 && pos<paragraphs.size()){ >+ return paragraphs.get(pos); >+ } >+ return null; > } > > /** >@@ -425,7 +427,7 @@ > */ > public XWPFTable getTableArray(int pos) { > >- if(pos > 0 && pos < tables.size()){ >+ if(pos >= 0 && pos < tables.size()){ > return tables.get(pos); > } > return null; >Index: src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableCell.java >=================================================================== >--- src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableCell.java (revisi¢n: 1655973) >+++ src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableCell.java (copia de trabajo) >@@ -340,7 +340,7 @@ > * @see org.apache.poi.xwpf.usermodel.IBody#getParagraphArray(int) > */ > public XWPFParagraph getParagraphArray(int pos) { >- if(pos > 0 && pos < paragraphs.size()){ >+ if(pos >= 0 && pos < paragraphs.size()){ > return paragraphs.get(pos); > } > return null; >@@ -379,7 +379,7 @@ > * @see org.apache.poi.xwpf.usermodel.IBody#getTableArray(int) > */ > public XWPFTable getTableArray(int pos) { >- if(pos > 0 && pos < tables.size()){ >+ if(pos >= 0 && pos < tables.size()){ > return tables.get(pos); > } > return null; >Index: src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFBugs.java >=================================================================== >--- src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFBugs.java (revisi¢n: 1655973) >+++ src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFBugs.java (copia de trabajo) >@@ -20,6 +20,7 @@ > > import java.io.IOException; > >+import org.apache.poi.util.Units; > import org.apache.poi.xwpf.XWPFTestDataSamples; > import org.apache.poi.xwpf.usermodel.XWPFRun.FontCharRange; > import org.junit.Test; >@@ -77,4 +78,37 @@ > } > } > } >+ @Test >+ public void bug57495_getTableArrayInDoc() { >+ XWPFDocument doc =new XWPFDocument(); >+ //let's create a few tables for the test >+ for(int i=0;i<3;i++) { >+ doc.createTable(2, 2); >+ } >+ XWPFTable table = doc.getTableArray(0); >+ assertNotNull(table); >+ //let's check also that returns the correct table >+ XWPFTable same = doc.getTables().get(0); >+ assertEquals(table, same); >+ } >+ @Test >+ public void bug57495_getParagraphArrayInTableCell() { >+ XWPFDocument doc =new XWPFDocument(); >+ //let's create a table for the test >+ XWPFTable table = doc.createTable(2, 2); >+ assertNotNull(table); >+ XWPFParagraph p = table.getRow(0).getCell(0).getParagraphArray(0); >+ assertNotNull(p); >+ //let's check also that returns the correct paragraph >+ XWPFParagraph same = table.getRow(0).getCell(0).getParagraphs().get(0); >+ assertEquals(p, same); >+ } >+ >+ @Test >+ public void bug57495_convertPixelsToEMUs() { >+ int pixels= 100; >+ int expectedEMU=952500; >+ int result = Units.pixelToEMU(pixels); >+ assertEquals(expectedEMU, result); >+ } > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 57495
:
32412
| 32419