Skip to content

Commit b6e1d62

Browse files
authored
Merge pull request #1624 from antony-liu/master
Fix test cases TestAllNumberToText and TestReadWriteTokenValueBytes
2 parents cb78fb3 + 2c3515c commit b6e1d62

File tree

7 files changed

+300
-219
lines changed

7 files changed

+300
-219
lines changed

main/SS/Formula/OperationEvaluationContext.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -393,17 +393,17 @@ public ValueEval GetArea3DEval(Area3DPxg aptg)
393393
aptg.LastRow, aptg.LastColumn, sre);
394394
}
395395
public ValueEval GetAreaValueEval(int firstRowIndex, int firstColumnIndex,
396-
int lastRowIndex, int lastColumnIndex, Object[,] tokens)
396+
int lastRowIndex, int lastColumnIndex, Object[][] tokens)
397397
{
398398

399-
ValueEval[] values = new ValueEval[tokens.GetLength(0) * tokens.GetLength(1)];
399+
ValueEval[] values = new ValueEval[tokens.Length * tokens[0].Length];
400400

401401
int index = 0;
402-
for (int jdx = 0; jdx < tokens.GetLength(0); jdx++)
402+
for (int jdx = 0; jdx < tokens.Length; jdx++)
403403
{
404-
for (int idx = 0; idx < tokens.GetLength(1); idx++)
404+
for (int idx = 0; idx < tokens[0].Length; idx++)
405405
{
406-
values[index++] = ConvertObjectEval(tokens[jdx,idx]);
406+
values[index++] = ConvertObjectEval(tokens[jdx][idx]);
407407
}
408408
}
409409

main/SS/Formula/PTG/ArrayPtg.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,18 +96,20 @@ public ArrayPtg(Object[][] values2d)
9696
_reserved1Short = 0;
9797
_reserved2Byte = 0;
9898
}
99-
public Object[,] GetTokenArrayValues()
99+
public Object[][] GetTokenArrayValues()
100100
{
101101
if (_arrayValues == null)
102102
{
103103
throw new InvalidOperationException("array values not read yet");
104104
}
105-
Object[,] result = new Object[_nRows,_nColumns];
105+
Object[][] result = new Object[_nRows][];
106106
for (int r = 0; r < _nRows; r++)
107107
{
108+
result[r] = new object[_nColumns];
109+
object[] rowData = result[r];
108110
for (int c = 0; c < _nColumns; c++)
109111
{
110-
result[r,c] = _arrayValues[GetValueIndex(c, r)];
112+
rowData[c] = _arrayValues[GetValueIndex(c, r)];
111113
}
112114
}
113115
return result;

testcases/main/HSSF/Model/TestFormulaParser.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,17 +1239,17 @@ public void TestParseArray()
12391239
ClassicAssert.AreEqual("{1,2,2,#REF!;FALSE,3,3,2}", ptgs[0].ToFormulaString());
12401240

12411241
ArrayPtg aptg = (ArrayPtg)ptgs[0];
1242-
Object[,] values = aptg.GetTokenArrayValues();
1243-
ClassicAssert.AreEqual(ErrorConstant.ValueOf(FormulaError.REF.Code), values[0, 3]);
1244-
ClassicAssert.AreEqual(false, values[1, 0]);
1242+
Object[][] values = aptg.GetTokenArrayValues();
1243+
ClassicAssert.AreEqual(ErrorConstant.ValueOf(FormulaError.REF.Code), values[0][3]);
1244+
ClassicAssert.AreEqual(false, values[1][0]);
12451245
}
12461246
[Test]
12471247
public void TestParseStringElementInArray()
12481248
{
12491249
Ptg[] ptgs;
12501250
ptgs = ParseFormula("MAX({\"5\"},3)");
12511251
ConfirmTokenClasses(ptgs, typeof(ArrayPtg), typeof(IntPtg), typeof(FuncVarPtg));
1252-
object element = ((ArrayPtg)ptgs[0]).GetTokenArrayValues()[0, 0];
1252+
object element = ((ArrayPtg)ptgs[0]).GetTokenArrayValues()[0][0];
12531253
if (element is UnicodeString)
12541254
{
12551255
// this would cause ClassCastException below
@@ -1290,14 +1290,14 @@ public void TestParseArrayNegativeElement()
12901290
throw e;
12911291
}
12921292
ConfirmTokenClasses(ptgs, typeof(ArrayPtg));
1293-
Object element = ((ArrayPtg)ptgs[0]).GetTokenArrayValues()[0, 0];
1293+
Object element = ((ArrayPtg)ptgs[0]).GetTokenArrayValues()[0][0];
12941294

12951295
ClassicAssert.AreEqual(-42.0, (Double)element, 0.0);
12961296

12971297
// Should be able to handle whitespace between unary minus and digits (Excel
12981298
// accepts this formula after presenting the user with a Confirmation dialog).
12991299
ptgs = ParseFormula("{- 5}");
1300-
element = ((ArrayPtg)ptgs[0]).GetTokenArrayValues()[0, 0];
1300+
element = ((ArrayPtg)ptgs[0]).GetTokenArrayValues()[0][0];
13011301
ClassicAssert.AreEqual(-5.0, (Double)element, 0.0);
13021302
}
13031303
[Test]

