Skip to content

Commit d64f52e

Browse files
author
Edgar Sanchez
committed
Added UnitTesting project (not sure if this will break the solution for the other commiters). Rewrote the enumerator on StringTokenizer to make it a little bit more efficient. Created unit tests for StringTokenizer.
SVN: trunk@108
1 parent 14a1c07 commit d64f52e

10 files changed

+372
-28
lines changed

src/NHibernate/NHibernate.csproj

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,17 @@
7777
AssemblyName = "nunit.framework"
7878
HintPath = "..\..\..\..\..\Program Files\NUnit V2.0\bin\nunit.framework.dll"
7979
/>
80-
<Reference
81-
Name = "log4net"
82-
AssemblyName = "log4net"
83-
HintPath = "..\..\..\log4net1.2.0-beta5\build\bin\ReleaseStrong\log4net.dll"
84-
/>
8580
<Reference
8681
Name = "System.Runtime.Remoting"
8782
AssemblyName = "System.Runtime.Remoting"
8883
HintPath = "..\..\..\..\..\WINNT\Microsoft.NET\Framework\v1.0.3705\System.Runtime.Remoting.dll"
8984
/>
85+
<Reference
86+
Name = "log4net"
87+
AssemblyName = "log4net"
88+
HintPath = "C:\log4net1.2.0-beta5\build\bin\Debug\log4net.dll"
89+
Private = "False"
90+
/>
9091
</References>
9192
</Build>
9293
<Files>

src/NHibernate/NHibernate.csproj.user

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<VisualStudioProject>
22
<CSHARP>
33
<Build>
4-
<Settings ReferencePath = "C:\Program Files\log4net1.2.0-beta5\build\bin\ReleaseStrong\;C:\Program Files\NUnit V2.0\bin\;F:\DOTNET\Log4Net\log4net1.2.0-beta5\build\bin\Release\;C:\Documents and Settings\Owner\My Documents\Visual Studio Projects\log4net1.2.0-beta5\build\bin\ReleaseStrong\" >
4+
<Settings ReferencePath = "C:\Program Files\log4net1.2.0-beta5\build\bin\ReleaseStrong\;C:\Program Files\NUnit V2.0\bin\;F:\DOTNET\Log4Net\log4net1.2.0-beta5\build\bin\Release\;C:\Documents and Settings\Owner\My Documents\Visual Studio Projects\log4net1.2.0-beta5\build\bin\ReleaseStrong\;C:\log4net1.2.0-beta5\build\bin\Debug\" >
55
<Config
66
Name = "Debug"
77
EnableASPDebugging = "false"

src/NHibernate/NHibernate.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
Microsoft Visual Studio Solution File, Format Version 7.00
22
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NHibernate", "NHibernate.csproj", "{0D8B57B0-1310-4EF0-B50C-DD22F37310C7}"
33
EndProject
4+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTesting", "..\UnitTesting\UnitTesting.csproj", "{F550A23F-5311-4C23-A14D-C39388DFA6FD}"
5+
EndProject
46
Global
57
GlobalSection(SolutionConfiguration) = preSolution
68
ConfigName.0 = Debug
@@ -13,6 +15,10 @@ Global
1315
{0D8B57B0-1310-4EF0-B50C-DD22F37310C7}.Debug.Build.0 = Debug|.NET
1416
{0D8B57B0-1310-4EF0-B50C-DD22F37310C7}.Release.ActiveCfg = Release|.NET
1517
{0D8B57B0-1310-4EF0-B50C-DD22F37310C7}.Release.Build.0 = Release|.NET
18+
{F550A23F-5311-4C23-A14D-C39388DFA6FD}.Debug.ActiveCfg = Debug|.NET
19+
{F550A23F-5311-4C23-A14D-C39388DFA6FD}.Debug.Build.0 = Debug|.NET
20+
{F550A23F-5311-4C23-A14D-C39388DFA6FD}.Release.ActiveCfg = Release|.NET
21+
{F550A23F-5311-4C23-A14D-C39388DFA6FD}.Release.Build.0 = Release|.NET
1622
EndGlobalSection
1723
GlobalSection(ExtensibilityGlobals) = postSolution
1824
EndGlobalSection

