本文整理汇总了C#中C2Test类的典型用法代码示例。如果您正苦于以下问题:C# C2Test类的具体用法?C# C2Test怎么用?C# C2Test使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
C2Test类属于命名空间,在下文中一共展示了C2Test类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestThreadState
public void TestThreadState ()
{
if (is_win32 && is_mono)
Assert.Fail ("This test fails on mono on Win32. Our runtime should be fixed.");
//TODO: Test The rest of the possible transitions
C2Test test1 = new C2Test();
Thread TestThread = new Thread(new ThreadStart(test1.TestMethod));
Assert.AreEqual (ThreadState.Unstarted, TestThread.ThreadState, "#101 Wrong Thread State");
try {
TestThread.Start();
//while(!TestThread.IsAlive); //In the MS Documentation this is not necessary
//but in the MS SDK it is
Assert.IsTrue (TestThread.ThreadState == ThreadState.Running || (TestThread.ThreadState & ThreadState.Unstarted) != 0,
"#102 Wrong Thread State: " + TestThread.ThreadState.ToString ());
} finally {
#if MONO_FEATURE_THREAD_ABORT
TestThread.Abort();
#else
TestThread.Interrupt ();
#endif
}
TestUtil.WaitForNotAlive (TestThread, "wait12");
// Docs say state will be Stopped, but Aborted happens sometimes (?)
Assert.IsTrue ((ThreadState.Stopped & TestThread.ThreadState) != 0 || (ThreadState.Aborted & TestThread.ThreadState) != 0,
"#103 Wrong Thread State: " + TestThread.ThreadState.ToString ());
}
示例2: TestApartmentState
public void TestApartmentState ()
{
C2Test test1 = new C2Test();
Thread TestThread = new Thread(new ThreadStart(test1.TestMethod));
Assert.AreEqual (ApartmentState.Unknown, TestThread.ApartmentState, "#1");
TestThread.Start();
TestUtil.WaitForAlive (TestThread, "wait5");
Assert.AreEqual (ApartmentState.MTA, TestThread.ApartmentState, "#2");
#if MONO_FEATURE_THREAD_ABORT
TestThread.Abort();
#else
TestThread.Interrupt ();
#endif
}
示例3: TestName
public void TestName()
{
if (is_win32 && is_mono)
Assert.Fail ("This test fails on mono on Win32. Our runtime should be fixed.");
C2Test test1 = new C2Test();
Thread TestThread = new Thread(new ThreadStart(test1.TestMethod));
try {
TestThread.Start();
TestUtil.WaitForAlive (TestThread, "wait10");
string name = TestThread.Name;
Assert.IsNull (name, "#61 Name set when mustn't be set: ");
string newname = "Testing....";
TestThread.Name = newname;
Assert.AreEqual (newname, TestThread.Name, "#62 Name not set when must be set: ");
} finally {
#if MONO_FEATURE_THREAD_ABORT
TestThread.Abort();
#else
TestThread.Interrupt ();
#endif
}
}
示例4: TestIsBackground1
public void TestIsBackground1()
{
C2Test test1 = new C2Test();
Thread TestThread = new Thread(new ThreadStart(test1.TestMethod));
try {
TestThread.Start();
TestUtil.WaitForAlive (TestThread, "wait9");
bool state = TestThread.IsBackground;
Assert("#51 IsBackground not set at the default state: ",!(state));
}
finally {
TestThread.Abort();
}
}
示例5: TestName
public void TestName()
{
C2Test test1 = new C2Test();
Thread TestThread = new Thread(new ThreadStart(test1.TestMethod));
try {
TestThread.Start();
TestUtil.WaitForAlive (TestThread, "wait10");
string name = TestThread.Name;
AssertEquals("#61 Name set when mustn't be set: ", name, (string)null);
string newname = "Testing....";
TestThread.Name = newname;
AssertEquals("#62 Name not set when must be set: ",TestThread.Name,newname);
}
finally {
TestThread.Abort();
}
}
示例6: TestPriority1
public void TestPriority1()
{
C2Test test1 = new C2Test();
Thread TestThread = new Thread(new ThreadStart(test1.TestMethod));
try {
TestThread.Priority=ThreadPriority.BelowNormal;
ThreadPriority after = TestThread.Priority;
TestThread.Start();
TestUtil.WaitForAlive (TestThread, "wait7");
ThreadPriority before = TestThread.Priority;
AssertEquals("#41 Unexpected Priority Change: ",before,after);
}
finally {
TestThread.Abort();
}
}
示例7: TestPriority2
[Category("NotWorking")] // this is a MonoTODO -> no support for Priority
public void TestPriority2()
{
C2Test test1 = new C2Test();
Thread TestThread = new Thread(new ThreadStart(test1.TestMethod));
try {
AssertEquals("#42 Incorrect Priority in New thread: ",ThreadPriority.Normal, TestThread.Priority);
TestThread.Start();
TestUtil.WaitForAliveOrStop (TestThread, "wait8");
AssertEquals("#43 Incorrect Priority in Started thread: ",ThreadPriority.Normal, TestThread.Priority);
}
finally {
TestThread.Abort();
}
AssertEquals("#44 Incorrect Priority in Aborted thread: ",ThreadPriority.Normal, TestThread.Priority);
}
示例8: TestStart
[Category ("NotDotNet")] // it hangs.
public void TestStart()
{
if (is_win32 && is_mono)
Assert.Fail ("This test fails on Win32. The test should be fixed.");
{
C1Test test1 = new C1Test();
Thread TestThread = new Thread(new ThreadStart(test1.TestMethod));
TestThread.Start();
TestThread.Join();
Assert.AreEqual (10, test1.cnt, "#1");
}
{
C2Test test1 = new C2Test();
Thread TestThread = new Thread(new ThreadStart(test1.TestMethod));
TestThread.Start();
#if MONO_FEATURE_THREAD_ABORT
TestThread.Abort();
#else
TestThread.Interrupt ();
#endif
try {
TestThread.Start();
Assert.Fail ("#2");
} catch (ThreadStateException) {
}
}
{
C2Test test1 = new C2Test();
Thread TestThread = new Thread(new ThreadStart(test1.TestMethod));
TestThread.Start();
while (!test1.run) {
}
bool started = (TestThread.ThreadState == ThreadState.Running);
Assert.AreEqual (started, test1.run, "#15 Thread Is not in the correct state: ");
#if MONO_FEATURE_THREAD_ABORT
TestThread.Abort();
#else
TestThread.Interrupt ();
#endif
}
}
示例9: TestApartmentState
public void TestApartmentState ()
{
if (is_win32 && is_mono)
Assert.Fail ("This test fails on mono on win32. Our runtime should be fixed.");
C2Test test1 = new C2Test();
Thread TestThread = new Thread(new ThreadStart(test1.TestMethod));
Assert.AreEqual (ApartmentState.Unknown, TestThread.ApartmentState, "#1");
TestThread.Start();
TestUtil.WaitForAlive (TestThread, "wait5");
Assert.AreEqual (ApartmentState.MTA, TestThread.ApartmentState, "#2");
#if MONO_FEATURE_THREAD_ABORT
TestThread.Abort();
#else
TestThread.Interrupt ();
#endif
}
示例10: TestIsBackground2
public void TestIsBackground2 ()
{
C2Test test1 = new C2Test();
Thread TestThread = new Thread(new ThreadStart(test1.TestMethod));
TestThread.IsBackground = true;
try {
TestThread.Start();
} finally {
TestThread.Abort();
}
if (TestThread.IsAlive) {
try {
Assert.IsTrue (TestThread.IsBackground, "#52 Is Background Changed to Start ");
} catch (ThreadStateException) {
// Ignore if thread died meantime
}
}
}
示例11: TestPriority1
public void TestPriority1()
{
if (is_win32 && is_mono)
Assert.Fail ("This test fails on mono on Win32. Our runtime should be fixed.");
C2Test test1 = new C2Test();
Thread TestThread = new Thread(new ThreadStart(test1.TestMethod));
try {
TestThread.Priority=ThreadPriority.BelowNormal;
ThreadPriority after = TestThread.Priority;
TestThread.Start();
TestUtil.WaitForAlive (TestThread, "wait7");
ThreadPriority before = TestThread.Priority;
Assert.AreEqual (before, after, "#41 Unexpected Priority Change: ");
} finally {
TestThread.Abort();
}
}
示例12: TestName
public void TestName()
{
C2Test test1 = new C2Test();
Thread TestThread = new Thread(new ThreadStart(test1.TestMethod));
try {
TestThread.Start();
TestUtil.WaitForAlive (TestThread, "wait10");
string name = TestThread.Name;
Assert.IsNull (name, "#61 Name set when mustn't be set: ");
string newname = "Testing....";
TestThread.Name = newname;
Assert.AreEqual (newname, TestThread.Name, "#62 Name not set when must be set: ");
} finally {
#if MONO_FEATURE_THREAD_ABORT
TestThread.Abort();
#else
TestThread.Interrupt ();
#endif
}
}
示例13: TestIsBackground1
public void TestIsBackground1 ()
{
C2Test test1 = new C2Test();
Thread TestThread = new Thread(new ThreadStart(test1.TestMethod));
try {
TestThread.Start();
TestUtil.WaitForAlive (TestThread, "wait9");
bool state = TestThread.IsBackground;
Assert.IsFalse (state, "#51 IsBackground not set at the default state: ");
} finally {
#if MONO_FEATURE_THREAD_ABORT
TestThread.Abort();
#else
TestThread.Interrupt ();
#endif
}
}
示例14: TestPriority1
[Category ("NotWorking")] // setting the priority of a Thread before it is started isn't implemented in Mono yet
public void TestPriority1()
{
C2Test test1 = new C2Test();
Thread TestThread = new Thread(new ThreadStart(test1.TestMethod));
try {
TestThread.Priority=ThreadPriority.BelowNormal;
ThreadPriority before = TestThread.Priority;
Assert.AreEqual (ThreadPriority.BelowNormal, before, "#40 Unexpected priority before thread start: ");
TestThread.Start();
TestUtil.WaitForAlive (TestThread, "wait7");
ThreadPriority after = TestThread.Priority;
Assert.AreEqual (before, after, "#41 Unexpected Priority Change: ");
} finally {
#if MONO_FEATURE_THREAD_ABORT
TestThread.Abort();
#else
TestThread.Interrupt ();
#endif
}
}
示例15: TestStart
public void TestStart()
{
{
C1Test test1 = new C1Test();
Thread TestThread = 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 = false;
C2Test test1 = new C2Test();
Thread TestThread = new Thread(new ThreadStart(test1.TestMethod));
TestThread.Start();
TestThread.Abort();
try
{
TestThread.Start();
}
catch(ThreadStateException)
{
errorThrown = true;
}
Assert ("#14 no ThreadStateException trown", errorThrown);
}
{
C2Test test1 = new C2Test();
Thread TestThread = new Thread(new ThreadStart(test1.TestMethod));
TestThread.Start();
while(!test1.run);
bool started = (TestThread.ThreadState == ThreadState.Running);
AssertEquals("#15 Thread Is not in the correct state: ", started , test1.run);
TestThread.Abort();
}
}