Skip to content

Commit 7d4c941

Browse files
committed
improved unit tests for error values
1 parent a7f039b commit 7d4c941

File tree

6 files changed

+145
-18
lines changed

6 files changed

+145
-18
lines changed

ExcelOpsTest-FreeSpireXls/TestExcelOps-FreeSpireXls.vbproj

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,74 @@
1515
</PropertyGroup>
1616

1717
<ItemGroup>
18+
<None Remove="test_data\ChartSheet01.xlsx" />
19+
<None Remove="test_data\CircularRefs01.xlsx" />
20+
<None Remove="test_data\EmbeddedPicture01.xlsx" />
21+
<None Remove="test_data\EmbeddedPicture02.xlsx" />
22+
<None Remove="test_data\EmbeddedPicture03.xlsx" />
23+
<None Remove="test_data\ExcelBaseDateSystem_mac_1904.xlsx" />
24+
<None Remove="test_data\ExcelBaseDateSystem_mac_1904b.xlsx" />
25+
<None Remove="test_data\ExcelBaseDateSystem_windows_1900.xlsx" />
26+
<None Remove="test_data\ExcelOpsErrorValues.xlsx" />
1827
<None Remove="test_data\ExcelOpsGrund01.xlsx" />
1928
<None Remove="test_data\ExcelOpsGrund02.xlsx" />
29+
<None Remove="test_data\ExcelOpsGrund03.xlsx" />
2030
<None Remove="test_data\ExcelOpsMergedCells.xlsx" />
2131
<None Remove="test_data\ExcelOpsTestCollection.xlsx" />
32+
<None Remove="test_data\HtmlExport01.xlsx" />
33+
<None Remove="test_data\SampleTable01.xlsx" />
2234
<None Remove="test_data\VbaProject.xlsm" />
2335
</ItemGroup>
2436

2537
<ItemGroup>
38+
<Content Include="test_data\ChartSheet01.xlsx">
39+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
40+
</Content>
41+
<Content Include="test_data\CircularRefs01.xlsx">
42+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
43+
</Content>
44+
<Content Include="test_data\EmbeddedPicture01.xlsx">
45+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
46+
</Content>
47+
<Content Include="test_data\EmbeddedPicture02.xlsx">
48+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
49+
</Content>
50+
<Content Include="test_data\EmbeddedPicture03.xlsx">
51+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
52+
</Content>
53+
<Content Include="test_data\ExcelBaseDateSystem_mac_1904.xlsx">
54+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
55+
</Content>
56+
<Content Include="test_data\ExcelBaseDateSystem_mac_1904b.xlsx">
57+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
58+
</Content>
59+
<Content Include="test_data\ExcelBaseDateSystem_windows_1900.xlsx">
60+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
61+
</Content>
62+
<Content Include="test_data\ExcelOpsErrorValues.xlsx">
63+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
64+
</Content>
2665
<Content Include="test_data\ExcelOpsGrund01.xlsx">
2766
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
2867
</Content>
2968
<Content Include="test_data\ExcelOpsGrund02.xlsx">
3069
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
3170
</Content>
71+
<Content Include="test_data\ExcelOpsGrund03.xlsx">
72+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
73+
</Content>
3274
<Content Include="test_data\ExcelOpsMergedCells.xlsx">
3375
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
3476
</Content>
3577
<Content Include="test_data\ExcelOpsTestCollection.xlsx">
3678
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
3779
</Content>
80+
<Content Include="test_data\HtmlExport01.xlsx">
81+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
82+
</Content>
83+
<Content Include="test_data\SampleTable01.xlsx">
84+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
85+
</Content>
3886
<Content Include="test_data\VbaProject.xlsm">
3987
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
4088
</Content>
748 Bytes
Binary file not shown.

ExcelOpsTest-SpireXls/TestExcelOps-SpireXls.vbproj

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,74 @@
1515
</PropertyGroup>
1616

