📄 testbugs.java
字号:
FileInputStream in = new FileInputStream(filename); HSSFWorkbook wb = new HSSFWorkbook(in); this.assertTrue("Read workbook!" , true); } /** Reference to Name*/ public void test13224() throws java.io.IOException { String filename = System.getProperty("HSSF.testdata.path"); filename=filename+"/13224.xls"; FileInputStream in = new FileInputStream(filename); HSSFWorkbook wb = new HSSFWorkbook(in); this.assertTrue("Read workbook!" , true); } /** Illegal argument exception - cannot store duplicate value in Map*/ public void test19599() throws java.io.IOException { String filename = System.getProperty("HSSF.testdata.path"); FileInputStream in = new FileInputStream(filename+"/19599-1.xls"); HSSFWorkbook wb = new HSSFWorkbook(in); in = new FileInputStream(filename+"/19599-2.xls"); wb = new HSSFWorkbook(in); this.assertTrue("Read workbook, No exceptions" , true); } public void test24215() throws Exception { String filename = System.getProperty("HSSF.testdata.path"); HSSFWorkbook wb = new HSSFWorkbook(new FileInputStream(filename+"/24215.xls")); for (int sheetIndex = 0; sheetIndex < wb.getNumberOfSheets();sheetIndex++) { HSSFSheet sheet = wb.getSheetAt(sheetIndex); int rows = sheet.getLastRowNum(); for (int rowIndex = 0; rowIndex < rows; rowIndex++) { HSSFRow row = sheet.getRow(rowIndex); int cells = row.getLastCellNum(); for (short cellIndex = 0; cellIndex < cells; cellIndex++) { HSSFCell cell = row.getCell(cellIndex); } } } assertTrue("No Exceptions while reading file", true); } public void test18800() throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); HSSFWorkbook book = new HSSFWorkbook(); book.createSheet("TEST"); HSSFSheet sheet = book.cloneSheet(0); book.setSheetName(1,"CLONE"); sheet.createRow(0).createCell((short)0).setCellValue("Test"); book.write(out); book = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray())); sheet = book.getSheet("CLONE"); HSSFRow row = sheet.getRow(0); HSSFCell cell = row.getCell((short)0); System.out.println(cell.getStringCellValue()); } /** * Merged regions were being removed from the parent in cloned sheets * @throws Exception */ public void test22720() throws Exception { HSSFWorkbook workBook = new HSSFWorkbook(); workBook.createSheet("TEST"); HSSFSheet template = workBook.getSheetAt(0); template.addMergedRegion(new Region(0, (short)0, 1, (short)2)); template.addMergedRegion(new Region(1, (short)0, 2, (short)2)); HSSFSheet clone = workBook.cloneSheet(0); int originalMerged = template.getNumMergedRegions(); assertEquals("2 merged regions", 2, originalMerged);// remove merged regions from clone for (int i=template.getNumMergedRegions()-1; i>=0; i--) { clone.removeMergedRegion(i); } assertEquals("Original Sheet's Merged Regions were removed", originalMerged, template.getNumMergedRegions());// check if template's merged regions are OK if (template.getNumMergedRegions()>0) { // fetch the first merged region...EXCEPTION OCCURS HERE template.getMergedRegionAt(0); } //make sure we dont exception } /*Tests read and write of Unicode strings in formula results * bug and testcase submitted by Sompop Kumnoonsate * The file contains THAI unicode characters. */ public void testUnicodeStringFormulaRead() throws Exception { String filename = System.getProperty("HSSF.testdata.path"); filename=filename+"/25695.xls"; FileInputStream in = new FileInputStream(filename); HSSFWorkbook w; w = new HSSFWorkbook(in); in.close(); HSSFCell a1 = w.getSheetAt(0).getRow(0).getCell((short) 0); HSSFCell a2 = w.getSheetAt(0).getRow(0).getCell((short) 1); HSSFCell b1 = w.getSheetAt(0).getRow(1).getCell((short) 0); HSSFCell b2 = w.getSheetAt(0).getRow(1).getCell((short) 1); HSSFCell c1 = w.getSheetAt(0).getRow(2).getCell((short) 0); HSSFCell c2 = w.getSheetAt(0).getRow(2).getCell((short) 1); HSSFCell d1 = w.getSheetAt(0).getRow(3).getCell((short) 0); HSSFCell d2 = w.getSheetAt(0).getRow(3).getCell((short) 1); /* // THAI code page System.out.println("a1="+unicodeString(a1.getStringCellValue())); System.out.println("a2="+unicodeString(a2.getStringCellValue())); // US code page System.out.println("b1="+unicodeString(b1.getStringCellValue())); System.out.println("b2="+unicodeString(b2.getStringCellValue())); // THAI+US System.out.println("c1="+unicodeString(c1.getStringCellValue())); System.out.println("c2="+unicodeString(c2.getStringCellValue())); // US+THAI System.out.println("d1="+unicodeString(d1.getStringCellValue())); System.out.println("d2="+unicodeString(d2.getStringCellValue()));*/ assertEquals("String Cell value", a1.getStringCellValue(), a2.getStringCellValue()); assertEquals("String Cell value", b1.getStringCellValue(), b2.getStringCellValue()); assertEquals("String Cell value", c1.getStringCellValue(), c2.getStringCellValue()); assertEquals("String Cell value", d1.getStringCellValue(), d2.getStringCellValue()); File xls = TempFile.createTempFile("testFormulaUnicode", ".xls"); FileOutputStream out = new FileOutputStream(xls); w.write(out); out.close(); in = new FileInputStream(xls); HSSFWorkbook rw = new HSSFWorkbook(in); in.close(); HSSFCell ra1 = rw.getSheetAt(0).getRow(0).getCell((short) 0); HSSFCell ra2 = rw.getSheetAt(0).getRow(0).getCell((short) 1); HSSFCell rb1 = rw.getSheetAt(0).getRow(1).getCell((short) 0); HSSFCell rb2 = rw.getSheetAt(0).getRow(1).getCell((short) 1); HSSFCell rc1 = rw.getSheetAt(0).getRow(2).getCell((short) 0); HSSFCell rc2 = rw.getSheetAt(0).getRow(2).getCell((short) 1); HSSFCell rd1 = rw.getSheetAt(0).getRow(3).getCell((short) 0); HSSFCell rd2 = rw.getSheetAt(0).getRow(3).getCell((short) 1); assertEquals("Re-Written String Cell value", a1.getStringCellValue(), ra1.getStringCellValue()); assertEquals("Re-Written String Cell value", b1.getStringCellValue(), rb1.getStringCellValue()); assertEquals("Re-Written String Cell value", c1.getStringCellValue(), rc1.getStringCellValue()); assertEquals("Re-Written String Cell value", d1.getStringCellValue(), rd1.getStringCellValue()); assertEquals("Re-Written Formula String Cell value", a1.getStringCellValue(), ra2.getStringCellValue()); assertEquals("Re-Written Formula String Cell value", b1.getStringCellValue(), rb2.getStringCellValue()); assertEquals("Re-Written Formula String Cell value", c1.getStringCellValue(), rc2.getStringCellValue()); assertEquals("Re-Written Formula String Cell value", d1.getStringCellValue(), rd2.getStringCellValue()); } private static String unicodeString(String ss) { char s[] = ss.toCharArray(); java.lang.StringBuffer sb=new java.lang.StringBuffer(); for (int x=0;x<s.length;x++) { sb.append("\\u").append(Integer.toHexString(s[x])); } return sb.toString(); } /** Error in opening wb*/ public void test32822() throws Exception{ String readFilename = System.getProperty("HSSF.testdata.path"); FileInputStream in = new FileInputStream(readFilename+File.separator+"32822.xls"); HSSFWorkbook wb = new HSSFWorkbook(in); assertTrue("No Exceptions while reading file", true); } /**fail to read wb with chart */ public void test15573() throws java.io.IOException { String filename = System.getProperty("HSSF.testdata.path"); filename=filename+"/15573.xls"; FileInputStream in = new FileInputStream(filename); HSSFWorkbook wb = new HSSFWorkbook(in); assertTrue("No Exceptions while reading file", true); } /**names and macros */ public void test27852() throws java.io.IOException { String filename = System.getProperty("HSSF.testdata.path"); filename=filename+"/27852.xls"; FileInputStream in = new FileInputStream(filename); HSSFWorkbook wb = new HSSFWorkbook(in); assertTrue("No Exceptions while reading file", true); for(int i = 0 ; i < wb.getNumberOfNames() ; i++) { HSSFName name = wb.getNameAt(i); name.getNameName(); name.getReference(); } assertTrue("No Exceptions till here!", true); } public void test33082() throws java.io.IOException { String filename = System.getProperty("HSSF.testdata.path"); filename=filename+"/33082.xls"; FileInputStream in = new FileInputStream(filename); HSSFWorkbook wb = new HSSFWorkbook(in); assertTrue("Read book fine!" , true); } /*NullPointerException on reading file*/ public void test34775() throws java.io.IOException { String filename = System.getProperty("HSSF.testdata.path"); filename=filename+"/34775.xls"; FileInputStream in = new FileInputStream(filename); HSSFWorkbook wb = new HSSFWorkbook(in); assertTrue("Read book fine!" , true); } /** Error when reading then writing ArrayValues in NameRecord's*/ public void test37630() throws java.io.IOException { String filename = System.getProperty("HSSF.testdata.path"); filename=filename+"/37630.xls"; FileInputStream in = new FileInputStream(filename); HSSFWorkbook wb = new HSSFWorkbook(in); File file = TempFile.createTempFile("test37630",".xls"); FileOutputStream out = new FileOutputStream(file); wb.write(out); assertTrue("Read book fine!" , true); } protected String cwd = System.getProperty("HSSF.testdata.path"); /** * Bug 25183: org.apache.poi.hssf.usermodel.HSSFSheet.setPropertiesFromSheet */ public void test25183() throws Exception { FileInputStream in = new FileInputStream(new File(cwd, "25183.xls")); HSSFWorkbook wb = new HSSFWorkbook(in); in.close(); assertTrue("No Exceptions while reading file", true); //serialize and read again ByteArrayOutputStream out = new ByteArrayOutputStream(); wb.write(out); out.close(); wb = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray())); assertTrue("No Exceptions while reading file", true); } /** * Bug 26100: 128-character message in IF statement cell causes HSSFWorkbook open failure */ public void test26100() throws Exception { FileInputStream in = new FileInputStream(new File(cwd, "26100.xls")); HSSFWorkbook wb = new HSSFWorkbook(in); in.close(); assertTrue("No Exceptions while reading file", true); ByteArrayOutputStream out = new ByteArrayOutputStream(); wb.write(out); out.close(); wb = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray())); assertTrue("No Exceptions while reading file", true); } /** * Bug 27933: Unable to use a template (xls) file containing a wmf graphic */ public void test27933() throws Exception { FileInputStream in = new FileInputStream(new File(cwd, "27933.xls")); HSSFWorkbook wb = new HSSFWorkbook(in); in.close(); assertTrue("No Exceptions while reading file", true); //serialize and read again ByteArrayOutputStream out = new ByteArrayOutputStream(); wb.write(out); out.close(); wb = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray())); assertTrue("No Exceptions while reading file", true); } /** * Bug 29206: NPE on HSSFSheet.getRow for blank rows */ public void test29206() throws Exception { //the first check with blank workbook HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.createSheet(); for(int i = 1; i < 400; i++) { HSSFRow row = sheet.getRow(i); if(row != null) { HSSFCell cell = row.getCell((short)0); } } //now check on an existing xls file FileInputStream in = new FileInputStream(new File(cwd, "Simple.xls")); wb = new HSSFWorkbook(in);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -