2 // LosFormatterTest.cs - Unit tests for System.Web.UI.LosFormatter
5 // Gert Driesen <drieseng@users.sourceforge.net>
7 // Copyright (C) 2007 Gert Driesen
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:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
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.
34 using NUnit.Framework;
36 namespace MonoTests.System.Web.UI
39 public class LosFormatterTest
42 public void Deserialize_Stream_NonSeekable ()
44 string s1 = "Hello world";
45 NonSeekableStream ns = new NonSeekableStream ();
46 LosFormatter lf = new LosFormatter ();
47 lf.Serialize (ns, s1);
49 string s2 = lf.Deserialize (ns) as string;
50 Assert.AreEqual (s1, s2);
54 public void Serialize ()
56 string s = "Hello world";
57 LosFormatter lf = new LosFormatter ();
58 StringWriter sw = new StringWriter ();
60 string s1 = sw.ToString ();
61 Assert.IsNotNull (s1, "#1");
62 string s2 = lf.Deserialize (s1) as string;
63 Assert.IsNotNull (s2, "#2");
64 Assert.AreEqual (s, s2, "#3");
68 [Category ("NotWorking")]
69 public void Serialize_Output ()
71 string s = "Hello world";
72 LosFormatter lf = new LosFormatter ();
73 StringWriter sw = new StringWriter ();
75 string s1 = sw.ToString ();
77 Assert.AreEqual ("/wEFC0hlbGxvIHdvcmxk", s1, "#1");
79 Assert.AreEqual ("SGVsbG8gd29ybGQ=", s1, "#1");
81 string s2 = lf.Deserialize (s1) as string;
82 Assert.IsNotNull (s2, "#2");
83 Assert.AreEqual (s, s2, "#3");
87 [Category ("NotDotNet")] // MS throws NullReferenceException
88 public void Serialize_Output_Null ()
90 LosFormatter lf = new LosFormatter ();
92 lf.Serialize ((TextWriter) null, "test");
94 } catch (ArgumentNullException ex) {
95 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
96 Assert.IsNull (ex.InnerException, "#3");
97 Assert.IsNotNull (ex.Message, "#4");
98 Assert.IsNotNull (ex.ParamName, "#5");
99 Assert.AreEqual ("output", ex.ParamName, "#6");
104 [Category ("NotWorking")]
105 public void Serialize_Stream ()
107 string s = "Hello world";
108 LosFormatter lf = new LosFormatter ();
109 MemoryStream ms = new MemoryStream ();
110 lf.Serialize (ms, s);
111 string s1 = Encoding.UTF8.GetString (ms.GetBuffer (), 0, (int) ms.Length);
113 Assert.AreEqual ("/wEFC0hlbGxvIHdvcmxk", s1, "#1");
115 Assert.AreEqual ("SGVsbG8gd29ybGQ=", s1, "#1");
117 string s2 = lf.Deserialize (s1) as string;
118 Assert.IsNotNull (s2, "#2");
119 Assert.AreEqual (s, s2, "#3");
123 public void Serialize_Stream_Null ()
125 LosFormatter lf = new LosFormatter ();
127 lf.Serialize ((Stream) null, "test");
129 } catch (ArgumentNullException ex) {
130 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
131 Assert.IsNull (ex.InnerException, "#3");
132 Assert.IsNotNull (ex.Message, "#4");
133 Assert.IsNotNull (ex.ParamName, "#5");
134 Assert.AreEqual ("stream", ex.ParamName, "#6");
139 [Category ("NotWorking")]
140 public void Serialize_Value_Null ()
142 LosFormatter lf = new LosFormatter ();
143 MemoryStream ms = new MemoryStream ();
144 lf.Serialize (ms, null);
145 string s1 = Encoding.UTF8.GetString (ms.GetBuffer (), 0, (int) ms.Length);
147 Assert.AreEqual ("/wFk", s1, "#1");
149 Assert.AreEqual (string.Empty, s1, "#1");
152 StringWriter sw = new StringWriter ();
153 lf.Serialize (sw, null);
154 string s2 = sw.ToString ();
156 Assert.AreEqual ("/wFk", s1, "#2");
158 Assert.AreEqual (string.Empty, s1, "#2");
162 class NonSeekableStream : MemoryStream
164 private bool canSeek;
166 public override bool CanSeek {
167 get { return canSeek; }
170 public override long Length {
173 throw new NotSupportedException ();
178 public override long Position {
181 throw new NotSupportedException ();
182 return base.Position;
185 base.Position = value;
189 public override long Seek (long offset, SeekOrigin origin)
192 throw new NotSupportedException ();
193 return base.Seek (offset, origin);