1717
<ItemGroup>
18+
<None Remove="test_data\ChartSheet01.xlsx" />
19+
<None Remove="test_data\CircularRefs01.xlsx" />
20+
<None Remove="test_data\EmbeddedPicture01.xlsx" />
21+
<None Remove="test_data\EmbeddedPicture02.xlsx" />
22+
<None Remove="test_data\EmbeddedPicture03.xlsx" />
23+
<None Remove="test_data\ExcelBaseDateSystem_mac_1904.xlsx" />
24+
<None Remove="test_data\ExcelBaseDateSystem_mac_1904b.xlsx" />
25+
<None Remove="test_data\ExcelBaseDateSystem_windows_1900.xlsx" />
26+
<None Remove="test_data\ExcelOpsErrorValues.xlsx" />
1827
<None Remove="test_data\ExcelOpsGrund01.xlsx" />
1928
<None Remove="test_data\ExcelOpsGrund02.xlsx" />
29+
<None Remove="test_data\ExcelOpsGrund03.xlsx" />
30+
<None Remove="test_data\ExcelOpsMergedCells.xlsx" />
2031
<None Remove="test_data\ExcelOpsTestCollection.xlsx" />
32+
<None Remove="test_data\HtmlExport01.xlsx" />
33+
<None Remove="test_data\SampleTable01.xlsx" />
2134
<None Remove="test_data\VbaProject.xlsm" />
2235
</ItemGroup>
2336

2437
<ItemGroup>
38+
<Content Include="test_data\ChartSheet01.xlsx">
39+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
40+
</Content>
41+
<Content Include="test_data\CircularRefs01.xlsx">
42+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
43+
</Content>
44+
<Content Include="test_data\EmbeddedPicture01.xlsx">
45+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
46+
</Content>
47+
<Content Include="test_data\EmbeddedPicture02.xlsx">
48+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
49+
</Content>
50+
<Content Include="test_data\EmbeddedPicture03.xlsx">
51+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
52+
</Content>
53+
<Content Include="test_data\ExcelBaseDateSystem_mac_1904.xlsx">
54+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
55+
</Content>
56+
<Content Include="test_data\ExcelBaseDateSystem_mac_1904b.xlsx">
57+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
58+
</Content>
59+
<Content Include="test_data\ExcelBaseDateSystem_windows_1900.xlsx">
60+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
61+
</Content>
62+
<Content Include="test_data\ExcelOpsErrorValues.xlsx">
63+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
64+
</Content>
2565
<Content Include="test_data\ExcelOpsGrund01.xlsx">
2666
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
2767
</Content>
2868
<Content Include="test_data\ExcelOpsGrund02.xlsx">
2969
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
3070
</Content>
71+
<Content Include="test_data\ExcelOpsGrund03.xlsx">
72+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
73+
</Content>
74+
<Content Include="test_data\ExcelOpsMergedCells.xlsx">
75+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
76+
</Content>
3177
<Content Include="test_data\ExcelOpsTestCollection.xlsx">
3278
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
3379
</Content>
80+
<Content Include="test_data\HtmlExport01.xlsx">
81+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
82+
</Content>
83+
<Content Include="test_data\SampleTable01.xlsx">
84+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
85+
</Content>
3486
<Content Include="test_data\VbaProject.xlsm">
3587
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
3688
</Content>
748 Bytes
Binary file not shown.

ExcelOpsTest/ExcelOpsTests.Engines/ExcelOpsTestBase.vb

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
Option Strict On
22
Option Explicit On
33

4-
Imports NUnit.Framework
4+
Imports CompuMaster.Epplus4.FormulaParsing.Excel.Functions.Text
55
Imports CompuMaster.Excel.ExcelOps
6+
Imports NUnit.Framework
67
Imports NUnit.Framework.Interfaces
78

89
Namespace ExcelOpsTests.Engines
@@ -1287,7 +1288,7 @@ Namespace ExcelOpsTests.Engines
12871288
#End Region
12881289

12891290
#Region "Excel error values in cells"
1290-
<Test> Public Sub LookupErrorCellValue(<Values("invariant", "de-DE")> cultureName As String)
1291+
<Test> Public Sub LookupErrorCellValue(<Values("invariant", "de-DE", "en-US")> cultureName As String)
12911292
Dim TestControllingToolFileName As String = TestFiles.TestFileExcelOpsErrorValues.FullName
12921293
Dim TestSheet As String = "Tabelle1"
12931294

@@ -1298,28 +1299,37 @@ Namespace ExcelOpsTests.Engines
12981299

12991300
Console.WriteLine(eppeo.SheetContentMatrix(TestSheet, ExcelDataOperationsBase.MatrixContent.Errors).ToUIExcelTable)
13001301
'## Expected matrix like following
1301-
'# |A |B |C |D |E
1302-
'--+-------+------+-----+-----+-------
1303-
'1 |#DIV/0!|#NAME?|#REF!|#NUM!|#VALUE!
1302+
'# |A |B |C |D |E |F
1303+
'--+-------+------+-----+-----+-----+-------
1304+
'1 |#DIV/0!|#NAME?|#REF!|#REF!|#NUM!|#VALUE!
13041305

