[bcl] Remove more NET_2_0 checks from class libs
[mono.git] / mcs / class / System / Test / System.Text.RegularExpressions / RegexRunnerCas.cs
1 //
2 // RegexRunnerCas.cs 
3 //      - CAS unit tests for System.Text.RegularExpressions.RegexRunner
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 #if !MOBILE
32
33 using NUnit.Framework;
34
35 using System;
36 using System.Reflection;
37 using System.Security;
38 using System.Security.Permissions;
39 using System.Text.RegularExpressions;
40
41 namespace MonoCasTests.System.Text.RegularExpressions {
42
43         class TestRegexRunner : RegexRunner {
44
45                 public TestRegexRunner ()
46                 {
47                 }
48
49                 protected override bool FindFirstChar ()
50                 {
51                         return false;
52                 }
53
54                 protected override void Go ()
55                 {
56                 }
57
58                 protected override void InitTrackCount ()
59                 {
60                 }
61
62                 // easier to test from inside
63                 public void Test ()
64                 {
65                         // abstract (and protected) stuff
66                         Assert.IsFalse (this.FindFirstChar (), "FindFirstChar");
67                         Go ();
68                         InitTrackCount ();
69
70                         // protected stuff
71                         Assert.IsNull (runcrawl, "runcrawl");
72                         runcrawl = new int[3] { 0, 0, 0 };
73                         Assert.AreEqual (0, runcrawlpos, "runcrawlpos");
74                         runcrawlpos = 1;
75                         Assert.IsNull (runmatch, "runmatch");
76                         runmatch = Match.Empty;
77                         Assert.IsNull (runregex, "runregex");
78                         runregex = new Regex (String.Empty);
79                         Assert.IsNull (runstack, "runstack");
80                         runstack = new int[3] { 0, 0, 0 };
81                         Assert.AreEqual (0, runstackpos, "runstackpos");
82                         runstackpos = 1;
83                         Assert.IsNull (runtext, "runtext");
84                         runtext = "mono";
85                         Assert.AreEqual (0, runtextbeg, "runtextbeg");
86                         runtextbeg = 1;
87                         Assert.AreEqual (0, runtextend, "runtextend");
88                         runtextend = 1;
89                         Assert.AreEqual (0, runtextpos, "runtextpos");
90                         runtextpos = 1;
91                         Assert.AreEqual (0, runtextstart, "runtextstart");
92                         runtextstart = 1;
93                         Assert.IsNull (runtrack, "runtrack");
94                         runtrack = new int[3] { 0, 0, 0 };
95                         Assert.AreEqual (0, runtrackcount, "runtrackcount");
96                         runtrackcount = 1;
97                         Assert.AreEqual (0, runtrackpos, "runtrackpos");
98                         runtrackpos = 1;
99
100                         Capture (0, 0, 0);
101                         Assert.IsTrue (CharInSet ('a', "a", ""), "CharInSet");
102                         Crawl (1);
103                         Assert.AreEqual (4, Crawlpos (), "Crawlpos");
104                         DoubleCrawl ();
105                         DoubleStack ();
106                         DoubleTrack ();
107                         EnsureStorage ();
108                         Assert.IsFalse (IsBoundary (0, 0, 0), "IsBoundary");
109                         Assert.IsFalse (IsECMABoundary (0, 0, 0), "IsECMABoundary");
110                         Assert.IsTrue (IsMatched (0), "IsMatched");
111                         Assert.AreEqual (0, MatchIndex (0), "MatchIndex");
112                         Assert.AreEqual (0, MatchLength (0), "MatchLength");
113                         Assert.AreEqual (1, Popcrawl (), "Popcrawl");
114                         TransferCapture (0, 0, 0, 0);
115                         Uncapture ();
116                         Assert.IsNotNull (Scan (new Regex (String.Empty), "mono", 0, 0, 0, 0, true), "Scan");
117                         Assert.IsTrue (CharInSet ('a', "a", String.Empty), "CharInSet");
118                 }
119         }
120
121         [TestFixture]
122         [Category ("CAS")]
123         public class RegexRunnerCas {
124
125                 [SetUp]
126                 public void SetUp ()
127                 {
128                         if (!SecurityManager.SecurityEnabled)
129                                 Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
130                 }
131
132                 [Test]
133                 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
134                 [Category ("NotWorking")]
135                 public void Deny_Unrestricted ()
136                 {
137                         TestRegexRunner runner = new TestRegexRunner ();
138                         runner.Test ();
139                 }
140
141                 [Test]
142                 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
143                 public void LinkDemand_Deny_Unrestricted ()
144                 {
145                         ConstructorInfo ci = typeof (TestRegexRunner).GetConstructor (new Type[0]);
146                         Assert.IsNotNull (ci, "default .ctor");
147                         Assert.IsNotNull (ci.Invoke (null), "invoke");
148                 }
149         }
150 }
151
152 #endif