[Mono-list] New Test for System.Threading.Thread
Eduardo Garcia Cebollero
kiwnix@yahoo.es
21 Nov 2002 03:53:10 +0100
--=-85zWpyWLWHl6f054ieN+
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
Hi!
Here are the test for System.Threading.Thread.
The problem is that this test doesn't run well with mono, when running
it in mono, it gets a Segmentation Fault (as described in:
http://bugzilla.ximian.com/show_bug.cgi?id=34323 ), or it hangs mono.
Somebody can add this to the CVS (i haven't cvs account).
The patch is attached.
The "ThreadTest.cs" and "AllTests.cs" are in a new directory called
System.Threading (mcs/class/corlib/Test/System.Threading) that should be
created.
Best wishes.
--
Eduardo Garcia Cebollero <kiwnix@yahoo.es>
--=-85zWpyWLWHl6f054ieN+
Content-Disposition: attachment; filename=1.diff
Content-Type: text/x-patch; name=1.diff; charset=ISO-8859-15
Content-Transfer-Encoding: quoted-printable
Index: AllTests.cs
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /mono/mcs/class/corlib/Test/AllTests.cs,v
retrieving revision 1.17
diff -u -r1.17 AllTests.cs
--- AllTests.cs 28 Oct 2002 03:10:23 -0000 1.17
+++ AllTests.cs 21 Nov 2002 02:39:38 -0000
@@ -32,6 +32,7 @@
suite.AddTest(System.Resources.AllTests.Su=
ite);
suite.AddTest(System.Runtime.Serialization.AllTests.Suite);
suite.AddTest(System.Runtime.CompilerServices.AllTests.Suite);
+ suite.AddTest(System.Threading.AllTests.Suite);
// suite.AddTest(System.Security.Policy.AllTests.Suite);
return suite;
}
Index: corlib_linux_test.args
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /mono/mcs/class/corlib/Test/corlib_linux_test.args,v
retrieving revision 1.12
diff -u -r1.12 corlib_linux_test.args
--- corlib_linux_test.args 17 Nov 2002 21:55:50 -0000 1.12
+++ corlib_linux_test.args 21 Nov 2002 02:39:38 -0000
@@ -122,3 +122,5 @@
System.Text/ASCIIEncodingTest.cs
System.Text/AllTests.cs
System.Text/StringBuilderTest.cs
+System.Threading/AllTests.cs
+System.Threading/ThreadTest.cs
--=-85zWpyWLWHl6f054ieN+
Content-Disposition: attachment; filename=AllTests.cs
Content-Type: text/plain; name=AllTests.cs; charset=ISO-8859-15
Content-Transfer-Encoding: quoted-printable
// Testsuite.System.AllSystemTests.cs
//
// Mario Martinez (mariom925@home.om)
//
// (C) Ximian, Inc. http://www.ximian.com
//=20
using System;
using NUnit.Framework;
namespace MonoTests.System.Threading {
/// <summary>
/// Combines all available unit tests into one test suite.
/// </summary>
public class AllTests : TestCase {
public AllTests(string name) : base(name) {}
=20
public static ITest Suite=20
{=20
get=20
{
TestSuite suite =3D new TestSuite();
suite.AddTest(ThreadTest.Suite);
return suite;
}
}
}
}
--=-85zWpyWLWHl6f054ieN+
Content-Disposition: attachment; filename=ThreadTest.cs
Content-Type: text/plain; name=ThreadTest.cs; charset=ISO-8859-15
Content-Transfer-Encoding: quoted-printable
// ThreadTest.cs - NUnit Test Cases for the System.Threading.Thread class
//
// Eduardo Garcia Cebollero (kiwnix@yahoo.es)
//
// (C) Eduardo Garcia Cebollero.
// (C) Ximian, Inc. http://www.ximian.com
//
using NUnit.Framework;
using System;
using System.Threading;
namespace MonoTests.System.Threading
{
public class ThreadTest : TestCase
{
public ThreadTest () :=20
base ("MonoTests.System.Threading.ThreadTest testsuite") {}
=09
public ThreadTest (string name) : base (name) {}
=09
protected override void SetUp () {}
=09
public static ITest Suite
{
get=20
{=20
return new TestSuite (typeof (ThreadTest));=20
}
}
=09
//Some Classes to test as threads
private class C1Test
{
public int cnt;
public Thread thread1;
public bool endm1;
public bool endm2;
public C1Test()
{
thread1 =3D (Thread)null;
this.cnt =3D 0;
endm1 =3D endm2 =3D false;
}
=09
public void TestMethod()
{
while (cnt < 10)
{
cnt++;
}
endm1 =3D true;
}
public void TestMethod2()
{
if (!(thread1=3D=3D(Thread)null) )
{
thread1.Join();
}
endm2 =3D true;
}
}
private class C2Test
{
public int cnt;
public bool run =3D false;
=09
public C2Test()
{
this.cnt =3D 0;
}
public void TestMethod()
{
run =3D true;
while (true)
{
if (cnt < 1000)
cnt++;
else
cnt =3D 0;
}
}
}
=09
private class C3Test
{
public C1Test sub_class;
public Thread sub_thread;
public C3Test()
{
sub_class =3D new C1Test();
sub_thread =3D new Thread(new ThreadStart(sub_class.TestMethod));
}
public void TestMethod1()
{
sub_thread.Start();
sub_thread.Abort();
}
}
=09
private class C4Test
{
public C1Test class1;
public C1Test class2;
public Thread thread1;
public Thread thread2;
public bool T1ON ;
public bool T2ON ;
public C4Test()
{
T1ON =3D false;
T2ON =3D false;
class1 =3D new C1Test();
class2 =3D new C1Test();
thread1 =3D new Thread(new ThreadStart(class1.TestMethod));
thread2 =3D new Thread(new ThreadStart(class2.TestMethod));
}
public void TestMethod1()
{
thread1.Start();
while (!thread1.IsAlive);
T1ON =3D true;
thread2.Start();
while (!thread2.IsAlive);
T2ON =3D true;
thread2.Abort();
while (thread2.IsAlive);
T2ON =3D false;
thread1.Abort();
while (thread2.IsAlive);
T1ON =3D false;
}
=09
public void TestMethod2()
{
thread1.Start();
thread1.Join();
}
}
=09
=09
public void TestCtor1()
{ =09
C1Test test1 =3D new C1Test();
try
{
Thread TestThread =3D new Thread(new ThreadStart(test1.TestMethod));
}
catch (Exception e)
{
Fail ("#01 Unexpected Exception Thrown: " + e.ToString ());
}
}
//TODO: Test to make a constructor in a thread :)
=09
public void TestStart()
{
{
C1Test test1 =3D new C1Test();
Thread TestThread =3D new Thread(new ThreadStart(test1.TestMethod));
try
{
TestThread.Start();
}
catch (Exception e)
{
Fail ("#12 Unexpected Exception Thrown: " + e.ToString ());
}
TestThread.Join();
AssertEquals("#13 Thread Not started: ", 10,test1.cnt);
}
{
bool errorThrown =3D false;
C2Test test1 =3D new C2Test();
Thread TestThread =3D new Thread(new ThreadStart(test1.TestMethod));
TestThread.Start();
TestThread.Abort();
try
{
TestThread.Start();
}
catch(ThreadStateException)
{
errorThrown =3D true;
}
Assert ("#14 no ThreadStateException trown", errorThrown);
}
{
C2Test test1 =3D new C2Test();
Thread TestThread =3D new Thread(new ThreadStart(test1.TestMethod));
TestThread.Start();
while(!test1.run);
bool started =3D (TestThread.ThreadState =3D=3D ThreadState.Running);
AssertEquals("#15 Thread Is not in the correct state: ", started , test1=
.run);=09
}
}
public void TestApartment()
{
C2Test test1 =3D new C2Test();
Thread TestThread =3D new Thread(new ThreadStart(test1.TestMethod));
ApartmentState before =3D TestThread.ApartmentState;
TestThread.Start();
while(!TestThread.IsAlive);
ApartmentState after =3D TestThread.ApartmentState;
TestThread.Abort();
AssertEquals("#21 Apartment State Changed when not needed",before,after)=
;
}
public void TestApartmentState()
{
C2Test test1 =3D new C2Test();
Thread TestThread =3D new Thread(new ThreadStart(test1.TestMethod));
ApartmentState before =3D TestThread.ApartmentState;
TestThread.Start();
while(!TestThread.IsAlive);
ApartmentState after =3D TestThread.ApartmentState;
TestThread.Abort();
AssertEquals("#31 Apartment State Changed when not needed: ",before,afte=
r);
}
public void TestPriority()
{
C2Test test1 =3D new C2Test();
Thread TestThread =3D new Thread(new ThreadStart(test1.TestMethod));
ThreadPriority after =3D TestThread.Priority;
TestThread.Start();
while(!TestThread.IsAlive);
ThreadPriority before =3D TestThread.Priority;
TestThread.Abort();
AssertEquals("#41 Priority Changed when not needed: ",before,after);
}
public void TestIsBackground()
{
C2Test test1 =3D new C2Test();
Thread TestThread =3D new Thread(new ThreadStart(test1.TestMethod));
TestThread.Start();
while(!TestThread.IsAlive);
bool state =3D TestThread.IsBackground;
TestThread.Abort();
AssertEquals("#51 IsBackground not set at the default state: ", state, f=
alse);
}
public void TestName()
{
C2Test test1 =3D new C2Test();
Thread TestThread =3D new Thread(new ThreadStart(test1.TestMethod));
TestThread.Start();
while(!TestThread.IsAlive);
string name =3D TestThread.Name;
AssertEquals("#61 Name set when mustn't be set: ", name, (string)null);
string newname =3D "Testing....";
TestThread.Name =3D newname;
AssertEquals("#62 Name not set when must be set: ",TestThread.Name,newna=
me);
TestThread.Abort();
}
public void TestNestedThreads1()
{
C3Test test1 =3D new C3Test();
Thread TestThread =3D new Thread(new ThreadStart(test1.TestMethod1));
try
{
TestThread.Start();
while(!TestThread.IsAlive);
TestThread.Abort();
}
catch(Exception e)
{
Fail("#71 Unexpected Exception" + e.Message);
}
}
public void TestNestedThreads2()
{
C4Test test1 =3D new C4Test();
test1.thread1.Start();
test1.thread1.Abort();
while(test1.thread1.IsAlive);
Thread TestThread =3D new Thread(new ThreadStart(test1.TestMethod1));
try
{
TestThread.Start();
TestThread.Abort();
}
catch(Exception e)
{
Fail("#81 Unexpected Exception" + e.ToString());
}
}
public void TestJoin1()
{
C1Test test1 =3D new C1Test();
C1Test test2 =3D new C1Test();
Thread thread1 =3D new Thread(new ThreadStart(test1.TestMethod));
Thread thread2 =3D new Thread(new ThreadStart(test1.TestMethod2));
try
{
thread1.Start();
thread2.Start();
thread2.Join();
}
catch(Exception e)
{
Fail("#91 Unexpected Exception " + e.ToString());
}
}
}
}
=09
=09
=09
=09
=09
=09
=09
--=-85zWpyWLWHl6f054ieN+--