13051306
Assert.AreEqual("#DIV/0!", eppeo.LookupCellErrorValue(New ExcelOps.ExcelCell(TestSheet, "A1", ExcelOps.ExcelCell.ValueTypes.All)))
13061307
Assert.AreEqual("#NAME?", eppeo.LookupCellErrorValue(New ExcelOps.ExcelCell(TestSheet, "B1", ExcelOps.ExcelCell.ValueTypes.All)))
13071308
Assert.AreEqual("#REF!", eppeo.LookupCellErrorValue(New ExcelOps.ExcelCell(TestSheet, "C1", ExcelOps.ExcelCell.ValueTypes.All)))
1308-
Assert.AreEqual("#VALUE!", eppeo.LookupCellErrorValue(New ExcelOps.ExcelCell(TestSheet, "E1", ExcelOps.ExcelCell.ValueTypes.All)))
1309+
Assert.AreEqual("#REF!", eppeo.LookupCellErrorValue(New ExcelOps.ExcelCell(TestSheet, "D1", ExcelOps.ExcelCell.ValueTypes.All)))
1310+
Assert.AreEqual("#VALUE!", eppeo.LookupCellErrorValue(New ExcelOps.ExcelCell(TestSheet, "F1", ExcelOps.ExcelCell.ValueTypes.All)))
13091311

13101312
'NOTE: Known expected behaviour for #NUM! error value is differently between the several engines
13111313
Select Case eppeo.EngineName
13121314
Case "Spire.Xls", "FreeSpire.Xls" ', "Epplus (Polyform license edition)"
1313-
Assert.AreEqual(Nothing, eppeo.LookupCellErrorValue(New ExcelOps.ExcelCell(TestSheet, "D1", ExcelOps.ExcelCell.ValueTypes.All)))
1315+
Assert.AreEqual(Nothing, eppeo.LookupCellErrorValue(New ExcelOps.ExcelCell(TestSheet, "E1", ExcelOps.ExcelCell.ValueTypes.All)))
13141316
Assert.Ignore(eppeo.EngineName & " is not fully compatible and doesn't show up with #NUM! error value in cell E1 (=10^1000)")
13151317
Case Else
1316-
Assert.AreEqual("#NUM!", eppeo.LookupCellErrorValue(New ExcelOps.ExcelCell(TestSheet, "D1", ExcelOps.ExcelCell.ValueTypes.All)))
1318+
Assert.AreEqual("#NUM!", eppeo.LookupCellErrorValue(New ExcelOps.ExcelCell(TestSheet, "E1", ExcelOps.ExcelCell.ValueTypes.All)))
13171319
End Select
13181320

13191321
End Sub)
13201322
End Sub
13211323

1322-
<Test> Public Sub FindErrorCellsInWorkbook(<Values("invariant", "de-DE")> cultureName As String)
1324+
<Test> Public Sub FindErrorCellsInWorkbook_LookupLastCell()
1325+
Dim TestControllingToolFileName As String = TestFiles.TestFileExcelOpsErrorValues.FullName
1326+
Dim TestSheet As String = "Tabelle1"
1327+
System.Console.WriteLine("Testing XLSX: " & TestControllingToolFileName)
1328+
Dim eppeo As ExcelOps.ExcelDataOperationsBase = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly))
1329+
Assert.AreEqual("F1", eppeo.LookupLastCell(TestSheet).Address)
1330+
End Sub
1331+
1332+
<Test> Public Sub FindErrorCellsInWorkbook(<Values("invariant", "de-DE", "en-US")> cultureName As String)
13231333
Dim TestControllingToolFileName As String = TestFiles.TestFileExcelOpsErrorValues.FullName
13241334
Dim TestSheet As String = "Tabelle1"
13251335

@@ -1328,27 +1338,44 @@ Namespace ExcelOpsTests.Engines
13281338
Sub()
13291339
Dim eppeo As ExcelOps.ExcelDataOperationsBase = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly))
13301340

