Skip to content

Commit

Permalink
Merge pull request #1488 from antony-liu/master
Browse files Browse the repository at this point in the history
Add test case for issue #1057
  • Loading branch information
tonyqus authored Feb 13, 2025
2 parents 5126e0d + ad57b0e commit af9bd4f
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 2 deletions.
10 changes: 8 additions & 2 deletions testcases/main/HSSF/UserModel/TestHSSFFormulaEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ public void TestEvaluateSimple()
}

/**
* Test for bug due to attempt to convert a cached formula error result to a boolean
*/
* Test for bug due to attempt to convert a cached formula error result to a boolean
*/
[Test]
public override void TestUpdateCachedFormulaResultFromErrorToNumber_bug46479()
{
Expand Down Expand Up @@ -355,5 +355,11 @@ public void TestSharedFormulas()
{
BaseTestSharedFormulas("shared_formulas.xls");
}

[Test]
public void TestNPOIIssue_1057()
{
BaseTestNPOIIssue_1057("hparams.xls", "hinstall.xls");
}
}
}
30 changes: 30 additions & 0 deletions testcases/main/SS/UserModel/BaseTestFormulaEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace TestCases.SS.UserModel
using NPOI.SS.UserModel;
using NUnit.Framework;
using System;
using System.Collections.Generic;

/**
* Common superclass for Testing implementatiosn of{@link FormulaEvaluator}
Expand Down Expand Up @@ -352,5 +353,34 @@ public void EvaluateInCellReturnsSameCell()
Assert.AreSame(cell, same);
wb.Close();
}

public void BaseTestNPOIIssue_1057(string paramsFile, string installFile)
{
DataFormatter formatter = new DataFormatter();
var paramswb = _testDataProvider.OpenSampleWorkbook(paramsFile);
var installwb = _testDataProvider.OpenSampleWorkbook(installFile);

var paramsevaluator = paramswb.GetCreationHelper().CreateFormulaEvaluator();
var installevaluator = installwb.GetCreationHelper().CreateFormulaEvaluator();

var refs = new Dictionary<string, IFormulaEvaluator>();
refs.Add(paramsFile, paramsevaluator);
refs.Add(installFile, installevaluator);
installevaluator.SetupReferencedWorkbooks(refs);

var suffix = installFile[0].ToString().ToUpper();
var sheet = installwb.GetSheetAt(0);
var row = sheet.GetRow(0);
var cell = row.GetCell(1);


String cellValue = formatter.FormatCellValue(cell, installevaluator);
Assert.AreEqual("Referenced value in sheet 1" + suffix, cellValue);

row = sheet.GetRow(1);
cell = row.GetCell(1);
cellValue = formatter.FormatCellValue(cell, installevaluator);
Assert.AreEqual("Referenced value in sheet 2" + suffix, cellValue);
}
}
}
6 changes: 6 additions & 0 deletions testcases/ooxml/XSSF/UserModel/TestXSSFFormulaEvaluation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,12 @@ public void EvaluateInCellReturnsSameDataType()
Assert.AreSame(cell, same);
wb.Close();
}

[Test]
public void TestNPOIIssue_1057()
{
BaseTestNPOIIssue_1057("xparams.xlsx", "xinstall.xlsx");
}
}

}
Binary file added testcases/test-data/spreadsheet/hinstall.xls
Binary file not shown.
Binary file added testcases/test-data/spreadsheet/hparams.xls
Binary file not shown.
Binary file added testcases/test-data/spreadsheet/xinstall.xlsx
Binary file not shown.
Binary file added testcases/test-data/spreadsheet/xparams.xlsx
Binary file not shown.

0 comments on commit af9bd4f

Please # to comment.