CompressedStackTest.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. #if FEATURE_COMPRESSEDSTACK
  29. using System;
  30. using System.Runtime.Serialization;
  31. using System.Security;
  32. using System.Threading;
  33. using NUnit.Framework;
  34. namespace MonoTests.System.Threading {
  35. // NOTES
  36. // The tests will fails on 2.0 beta 1 (and a few CTP afterwards) because it relies
  37. // on a LinkDemand for ECMA key (and identity permissions now support unrestricted).
  38. [TestFixture]
  39. public class CompressedStackTest {
  40. static bool success;
  41. static void Callback (object o)
  42. {
  43. success = (bool) o;
  44. }
  45. [SetUp]
  46. public void SetUp ()
  47. {
  48. success = false;
  49. }
  50. [Test]
  51. public void Capture ()
  52. {
  53. CompressedStack cs1 = CompressedStack.Capture ();
  54. Assert.IsNotNull (cs1, "Capture-1");
  55. CompressedStack cs2 = CompressedStack.Capture ();
  56. Assert.IsNotNull (cs2, "Capture-2");
  57. Assert.IsFalse (cs1.Equals (cs2), "cs1.Equals (cs2)");
  58. Assert.IsFalse (cs2.Equals (cs1), "cs2.Equals (cs1)");
  59. Assert.IsFalse (cs1.GetHashCode () == cs2.GetHashCode (), "GetHashCode");
  60. }
  61. [Test]
  62. public void CreateCopy ()
  63. {
  64. CompressedStack cs1 = CompressedStack.Capture ();
  65. CompressedStack cs2 = cs1.CreateCopy ();
  66. Assert.IsFalse (cs1.Equals (cs2), "cs1.Equals (cs2)");
  67. Assert.IsFalse (cs2.Equals (cs1), "cs2.Equals (cs1)");
  68. Assert.IsFalse (cs1.GetHashCode () == cs2.GetHashCode (), "GetHashCode");
  69. Assert.IsFalse (Object.ReferenceEquals (cs1, cs2), "ReferenceEquals");
  70. }
  71. [Test]
  72. public void GetCompressedStack ()
  73. {
  74. CompressedStack cs1 = CompressedStack.GetCompressedStack ();
  75. Assert.IsNotNull (cs1, "GetCompressedStack");
  76. CompressedStack cs2 = CompressedStack.Capture ();
  77. Assert.IsNotNull (cs2, "Capture");
  78. Assert.IsFalse (cs1.Equals (cs2), "cs1.Equals (cs2)");
  79. Assert.IsFalse (cs2.Equals (cs1), "cs2.Equals (cs1)");
  80. Assert.IsFalse (cs1.GetHashCode () == cs2.GetHashCode (), "GetHashCode");
  81. }
  82. [Test]
  83. [ExpectedException (typeof (ArgumentNullException))]
  84. public void GetObjectData_Null ()
  85. {
  86. StreamingContext sc = new StreamingContext ();
  87. CompressedStack cs = CompressedStack.Capture ();
  88. cs.GetObjectData (null, sc);
  89. }
  90. [Test]
  91. [ExpectedException (typeof (ArgumentException))]
  92. public void Run_Null ()
  93. {
  94. CompressedStack.Run (null, new ContextCallback (Callback), true);
  95. }
  96. [Test]
  97. public void Run_Capture ()
  98. {
  99. Assert.IsFalse (success, "pre-check");
  100. CompressedStack.Run (CompressedStack.Capture (), new ContextCallback (Callback), true);
  101. Assert.IsTrue (success, "post-check");
  102. }
  103. [Test]
  104. public void Run_GetCompressedStack ()
  105. {
  106. Assert.IsFalse (success, "pre-check");
  107. CompressedStack.Run (CompressedStack.GetCompressedStack (), new ContextCallback (Callback), true);
  108. Assert.IsTrue (success, "post-check");
  109. }
  110. [Test]
  111. [ExpectedException (typeof (ArgumentException))]
  112. public void Run_Thread ()
  113. {
  114. // this is because Thread.CurrentThread.GetCompressedStack () returns null for an empty
  115. // compressed stack while CompressedStack.GetCompressedStack () return "something" empty ;-)
  116. CompressedStack.Run (null, new ContextCallback (Callback), true);
  117. }
  118. }
  119. }
  120. #endif