Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 3 additions & 17 deletions testcases/main/POIFS/FileSystem/TestOffice2007XMLException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,25 +102,11 @@ public void TestDetectAsPOIFS()
}
private void ConfirmIsPOIFS(String sampleFileName, bool expectedResult)
{
Stream in1 = OpenSampleStream(sampleFileName);
try
using(Stream fs = OpenSampleStream(sampleFileName))
{
bool actualResult;
try
{
actualResult = POIFSFileSystem.HasPOIFSHeader(in1);
}
catch (IOException ex)
{
throw new RuntimeException(ex);
}
bool actualResult = POIFSFileSystem.HasPOIFSHeader(fs);
ClassicAssert.AreEqual(expectedResult, actualResult);
}
finally
{
in1.Close();
}

}
}
[Test]
public void TestFileCorruption()
Expand Down
126 changes: 63 additions & 63 deletions testcases/main/SS/UserModel/BaseTestWorkbook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -411,71 +411,71 @@ public void TestGetSetActiveSheet()
[Test]
public void TestSetSheetOrder()
{
IWorkbook wb = _testDataProvider.CreateWorkbook();

for (int i = 0; i < 10; i++)
{
wb.CreateSheet("Sheet " + i);
}

// Check the Initial order
ClassicAssert.AreEqual(0, wb.GetSheetIndex("Sheet 0"));
ClassicAssert.AreEqual(1, wb.GetSheetIndex("Sheet 1"));
ClassicAssert.AreEqual(2, wb.GetSheetIndex("Sheet 2"));
ClassicAssert.AreEqual(3, wb.GetSheetIndex("Sheet 3"));
ClassicAssert.AreEqual(4, wb.GetSheetIndex("Sheet 4"));
ClassicAssert.AreEqual(5, wb.GetSheetIndex("Sheet 5"));
ClassicAssert.AreEqual(6, wb.GetSheetIndex("Sheet 6"));
ClassicAssert.AreEqual(7, wb.GetSheetIndex("Sheet 7"));
ClassicAssert.AreEqual(8, wb.GetSheetIndex("Sheet 8"));
ClassicAssert.AreEqual(9, wb.GetSheetIndex("Sheet 9"));

// check active sheet
ClassicAssert.AreEqual(0, wb.ActiveSheetIndex);

// Change
wb.SetSheetOrder("Sheet 6", 0);
ClassicAssert.AreEqual(1, wb.ActiveSheetIndex);
wb.SetSheetOrder("Sheet 3", 7);
wb.SetSheetOrder("Sheet 1", 9);
// now the first sheet is at index 1
ClassicAssert.AreEqual(1, wb.ActiveSheetIndex);

// Check they're currently right
ClassicAssert.AreEqual(0, wb.GetSheetIndex("Sheet 6"));
ClassicAssert.AreEqual(1, wb.GetSheetIndex("Sheet 0"));
ClassicAssert.AreEqual(2, wb.GetSheetIndex("Sheet 2"));
ClassicAssert.AreEqual(3, wb.GetSheetIndex("Sheet 4"));
ClassicAssert.AreEqual(4, wb.GetSheetIndex("Sheet 5"));
ClassicAssert.AreEqual(5, wb.GetSheetIndex("Sheet 7"));
ClassicAssert.AreEqual(6, wb.GetSheetIndex("Sheet 3"));
ClassicAssert.AreEqual(7, wb.GetSheetIndex("Sheet 8"));
ClassicAssert.AreEqual(8, wb.GetSheetIndex("Sheet 9"));
ClassicAssert.AreEqual(9, wb.GetSheetIndex("Sheet 1"));

IWorkbook wbr = _testDataProvider.WriteOutAndReadBack(wb);
wb.Close();

ClassicAssert.AreEqual(0, wbr.GetSheetIndex("Sheet 6"));
ClassicAssert.AreEqual(1, wbr.GetSheetIndex("Sheet 0"));
ClassicAssert.AreEqual(2, wbr.GetSheetIndex("Sheet 2"));
ClassicAssert.AreEqual(3, wbr.GetSheetIndex("Sheet 4"));
ClassicAssert.AreEqual(4, wbr.GetSheetIndex("Sheet 5"));
ClassicAssert.AreEqual(5, wbr.GetSheetIndex("Sheet 7"));
ClassicAssert.AreEqual(6, wbr.GetSheetIndex("Sheet 3"));
ClassicAssert.AreEqual(7, wbr.GetSheetIndex("Sheet 8"));
ClassicAssert.AreEqual(8, wbr.GetSheetIndex("Sheet 9"));
ClassicAssert.AreEqual(9, wbr.GetSheetIndex("Sheet 1"));

ClassicAssert.AreEqual(1, wb.ActiveSheetIndex);

// Now Get the index by the sheet, not the name
for (int i = 0; i < 10; i++)
using(var wb = _testDataProvider.CreateWorkbook())
{
ISheet s = wbr.GetSheetAt(i);
ClassicAssert.AreEqual(i, wbr.GetSheetIndex(s));
for(int i = 0; i < 10; i++)
{
wb.CreateSheet("Sheet " + i);
}

// Check the Initial order
ClassicAssert.AreEqual(0, wb.GetSheetIndex("Sheet 0"));
ClassicAssert.AreEqual(1, wb.GetSheetIndex("Sheet 1"));
ClassicAssert.AreEqual(2, wb.GetSheetIndex("Sheet 2"));
ClassicAssert.AreEqual(3, wb.GetSheetIndex("Sheet 3"));
ClassicAssert.AreEqual(4, wb.GetSheetIndex("Sheet 4"));
ClassicAssert.AreEqual(5, wb.GetSheetIndex("Sheet 5"));
ClassicAssert.AreEqual(6, wb.GetSheetIndex("Sheet 6"));
ClassicAssert.AreEqual(7, wb.GetSheetIndex("Sheet 7"));
ClassicAssert.AreEqual(8, wb.GetSheetIndex("Sheet 8"));
ClassicAssert.AreEqual(9, wb.GetSheetIndex("Sheet 9"));

// check active sheet
ClassicAssert.AreEqual(0, wb.ActiveSheetIndex);

// Change
wb.SetSheetOrder("Sheet 6", 0);
ClassicAssert.AreEqual(1, wb.ActiveSheetIndex);
wb.SetSheetOrder("Sheet 3", 7);
wb.SetSheetOrder("Sheet 1", 9);
// now the first sheet is at index 1
ClassicAssert.AreEqual(1, wb.ActiveSheetIndex);

// Check they're currently right
ClassicAssert.AreEqual(0, wb.GetSheetIndex("Sheet 6"));
ClassicAssert.AreEqual(1, wb.GetSheetIndex("Sheet 0"));
ClassicAssert.AreEqual(2, wb.GetSheetIndex("Sheet 2"));
ClassicAssert.AreEqual(3, wb.GetSheetIndex("Sheet 4"));
ClassicAssert.AreEqual(4, wb.GetSheetIndex("Sheet 5"));
ClassicAssert.AreEqual(5, wb.GetSheetIndex("Sheet 7"));
ClassicAssert.AreEqual(6, wb.GetSheetIndex("Sheet 3"));
ClassicAssert.AreEqual(7, wb.GetSheetIndex("Sheet 8"));
ClassicAssert.AreEqual(8, wb.GetSheetIndex("Sheet 9"));
ClassicAssert.AreEqual(9, wb.GetSheetIndex("Sheet 1"));

using(var wbr = _testDataProvider.WriteOutAndReadBack(wb))
{
ClassicAssert.AreEqual(0, wbr.GetSheetIndex("Sheet 6"));
ClassicAssert.AreEqual(1, wbr.GetSheetIndex("Sheet 0"));
ClassicAssert.AreEqual(2, wbr.GetSheetIndex("Sheet 2"));
ClassicAssert.AreEqual(3, wbr.GetSheetIndex("Sheet 4"));
ClassicAssert.AreEqual(4, wbr.GetSheetIndex("Sheet 5"));
ClassicAssert.AreEqual(5, wbr.GetSheetIndex("Sheet 7"));
ClassicAssert.AreEqual(6, wbr.GetSheetIndex("Sheet 3"));
ClassicAssert.AreEqual(7, wbr.GetSheetIndex("Sheet 8"));
ClassicAssert.AreEqual(8, wbr.GetSheetIndex("Sheet 9"));
ClassicAssert.AreEqual(9, wbr.GetSheetIndex("Sheet 1"));

ClassicAssert.AreEqual(1, wb.ActiveSheetIndex);

// Now Get the index by the sheet, not the name
for(int i = 0; i < 10; i++)
{
ISheet s = wbr.GetSheetAt(i);
ClassicAssert.AreEqual(i, wbr.GetSheetIndex(s));
}
}
}
wbr.Close();
}

