You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by di...@apache.org on 2009/11/10 18:49:20 UTC
svn commit: r834563 - in /incubator/lucene.net/trunk/C#/src:
Lucene.Net/SupportClass.cs Test/TestSupportClass.cs
Author: digy
Date: Tue Nov 10 17:49:20 2009
New Revision: 834563
URL: http://svn.apache.org/viewvc?rev=834563&view=rev
Log:
LUCENENET-211 SupportClass.ThreadClass bug
Modified:
incubator/lucene.net/trunk/C#/src/Lucene.Net/SupportClass.cs
incubator/lucene.net/trunk/C#/src/Test/TestSupportClass.cs
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/SupportClass.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/SupportClass.cs?rev=834563&r1=834562&r2=834563&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/SupportClass.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/SupportClass.cs Tue Nov 10 17:49:20 2009
@@ -143,7 +143,6 @@
public ThreadClass()
{
threadField = new System.Threading.Thread(new System.Threading.ThreadStart(Run));
- This = this;
}
/// <summary>
@@ -154,7 +153,6 @@
{
threadField = new System.Threading.Thread(new System.Threading.ThreadStart(Run));
this.Name = Name;
- This = this;
}
/// <summary>
@@ -164,7 +162,6 @@
public ThreadClass(System.Threading.ThreadStart Start)
{
threadField = new System.Threading.Thread(Start);
- This = this;
}
/// <summary>
@@ -176,7 +173,6 @@
{
threadField = new System.Threading.Thread(Start);
this.Name = Name;
- This = this;
}
/// <summary>
@@ -192,11 +188,6 @@
public virtual void Start()
{
threadField.Start();
- if (This == null)
- {
- This = this;
- This.Instance = threadField;
- }
}
/// <summary>
@@ -379,7 +370,7 @@
/// <returns>A String that represents the current object</returns>
public override System.String ToString()
{
- return "Thread[" + Name + "," + Priority.ToString() + "," + "" + "]";
+ return "Thread[" + Name + "," + Priority.ToString() + "]";
}
[ThreadStatic]
@@ -411,6 +402,24 @@
}
return This;
}
+
+ public static bool operator ==(ThreadClass t1, object t2)
+ {
+ if (((object)t1) == null) return t2 == null;
+ return t1.Equals(t2);
+ }
+
+ public static bool operator !=(ThreadClass t1, object t2)
+ {
+ return !(t1 == t2);
+ }
+
+ public override bool Equals(object obj)
+ {
+ if (obj == null) return false;
+ if (obj is ThreadClass) return this.threadField.Equals( ((ThreadClass)obj).threadField );
+ return false;
+ }
}
/// <summary>
Modified: incubator/lucene.net/trunk/C#/src/Test/TestSupportClass.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/TestSupportClass.cs?rev=834563&r1=834562&r2=834563&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/TestSupportClass.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/TestSupportClass.cs Tue Nov 10 17:49:20 2009
@@ -24,6 +24,42 @@
namespace Lucene.Net._SupportClass
{
+ [TestFixture]
+ public class _SupportClassTestCases
+ {
+ [Test]
+ public void Count()
+ {
+ System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly();
+ Type[] types = asm.GetTypes();
+
+ int countSupport = 0;
+ int countOther = 0;
+ foreach (Type type in types)
+ {
+ object[] o1 = type.GetCustomAttributes(typeof(NUnit.Framework.TestFixtureAttribute), true);
+ if (o1 == null || o1.Length == 0) continue;
+
+ foreach (System.Reflection.MethodInfo mi in type.GetMethods())
+ {
+ object[] o2 = mi.GetCustomAttributes(typeof(NUnit.Framework.TestAttribute), true);
+ if (o2 == null || o2.Length == 0) continue;
+
+ if (type.FullName.StartsWith("Lucene.Net._SupportClass"))
+ {
+ countSupport++;
+ }
+ else
+ {
+ countOther++;
+ }
+ }
+ }
+
+ Assert.Fail("Lucene.Net TestCases:" + countSupport + " Others TestCases:" + countOther);
+ }
+ }
+
/// <summary>
/// </summary>
[TestFixture]
@@ -39,10 +75,10 @@
b[i] = (byte)i;
SupportClass.Checksum digest = new SupportClass.CRC32();
- digest.update(b, 0, b.Length);
+ digest.Update(b, 0, b.Length);
Int64 expected = 688229491;
- Assert.AreEqual(expected, digest.getValue());
+ Assert.AreEqual(expected, digest.GetValue());
}
}
@@ -609,4 +645,38 @@
this.i = i;
}
}
+
+ [TestFixture]
+ public class TestThreadClass
+ {
+ [Test]
+ public void Test()
+ {
+ SupportClass.ThreadClass thread = new SupportClass.ThreadClass();
+
+ //Compare Current Thread Ids
+ Assert.IsTrue(SupportClass.ThreadClass.Current().Instance.ManagedThreadId == System.Threading.Thread.CurrentThread.ManagedThreadId);
+
+
+ //Compare instances of ThreadClass
+ MyThread mythread = new MyThread();
+ mythread.Start();
+ while (mythread.Result == null) System.Threading.Thread.Sleep(1);
+ Assert.IsTrue((bool)mythread.Result);
+
+
+ SupportClass.ThreadClass nullThread = null;
+ Assert.IsTrue(nullThread == null); //test overloaded operator == with null values
+ Assert.IsFalse(nullThread != null); //test overloaded operator != with null values
+ }
+
+ class MyThread : SupportClass.ThreadClass
+ {
+ public object Result = null;
+ public override void Run()
+ {
+ Result = SupportClass.ThreadClass.Current() == this;
+ }
+ }
+ }
}
\ No newline at end of file