From 9b69e03cf59ec77a5da822b9a6617810fe488268 Mon Sep 17 00:00:00 2001 From: Ami Bar Date: Tue, 21 Aug 2012 09:00:05 +0300 Subject: [PATCH] Added thread IsBackground unit test --- STPTests/STPTests.csproj | 1 + STPTests/TestThreadApartmentState.cs | 4 +-- STPTests/TestThreadIsBackground.cs | 47 ++++++++++++++++++++++++++++ SmartThreadPool/SmartThreadPool.cs | 1 - 4 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 STPTests/TestThreadIsBackground.cs diff --git a/STPTests/STPTests.csproj b/STPTests/STPTests.csproj index da184f3..feed401 100644 --- a/STPTests/STPTests.csproj +++ b/STPTests/STPTests.csproj @@ -111,6 +111,7 @@ Code + diff --git a/STPTests/TestThreadApartmentState.cs b/STPTests/TestThreadApartmentState.cs index ea6d4f3..9e43a45 100644 --- a/STPTests/TestThreadApartmentState.cs +++ b/STPTests/TestThreadApartmentState.cs @@ -5,7 +5,7 @@ using Amib.Threading; namespace SmartThreadPoolTests { /// - /// Summary description for TestThreadPriority. + /// Summary description for TestThreadApartment. /// [TestFixture] [Category("TestThreadApartment")] @@ -26,7 +26,7 @@ namespace SmartThreadPoolTests private static void CheckApartmentState(ApartmentState requestApartmentState) { STPStartInfo stpStartInfo = new STPStartInfo(); - stpStartInfo.ApartmentState = requestApartmentState; + stpStartInfo.ApartmentState = requestApartmentState; SmartThreadPool stp = new SmartThreadPool(stpStartInfo); diff --git a/STPTests/TestThreadIsBackground.cs b/STPTests/TestThreadIsBackground.cs new file mode 100644 index 0000000..1383725 --- /dev/null +++ b/STPTests/TestThreadIsBackground.cs @@ -0,0 +1,47 @@ +using System.Threading; +using NUnit.Framework; +using Amib.Threading; + +namespace SmartThreadPoolTests +{ + /// + /// Summary description for TestThreadIsBackground. + /// + [TestFixture] + [Category("TestThreadIsBackground")] + public class TestThreadIsBackground + { + [Test] + public void TestIsBackground() + { + CheckIsBackground(true); + } + + [Test] + public void TestNotIsBackground() + { + CheckIsBackground(false); + } + + private static void CheckIsBackground(bool isBackground) + { + STPStartInfo stpStartInfo = new STPStartInfo(); + stpStartInfo.AreThreadsBackground = isBackground; + + SmartThreadPool stp = new SmartThreadPool(stpStartInfo); + + IWorkItemResult wir = stp.QueueWorkItem(() => GetCurrentThreadIsBackground()); + + bool resultIsBackground = wir.GetResult(); + + stp.WaitForIdle(); + + Assert.AreEqual(isBackground, resultIsBackground); + } + + private static bool GetCurrentThreadIsBackground() + { + return Thread.CurrentThread.IsBackground; + } + } +} \ No newline at end of file diff --git a/SmartThreadPool/SmartThreadPool.cs b/SmartThreadPool/SmartThreadPool.cs index 65dc701..d512137 100644 --- a/SmartThreadPool/SmartThreadPool.cs +++ b/SmartThreadPool/SmartThreadPool.cs @@ -89,7 +89,6 @@ // - Added IsBackground option to threads // - Added ApartmentState to threads // - Fixed thread creation when queuing many work items at the same time. - #endregion using System;