2 // IndentedTextWriterCas.cs
3 // - CAS unit tests for System.CodeDom.Compiler.IndentedTextWriter
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.
30 using NUnit.Framework;
33 using System.CodeDom.Compiler;
35 using System.Reflection;
36 using System.Security;
37 using System.Security.Permissions;
39 namespace MonoCasTests.System.CodeDom.Compiler {
43 public class IndentedTextWriterCas {
45 private TextWriter writer;
50 if (!SecurityManager.SecurityEnabled)
51 Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
52 writer = new StringWriter ();
56 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
57 public void Defaults_Deny_Unrestricted ()
59 // note: CAS doesn't apply to fields
60 Assert.AreEqual (" ", IndentedTextWriter.DefaultTabString, "DefaultTabString");
63 private void TouchEverything (IndentedTextWriter itw)
65 Assert.AreSame (writer.Encoding, itw.Encoding, "Encoding");
66 Assert.AreEqual (0, itw.Indent, "Indent");
68 Assert.AreSame (writer, itw.InnerWriter, "InnerWriter");
69 Assert.AreEqual (writer.NewLine, itw.NewLine, "NewLine");
72 itw.Write (Char.MinValue);
73 itw.Write (Path.InvalidPathChars); // char[]
74 itw.Write (Double.MinValue);
75 itw.Write (Int32.MinValue);
76 itw.Write (Int64.MaxValue);
77 itw.Write (new object ());
78 itw.Write (Single.MinValue);
79 itw.Write (String.Empty);
80 itw.Write ("{0}", String.Empty);
81 itw.Write ("{0}{1}", Int32.MinValue, Int32.MaxValue);
82 itw.Write ("{0}{1}{2}", Int32.MinValue, 0, Int32.MaxValue);
83 itw.Write (Path.InvalidPathChars, 0, Path.InvalidPathChars.Length);
86 itw.WriteLine (Char.MinValue);
87 itw.WriteLine (Path.InvalidPathChars); // char[]
88 itw.WriteLine (Double.MinValue);
89 itw.WriteLine (Int32.MinValue);
90 itw.WriteLine (Int64.MaxValue);
91 itw.WriteLine (new object ());
92 itw.WriteLine (Single.MinValue);
93 itw.WriteLine (String.Empty);
94 itw.WriteLine (UInt32.MaxValue);
95 itw.WriteLine ("{0}", String.Empty);
96 itw.WriteLine ("{0}{1}", Int32.MinValue, Int32.MaxValue);
97 itw.WriteLine ("{0}{1}{2}", Int32.MinValue, 0, Int32.MaxValue);
98 itw.WriteLine (Path.InvalidPathChars, 0, Path.InvalidPathChars.Length);
99 itw.WriteLineNoTabs (String.Empty);
105 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
106 public void Constructor1_Deny_Unrestricted ()
108 IndentedTextWriter itw = new IndentedTextWriter (writer);
109 TouchEverything (itw);
113 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
114 public void Constructor2_Deny_Unrestricted ()
116 IndentedTextWriter itw = new IndentedTextWriter (writer, "\t");
117 TouchEverything (itw);
121 public void LinkDemand_No_Restriction ()
123 Type[] types = new Type[1] { typeof (TextWriter) };
124 ConstructorInfo ci = typeof (IndentedTextWriter).GetConstructor (types);
125 Assert.IsNotNull (ci, ".ctor(TextWriter)");
126 Assert.IsNotNull (ci.Invoke (new object[1] { writer }), "invoke");
130 [EnvironmentPermission (SecurityAction.Deny, Read = "Mono")]
131 [ExpectedException (typeof (SecurityException))]
132 public void LinkDemand_Deny_Anything ()
134 // denying anything results in a non unrestricted permission set
135 Type[] types = new Type[1] { typeof (TextWriter) };
136 ConstructorInfo ci = typeof (IndentedTextWriter).GetConstructor (types);
137 Assert.IsNotNull (ci, ".ctor(TextWriter)");
138 Assert.IsNotNull (ci.Invoke (new object[1] { writer }), "invoke");