LosFormatterTest.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. //
  2. // LosFormatterTest.cs - Unit tests for System.Web.UI.LosFormatter
  3. //
  4. // Author:
  5. // Gert Driesen <[email protected]>
  6. //
  7. // Copyright (C) 2007 Gert Driesen
  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. using System;
  29. using System.IO;
  30. using System.Text;
  31. using System.Web.UI;
  32. using NUnit.Framework;
  33. namespace MonoTests.System.Web.UI
  34. {
  35. [TestFixture]
  36. public class LosFormatterTest
  37. {
  38. [Test] // bug #81851
  39. public void Serialize ()
  40. {
  41. string s = "Hello world";
  42. LosFormatter lf = new LosFormatter ();
  43. StringWriter sw = new StringWriter ();
  44. lf.Serialize (sw, s);
  45. string s1 = sw.ToString ();
  46. Assert.IsNotNull (s1, "#1");
  47. string s2 = lf.Deserialize (s1) as string;
  48. Assert.IsNotNull (s2, "#2");
  49. Assert.AreEqual (s, s2, "#3");
  50. }
  51. [Test]
  52. [Category ("NotWorking")]
  53. public void Serialize_Output ()
  54. {
  55. string s = "Hello world";
  56. LosFormatter lf = new LosFormatter ();
  57. StringWriter sw = new StringWriter ();
  58. lf.Serialize (sw, s);
  59. string s1 = sw.ToString ();
  60. #if NET_2_0
  61. Assert.AreEqual ("/wEFC0hlbGxvIHdvcmxk", s1, "#1");
  62. #else
  63. Assert.AreEqual ("SGVsbG8gd29ybGQ=", s1, "#1");
  64. #endif
  65. string s2 = lf.Deserialize (s1) as string;
  66. Assert.IsNotNull (s2, "#2");
  67. Assert.AreEqual (s, s2, "#3");
  68. }
  69. [Test]
  70. [Category ("NotDotNet")] // MS throws NullReferenceException
  71. public void Serialize_Output_Null ()
  72. {
  73. LosFormatter lf = new LosFormatter ();
  74. try {
  75. lf.Serialize ((TextWriter) null, "test");
  76. Assert.Fail ("#1");
  77. } catch (ArgumentNullException ex) {
  78. Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
  79. Assert.IsNull (ex.InnerException, "#3");
  80. Assert.IsNotNull (ex.Message, "#4");
  81. Assert.IsNotNull (ex.ParamName, "#5");
  82. Assert.AreEqual ("output", ex.ParamName, "#6");
  83. }
  84. }
  85. [Test]
  86. [Category ("NotWorking")]
  87. public void Serialize_Stream ()
  88. {
  89. string s = "Hello world";
  90. LosFormatter lf = new LosFormatter ();
  91. MemoryStream ms = new MemoryStream ();
  92. lf.Serialize (ms, s);
  93. string s1 = Encoding.UTF8.GetString (ms.GetBuffer (), 0, (int) ms.Length);
  94. #if NET_2_0
  95. Assert.AreEqual ("/wEFC0hlbGxvIHdvcmxk", s1, "#1");
  96. #else
  97. Assert.AreEqual ("SGVsbG8gd29ybGQ=", s1, "#1");
  98. #endif
  99. string s2 = lf.Deserialize (s1) as string;
  100. Assert.IsNotNull (s2, "#2");
  101. Assert.AreEqual (s, s2, "#3");
  102. }
  103. [Test]
  104. public void Serialize_Stream_Null ()
  105. {
  106. LosFormatter lf = new LosFormatter ();
  107. try {
  108. lf.Serialize ((Stream) null, "test");
  109. Assert.Fail ("#1");
  110. } catch (ArgumentNullException ex) {
  111. Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
  112. Assert.IsNull (ex.InnerException, "#3");
  113. Assert.IsNotNull (ex.Message, "#4");
  114. Assert.IsNotNull (ex.ParamName, "#5");
  115. Assert.AreEqual ("stream", ex.ParamName, "#6");
  116. }
  117. }
  118. [Test]
  119. [Category ("NotWorking")]
  120. public void Serialize_Value_Null ()
  121. {
  122. LosFormatter lf = new LosFormatter ();
  123. MemoryStream ms = new MemoryStream ();
  124. lf.Serialize (ms, null);
  125. string s1 = Encoding.UTF8.GetString (ms.GetBuffer (), 0, (int) ms.Length);
  126. #if NET_2_0
  127. Assert.AreEqual ("/wFk", s1, "#1");
  128. #else
  129. Assert.AreEqual (string.Empty, s1, "#1");
  130. #endif
  131. StringWriter sw = new StringWriter ();
  132. lf.Serialize (sw, null);
  133. string s2 = sw.ToString ();
  134. #if NET_2_0
  135. Assert.AreEqual ("/wFk", s1, "#2");
  136. #else
  137. Assert.AreEqual (string.Empty, s1, "#2");
  138. #endif
  139. }
  140. }
  141. }