[Test]
Expand Down
39 changes: 21 additions & 18 deletions testcases/ooxml/XSSF/Streaming/TestSXSSFCell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace TestCases.XSSF.Streaming
* Tests various functionality having to do with {@link SXSSFCell}. For instance support for
* particular datatypes, etc.
*/
[TestFixture]
[Ignore("This may cause file access denied")]
public class TestSXSSFCell : BaseTestXCell
{

Expand All @@ -55,27 +55,30 @@ public void TestPreserveSpaces() {
"\nPOI",
"\n\nPOI \n",
};
foreach (String str in samplesWithSpaces) {
IWorkbook swb = _testDataProvider.CreateWorkbook();
ICell sCell = swb.CreateSheet().CreateRow(0).CreateCell(0);
sCell.SetCellValue(str);
ClassicAssert.AreEqual(sCell.StringCellValue, str);
foreach (String str in samplesWithSpaces)
{
using(var swb = _testDataProvider.CreateWorkbook())
{
ICell sCell = swb.CreateSheet().CreateRow(0).CreateCell(0);
sCell.SetCellValue(str);
ClassicAssert.AreEqual(sCell.StringCellValue, str);

// read back as XSSF and check that xml:spaces="preserve" is Set
XSSFWorkbook xwb = (XSSFWorkbook)_testDataProvider.WriteOutAndReadBack(swb);
XSSFCell xCell = xwb.GetSheetAt(0).GetRow(0).GetCell(0) as XSSFCell;
// read back as XSSF and check that xml:spaces="preserve" is Set
using(var xwb = (XSSFWorkbook) _testDataProvider.WriteOutAndReadBack(swb))
{
XSSFCell xCell = xwb.GetSheetAt(0).GetRow(0).GetCell(0) as XSSFCell;

CT_Rst is1 = xCell.GetCTCell().@is;
//XmlCursor c = is1.NewCursor();
//c.ToNextToken();
//String t = c.GetAttributeText(new QName("http://www.w3.org/XML/1998/namespace", "space"));
//c.Dispose();
CT_Rst is1 = xCell.GetCTCell().@is;
//XmlCursor c = is1.NewCursor();
//c.ToNextToken();
//String t = c.GetAttributeText(new QName("http://www.w3.org/XML/1998/namespace", "space"));
//c.Dispose();


//write is1 to xml stream writer ,get the xml text and parse it and get space attr.
//ClassicAssert.AreEqual("preserve", t, "expected xml:spaces=\"preserve\" \"" + str + "\"");
xwb.Close();
swb.Close();
//write is1 to xml stream writer ,get the xml text and parse it and get space attr.
//ClassicAssert.AreEqual("preserve", t, "expected xml:spaces=\"preserve\" \"" + str + "\"");
}
}
}
}
}
Expand Down
128 changes: 65 additions & 63 deletions testcases/ooxml/XSSF/Streaming/TestSXSSFWorkbook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,86 +228,88 @@ public void AddToExistingWorkbook()
[Test]
public void SheetdataWriter()
{
SXSSFWorkbook wb = new SXSSFWorkbook();
SXSSFSheet sh = wb.CreateSheet() as SXSSFSheet;
SheetDataWriter wr = sh.SheetDataWriter;
ClassicAssert.IsTrue(wr.GetType() == typeof(SheetDataWriter));
FileInfo tmp = wr.TempFileInfo;
ClassicAssert.IsTrue(tmp.Name.StartsWith("poi-sxssf-sheet"));
ClassicAssert.IsTrue(tmp.Name.EndsWith(".xml"));
ClassicAssert.IsTrue(wb.Dispose());
wb.Close();
using(SXSSFWorkbook wb = new SXSSFWorkbook())
{
SXSSFSheet sh = wb.CreateSheet() as SXSSFSheet;
SheetDataWriter wr = sh.SheetDataWriter;
ClassicAssert.IsTrue(wr.GetType() == typeof(SheetDataWriter));
FileInfo tmp = wr.TempFileInfo;
ClassicAssert.IsTrue(tmp.Name.StartsWith("poi-sxssf-sheet"));
ClassicAssert.IsTrue(tmp.Name.EndsWith(".xml"));
}

wb = new SXSSFWorkbook();
wb.CompressTempFiles = (/*setter*/true);
sh = wb.CreateSheet() as SXSSFSheet;
wr = sh.SheetDataWriter;
ClassicAssert.IsTrue(wr.GetType() == typeof(GZIPSheetDataWriter));
tmp = wr.TempFileInfo;
ClassicAssert.IsTrue(tmp.Name.StartsWith("poi-sxssf-sheet-xml"));
ClassicAssert.IsTrue(tmp.Name.EndsWith(".gz"));
ClassicAssert.IsTrue(wb.Dispose());
wb.Close();
using(var wb2 = new SXSSFWorkbook())
{
wb2.CompressTempFiles = (/*setter*/true);
var sh2 = wb2.CreateSheet() as SXSSFSheet;
var wr2 = sh2.SheetDataWriter;
ClassicAssert.IsTrue(wr2.GetType() == typeof(GZIPSheetDataWriter));
var tmp2 = wr2.TempFileInfo;
ClassicAssert.IsTrue(tmp2.Name.StartsWith("poi-sxssf-sheet-xml"));
ClassicAssert.IsTrue(tmp2.Name.EndsWith(".gz"));
}

//Test escaping of Unicode control characters
wb = new SXSSFWorkbook();
wb.CreateSheet("S1").CreateRow(0).CreateCell(0).SetCellValue("value\u0019");
XSSFWorkbook xssfWorkbook = SXSSFITestDataProvider.instance.WriteOutAndReadBack(wb) as XSSFWorkbook;
ICell cell = xssfWorkbook.GetSheet("S1").GetRow(0).GetCell(0);
ClassicAssert.AreEqual("value?", cell.StringCellValue);

ClassicAssert.IsTrue(wb.Dispose());
wb.Close();
xssfWorkbook.Close();
using(var wb3 = new SXSSFWorkbook())
{
wb3.CreateSheet("S1").CreateRow(0).CreateCell(0).SetCellValue("value\u0019");
using(var xssfWorkbook = SXSSFITestDataProvider.instance.WriteOutAndReadBack(wb3) as XSSFWorkbook)
{
ICell cell = xssfWorkbook.GetSheet("S1").GetRow(0).GetCell(0);
ClassicAssert.AreEqual("value?", cell.StringCellValue);
}
}
;
}

