Browse Source

IntegrationTests

reports
Peter Forstmeier 13 years ago
parent
commit
59b769e2ac
  1. 2
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/ICSharpCode.Reporting.csproj
  2. 18
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Exporter/Visitors/ExpressionVisitor.cs
  3. 24
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/ExpressionHelper.cs
  4. 104
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/ExpressionRunner.cs
  5. 139
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Globals/StringHelper.cs
  6. 2
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/ExportColumns/ExportColumn.cs
  7. 1
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/ICSharpCode.Reporting.Test.csproj
  8. 99
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/IntegrationTests.cs
  9. 2
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/TestReports/FromList.srd
  10. 2
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/TestReports/ReportWithTwoItems.srd

2
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/ICSharpCode.Reporting.csproj

@ -107,11 +107,13 @@ @@ -107,11 +107,13 @@
<Compile Include="Src\Exporter\Visitors\DebugVisitor.cs" />
<Compile Include="Src\Exporter\Visitors\WpfVisitor.cs" />
<Compile Include="Src\ExportRenderer\FixedDocumentCreator.cs" />
<Compile Include="Src\Expressions\ExpressionHelper.cs" />
<Compile Include="Src\Expressions\ExpressionRunner.cs" />
<Compile Include="Src\Factories\ExportColumnFactory.cs" />
<Compile Include="Src\Factories\ReportCreatorFactory.cs" />
<Compile Include="Src\Globals\CreateGraphics.cs" />
<Compile Include="Src\Globals\MeasurementService.cs" />
<Compile Include="Src\Globals\StringHelper.cs" />
<Compile Include="Src\Interfaces\Data\IDataViewHandling.cs" />
<Compile Include="Src\Interfaces\Export\IExportColumn.cs" />
<Compile Include="Src\Interfaces\Export\IExportContainer.cs" />

18
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Exporter/Visitors/ExpressionVisitor.cs

@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.ObjectModel;
using ICSharpCode.Reporting.Expressions;
using ICSharpCode.Reporting.PageBuilder.ExportColumns;
using Irony.Interpreter.Evaluator;
@ -23,6 +24,11 @@ namespace ICSharpCode.Reporting.Exporter.Visitors @@ -23,6 +24,11 @@ namespace ICSharpCode.Reporting.Exporter.Visitors
evaluator = new ExpressionEvaluator(grammar);
}
internal ExpressionVisitor() {
grammar = new ExpressionEvaluatorGrammar();
evaluator = new ExpressionEvaluator(grammar);
}
public override void Visit(ExportPage page)
{
var result = evaluator.Evaluate("5 * 10");
@ -49,8 +55,16 @@ namespace ICSharpCode.Reporting.Exporter.Visitors @@ -49,8 +55,16 @@ namespace ICSharpCode.Reporting.Exporter.Visitors
public override void Visit(ExportText exportColumn)
{
var result = evaluator.Evaluate("2 + 3");
Console.WriteLine("\t\tExpressionVisitor <{0}> - {1}",exportColumn.Name,result);
if (exportColumn.Text.StartsWith("=")) {
try {
var str = ExpressionHelper.ExtractExpressionPart(exportColumn.Text);
var result = evaluator.Evaluate(str);
exportColumn.Text = result.ToString();
} catch (Exception) {
throw;
}
}
}
}
}

24
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/ExpressionHelper.cs

@ -0,0 +1,24 @@ @@ -0,0 +1,24 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Globalization;
using ICSharpCode.Reporting.Globals;
namespace ICSharpCode.Reporting.Expressions
{
/// <summary>
/// Description of ExpressionHelper.
/// </summary>
class ExpressionHelper
{
public ExpressionHelper()
{
}
public static string ExtractExpressionPart (string src)
{
char v = Convert.ToChar("=",CultureInfo.CurrentCulture );
return StringHelper.RightOf(src,v).Trim();
}
}
}

104
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/ExpressionRunner.cs