testcases/main/HSSF/Record/TestNameRecord.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -698,9 +698,9 @@ private void assert_bug50244(NameRecord nr)
698698
ArrayPtg arr = (ArrayPtg)ptg[0];
699699
ClassicAssert.AreEqual(696, arr.RowCount);
700700
ClassicAssert.AreEqual(1, arr.ColumnCount);
701-
Object[,] vals = arr.GetTokenArrayValues();
702-
ClassicAssert.AreEqual("1.T20.001", vals[0,0]);
703-
ClassicAssert.AreEqual("1.T20.010", vals[vals.Length - 1,0]);
701+
Object[][] vals = arr.GetTokenArrayValues();
702+
ClassicAssert.AreEqual("1.T20.001", vals[0][0]);
703+
ClassicAssert.AreEqual("1.T20.010", vals[vals.Length - 1][0]);
704704
}
705705
[Test]
706706
public void TestBug57923()

testcases/main/SS/Formula/PTG/TestArrayPtg.cs

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,19 @@ public class TestArrayPtg
3535
{
3636

3737
private static byte[] ENCODED_PTG_DATA = {
38-
0x40,
39-
0, 0, 0, 0, 0, 0, 0,
40-
};
38+
0x40,
39+
0, 0, 0, 0, 0, 0, 0,
40+
};
4141
private static byte[] ENCODED_CONSTANT_DATA = {
42-
2, // 3 columns
43-
1, 0, // 2 rows
44-
4, 1, 0, 0, 0, 0, 0, 0, 0, // TRUE
45-
2, 4, 0, 0, 65, 66, 67, 68, // "ABCD"
46-
2, 1, 0, 0, 69, // "E"
47-
1, 0, 0, 0, 0, 0, 0, 0, 0, // 0
48-
4, 0, 0, 0, 0, 0, 0, 0, 0, // FALSE
49-
2, 2, 0, 0, 70, 71, // "FG"
50-
};
42+
2, // 3 columns
43+
1, 0, // 2 rows
44+
4, 1, 0, 0, 0, 0, 0, 0, 0, // TRUE
45+
2, 4, 0, 0, 65, 66, 67, 68, // "ABCD"
46+
2, 1, 0, 0, 69, // "E"
47+
1, 0, 0, 0, 0, 0, 0, 0, 0, // 0
48+
4, 0, 0, 0, 0, 0, 0, 0, 0, // FALSE
49+
2, 2, 0, 0, 70, 71, // "FG"
50+
};
5151

5252
private static ArrayPtg Create(byte[] initialData, byte[] constantData)
5353
{
@@ -59,21 +59,20 @@ private static ArrayPtg Create(byte[] initialData, byte[] constantData)
5959
* Lots of problems with ArrayPtg's decoding and encoding of the element value data
6060
*/
6161
[Test]
62-
[Ignore("TODO FIX CI TESTS")]
6362
public void TestReadWriteTokenValueBytes()
6463
{
6564
ArrayPtg ptg = Create(ENCODED_PTG_DATA, ENCODED_CONSTANT_DATA);
6665
ClassicAssert.AreEqual(3, ptg.ColumnCount);
6766
ClassicAssert.AreEqual(2, ptg.RowCount);
68-
Object[,] values = ptg.GetTokenArrayValues();
67+
Object[][] values = ptg.GetTokenArrayValues();
6968
ClassicAssert.AreEqual(2, values.Length);
7069

7170

72-
ClassicAssert.AreEqual(true, values[0,0]);
73-
ClassicAssert.AreEqual("ABCD", values[0,1]);
74-
ClassicAssert.AreEqual(0d, values[1,0]);
75-
ClassicAssert.AreEqual(false, values[1,1]);
76-
ClassicAssert.AreEqual("FG", values[1,2]);
71+
ClassicAssert.AreEqual(true, values[0][0]);
72+
ClassicAssert.AreEqual("ABCD", values[0][1]);
73+
ClassicAssert.AreEqual(0d, values[1][0]);
74+
ClassicAssert.AreEqual(false, values[1][1]);
75+
ClassicAssert.AreEqual("FG", values[1][2]);
7776

7877
byte[] outBuf = new byte[ENCODED_CONSTANT_DATA.Length];
7978
ptg.WriteTokenValueBytes(new LittleEndianByteArrayOutputStream(outBuf, 0));

0 commit comments

Comments
 (0)