Browse Source

fix bug 40520 of POI

git-svn-id: http://npoi.googlecode.com/svn/trunk@26 3d0cb27c-5942-9f1f-b0c8-b51bd5f61ba7
pull/44/head
tonyqus@gmail.com 14 years ago
parent
commit
5730c27834
  1. 2
      main/HSSF/UserModel/HSSFRichTextString.cs
  2. 39
      testcases/main/HSSF/Model/TestFormulaParser.cs
  3. 59
      testcases/main/HSSF/UserModel/TestHSSFRichTextString.cs

2
main/HSSF/UserModel/HSSFRichTextString.cs

@ -135,7 +135,7 @@ namespace NPOI.HSSF.UserModel
short currentFont = NO_FONT;
if (endIndex != Length)
{
currentFont = this.GetFontAtIndex(startIndex);
currentFont = this.GetFontAtIndex(endIndex);
}
//Need to clear the current formatting between the startIndex and endIndex

39
testcases/main/HSSF/Model/TestFormulaParser.cs

@ -24,6 +24,7 @@ namespace TestCases.HSSF.Model
using NPOI.HSSF.UserModel;
using TestCases.SS.Formula;
using NPOI.SS.UserModel;
using NPOI.SS.Formula;
/**
* Test the low level formula Parser functionality. High level tests are to
@ -829,5 +830,43 @@ namespace TestCases.HSSF.Model
Assert.AreEqual("Parse error near char 10 ';' in specified formula 'round(3.14;2)'. Expected ',' or ')'", e.Message);
}
}
[TestMethod]
public void TestRange_bug46643()
{
String formula = "Sheet1!A1:Sheet1!B3";
HSSFWorkbook wb = new HSSFWorkbook();
wb.CreateSheet("Sheet1");
Ptg[] ptgs = FormulaParser.Parse(formula, HSSFEvaluationWorkbook.Create(wb), FormulaType.CELL, -1);
if (ptgs.Length == 3)
{
ConfirmTokenClasses(ptgs, typeof(Ref3DPtg), typeof(Ref3DPtg), typeof(RangePtg));
throw new AssertFailedException("Identified bug 46643");
}
ConfirmTokenClasses(ptgs,
typeof(MemFuncPtg),
typeof(Ref3DPtg),
typeof(Ref3DPtg),
typeof(RangePtg)
);
MemFuncPtg mf = (MemFuncPtg)ptgs[0];
Assert.AreEqual(15, mf.LenRefSubexpression);
}
/* package */
internal void ConfirmTokenClasses(Ptg[] ptgs, params Type[] expectedClasses)
{
Assert.AreEqual(expectedClasses.Length, ptgs.Length);
for (int i = 0; i < expectedClasses.Length; i++)
{
if (expectedClasses[i] != ptgs[i].GetType())
{
Assert.Fail("difference at token[" + i + "]: expected ("
+ expectedClasses[i].Name + ") but got ("
+ ptgs[i].GetType().Name + ")");
}
}
}
}
}

59
testcases/main/HSSF/UserModel/TestHSSFRichTextString.cs

@ -82,5 +82,64 @@ namespace TestCases.HSSF.UserModel
r.ClearFormatting();
Assert.AreEqual(0, r.NumFormattingRuns);
}
/**
* Test case proposed in Bug 40520: formated twice => will format whole String
*/
[TestMethod]
public void Test40520_1()
{
short font = 3;
HSSFRichTextString r = new HSSFRichTextString("f0_123456789012345678901234567890123456789012345678901234567890");
r.ApplyFont(0, 7, font);
r.ApplyFont(5, 9, font);
for (int i = 0; i < 7; i++) Assert.AreEqual(font, r.GetFontAtIndex(i));
for (int i = 5; i < 9; i++) Assert.AreEqual(font, r.GetFontAtIndex(i));
for (int i = 9; i < r.Length; i++) Assert.AreEqual(HSSFRichTextString.NO_FONT, r.GetFontAtIndex(i));
}
/**
* Test case proposed in Bug 40520: overlapped range => will format whole String
*/
[TestMethod]
public void Test40520_2()
{
short font = 3;
HSSFRichTextString r = new HSSFRichTextString("f0_123456789012345678901234567890123456789012345678901234567890");
r.ApplyFont(0, 2, font);
for (int i = 0; i < 2; i++) Assert.AreEqual(font, r.GetFontAtIndex(i));
for (int i = 2; i < r.Length; i++) Assert.AreEqual(HSSFRichTextString.NO_FONT, r.GetFontAtIndex(i));
r.ApplyFont(0, 2, font);
for (int i = 0; i < 2; i++) Assert.AreEqual(font, r.GetFontAtIndex(i));
for (int i = 2; i < r.Length; i++) Assert.AreEqual(HSSFRichTextString.NO_FONT, r.GetFontAtIndex(i));
}
/**
* Test case proposed in Bug 40520: formated twice => will format whole String
*/
[TestMethod]
public void Test40520_3()
{
short font = 3;
HSSFRichTextString r = new HSSFRichTextString("f0_123456789012345678901234567890123456789012345678901234567890");
// wrong order => will format 0-6
r.ApplyFont(0, 2, font);
r.ApplyFont(5, 7, font);
r.ApplyFont(0, 2, font);
r.ApplyFont(0, 2, font);
for (int i = 0; i < 2; i++) Assert.AreEqual(font, r.GetFontAtIndex(i));
for (int i = 2; i < 5; i++) Assert.AreEqual(HSSFRichTextString.NO_FONT, r.GetFontAtIndex(i));
for (int i = 5; i < 7; i++) Assert.AreEqual(font, r.GetFontAtIndex(i));
for (int i = 7; i < r.Length; i++) Assert.AreEqual(HSSFRichTextString.NO_FONT, r.GetFontAtIndex(i));
}
}
}
Loading…
Cancel
Save