@ -32,113 +32,9 @@ namespace ICSharpCode.Reporting.Expressions @@ -32,113 +32,9 @@ namespace ICSharpCode.Reporting.Expressions
foreach (var page in Pages) {
var acceptor = page as IAcceptor;
acceptor.Accept(visitor);
// RunInternal(page);
}
Console.WriteLine("Finish ExpressionVisitor");
Console.WriteLine();
}
// "Visitor"
// http://irony.codeplex.com/discussions/213938
//
// http://irony.codeplex.com/discussions/35310
/*
void RunInternal(IExportContainer container)
{
// Console.WriteLine();
// Console.WriteLine("{0}{1}",leading,container.Name);
foreach (var item in container.ExportedItems) {
var exportContainer = item as IExportContainer;
var acceptor = item as IAcceptor;
if (exportContainer != null) {
if (exportContainer.ExportedItems.Count > 0) {
// acceptor.Accept(visitor);
bRunInternal(exportContainer.ExportedItems);
acceptor.Accept(visitor);
// ShowDebug(leading = leading + "--",exportContainer);
}
}
// acceptor.Accept(visitor);
}
}
*/
/*
void bRunInternal(List<IExportColumn> list)
{
// Console.WriteLine();
// Console.WriteLine("{0}{1}",leading,container.Name);
foreach (var item in list) {
var exportContainer = item as IExportContainer;
var acceptor = item as IAcceptor;
if (exportContainer != null) {
if (exportContainer.ExportedItems.Count > 0) {
acceptor.Accept(visitor);
RunInternal(exportContainer);
// ShowDebug(leading = leading + "--",exportContainer);
}
}
acceptor.Accept(visitor);
}
}
*/
/*
void bRunInternal(IExportContainer container)
{
// Console.WriteLine();
// Console.WriteLine("{0}{1}",leading,container.Name);
foreach (var item in container.ExportedItems) {
var exportContainer = item as IExportContainer;
var acceptor = item as IAcceptor;
if (exportContainer != null) {
if (exportContainer.ExportedItems.Count > 0) {
acceptor.Accept(visitor);
RunInternal(exportContainer);
// ShowDebug(leading = leading + "--",exportContainer);
}
}
acceptor.Accept(visitor);
}
}
*/
/*
//Items first, then container
void aRunInternal(IExportContainer container)
{
// Console.WriteLine();
// Console.WriteLine("{0}{1}",leading,container.Name);
foreach (var item in container.ExportedItems) {
var exportContainer = item as IExportContainer;
var acceptor = item as IAcceptor;
if (exportContainer != null) {
if (exportContainer.ExportedItems.Count > 0) {
RunInternal(exportContainer);
acceptor.Accept(visitor);
// ShowDebug(leading = leading + "--",exportContainer);
}
}
acceptor.Accept(visitor);
}
}
*/
/*
void InternalRun(ExportPage page)
{
page.Accept(visitor);
foreach (var item in page.ExportedItems) {
// ShowContainerRecursive(null,item);
var acceptor = item as IAcceptor;
acceptor.Accept(visitor);
}
}
*/
}
}

139
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Globals/StringHelper.cs

@ -0,0 +1,139 @@ @@ -0,0 +1,139 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
namespace ICSharpCode.Reporting.Globals
{
/// <summary>
/// Description of StringHelper.
/// </summary>
class StringHelper
{
/// <summary>
/// Left of the first occurance of c
/// </summary>
/// <param name="src"></param>
/// <param name="c"></param>
/// <returns></returns>
public static string LeftOf(string src, char c)
{
int idx=src.IndexOf(c);
if (idx==-1)
{
return src;
}
return src.Substring(0, idx);
}
/// <summary>
/// Left of the n'th occurance of c
/// </summary>
/// <param name="src"></param>
/// <param name="c"></param>
/// <param name="n"></param>
/// <returns></returns>
public static string LeftOf(string src, char c, int n)
{
int idx=-1;
while (n != 0)
{
idx=src.IndexOf(c, idx+1);
if (idx==-1)
{
return src;
}
--n;
}
return src.Substring(0, idx);
}
/// <summary>
/// Right of the first occurance of c
/// </summary>
/// <param name="src"></param>
/// <param name="c"></param>
/// <returns></returns>
public static string RightOf(string src, char c)
{
int idx=src.IndexOf(c);
if (idx==-1)
{
return "";
}
return src.Substring(idx+1);
}
/// <summary>
/// Right of the n'th occurance of c
/// </summary>
/// <param name="src"></param>
/// <param name="c"></param>
/// <returns></returns>
public static string RightOf(string src, char c, int n)
{
int idx=-1;
while (n != 0)
{
idx=src.IndexOf(c, idx+1);
if (idx==-1)
{
return "";
}
--n;
}
return src.Substring(idx+1);
}
public static string LeftOfRightmostOf(string src, char c)
{
int idx=src.LastIndexOf(c);
if (idx==-1)
{
return src;
}
return src.Substring(0, idx);
}
public static string RightOfRightmostOf(string src, char c)
{
int idx=src.LastIndexOf(c);
if (idx==-1)
{
return src;
}
return src.Substring(idx+1);
}
public static string Between(string src, char start, char end)
{
string res=String.Empty;
int idxStart=src.IndexOf(start);
if (idxStart != -1)
{
++idxStart;
int idxEnd=src.IndexOf(end, idxStart);
if (idxEnd != -1)
{
res=src.Substring(idxStart, idxEnd-idxStart);
}
}
return res;
}
public static int Count(string src, char find)
{
int ret=0;
foreach(char s in src)
{
if (s==find)
{
++ret;
}
}
return ret;
}
}
}

