2 // SynchronizationAttributeTest.cs - Unit tests for
3 // System.Runtime.Remoting.Contexts.SynchronizationAttribute
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.Runtime.Remoting.Contexts;
33 using System.Runtime.Serialization.Formatters.Binary;
35 using NUnit.Framework;
37 namespace MonoTests.System.Runtime.Remoting.Contexts {
40 public class SynchronizationAttributeTest {
43 public void Constructor_Default ()
45 SynchronizationAttribute sa = new SynchronizationAttribute ();
46 Assert.IsFalse (sa.IsReEntrant, "IsReEntrant");
47 Assert.IsFalse (sa.Locked, "Locked");
51 public void Constructor_Bool ()
53 SynchronizationAttribute sa = new SynchronizationAttribute (true);
54 Assert.IsTrue (sa.IsReEntrant, "IsReEntrant");
55 Assert.IsFalse (sa.Locked, "Locked");
59 public void Constructor_Int ()
61 SynchronizationAttribute sa = new SynchronizationAttribute (SynchronizationAttribute.NOT_SUPPORTED);
62 Assert.IsFalse (sa.IsReEntrant, "IsReEntrant");
63 Assert.IsFalse (sa.Locked, "Locked");
67 public void Constructor_IntBool ()
69 SynchronizationAttribute sa = new SynchronizationAttribute (SynchronizationAttribute.NOT_SUPPORTED, true);
70 Assert.IsTrue (sa.IsReEntrant, "IsReEntrant");
71 Assert.IsFalse (sa.Locked, "Locked");
75 public void SerializationRoundtrip ()
77 SynchronizationAttribute sa = new SynchronizationAttribute (SynchronizationAttribute.NOT_SUPPORTED, true);
78 BinaryFormatter bf = new BinaryFormatter ();
79 MemoryStream ms = new MemoryStream ();
80 bf.Serialize (ms, sa);
83 SynchronizationAttribute clone = (SynchronizationAttribute) bf.Deserialize (ms);
85 Assert.IsTrue (sa.IsReEntrant, "IsReEntrant");
86 Assert.IsFalse (sa.Locked, "Locked");
89 static private byte[] serialized_sync_attr = {
90 0x00, 0x01, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00,
91 0x00, 0x00, 0x00, 0x04, 0x01, 0x00, 0x00, 0x00, 0x39, 0x53, 0x79, 0x73, 0x74, 0x65,
92 0x6D, 0x2E, 0x52, 0x75, 0x6E, 0x74, 0x69, 0x6D, 0x65, 0x2E, 0x52, 0x65, 0x6D, 0x6F,
93 0x74, 0x69, 0x6E, 0x67, 0x2E, 0x43, 0x6F, 0x6E, 0x74, 0x65, 0x78, 0x74, 0x73, 0x2E,
94 0x53, 0x79, 0x6E, 0x63, 0x68, 0x72, 0x6F, 0x6E, 0x69, 0x7A, 0x61, 0x74, 0x69, 0x6F,
95 0x6E, 0x41, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x04, 0x00, 0x00, 0x00,
96 0x0B, 0x5F, 0x62, 0x52, 0x65, 0x45, 0x6E, 0x74, 0x72, 0x61, 0x6E, 0x74, 0x07, 0x5F,
97 0x66, 0x6C, 0x61, 0x76, 0x6F, 0x72, 0x0D, 0x41, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75,
98 0x74, 0x65, 0x4E, 0x61, 0x6D, 0x65, 0x1E, 0x43, 0x6F, 0x6E, 0x74, 0x65, 0x78, 0x74,
99 0x41, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x2B, 0x41, 0x74, 0x74, 0x72,
100 0x69, 0x62, 0x75, 0x74, 0x65, 0x4E, 0x61, 0x6D, 0x65, 0x00, 0x00, 0x01, 0x01, 0x01,
101 0x08, 0x01, 0x01, 0x00, 0x00, 0x00, 0x06, 0x02, 0x00, 0x00, 0x00, 0x0F, 0x53, 0x79,
102 0x6E, 0x63, 0x68, 0x72, 0x6F, 0x6E, 0x69, 0x7A, 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x09,
103 0x02, 0x00, 0x00, 0x00, 0x0B
107 public void DeserializeKnownValue ()
109 MemoryStream ms = new MemoryStream (serialized_sync_attr);
111 BinaryFormatter bf = (BinaryFormatter)vmw.@internal.remoting.BinaryFormatterUtils.CreateBinaryFormatter (false);
113 BinaryFormatter bf = new BinaryFormatter ();
115 SynchronizationAttribute sa = (SynchronizationAttribute) bf.Deserialize (ms);
116 Assert.IsTrue (sa.IsReEntrant, "IsReEntrant");
117 Assert.IsFalse (sa.Locked, "Locked");