Merge pull request #1513 from akoeplinger/remove-net20-ifdefs
[mono.git] / mcs / class / System / Test / System.CodeDom.Compiler / CompilerInfoCas.cs
1 //
2 // CompilerInfoCas.cs -
3 //      CAS unit tests for System.CodeDom.Compiler.CompilerInfo
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
31 using NUnit.Framework;
32
33 using System;
34 using System.IO;
35 using System.CodeDom;
36 using System.CodeDom.Compiler;
37 using System.Reflection;
38 using System.Security;
39 using System.Security.Permissions;
40
41 using MCSharp = Microsoft.CSharp;
42 using MonoTests.System.CodeDom.Compiler;
43
44 namespace MonoCasTests.System.CodeDom.Compiler {
45
46         [TestFixture]
47         [Category ("CAS")]
48         [Category ("NotWorking")] // FIXME: missing config stuff ???
49         public class CompilerInfoCas {
50
51                 private CompilerInfo ci;
52
53                 [TestFixtureSetUp]
54                 public void FixtureSetUp ()
55                 {
56                         ci = CodeDomProvider.GetCompilerInfo ("c#");
57                 }
58
59                 [SetUp]
60                 public void SetUp ()
61                 {
62                         if (!SecurityManager.SecurityEnabled)
63                                 Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
64                 }
65                 
66                 [Test]
67                 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
68                 public void Default ()
69                 {
70                         Assert.AreEqual (typeof (MCSharp.CSharpCodeProvider), ci.CodeDomProviderType, "CodeDomProviderType");
71                         Assert.IsTrue (ci.IsCodeDomProviderTypeValid, "IsCodeDomProviderTypeValid");
72
73                         Assert.IsTrue (ci.Equals (ci), "Equals");
74                         Assert.IsTrue (ci.GetHashCode () != 0, "GetHashCode");
75                         Assert.AreEqual (2, ci.GetExtensions ().Length, "GetExtensions"); // .cs cs
76                         Assert.AreEqual (3, ci.GetLanguages ().Length, "GetLanguages"); // c# cs csharp
77
78                         try {
79                                 Assert.IsNotNull (ci.CreateDefaultCompilerParameters (), "CreateDefaultCompilerParameters");
80                         }
81                         catch (NotImplementedException) {
82                                 // mono
83                         }
84                 }
85
86                 [Test]
87                 // no restriction
88                 public void CreateProvider_No_Restriction ()
89                 {
90                         Assert.IsNotNull (ci.CreateProvider (), "CreateProvider");
91                 }
92
93                 [Test]
94                 [EnvironmentPermission (SecurityAction.Deny, Read = "Mono")]
95                 [ExpectedException (typeof (SecurityException))]
96                 public void CreateProvider_Deny_Anything ()
97                 {
98                         ci.CreateProvider ();
99                 }
100
101                 [Test]
102                 public void LinkDemand_No_Restriction ()
103                 {
104                         MethodInfo mi = typeof (CompilerInfo).GetProperty ("IsCodeDomProviderTypeValid").GetGetMethod ();
105                         Assert.IsNotNull (mi, "IsCodeDomProviderTypeValid");
106                         Assert.IsTrue ((bool) mi.Invoke (ci, null), "invoke");
107                 }
108
109                 [Test]
110                 [EnvironmentPermission (SecurityAction.Deny, Read = "Mono")]
111                 [ExpectedException (typeof (SecurityException))]
112                 public void LinkDemand_Deny_Anything ()
113                 {
114                         // denying anything results in a non unrestricted permission set
115                         MethodInfo mi = typeof (CompilerInfo).GetProperty ("IsCodeDomProviderTypeValid").GetGetMethod ();
116                         Assert.IsNotNull (mi, "IsCodeDomProviderTypeValid");
117                         Assert.IsTrue ((bool) mi.Invoke (ci, null), "invoke");
118                 }
119         }
120 }
121