2
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/ExportColumns/ExportColumn.cs

@ -42,10 +42,8 @@ namespace ICSharpCode.Reporting.PageBuilder.ExportColumns @@ -42,10 +42,8 @@ namespace ICSharpCode.Reporting.PageBuilder.ExportColumns
public bool CanGrow {get;set;}
public Rectangle DisplayRectangle {
get {
// return new Rectangle(Location,Size);
return new Rectangle(Location,DesiredSize);
}
}

1
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/ICSharpCode.Reporting.Test.csproj

@ -66,6 +66,7 @@ @@ -66,6 +66,7 @@
<ItemGroup>
<Compile Include="src\DataSource\ContributorsList.cs" />
<Compile Include="src\DataSource\CollectionHandlingFixture.cs" />
<Compile Include="src\Expressions\IntegrationTests.cs" />
<Compile Include="src\Expressions\IronyGeneral.cs" />
<Compile Include="src\MeasureArrange\ContainerArrangeStrategyFixture.cs" />
<Compile Include="src\Model\ReportModelFixture.cs" />

99
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/IntegrationTests.cs

@ -0,0 +1,99 @@ @@ -0,0 +1,99 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.ObjectModel;
using ICSharpCode.Reporting.Exporter.Visitors;
using ICSharpCode.Reporting.PageBuilder.ExportColumns;
using NUnit.Framework;
namespace ICSharpCode.Reporting.Test.Expressions
{
[TestFixture]
public class IntegrationTests
{
Collection<ExportText> collection;
ExpressionVisitor expressionVisitor;
[Test]
public void ExpressionMustStartWithEqualChar()
{
var result = collection[0];
expressionVisitor.Visit(collection[0]);
Assert.That(result.Text,Is.EqualTo(collection[0].Text));
}
[Test]
public void SimpleMath() {
expressionVisitor.Visit(collection[1]);
Assert.That(collection[1].Text,Is.EqualTo("8"));
var res = Convert.ToInt32(collection[1].Text);
Assert.That(res is int);
}
[Test]
public void SimpleStringHandling () {
var script = "='Sharpdevelop' + ' is great'";
collection.Add(new ExportText()
{
Text = script
});
expressionVisitor.Visit(collection[2]);
Assert.That(collection[2].Text,Is.EqualTo("Sharpdevelop is great"));
}
#region System.Environment
[Test]
[Ignore]
public void CanUserSystemEnvironment() {
/*
//Using methods imported from System.Environment
var script = @"report = '#{MachineName}-#{OSVersion}-#{UserName}'";
var result = evaluator.Evaluate(script);
var expected = string.Format("{0}-{1}-{2}", Environment.MachineName, Environment.OSVersion, Environment.UserName);
Assert.AreEqual(expected, result, "Unexpected computation result");
*/
}
#endregion
#region System.Math
[Test]
public void CanRunSystemMath () {
//Using methods imported from System.Math class
var script = @"=abs(-1.0) + Log10(100.0) + sqrt(9) + floor(4.5) + sin(PI/2)";
collection[1].Text = script;
expressionVisitor.Visit(collection[1]);
var res = Convert.ToDouble(collection[1].Text);
Assert.That(collection[1].Text,Is.EqualTo("11"));
}
#endregion
[SetUp]
public void CreateExportlist() {
collection = new Collection<ExportText>();
collection.Add(new ExportText()
{
Text = "myExporttextColumn"
});
collection.Add(new ExportText()
{
Text ="= 3 + 5"
});
}
[TestFixtureSetUp]
public void Setup() {
expressionVisitor = new ExpressionVisitor();
}
}
}

2
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/TestReports/FromList.srd

@ -120,7 +120,7 @@ @@ -120,7 +120,7 @@
<CanShrink>False</CanShrink>
<DataType>System.String</DataType>
<RTL>No</RTL>
<Text>=Globals!PageNumber</Text>
<Text>Globals!PageNumber</Text>
<DrawBorder>False</DrawBorder>
<FrameColor>Black</FrameColor>
<ForeColor>Black</ForeColor>

2
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/TestReports/ReportWithTwoItems.srd

@ -118,7 +118,7 @@ @@ -118,7 +118,7 @@
<CanShrink>False</CanShrink>
<DataType>System.String</DataType>
<RTL>No</RTL>
<Text>=Globals!PageNumber</Text>
<Text>Globals!PageNumber</Text>
<DrawBorder>False</DrawBorder>
<FrameColor>Black</FrameColor>
<ForeColor>Black</ForeColor>

Loading…
Cancel
Save