added tests

This commit is contained in:
eeichinger
2008-06-08 20:30:25 +00:00
parent 6d92bf9176
commit 7555bd26bc
4 changed files with 220 additions and 0 deletions

View File

@@ -0,0 +1,125 @@
#region License
/*
* Copyright <20> 2002-2008 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Collections;
using System.Text;
using NUnit.Framework;
#endregion
namespace Spring.Collections
{
/// <summary>
///
/// </summary>
/// <author>Erich Eichinger</author>
/// <version>$Id: $</version>
[TestFixture]
public class SynchronizedHashtableTests
{
/// <summary>
/// On my Notebook gives
/// Normal Hashtable: 00:00:01.5937500
/// Synced Hashtable: 00:00:02.8593750
/// </summary>
[Test, Explicit]
public void TestLockingPerformanceImpact()
{
StopWatch watch = new StopWatch();
object[] buckets = new object[10];
int iterations = 10000000;
IDictionary testDict = new Hashtable();
buckets[5] = "value";
object testResult;
using(watch.Start("Normal Hashtable: {0}"))
for(int i=0;i<iterations;i++)
{
testResult = buckets[6];
buckets[5] = "value 2";
}
testDict = new Hashtable();
testDict.Add( "key", "value" );
using(watch.Start("Synced Hashtable: {0}"))
for(int i=0;i<iterations;i++)
{
lock(buckets)
{
testResult = buckets[6];
}
lock(buckets)
{
buckets[5] = "value 2";
}
}
}
/// <summary>
/// On my Notebook gives
/// Method returning exception: 00:00:00.0156250
/// Method throwing exception: 00:00:02.1562500
/// </summary>
[Test, Explicit]
public void TestPeformanceImpactOfThrowingExceptions()
{
StopWatch watch = new StopWatch();
int iterations = 1000000;
using(watch.Start("Method returning exception: {0}"))
for(int i=0;i<iterations;i++)
{
Exception ex = MethodReturnExceptionInformation();
}
using(watch.Start("Method throwing exception: {0}"))
for(int i=0;i<iterations;i++)
{
Exception ex;
try
{
MethodThrowingException();
}
catch (Exception innerEx)
{
ex = innerEx;
}
}
}
private void MethodThrowingException()
{
throw new InvalidOperationException( "da message" );
}
private Exception MethodReturnExceptionInformation()
{
return new InvalidOperationException( "da message" );
}
}
}

View File

@@ -0,0 +1,58 @@
#region License
/*
* Copyright <20> 2002-2008 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using NUnit.Framework;
#endregion
namespace Spring.Expressions
{
/// <summary>
/// Tests the behavior of PropertyOrFieldNode expression node
/// </summary>
/// <author>Erich Eichinger</author>
/// <version>$Id: $</version>
[TestFixture]
public class PropertyOrFieldNodeTests
{
private class BaseClass
{
public string StringProp { get { return "BaseStringProp"; }}
}
private class DerivedClass : BaseClass
{
public new DateTime StringProp { get { return new DateTime(2008,1,1); }}
}
[Test]
public void UseMostSpecificOverride()
{
PropertyOrFieldNode pofNode = new PropertyOrFieldNode();
pofNode.Text = "StringProp";
Assert.AreEqual(new DateTime(2008,1,1), ((IExpression) pofNode).GetValue(new DerivedClass()));
}
}
}

View File

@@ -895,6 +895,41 @@
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Expressions\FunctionNodeTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Expressions\MethodNodeTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Expressions\PropertyOrFieldNodeTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Expressions\ReferenceNodeTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Expressions\SelectionNodeTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Expressions\Processors\ConversionProcessorTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Expressions\Processors\OrderByProcessorTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Globalization\AbstractLocalizerTests.cs"
SubType = "Code"

View File

@@ -143,6 +143,7 @@
<Compile Include="Collections\StaticSetTests.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Collections\SynchronizedHashtableTests.cs" />
<Compile Include="CommonTypes.cs">
<SubType>Code</SubType>
</Compile>
@@ -276,6 +277,7 @@
<Compile Include="Expressions\MethodNodeTests.cs" />
<Compile Include="Expressions\Processors\ConversionProcessorTests.cs" />
<Compile Include="Expressions\Processors\OrderByProcessorTests.cs" />
<Compile Include="Expressions\PropertyOrFieldNodeTests.cs" />
<Compile Include="Expressions\ReferenceNodeTests.cs" />
<Compile Include="Expressions\SelectionNodeTests.cs" />
<Compile Include="Globalization\AbstractLocalizerTests.cs">