src/NHibernate/Util/SequencedHashMap.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ public object Value {
9393
public override int GetHashCode() {
9494
return ((Key == null ? 0 : Key.GetHashCode()) ^ (Value == null ? 0 : Value.GetHashCode()) );
9595
}
96+
9697
public override bool Equals(object obj) {
9798
Entry other = obj as Entry;
9899
if (other == null) return false;
@@ -101,6 +102,7 @@ public override bool Equals(object obj) {
101102
return ( (Key == null ? other.Key == null : Key.Equals(other.Key)) &&
102103
(Value == null ? other.Value == null : Value.Equals(other.Value)) );
103104
}
105+
104106
public override string ToString() {
105107
return "[" + Key + "=" + Value + "]";
106108
}

src/NHibernate/Util/StringHelper.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,20 @@ public static string ReplaceOnce(string template, string placeholder, string rep
5353
}
5454
}
5555

56-
public static string[] Split(string seperators, string list) {
57-
return Split(seperators, list, false);
58-
}
59-
60-
public static string[] Split(string seperators, string list, bool include) {
61-
StringTokenizer tokens = new StringTokenizer(list, seperators, include);
56+
/// <summary>
57+
/// Just a façade for calling string.Split()
58+
/// We don't use our StringTokenizer because string.Split() is
59+
/// more efficient (but it only works when we don't want to retrieve the delimiters)
60+
/// </summary>
61+
/// <param name="separators">separators for the tokens of the list</param>
62+
/// <param name="list">the string that will be broken into tokens</param>
63+
/// <returns></returns>
64+
public static string[] Split(string separators, string list) {
65+
return list.Split(separators.ToCharArray());
66+
}
67+
68+
public static string[] Split(string separators, string list, bool include) {
69+
StringTokenizer tokens = new StringTokenizer(list, separators, include);
6270
ArrayList results = new ArrayList();
6371
foreach(string token in tokens) {
6472
results.Add( token );

src/NHibernate/Util/StringTokenizer.cs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@ public StringTokenizerEnumerator(StringTokenizer stok) {
4646

4747
public bool MoveNext() {
4848
_next = GetNext();
49-
if (_next == null)
50-
return false;
51-
return true;
49+
return _next != null;
5250
}
5351

5452
public void Reset() {
@@ -62,35 +60,31 @@ public object Current {
6260
}
6361

6462
private string GetNext() {
65-
StringBuilder sb;
6663
char c;
6764
bool isDelim;
6865

69-
if( _cursor == _stokenizer._origin.Length )
66+
if( _cursor >= _stokenizer._origin.Length )
7067
return null;
7168

72-
sb = new StringBuilder();
73-
7469
c = _stokenizer._origin[_cursor];
7570
isDelim = (_stokenizer._delim.IndexOf(c) != -1);
7671

77-
if( isDelim ) {
72+
if ( isDelim ) {
7873
_cursor++;
7974
if ( _stokenizer._returnDelim ) {
8075
return c.ToString();
8176
}
8277
return GetNext();
8378
}
8479

85-
while( _cursor < _stokenizer._origin.Length && !isDelim ) {
86-
sb.Append(c);
87-
if( ++_cursor == _stokenizer._origin.Length)
88-
break;
89-
c = _stokenizer._origin[_cursor];
90-
isDelim = (_stokenizer._delim.IndexOf(c) != -1);
80+
int nextDelimPos = _stokenizer._origin.IndexOfAny(_stokenizer._delim.ToCharArray(), _cursor);
81+
if (nextDelimPos == -1) {
82+
nextDelimPos = _stokenizer._origin.Length;
9183
}
92-
93-
return sb.ToString();
84+
85+
string nextToken = _stokenizer._origin.Substring(_cursor, nextDelimPos - _cursor);
86+
_cursor = nextDelimPos;
87+
return nextToken;
9488
}
9589

9690
}

src/UnitTesting/AssemblyInfo.cs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
4+
//
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
//
9+
[assembly: AssemblyTitle("")]
10+
[assembly: AssemblyDescription("")]
11+
[assembly: AssemblyConfiguration("")]
12+
[assembly: AssemblyCompany("")]
13+
[assembly: AssemblyProduct("")]
14+
[assembly: AssemblyCopyright("")]
15+
[assembly: AssemblyTrademark("")]
16+
[assembly: AssemblyCulture("")]
17+
18+
//
19+
// Version information for an assembly consists of the following four values:
20+
//
21+
// Major Version
22+
// Minor Version
23+
// Build Number
24+
// Revision
25+
//
26+
// You can specify all the values or you can default the Revision and Build Numbers
27+
// by using the '*' as shown below:
28+
29+
[assembly: AssemblyVersion("1.0.*")]
30+
31+
//
32+
// In order to sign your assembly you must specify a key to use. Refer to the
33+
// Microsoft .NET Framework documentation for more information on assembly signing.
34+
//
35+
// Use the attributes below to control which key is used for signing.
36+
//
37+
// Notes:
38+
// (*) If no key is specified, the assembly is not signed.
39+
// (*) KeyName refers to a key that has been installed in the Crypto Service
40+
// Provider (CSP) on your machine. KeyFile refers to a file which contains
41+
// a key.
42+
// (*) If the KeyFile and the KeyName values are both specified, the
43+
// following processing occurs:
44+
// (1) If the KeyName can be found in the CSP, that key is used.
45+
// (2) If the KeyName does not exist and the KeyFile does exist, the key
46+
// in the KeyFile is installed into the CSP and used.
47+
// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility.
48+
// When specifying the KeyFile, the location of the KeyFile should be
49+
// relative to the project output directory which is
50+
// %Project Directory%\obj\<configuration>. For example, if your KeyFile is
51+
// located in the project directory, you would specify the AssemblyKeyFile
52+
// attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]
53+
// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework
54+
// documentation for more information on this.
55+
//
56+
[assembly: AssemblyDelaySign(false)]
57+
[assembly: AssemblyKeyFile("")]
58+
[assembly: AssemblyKeyName("")]
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
using System;
2+
using System.Collections;
3+
4+
using NUnit.Framework;
5+
6+
using NHibernate.Util;
7+
8+
namespace NHibernate.UnitTesting
9+
{
10+
[TestFixture]
11+
public class StringTokenizerUnitTesting
12+
{
13+
[Test]
14+
public void SimpleStringWithoutDelimiters()
15+
{
16+
string s = "Hello world!";
17+
StringTokenizer st = new StringTokenizer(s);
18+
IEnumerator enumerator = st.GetEnumerator();
19+
enumerator.MoveNext();
20+
Assertion.AssertEquals("Can't get first token", "Hello", (string) enumerator.Current);
21+
enumerator.MoveNext();
22+
Assertion.AssertEquals("Can't get second token", "world!", (string) enumerator.Current);
23+
Assertion.AssertEquals("Still thinking there are more tokens", false, enumerator.MoveNext());
24+
}
25+
26+
[Test]
27+
public void SimpleStringWithDelimiters()
28+
{
29+
string s = "Hello world!";
30+
StringTokenizer st = new StringTokenizer(s," ",true);
31+
IEnumerator enumerator = st.GetEnumerator();
32+
enumerator.MoveNext();
33+
Assertion.AssertEquals("Can't get first token", "Hello", (string) enumerator.Current);
34+
enumerator.MoveNext();
35+
Assertion.AssertEquals("Can't get first space", " ", (string) enumerator.Current);
36+
enumerator.MoveNext();
37+
Assertion.AssertEquals("Can't get second token", "world!", (string) enumerator.Current);
38+
Assertion.AssertEquals("Still thinking there are more tokens", false, enumerator.MoveNext());
39+
}
40+
41+
[Test]
42+
public void NotSoSimpleWithoutDelimiters()
43+
{
44+
string s = "The lazy... I don't know ";
45+
StringTokenizer st = new StringTokenizer(s," .",false);
46+
IEnumerator enumerator = st.GetEnumerator();
47+
enumerator.MoveNext();
48+
Assertion.AssertEquals("Can't get first token", "The", (string) enumerator.Current);
49+
enumerator.MoveNext();
50+
Assertion.AssertEquals("Can't get second token", "lazy", (string) enumerator.Current);
51+
enumerator.MoveNext();
52+
Assertion.AssertEquals("Can't get third token", "I", (string) enumerator.Current);
53+
enumerator.MoveNext();
54+
Assertion.AssertEquals("Can't get fourth token", "don't", (string) enumerator.Current);
55+
enumerator.MoveNext();
56+
Assertion.AssertEquals("Can't get fifth token", "know", (string) enumerator.Current);
57+
Assertion.AssertEquals("Still thinking there are more tokens", false, enumerator.MoveNext());
58+
}
59+
60+
[Test]
61+
public void NotSoSimpleWithDelimiters()
62+
{
63+
string s = "The lazy... I don't know ";
64+
StringTokenizer st = new StringTokenizer(s," .",true);
65+
IEnumerator enumerator = st.GetEnumerator();
66+
enumerator.MoveNext();
67+
Assertion.AssertEquals("Can't get first token", "The", (string) enumerator.Current);
68+
enumerator.MoveNext();
69+
Assertion.AssertEquals("Can't get first space", " ", (string) enumerator.Current);
70+
enumerator.MoveNext();
71+
Assertion.AssertEquals("Can't get second token", "lazy", (string) enumerator.Current);
72+
enumerator.MoveNext();
73+
Assertion.AssertEquals("Can't get first dot", ".", (string) enumerator.Current);
74+
enumerator.MoveNext();
75+
Assertion.AssertEquals("Can't get second dot", ".", (string) enumerator.Current);
76+
enumerator.MoveNext();
77+
Assertion.AssertEquals("Can't get third dot", ".", (string) enumerator.Current);
78+
enumerator.MoveNext();
79+
Assertion.AssertEquals("Can't get second space", " ", (string) enumerator.Current);
80+
enumerator.MoveNext();
81+
Assertion.AssertEquals("Can't get third token", "I", (string) enumerator.Current);
82+
enumerator.MoveNext();
83+
Assertion.AssertEquals("Can't get third space", " ", (string) enumerator.Current);
84+
enumerator.MoveNext();
85+
Assertion.AssertEquals("Can't get fourth token", "don't", (string) enumerator.Current);
86+
enumerator.MoveNext();
87+
Assertion.AssertEquals("Can't get fourth space", " ", (string) enumerator.Current);
88+
enumerator.MoveNext();
89+
Assertion.AssertEquals("Can't get fifth token", "know", (string) enumerator.Current);
90+
enumerator.MoveNext();
91+
Assertion.AssertEquals("Can't get last space", " ", (string) enumerator.Current);
92+
Assertion.AssertEquals("Still thinking there are more tokens", false, enumerator.MoveNext());
93+
}
94+
95+
[Test]
96+
public void OnlyDelimitersWithoutDelimiters()
97+
{
98+
string s = " .,,,";
99+
StringTokenizer st = new StringTokenizer(s, " ,.", false);
100+
IEnumerator enumerator = st.GetEnumerator();
101+
Assertion.AssertEquals("Still thinking there are more tokens", false, enumerator.MoveNext());
102+
}
103+
104+
[Test]
105+
public void OnlyDelimitersWithDelimiters()
106+
{
107+
string s = " .,,,";
108+
StringTokenizer st = new StringTokenizer(s, " ,.", true);
109+
IEnumerator enumerator = st.GetEnumerator();
110+
enumerator.MoveNext();
111+
Assertion.AssertEquals("Can't get first delimiter", " ", (string) enumerator.Current);
112+
enumerator.MoveNext();
113+
Assertion.AssertEquals("Can't get second delimiter", ".", (string) enumerator.Current);
114+
enumerator.MoveNext();
115+
Assertion.AssertEquals("Can't get third delimiter", ",", (string) enumerator.Current);
116+
enumerator.MoveNext();
117+
Assertion.AssertEquals("Can't get fourth delimiter", ",", (string) enumerator.Current);
118+
enumerator.MoveNext();
119+
Assertion.AssertEquals("Can't get fifth delimiter", ",", (string) enumerator.Current);
120+
Assertion.AssertEquals("Still thinking there are more tokens", false, enumerator.MoveNext());
121+
}
122+
123+
}
124+
}

0 commit comments

Comments
 (0)