CompressedStackTest.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. //
  2. // CompressedStackTest.cs - NUnit Test Cases for CompressedStack
  3. //
  4. // Author:
  5. // Sebastien Pouliot ([email protected])
  6. //
  7. // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. // Note: the class existed in 1.1 but the only thing we know about it is that
  29. // it has a finalizer ;-)
  30. #if NET_2_0
  31. using System;
  32. using System.Runtime.Serialization;
  33. using System.Security;
  34. using System.Threading;
  35. using NUnit.Framework;
  36. namespace MonoTests.System.Threading {
  37. // NOTES
  38. // The tests will fails on 2.0 beta 1 (and a few CTP afterwards) because it relies
  39. // on a LinkDemand for ECMA key (and identity permissions now support unrestricted).
  40. [TestFixture]
  41. public class CompressedStackTest {
  42. static bool success;
  43. static void Callback (object o)
  44. {
  45. success = (bool) o;
  46. }
  47. [SetUp]
  48. public void SetUp ()
  49. {
  50. success = false;
  51. Thread.CurrentThread.SetCompressedStack (null);
  52. }
  53. [Test]
  54. public void Capture ()
  55. {
  56. CompressedStack cs1 = CompressedStack.Capture ();
  57. Assert.IsNotNull (cs1, "Capture-1");
  58. CompressedStack cs2 = CompressedStack.Capture ();
  59. Assert.IsNotNull (cs2, "Capture-2");
  60. Assert.IsFalse (cs1.Equals (cs2), "cs1.Equals (cs2)");
  61. Assert.IsFalse (cs2.Equals (cs1), "cs2.Equals (cs1)");
  62. Assert.IsFalse (cs1.GetHashCode () == cs2.GetHashCode (), "GetHashCode");
  63. }
  64. [Test]
  65. public void CreateCopy ()
  66. {
  67. CompressedStack cs1 = CompressedStack.Capture ();
  68. CompressedStack cs2 = cs1.CreateCopy ();
  69. Assert.IsFalse (cs1.Equals (cs2), "cs1.Equals (cs2)");
  70. Assert.IsFalse (cs2.Equals (cs1), "cs2.Equals (cs1)");
  71. Assert.IsFalse (cs1.GetHashCode () == cs2.GetHashCode (), "GetHashCode");
  72. Assert.IsFalse (Object.ReferenceEquals (cs1, cs2), "ReferenceEquals");
  73. }
  74. [Test]
  75. public void GetCompressedStack ()
  76. {
  77. CompressedStack cs1 = CompressedStack.GetCompressedStack ();
  78. Assert.IsNotNull (cs1, "GetCompressedStack");
  79. CompressedStack cs2 = CompressedStack.Capture ();
  80. Assert.IsNotNull (cs2, "Capture");
  81. Assert.IsFalse (cs1.Equals (cs2), "cs1.Equals (cs2)");
  82. Assert.IsFalse (cs2.Equals (cs1), "cs2.Equals (cs1)");
  83. Assert.IsFalse (cs1.GetHashCode () == cs2.GetHashCode (), "GetHashCode");
  84. }
  85. [Test]
  86. [ExpectedException (typeof (ArgumentNullException))]
  87. public void GetObjectData_Null ()
  88. {
  89. StreamingContext sc = new StreamingContext ();
  90. CompressedStack cs = CompressedStack.Capture ();
  91. cs.GetObjectData (null, sc);
  92. }
  93. [Test]
  94. [ExpectedException (typeof (ArgumentException))]
  95. public void Run_Null ()
  96. {
  97. CompressedStack.Run (null, new ContextCallback (Callback), true);
  98. }
  99. [Test]
  100. public void Run_Capture ()
  101. {
  102. Assert.IsFalse (success, "pre-check");
  103. CompressedStack.Run (CompressedStack.Capture (), new ContextCallback (Callback), true);
  104. Assert.IsTrue (success, "post-check");
  105. }
  106. [Test]
  107. public void Run_GetCompressedStack ()
  108. {
  109. Assert.IsFalse (success, "pre-check");
  110. CompressedStack.Run (CompressedStack.GetCompressedStack (), new ContextCallback (Callback), true);
  111. Assert.IsTrue (success, "post-check");
  112. }
  113. [Test]
  114. [ExpectedException (typeof (ArgumentException))]
  115. public void Run_Thread ()
  116. {
  117. // this is because Thread.CurrentThread.GetCompressedStack () returns null for an empty
  118. // compressed stack while CompressedStack.GetCompressedStack () return "something" empty ;-)
  119. CompressedStack.Run (Thread.CurrentThread.GetCompressedStack (), new ContextCallback (Callback), true);
  120. }
  121. }
  122. }
  123. #endif