[Test]
public void GzipSheetdataWriter()
{
SXSSFWorkbook wb = new SXSSFWorkbook();
wb.CompressTempFiles = true;
int rowNum = 1000;
int sheetNum = 5;
for(int i = 0; i < sheetNum; i++)
using(var wb = new SXSSFWorkbook())
{
ISheet sh = wb.CreateSheet("sheet" + i);
for(int j = 0; j < rowNum; j++)
wb.CompressTempFiles = true;
int rowNum = 1000;
int sheetNum = 5;
for(int i = 0; i < sheetNum; i++)
{
IRow row = sh.CreateRow(j);
ICell cell1 = row.CreateCell(0);
cell1.SetCellValue(new CellReference(cell1).FormatAsString());
ISheet sh = wb.CreateSheet("sheet" + i);
for(int j = 0; j < rowNum; j++)
{
IRow row = sh.CreateRow(j);
ICell cell1 = row.CreateCell(0);
cell1.SetCellValue(new CellReference(cell1).FormatAsString());

ICell cell2 = row.CreateCell(1);
cell2.SetCellValue(i);
ICell cell2 = row.CreateCell(1);
cell2.SetCellValue(i);

ICell cell3 = row.CreateCell(2);
cell3.SetCellValue(j);
ICell cell3 = row.CreateCell(2);
cell3.SetCellValue(j);
}
}
}

XSSFWorkbook xwb = SXSSFITestDataProvider.instance.WriteOutAndReadBack(wb) as XSSFWorkbook;
for(int i = 0; i < sheetNum; i++)
{
ISheet sh = xwb.GetSheetAt(i);
ClassicAssert.AreEqual("sheet" + i, sh.SheetName);
for(int j = 0; j < rowNum; j++)
{
IRow row = sh.GetRow(j);
ClassicAssert.IsNotNull(row, "row[" + j + "]");
ICell cell1 = row.GetCell(0);
ClassicAssert.AreEqual(new CellReference(cell1).FormatAsString(), cell1.StringCellValue);

ICell cell2 = row.GetCell(1);
ClassicAssert.AreEqual(i, (int) cell2.NumericCellValue);

ICell cell3 = row.GetCell(2);
ClassicAssert.AreEqual(j, (int) cell3.NumericCellValue);
using(XSSFWorkbook xwb = SXSSFITestDataProvider.instance.WriteOutAndReadBack(wb) as XSSFWorkbook)
{
for(int i = 0; i < sheetNum; i++)
{
ISheet sh = xwb.GetSheetAt(i);
ClassicAssert.AreEqual("sheet" + i, sh.SheetName);
for(int j = 0; j < rowNum; j++)
{
IRow row = sh.GetRow(j);
ClassicAssert.IsNotNull(row, "row[" + j + "]");
ICell cell1 = row.GetCell(0);
ClassicAssert.AreEqual(new CellReference(cell1).FormatAsString(), cell1.StringCellValue);

ICell cell2 = row.GetCell(1);
ClassicAssert.AreEqual(i, (int) cell2.NumericCellValue);

ICell cell3 = row.GetCell(2);
ClassicAssert.AreEqual(j, (int) cell3.NumericCellValue);
}
}
}
}

ClassicAssert.IsTrue(wb.Dispose());
xwb.Close();
wb.Close();
}

protected static void assertWorkbookDispose(SXSSFWorkbook wb)
Expand Down
Loading