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