d0b31f1a8a85acff882023b59c82f55ebb3ba638
[mono.git] / mcs / class / corlib / Test / System.Runtime.Remoting.Contexts / SynchronizationAttributeTest.cs
1 //
2 // SynchronizationAttributeTest.cs - Unit tests for 
3 //      System.Runtime.Remoting.Contexts.SynchronizationAttribute
4 //
5 // Author:
6 //      Sebastien Pouliot  <sebastien@ximian.com>
7 //
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
9 //
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:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
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.
28 //
29
30 using System;
31 using System.IO;
32 using System.Runtime.Remoting.Contexts;
33 using System.Runtime.Serialization.Formatters.Binary;
34
35 using NUnit.Framework;
36
37 namespace MonoTests.System.Runtime.Remoting.Contexts {
38
39         [TestFixture]
40         public class SynchronizationAttributeTest {
41
42                 [Test]
43                 public void Constructor_Default ()
44                 {
45                         SynchronizationAttribute sa = new SynchronizationAttribute ();
46                         Assert.IsFalse (sa.IsReEntrant, "IsReEntrant");
47                         Assert.IsFalse (sa.Locked, "Locked");
48                 }
49
50                 [Test]
51                 public void Constructor_Bool ()
52                 {
53                         SynchronizationAttribute sa = new SynchronizationAttribute (true);
54                         Assert.IsTrue (sa.IsReEntrant, "IsReEntrant");
55                         Assert.IsFalse (sa.Locked, "Locked");
56                 }
57
58                 [Test]
59                 public void Constructor_Int ()
60                 {
61                         SynchronizationAttribute sa = new SynchronizationAttribute (SynchronizationAttribute.NOT_SUPPORTED);
62                         Assert.IsFalse (sa.IsReEntrant, "IsReEntrant");
63                         Assert.IsFalse (sa.Locked, "Locked");
64                 }
65
66                 [Test]
67                 public void Constructor_IntBool ()
68                 {
69                         SynchronizationAttribute sa = new SynchronizationAttribute (SynchronizationAttribute.NOT_SUPPORTED, true);
70                         Assert.IsTrue (sa.IsReEntrant, "IsReEntrant");
71                         Assert.IsFalse (sa.Locked, "Locked");
72                 }
73
74                 [Test]
75                 public void SerializationRoundtrip ()
76                 {
77                         SynchronizationAttribute sa = new SynchronizationAttribute (SynchronizationAttribute.NOT_SUPPORTED, true);
78                         BinaryFormatter bf = new BinaryFormatter ();
79                         MemoryStream ms = new MemoryStream ();
80                         bf.Serialize (ms, sa);
81
82                         ms.Position = 0;
83                         SynchronizationAttribute clone = (SynchronizationAttribute) bf.Deserialize (ms);
84
85                         Assert.IsTrue (sa.IsReEntrant, "IsReEntrant");
86                         Assert.IsFalse (sa.Locked, "Locked");
87                 }
88
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
104                 };
105
106                 [Test]
107                 public void DeserializeKnownValue ()
108                 {
109                         MemoryStream ms = new MemoryStream (serialized_sync_attr);
110 #if TARGET_JVM
111                         BinaryFormatter bf = (BinaryFormatter)vmw.@internal.remoting.BinaryFormatterUtils.CreateBinaryFormatter (false);
112 #else
113                         BinaryFormatter bf = new BinaryFormatter ();
114 #endif // TARGET_JVM
115                         SynchronizationAttribute sa = (SynchronizationAttribute) bf.Deserialize (ms);
116                         Assert.IsTrue (sa.IsReEntrant, "IsReEntrant");
117                         Assert.IsFalse (sa.Locked, "Locked");
118                 }
119         }
120 }