aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases/org/apache/poi/hssf/usermodel
diff options
context:
space:
mode:
authorJosh Micich <josh@apache.org>2008-08-07 23:49:10 +0000
committerJosh Micich <josh@apache.org>2008-08-07 23:49:10 +0000
commitb7ac0ea8ab973672055e9bdb43fd4003c0cc7545 (patch)
tree5a41dbb7383082e7a4780090ef982148dec3530e /src/testcases/org/apache/poi/hssf/usermodel
parent3889288070ca846f93e756c4992d9ab3562eb903 (diff)
downloadpoi-b7ac0ea8ab973672055e9bdb43fd4003c0cc7545.tar.gz
poi-b7ac0ea8ab973672055e9bdb43fd4003c0cc7545.zip
Consolidating ValueRecordsAggregate within RowRecordsAggregate
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@683758 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org/apache/poi/hssf/usermodel')
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java484
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java34
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java52
3 files changed, 274 insertions, 296 deletions
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
index cc5784c504..6904e6e876 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
@@ -31,12 +31,10 @@ import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.model.Workbook;
import org.apache.poi.hssf.record.CellValueRecordInterface;
import org.apache.poi.hssf.record.EmbeddedObjectRefSubRecord;
-import org.apache.poi.hssf.record.FormulaRecord;
import org.apache.poi.hssf.record.NameRecord;
import org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate;
import org.apache.poi.hssf.record.formula.DeletedArea3DPtg;
import org.apache.poi.hssf.util.CellRangeAddress;
-import org.apache.poi.hssf.util.Region;
import org.apache.poi.util.TempFile;
/**
@@ -991,8 +989,8 @@ public final class TestBugs extends TestCase {
assertEquals("Forms.CheckBox.1", obj.getOLE2ClassName());
try {
- obj.getDirectory();
- fail();
+ obj.getDirectory();
+ fail();
} catch(FileNotFoundException e) {}
}
@@ -1011,12 +1009,12 @@ public final class TestBugs extends TestCase {
// DeletedArea3DPtg
Workbook w = wb.getWorkbook();
for(int i=0; i<w.getNumNames(); i++) {
- NameRecord r = w.getNameRecord(i);
- assertTrue(r.getIndexToSheet() <= wb.getNumberOfSheets());
-
- List nd = r.getNameDefinition();
- assertEquals(1, nd.size());
- assertTrue(nd.get(0) instanceof DeletedArea3DPtg);
+ NameRecord r = w.getNameRecord(i);
+ assertTrue(r.getIndexToSheet() <= wb.getNumberOfSheets());
+
+ List nd = r.getNameDefinition();
+ assertEquals(1, nd.size());
+ assertTrue(nd.get(0) instanceof DeletedArea3DPtg);
}
@@ -1029,12 +1027,12 @@ public final class TestBugs extends TestCase {
assertEquals(2, wb.getNumberOfSheets());
for(int i=0; i<w.getNumNames(); i++) {
- NameRecord r = w.getNameRecord(i);
- assertTrue(r.getIndexToSheet() <= wb.getNumberOfSheets());
-
- List nd = r.getNameDefinition();
- assertEquals(1, nd.size());
- assertTrue(nd.get(0) instanceof DeletedArea3DPtg);
+ NameRecord r = w.getNameRecord(i);
+ assertTrue(r.getIndexToSheet() <= wb.getNumberOfSheets());
+
+ List nd = r.getNameDefinition();
+ assertEquals(1, nd.size());
+ assertTrue(nd.get(0) instanceof DeletedArea3DPtg);
}
@@ -1046,12 +1044,12 @@ public final class TestBugs extends TestCase {
assertEquals(2, wb.getNumberOfSheets());
for(int i=0; i<w.getNumNames(); i++) {
- NameRecord r = w.getNameRecord(i);
- assertTrue(r.getIndexToSheet() <= wb.getNumberOfSheets());
-
- List nd = r.getNameDefinition();
- assertEquals(1, nd.size());
- assertTrue(nd.get(0) instanceof DeletedArea3DPtg);
+ NameRecord r = w.getNameRecord(i);
+ assertTrue(r.getIndexToSheet() <= wb.getNumberOfSheets());
+
+ List nd = r.getNameDefinition();
+ assertEquals(1, nd.size());
+ assertTrue(nd.get(0) instanceof DeletedArea3DPtg);
}
}
@@ -1059,84 +1057,84 @@ public final class TestBugs extends TestCase {
* Test that fonts get added properly
*/
public void test45338() throws Exception {
- HSSFWorkbook wb = new HSSFWorkbook();
- assertEquals(4, wb.getNumberOfFonts());
-
- HSSFSheet s = wb.createSheet();
- s.createRow(0);
- s.createRow(1);
- HSSFCell c1 = s.getRow(0).createCell((short)0);
- HSSFCell c2 = s.getRow(1).createCell((short)0);
-
- assertEquals(4, wb.getNumberOfFonts());
-
- HSSFFont f1 = wb.getFontAt((short)0);
- assertEquals(400, f1.getBoldweight());
-
- // Check that asking for the same font
- // multiple times gives you the same thing.
- // Otherwise, our tests wouldn't work!
- assertEquals(
- wb.getFontAt((short)0),
- wb.getFontAt((short)0)
- );
- assertEquals(
- wb.getFontAt((short)2),
- wb.getFontAt((short)2)
- );
- assertTrue(
- wb.getFontAt((short)0)
- !=
- wb.getFontAt((short)2)
- );
-
- // Look for a new font we have
- // yet to add
- assertNull(
- wb.findFont(
- (short)11, (short)123, (short)22,
- "Thingy", false, true, (short)2, (byte)2
- )
- );
-
- HSSFFont nf = wb.createFont();
- assertEquals(5, wb.getNumberOfFonts());
-
- assertEquals(5, nf.getIndex());
- assertEquals(nf, wb.getFontAt((short)5));
-
- nf.setBoldweight((short)11);
- nf.setColor((short)123);
- nf.setFontHeight((short)22);
- nf.setFontName("Thingy");
- nf.setItalic(false);
- nf.setStrikeout(true);
- nf.setTypeOffset((short)2);
- nf.setUnderline((byte)2);
-
- assertEquals(5, wb.getNumberOfFonts());
- assertEquals(nf, wb.getFontAt((short)5));
-
- // Find it now
- assertNotNull(
- wb.findFont(
- (short)11, (short)123, (short)22,
- "Thingy", false, true, (short)2, (byte)2
- )
- );
- assertEquals(
- 5,
- wb.findFont(
- (short)11, (short)123, (short)22,
- "Thingy", false, true, (short)2, (byte)2
- ).getIndex()
- );
- assertEquals(nf,
- wb.findFont(
- (short)11, (short)123, (short)22,
- "Thingy", false, true, (short)2, (byte)2
- )
- );
+ HSSFWorkbook wb = new HSSFWorkbook();
+ assertEquals(4, wb.getNumberOfFonts());
+
+ HSSFSheet s = wb.createSheet();
+ s.createRow(0);
+ s.createRow(1);
+ HSSFCell c1 = s.getRow(0).createCell((short)0);
+ HSSFCell c2 = s.getRow(1).createCell((short)0);
+
+ assertEquals(4, wb.getNumberOfFonts());
+
+ HSSFFont f1 = wb.getFontAt((short)0);
+ assertEquals(400, f1.getBoldweight());
+
+ // Check that asking for the same font
+ // multiple times gives you the same thing.
+ // Otherwise, our tests wouldn't work!
+ assertEquals(
+ wb.getFontAt((short)0),
+ wb.getFontAt((short)0)
+ );
+ assertEquals(
+ wb.getFontAt((short)2),
+ wb.getFontAt((short)2)
+ );
+ assertTrue(
+ wb.getFontAt((short)0)
+ !=
+ wb.getFontAt((short)2)
+ );
+
+ // Look for a new font we have
+ // yet to add
+ assertNull(
+ wb.findFont(
+ (short)11, (short)123, (short)22,
+ "Thingy", false, true, (short)2, (byte)2
+ )
+ );
+
+ HSSFFont nf = wb.createFont();
+ assertEquals(5, wb.getNumberOfFonts());
+
+ assertEquals(5, nf.getIndex());
+ assertEquals(nf, wb.getFontAt((short)5));
+
+ nf.setBoldweight((short)11);
+ nf.setColor((short)123);
+ nf.setFontHeight((short)22);
+ nf.setFontName("Thingy");
+ nf.setItalic(false);
+ nf.setStrikeout(true);
+ nf.setTypeOffset((short)2);
+ nf.setUnderline((byte)2);
+
+ assertEquals(5, wb.getNumberOfFonts());
+ assertEquals(nf, wb.getFontAt((short)5));
+
+ // Find it now
+ assertNotNull(
+ wb.findFont(
+ (short)11, (short)123, (short)22,
+ "Thingy", false, true, (short)2, (byte)2
+ )
+ );
+ assertEquals(
+ 5,
+ wb.findFont(
+ (short)11, (short)123, (short)22,
+ "Thingy", false, true, (short)2, (byte)2
+ ).getIndex()
+ );
+ assertEquals(nf,
+ wb.findFont(
+ (short)11, (short)123, (short)22,
+ "Thingy", false, true, (short)2, (byte)2
+ )
+ );
}
/**
@@ -1145,94 +1143,90 @@ public final class TestBugs extends TestCase {
* @throws Exception
*/
public void testZipCodeFormulas() throws Exception {
- HSSFWorkbook wb = new HSSFWorkbook();
- HSSFSheet s = wb.createSheet();
- s.createRow(0);
- HSSFCell c1 = s.getRow(0).createCell((short)0);
- HSSFCell c2 = s.getRow(0).createCell((short)1);
- HSSFCell c3 = s.getRow(0).createCell((short)2);
-
- // As number and string
- c1.setCellFormula("70164");
- c2.setCellFormula("\"70164\"");
- c3.setCellFormula("\"90210\"");
-
- // Check the formulas
- assertEquals("70164.0", c1.getCellFormula());
- assertEquals("\"70164\"", c2.getCellFormula());
-
- // And check the values - blank
- assertEquals(0.0, c1.getNumericCellValue(), 0.00001);
- assertEquals("", c1.getRichStringCellValue().getString());
- assertEquals(0.0, c2.getNumericCellValue(), 0.00001);
- assertEquals("", c2.getRichStringCellValue().getString());
- assertEquals(0.0, c3.getNumericCellValue(), 0.00001);
- assertEquals("", c3.getRichStringCellValue().getString());
-
- // Try changing the cached value on one of the string
- // formula cells, so we can see it updates properly
- c3.setCellValue(new HSSFRichTextString("test"));
- assertEquals(0.0, c3.getNumericCellValue(), 0.00001);
- assertEquals("test", c3.getRichStringCellValue().getString());
-
-
- // Now evaluate, they should all be changed
- HSSFFormulaEvaluator eval = new HSSFFormulaEvaluator(s, wb);
- eval.setCurrentRow(s.getRow(0));
- eval.evaluateFormulaCell(c1);
- eval.evaluateFormulaCell(c2);
- eval.evaluateFormulaCell(c3);
-
- // Check that the cells now contain
- // the correct values
- assertEquals(70164.0, c1.getNumericCellValue(), 0.00001);
- assertEquals("", c1.getRichStringCellValue().getString());
- assertEquals(0.0, c2.getNumericCellValue(), 0.00001);
- assertEquals("70164", c2.getRichStringCellValue().getString());
- assertEquals(0.0, c3.getNumericCellValue(), 0.00001);
- assertEquals("90210", c3.getRichStringCellValue().getString());
+ HSSFWorkbook wb = new HSSFWorkbook();
+ HSSFSheet s = wb.createSheet();
+ s.createRow(0);
+ HSSFCell c1 = s.getRow(0).createCell((short)0);
+ HSSFCell c2 = s.getRow(0).createCell((short)1);
+ HSSFCell c3 = s.getRow(0).createCell((short)2);
+
+ // As number and string
+ c1.setCellFormula("70164");
+ c2.setCellFormula("\"70164\"");
+ c3.setCellFormula("\"90210\"");
+
+ // Check the formulas
+ assertEquals("70164.0", c1.getCellFormula());
+ assertEquals("\"70164\"", c2.getCellFormula());
+
+ // And check the values - blank
+ assertEquals(0.0, c1.getNumericCellValue(), 0.00001);
+ assertEquals("", c1.getRichStringCellValue().getString());
+ assertEquals(0.0, c2.getNumericCellValue(), 0.00001);
+ assertEquals("", c2.getRichStringCellValue().getString());
+ assertEquals(0.0, c3.getNumericCellValue(), 0.00001);
+ assertEquals("", c3.getRichStringCellValue().getString());
+
+ // Try changing the cached value on one of the string
+ // formula cells, so we can see it updates properly
+ c3.setCellValue(new HSSFRichTextString("test"));
+ assertEquals(0.0, c3.getNumericCellValue(), 0.00001);
+ assertEquals("test", c3.getRichStringCellValue().getString());
+
+
+ // Now evaluate, they should all be changed
+ HSSFFormulaEvaluator eval = new HSSFFormulaEvaluator(s, wb);
+ eval.setCurrentRow(s.getRow(0));
+ eval.evaluateFormulaCell(c1);
+ eval.evaluateFormulaCell(c2);
+ eval.evaluateFormulaCell(c3);
+
+ // Check that the cells now contain
+ // the correct values
+ assertEquals(70164.0, c1.getNumericCellValue(), 0.00001);
+ assertEquals("", c1.getRichStringCellValue().getString());
+ assertEquals(0.0, c2.getNumericCellValue(), 0.00001);
+ assertEquals("70164", c2.getRichStringCellValue().getString());
+ assertEquals(0.0, c3.getNumericCellValue(), 0.00001);
+ assertEquals("90210", c3.getRichStringCellValue().getString());
-
- // Write and read
- HSSFWorkbook nwb = writeOutAndReadBack(wb);
- HSSFSheet ns = nwb.getSheetAt(0);
- HSSFCell nc1 = ns.getRow(0).getCell((short)0);
- HSSFCell nc2 = ns.getRow(0).getCell((short)1);
- HSSFCell nc3 = ns.getRow(0).getCell((short)2);
-
- // Re-check
- assertEquals(70164.0, nc1.getNumericCellValue(), 0.00001);
- assertEquals("", nc1.getRichStringCellValue().getString());
- assertEquals(0.0, nc2.getNumericCellValue(), 0.00001);
- assertEquals("70164", nc2.getRichStringCellValue().getString());
- assertEquals(0.0, nc3.getNumericCellValue(), 0.00001);
- assertEquals("90210", nc3.getRichStringCellValue().getString());
-
- // Now check record level stuff too
- ns.getSheet().setLoc(0);
- int fn = 0;
- CellValueRecordInterface cvr;
- while((cvr = ns.getSheet().getNextValueRecord()) != null) {
- if(cvr instanceof FormulaRecordAggregate) {
- FormulaRecordAggregate fr = (FormulaRecordAggregate)cvr;
-
- if(fn == 0) {
- assertEquals(70164.0, fr.getFormulaRecord().getValue(), 0.0001);
- assertNull(fr.getStringRecord());
- } else if (fn == 1) {
- assertEquals(0.0, fr.getFormulaRecord().getValue(), 0.0001);
- assertNotNull(fr.getStringRecord());
- assertEquals("70164", fr.getStringRecord().getString());
- } else {
- assertEquals(0.0, fr.getFormulaRecord().getValue(), 0.0001);
- assertNotNull(fr.getStringRecord());
- assertEquals("90210", fr.getStringRecord().getString());
- }
-
- fn++;
- }
- }
- assertEquals(3, fn);
+
+ // Write and read
+ HSSFWorkbook nwb = writeOutAndReadBack(wb);
+ HSSFSheet ns = nwb.getSheetAt(0);
+ HSSFCell nc1 = ns.getRow(0).getCell((short)0);
+ HSSFCell nc2 = ns.getRow(0).getCell((short)1);
+ HSSFCell nc3 = ns.getRow(0).getCell((short)2);
+
+ // Re-check
+ assertEquals(70164.0, nc1.getNumericCellValue(), 0.00001);
+ assertEquals("", nc1.getRichStringCellValue().getString());
+ assertEquals(0.0, nc2.getNumericCellValue(), 0.00001);
+ assertEquals("70164", nc2.getRichStringCellValue().getString());
+ assertEquals(0.0, nc3.getNumericCellValue(), 0.00001);
+ assertEquals("90210", nc3.getRichStringCellValue().getString());
+
+ CellValueRecordInterface[] cvrs = ns.getSheet().getValueRecords();
+ for (int i = 0; i < cvrs.length; i++) {
+ CellValueRecordInterface cvr = cvrs[i];
+ if(cvr instanceof FormulaRecordAggregate) {
+ FormulaRecordAggregate fr = (FormulaRecordAggregate)cvr;
+
+ if(i == 0) {
+ assertEquals(70164.0, fr.getFormulaRecord().getValue(), 0.0001);
+ assertNull(fr.getStringRecord());
+ } else if (i == 1) {
+ assertEquals(0.0, fr.getFormulaRecord().getValue(), 0.0001);
+ assertNotNull(fr.getStringRecord());
+ assertEquals("70164", fr.getStringRecord().getString());
+ } else {
+ assertEquals(0.0, fr.getFormulaRecord().getValue(), 0.0001);
+ assertNotNull(fr.getStringRecord());
+ assertEquals("90210", fr.getStringRecord().getString());
+ }
+ }
+ }
+ assertEquals(3, cvrs.length);
}
/**
@@ -1263,8 +1257,8 @@ public final class TestBugs extends TestCase {
assertEquals("{=sin(B1:B9){9,1)[2][0]", c3.getCellFormula());
// Save and re-open, ensure it still works
- HSSFWorkbook nwb = writeOutAndReadBack(wb);
- HSSFSheet ns1 = nwb.getSheetAt(0);
+ HSSFWorkbook nwb = writeOutAndReadBack(wb);
+ HSSFSheet ns1 = nwb.getSheetAt(0);
HSSFCell nc1 = ns1.getRow(0).getCell(2);
HSSFCell nc2 = ns1.getRow(1).getCell(2);
HSSFCell nc3 = ns1.getRow(2).getCell(2);
@@ -1279,48 +1273,48 @@ public final class TestBugs extends TestCase {
* row and cell number
*/
public void test30635() throws Exception {
- HSSFWorkbook wb = new HSSFWorkbook();
- HSSFSheet s = wb.createSheet();
-
- // No rows, everything is 0
- assertEquals(0, s.getFirstRowNum());
- assertEquals(0, s.getLastRowNum());
- assertEquals(0, s.getPhysicalNumberOfRows());
-
- // One row, most things are 0, physical is 1
- s.createRow(0);
- assertEquals(0, s.getFirstRowNum());
- assertEquals(0, s.getLastRowNum());
- assertEquals(1, s.getPhysicalNumberOfRows());
-
- // And another, things change
- s.createRow(4);
- assertEquals(0, s.getFirstRowNum());
- assertEquals(4, s.getLastRowNum());
- assertEquals(2, s.getPhysicalNumberOfRows());
-
-
- // Now start on cells
- HSSFRow r = s.getRow(0);
- assertEquals(-1, r.getFirstCellNum());
- assertEquals(-1, r.getLastCellNum());
- assertEquals(0, r.getPhysicalNumberOfCells());
-
- // Add a cell, things move off -1
- r.createCell((short)0);
- assertEquals(0, r.getFirstCellNum());
- assertEquals(1, r.getLastCellNum()); // last cell # + 1
- assertEquals(1, r.getPhysicalNumberOfCells());
-
- r.createCell((short)1);
- assertEquals(0, r.getFirstCellNum());
- assertEquals(2, r.getLastCellNum()); // last cell # + 1
- assertEquals(2, r.getPhysicalNumberOfCells());
-
- r.createCell((short)4);
- assertEquals(0, r.getFirstCellNum());
- assertEquals(5, r.getLastCellNum()); // last cell # + 1
- assertEquals(3, r.getPhysicalNumberOfCells());
+ HSSFWorkbook wb = new HSSFWorkbook();
+ HSSFSheet s = wb.createSheet();
+
+ // No rows, everything is 0
+ assertEquals(0, s.getFirstRowNum());
+ assertEquals(0, s.getLastRowNum());
+ assertEquals(0, s.getPhysicalNumberOfRows());
+
+ // One row, most things are 0, physical is 1
+ s.createRow(0);
+ assertEquals(0, s.getFirstRowNum());
+ assertEquals(0, s.getLastRowNum());
+ assertEquals(1, s.getPhysicalNumberOfRows());
+
+ // And another, things change
+ s.createRow(4);
+ assertEquals(0, s.getFirstRowNum());
+ assertEquals(4, s.getLastRowNum());
+ assertEquals(2, s.getPhysicalNumberOfRows());
+
+
+ // Now start on cells
+ HSSFRow r = s.getRow(0);
+ assertEquals(-1, r.getFirstCellNum());
+ assertEquals(-1, r.getLastCellNum());
+ assertEquals(0, r.getPhysicalNumberOfCells());
+
+ // Add a cell, things move off -1
+ r.createCell((short)0);
+ assertEquals(0, r.getFirstCellNum());
+ assertEquals(1, r.getLastCellNum()); // last cell # + 1
+ assertEquals(1, r.getPhysicalNumberOfCells());
+
+ r.createCell((short)1);
+ assertEquals(0, r.getFirstCellNum());
+ assertEquals(2, r.getLastCellNum()); // last cell # + 1
+ assertEquals(2, r.getPhysicalNumberOfCells());
+
+ r.createCell((short)4);
+ assertEquals(0, r.getFirstCellNum());
+ assertEquals(5, r.getLastCellNum()); // last cell # + 1
+ assertEquals(3, r.getPhysicalNumberOfCells());
}
/**
@@ -1331,7 +1325,7 @@ public final class TestBugs extends TestCase {
HSSFSheet s;
HSSFRow r;
HSSFCell c;
-
+
// Check the contents of the formulas
// E4 to G9 of sheet 4 make up the table
@@ -1368,18 +1362,18 @@ public final class TestBugs extends TestCase {
* with diagrams on. Don't any more
*/
public void test45414() throws Exception {
- HSSFWorkbook wb = openSample("WithThreeCharts.xls");
- wb.getSheetAt(0).setForceFormulaRecalculation(true);
- wb.getSheetAt(1).setForceFormulaRecalculation(false);
- wb.getSheetAt(2).setForceFormulaRecalculation(true);
-
- // Write out and back in again
- // This used to break
- HSSFWorkbook nwb = writeOutAndReadBack(wb);
-
- // Check now set as it should be
- assertTrue(nwb.getSheetAt(0).getForceFormulaRecalculation());
- assertFalse(nwb.getSheetAt(1).getForceFormulaRecalculation());
- assertTrue(nwb.getSheetAt(2).getForceFormulaRecalculation());
+ HSSFWorkbook wb = openSample("WithThreeCharts.xls");
+ wb.getSheetAt(0).setForceFormulaRecalculation(true);
+ wb.getSheetAt(1).setForceFormulaRecalculation(false);
+ wb.getSheetAt(2).setForceFormulaRecalculation(true);
+
+ // Write out and back in again
+ // This used to break
+ HSSFWorkbook nwb = writeOutAndReadBack(wb);
+
+ // Check now set as it should be
+ assertTrue(nwb.getSheetAt(0).getForceFormulaRecalculation());
+ assertFalse(nwb.getSheetAt(1).getForceFormulaRecalculation());
+ assertTrue(nwb.getSheetAt(2).getForceFormulaRecalculation());
}
}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java b/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java
index 80bab8a445..3fdc1a9dba 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java
@@ -265,14 +265,14 @@ public final class TestFormulas extends TestCase {
HSSFCell c = null;
//get our minimum values
- r = s.createRow((short)0);
- c = r.createCell((short)1);
+ r = s.createRow(0);
+ c = r.createCell(1);
c.setCellFormula("A2" + operator + "A3");
- for (short x = 1; x < Short.MAX_VALUE && x > 0; x=(short)(x*2)) {
- r = s.createRow((short) x);
+ for (int x = 1; x < Short.MAX_VALUE && x > 0; x=(short)(x*2)) {
+ r = s.createRow(x);
- for (short y = 1; y < 256 && y > 0; y++) {
+ for (int y = 1; y < 256 && y > 0; y++) {
String ref=null;
String ref2=null;
@@ -296,13 +296,13 @@ public final class TestFormulas extends TestCase {
refy2=(short)(y-3);
}
- c = r.getCell((short) y);
+ c = r.getCell(y);
CellReference cr= new CellReference(refx1,refy1, false, false);
ref=cr.formatAsString();
cr=new CellReference(refx2,refy2, false, false);
ref2=cr.formatAsString();
- c = r.createCell((short) y);
+ c = r.createCell(y);
c.setCellFormula("" + ref + operator + ref2);
@@ -312,8 +312,8 @@ public final class TestFormulas extends TestCase {
//make sure we do the maximum value of the Int operator
if (s.getLastRowNum() < Short.MAX_VALUE) {
- r = s.createRow((short)0);
- c = r.createCell((short)0);
+ r = s.getRow(0);
+ c = r.createCell(0);
c.setCellFormula("" + "B1" + operator + "IV255");
}
@@ -453,16 +453,16 @@ public final class TestFormulas extends TestCase {
HSSFCell c = null;
//get our minimum values
- r = s.createRow((short)0);
- c = r.createCell((short)1);
+ r = s.createRow(0);
+ c = r.createCell(1);
c.setCellFormula(1 + operator + 1);
- for (short x = 1; x < Short.MAX_VALUE && x > 0; x=(short)(x*2)) {
- r = s.createRow((short) x);
+ for (int x = 1; x < Short.MAX_VALUE && x > 0; x=(short)(x*2)) {
+ r = s.createRow(x);
- for (short y = 1; y < 256 && y > 0; y++) {
+ for (int y = 1; y < 256 && y > 0; y++) {
- c = r.createCell((short) y);
+ c = r.createCell(y);
c.setCellFormula("" + x + operator + y);
}
@@ -470,8 +470,8 @@ public final class TestFormulas extends TestCase {
//make sure we do the maximum value of the Int operator
if (s.getLastRowNum() < Short.MAX_VALUE) {
- r = s.createRow((short)0);
- c = r.createCell((short)0);
+ r = s.getRow(0);
+ c = r.createCell(0);
c.setCellFormula("" + Short.MAX_VALUE + operator + Short.MAX_VALUE);
}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java b/src/testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java
index 3851cab56f..09b93cf870 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java
@@ -30,7 +30,7 @@ import org.apache.poi.hssf.model.Workbook;
import org.apache.poi.hssf.record.BackupRecord;
import org.apache.poi.hssf.record.LabelSSTRecord;
import org.apache.poi.hssf.record.Record;
-import org.apache.poi.hssf.record.aggregates.ValueRecordsAggregate;
+import org.apache.poi.hssf.record.aggregates.RowRecordsAggregate;
import org.apache.poi.hssf.util.CellRangeAddress;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.util.TempFile;
@@ -93,7 +93,7 @@ public final class TestWorkbook extends TestCase {
+ ((( double ) rownum / 1000)
+ (( double ) cellnum / 10000)));
c = r.createCell(( short ) (cellnum + 1));
- c.setCellValue("TEST");
+ c.setCellValue(new HSSFRichTextString("TEST"));
}
}
wb.write(out);
@@ -139,7 +139,7 @@ public final class TestWorkbook extends TestCase {
+ ((( double ) rownum / 1000)
+ (( double ) cellnum / 10000)));
c = r.createCell(( short ) (cellnum + 1));
- c.setCellValue("TEST");
+ c.setCellValue(new HSSFRichTextString("TEST"));
}
}
for (short rownum = ( short ) 0; rownum < 25; rownum++)
@@ -310,9 +310,9 @@ public final class TestWorkbook extends TestCase {
HSSFSheet sheet = workbook.getSheetAt(0);
HSSFCell cell = sheet.getRow(0).getCell(1);
- cell.setCellValue(REPLACED);
+ cell.setCellValue(new HSSFRichTextString(REPLACED));
cell = sheet.getRow(1).getCell(0);
- cell.setCellValue(REPLACED);
+ cell.setCellValue(new HSSFRichTextString(REPLACED));
workbook = HSSFTestDataSamples.writeOutAndReadBack(workbook);
@@ -380,11 +380,11 @@ public final class TestWorkbook extends TestCase {
HSSFSheet sheet = workbook.getSheetAt(0);
HSSFCell cell = sheet.getRow(3).getCell(2);
- cell.setCellValue(LAST_NAME_VALUE);
+ cell.setCellValue(new HSSFRichTextString(LAST_NAME_VALUE));
cell = sheet.getRow(4).getCell(2);
- cell.setCellValue(FIRST_NAME_VALUE);
+ cell.setCellValue(new HSSFRichTextString(FIRST_NAME_VALUE));
cell = sheet.getRow(5).getCell(2);
- cell.setCellValue(SSN_VALUE);
+ cell.setCellValue(new HSSFRichTextString(SSN_VALUE));
workbook = HSSFTestDataSamples.writeOutAndReadBack(workbook);
sheet = workbook.getSheetAt(0);
@@ -494,11 +494,11 @@ public final class TestWorkbook extends TestCase {
cell = row.createCell(( short ) 2);
// workbook.write(new FileOutputStream("/a2.xls"));
- ValueRecordsAggregate valueAggregate =
- ( ValueRecordsAggregate ) sheet.getSheet()
- .findFirstRecordBySid(ValueRecordsAggregate.sid);
+ RowRecordsAggregate rra = (RowRecordsAggregate)
+ sheet.getSheet().findFirstRecordBySid((short)-1000);
+
int sstRecords = 0;
- Iterator iterator = valueAggregate.getIterator();
+ Iterator iterator = rra.getAllRecordsIterator();
while (iterator.hasNext())
{
@@ -511,16 +511,11 @@ public final class TestWorkbook extends TestCase {
}
- public void testManyRows()
- throws Exception
- {
- String testName = "TestManyRows";
- File file = TempFile.createTempFile(testName, ".xls");
- FileOutputStream out = new FileOutputStream(file);
+ public void testManyRows() {
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet();
- HSSFRow row = null;
- HSSFCell cell = null;
+ HSSFRow row;
+ HSSFCell cell;
int i, j;
for ( i = 0, j = 32771; j > 0; i++, j-- )
{
@@ -528,22 +523,17 @@ public final class TestWorkbook extends TestCase {
cell = row.createCell((short) 0);
cell.setCellValue(i);
}
- workbook.write(out);
- out.close();
sanityChecker.checkHSSFWorkbook(workbook);
assertEquals("LAST ROW == 32770", 32770, sheet.getLastRowNum());
+ cell = sheet.getRow(32770).getCell(0);
double lastVal = cell.getNumericCellValue();
- FileInputStream in = new FileInputStream(file);
- POIFSFileSystem fs = new POIFSFileSystem(in);
- HSSFWorkbook wb = new HSSFWorkbook(fs);
+ HSSFWorkbook wb = HSSFTestDataSamples.writeOutAndReadBack(workbook);
HSSFSheet s = wb.getSheetAt(0);
row = s.getRow(32770);
- cell = row.getCell(( short ) 0);
+ cell = row.getCell(0);
assertEquals("Value from last row == 32770", lastVal, cell.getNumericCellValue(), 0);
assertEquals("LAST ROW == 32770", 32770, s.getLastRowNum());
- in.close();
- file.deleteOnExit();
}
/**
@@ -570,10 +560,4 @@ public final class TestWorkbook extends TestCase {
assertTrue("file exists",file.exists());
}
-
-
- public static void main(String [] ignored_args)
- {
- junit.textui.TestRunner.run(TestWorkbook.class);
- }
}