2 // BinaryFormatterTest.cs - Unit tests for
3 // System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
6 // Sebastien Pouliot <sebastien@ximian.com>
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Globalization;
33 using System.Runtime.Serialization.Formatters.Binary;
35 using NUnit.Framework;
37 namespace MonoTests.System.Globalization {
40 public class DaylightTimeTest {
43 public void Constructor ()
45 DaylightTime dt = new DaylightTime (DateTime.MinValue, DateTime.MaxValue, TimeSpan.MinValue);
46 Assert.AreEqual (DateTime.MinValue, dt.Start, "Start");
47 Assert.AreEqual (DateTime.MaxValue, dt.End, "End");
48 Assert.AreEqual (TimeSpan.MinValue, dt.Delta, "Delta");
52 public void SerializationRoundtrip ()
54 DaylightTime dt = new DaylightTime (DateTime.MinValue, DateTime.MaxValue, TimeSpan.MinValue);
55 BinaryFormatter bf = new BinaryFormatter ();
56 MemoryStream ms = new MemoryStream ();
57 bf.Serialize (ms, dt);
60 DaylightTime clone = (DaylightTime) bf.Deserialize (ms);
62 Assert.AreEqual (clone.Start, dt.Start, "Start");
63 Assert.AreEqual (clone.End, dt.End, "End");
64 Assert.AreEqual (clone.Delta, dt.Delta, "Delta");
67 static private byte[] serialized_daylighttime = {
68 0x00, 0x01, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
69 0x04, 0x01, 0x00, 0x00, 0x00, 0x21, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6D, 0x2E, 0x47, 0x6C, 0x6F, 0x62,
70 0x61, 0x6C, 0x69, 0x7A, 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x2E, 0x44, 0x61, 0x79, 0x6C, 0x69, 0x67, 0x68,
71 0x74, 0x54, 0x69, 0x6D, 0x65, 0x03, 0x00, 0x00, 0x00, 0x07, 0x6D, 0x5F, 0x73, 0x74, 0x61, 0x72, 0x74,
72 0x05, 0x6D, 0x5F, 0x65, 0x6E, 0x64, 0x07, 0x6D, 0x5F, 0x64, 0x65, 0x6C, 0x74, 0x61, 0x00, 0x00, 0x00,
73 0x0D, 0x0D, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x3F, 0x37, 0xF4, 0x75, 0x28,
74 0xCA, 0x2B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x0B
78 public void DeserializeKnownValue ()
80 MemoryStream ms = new MemoryStream (serialized_daylighttime);
82 BinaryFormatter bf = (BinaryFormatter)vmw.@internal.remoting.BinaryFormatterUtils.CreateBinaryFormatter (false);
84 BinaryFormatter bf = new BinaryFormatter ();
86 DaylightTime dt = (DaylightTime) bf.Deserialize (ms);
87 Assert.AreEqual (DateTime.MinValue, dt.Start, "Start");
88 Assert.AreEqual (DateTime.MaxValue, dt.End, "End");
89 Assert.AreEqual (TimeSpan.MinValue, dt.Delta, "Delta");