1341+
Assert.AreEqual("F1", eppeo.LookupLastCell(TestSheet).Address)
13311342
Console.WriteLine(eppeo.SheetContentMatrix(TestSheet, ExcelDataOperationsBase.MatrixContent.Errors).ToUIExcelTable)
13321343
'## Expected matrix like following
1333-
'# |A |B |C |D |E
1334-
'--+-------+------+-----+-----+-------
1335-
'1 |#DIV/0!|#NAME?|#REF!|#NUM!|#VALUE!
1344+
'# |A |B |C |D |E |F
1345+
'--+-------+------+-----+-----+-----+-------
1346+
'1 |#DIV/0!|#NAME?|#REF!|#REF!|#NUM!|#VALUE!
13361347

13371348
Assert.AreEqual(1, eppeo.FindErrorCellsInWorkbook("#DIV/0!").Count)
13381349
Assert.AreEqual(1, eppeo.FindErrorCellsInWorkbook("#NAME?").Count)
1339-
Assert.AreEqual(1, eppeo.FindErrorCellsInWorkbook("#REF!").Count)
13401350
Assert.AreEqual(1, eppeo.FindErrorCellsInWorkbook("#VALUE!").Count)
13411351

13421352
'NOTE: Known expected behaviour for #NUM! error value is differently between the several engines
13431353
Select Case eppeo.EngineName
1344-
Case "Spire.Xls", "FreeSpire.Xls" ', "Epplus (Polyform license edition)"
1345-
Assert.AreEqual(0, eppeo.FindErrorCellsInWorkbook("#NUM!").Count) 'Error detection not working (correctly) in engine
1346-
Assert.AreEqual(4, eppeo.FindErrorCellsInWorkbook().Count)
1347-
Assert.Ignore(eppeo.EngineName & " is not fully compatible and doesn't show up with #NUM! error value in cell E1 (=10^1000)")
1348-
Case Else
1354+
Case "Spire.Xls", "FreeSpire.Xls"
1355+
Assert.AreEqual(Nothing, eppeo.LookupCellErrorValue(TestSheet, 0, 3), "D1 >> #REF") 'Error detection not working (correctly) in engine at D1
1356+
Assert.AreEqual("#NUM!", eppeo.LookupCellErrorValue(TestSheet, 0, 4), "E1 >> #NUM") 'Error detection not working (correctly) in engine at E1
1357+
Assert.AreEqual(1, eppeo.FindErrorCellsInWorkbook("#NUM!").Count)
1358+
Assert.AreEqual(1, eppeo.FindErrorCellsInWorkbook("#REF!").Count) 'Error detection not working (correctly) in engine at D1
1359+
Assert.AreEqual(5, eppeo.FindErrorCellsInWorkbook().Count)
1360+
'Assert.Ignore(eppeo.EngineName & " is not fully compatible and doesn't show up with #NUM! error value in cell E1 (=SQRT(-1) alias =WURZEL(-1))")
1361+
Case "Epplus (Polyform license edition)"
1362+
Assert.AreEqual(Nothing, eppeo.LookupCellErrorValue(TestSheet, 0, 3), "D1 >> #REF") 'Error detection not working (correctly) in engine at D1
13491363
Assert.AreEqual(1, eppeo.FindErrorCellsInWorkbook("#NUM!").Count)
1364+
Assert.AreEqual(1, eppeo.FindErrorCellsInWorkbook("#REF!").Count)
13501365
Assert.AreEqual(5, eppeo.FindErrorCellsInWorkbook().Count)
1366+
'Assert.Ignore(eppeo.EngineName & " is not fully compatible and doesn't show up with #REF! error value in cell D1 (cell reference to a removed sheet (by EPPlus lib, which doesn't update formulas with #REF! on sheet removal)")
1367+
Case Else
1368+
Assert.AreEqual(1, eppeo.FindErrorCellsInWorkbook("#NUM!").Count)
1369+
Assert.AreEqual(2, eppeo.FindErrorCellsInWorkbook("#REF!").Count)
1370+
Assert.AreEqual(6, eppeo.FindErrorCellsInWorkbook().Count)
13511371
End Select
1372+
1373+
If eppeo.CalculationModuleDisabled = False Then
1374+
eppeo.RecalculateAll()
1375+
eppeo.RecalculateCell(TestSheet, 0, 3)
1376+
Console.WriteLine("Values after explicit recalculation")
1377+
Console.WriteLine(eppeo.SheetContentMatrix(TestSheet, ExcelDataOperationsBase.MatrixContent.Errors).ToUIExcelTable)
1378+
End If
13521379
End Sub)
13531380
End Sub
13541381

748 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)