public void TestThreePartComplexFormat1() { Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US"); // verify a rather complex format found e.g. in http://wahl.land-oberoesterreich.gv.at/Downloads/bp10.xls CellFormatPart posPart = new CellFormatPart("[$-F400]h:mm:ss\\ AM/PM"); Assert.IsNotNull(posPart); DateTime baseTime = new DateTime(1970, 1, 1, 0, 0, 0); double exceldata = DateUtil.GetExcelDate(baseTime.AddMilliseconds(12345)); //format part 'h', means hour, using a 12-hour clock from 1 to 12.(in excel and .net framework) //so the excepted value should be 12:00:12 AM Assert.AreEqual("12:00:12 AM", posPart.Apply(baseTime.AddMilliseconds(12345)).Text); CellFormatPart negPart = new CellFormatPart("[$-F40]h:mm:ss\\ AM/PM"); Assert.IsNotNull(negPart); Assert.AreEqual("12:00:12 AM", posPart.Apply(baseTime.AddMilliseconds(12345)).Text); //Assert.IsNotNull(new CellFormatPart("_-* \"\"??_-;_-@_-")); CellFormat instance = CellFormat.GetInstance("[$-F400]h:mm:ss\\ AM/PM;[$-F40]h:mm:ss\\ AM/PM;_-* \"\"??_-;_-@_-"); Assert.IsNotNull(instance); Assert.AreEqual("12:00:12 AM", instance.Apply(baseTime.AddMilliseconds(12345)).Text); }
private String tryColor(String desc, String cname, CellValue getter, Object value, String expectedText, Color expectedColor) { if (cname != null) { desc = "[" + cname + "]" + desc; } Color origColor = labelForeColor; CellFormatPart format = new CellFormatPart(desc); CellFormatResult result = format.Apply(value); if (!result.Applies) { // If this doesn't Apply, no color change is expected expectedColor = origColor; } String actualText = result.Text; Color actualColor = labelForeColor; getter.Equivalent(expectedText, actualText, format); Assert.AreEqual( expectedColor, actualColor, cname == null ? "no color" : "color " + cname); return(actualText); }
public override void Equivalent(String expected, String actual, CellFormatPart format) { double expectedVal = ExtractNumber(expected); double actualVal = ExtractNumber(actual); // equal within 1% double delta = expectedVal / 100; Assert.AreEqual(expectedVal, actualVal, delta, "format \"" + format + "\"," + expected + " ~= " + actual); }
public void TestThreePartComplexFormat2() { Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US"); // verify a rather complex format found e.g. in http://wahl.land-oberoesterreich.gv.at/Downloads/bp10.xls CellFormatPart posPart = new CellFormatPart("dd/mm/yyyy"); Assert.IsNotNull(posPart); DateTime baseTime = new DateTime(1970, 1, 1); Assert.AreEqual("01/01/1970", posPart.Apply(baseTime.AddMilliseconds(12345)).Text); CellFormatPart negPart = new CellFormatPart("dd/mm/yyyy"); Assert.IsNotNull(negPart); Assert.AreEqual("01/01/1970", posPart.Apply(baseTime.AddMilliseconds(12345)).Text); //Assert.IsNotNull(new CellFormatPart("_-* \"\"??_-;_-@_-")); CellFormat instance = CellFormat.GetInstance("dd/mm/yyyy;dd/mm/yyyy;_-* \"\"??_-;_-@_-"); Assert.IsNotNull(instance); Assert.AreEqual("01/01/1970", instance.Apply(baseTime.AddMilliseconds(12345)).Text); }
/** * Creates a new object. * * @param format The format. */ private CellFormat(String format) { this.format = format; MatchCollection mc = ONE_PART.Matches(format); List<CellFormatPart> parts = new List<CellFormatPart>(); //while (m.Success) foreach (Match m in mc) { try { String valueDesc = m.Groups[0].Value; // Strip out the semicolon if it's there if (valueDesc.EndsWith(";")) valueDesc = valueDesc.Substring(0, valueDesc.Length - 1); parts.Add(new CellFormatPart(valueDesc)); } catch (Exception) { //CellFormatter.logger.Log(Level.WARNING, // "Invalid format: " + CellFormatter.Quote(m.Group()), e); parts.Add(null); } } formatPartCount = parts.Count; switch (formatPartCount) { case 1: posNumFmt = parts[(0)]; negNumFmt = null; zeroNumFmt = null; textFmt = DEFAULT_TEXT_FORMAT; break; case 2: posNumFmt = parts[0]; negNumFmt = parts[1]; zeroNumFmt = null; textFmt = DEFAULT_TEXT_FORMAT; break; case 3: posNumFmt = parts[0]; negNumFmt = parts[1]; zeroNumFmt = parts[2]; textFmt = DEFAULT_TEXT_FORMAT; break; case 4: default: posNumFmt = parts[0]; negNumFmt = parts[1]; zeroNumFmt = parts[2]; textFmt = parts[3]; break; } }
public virtual void Equivalent(String expected, String actual, CellFormatPart format) { Assert.AreEqual('"' + expected + '"', '"' + actual + '"', "format \"" + format.ToString() + "\""); }
private String tryColor(String desc, String cname, CellValue Getter, Object value, String expectedText, Color expectedColor) { if (cname != null) desc = "[" + cname + "]" + desc; Color origColor = label.ForeColor; CellFormatPart format = new CellFormatPart(desc); if (!format.Apply(label, value).Applies) { // If this doesn't Apply, no color change is expected expectedColor = origColor; } String actualText = label.Text; Color actualColor = label.ForeColor; Getter.Equivalent(expectedText, actualText, format); Assert.AreEqual( expectedColor, actualColor,cname == null ? "no color" : "color " + cname); return actualText; }