Fixing an issue with output parameters that are of type IntPtr
[castle.git] / AspectSharp / AspectSharp.Lang.Tests / SemanticAnalizerTestCase.cs
blob0891d81054acebdc01cf204acb2d6406492a8fef
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace AspectSharp.Lang.Tests
17 using System;
18 using System.Text;
20 using NUnit.Framework;
22 using AspectSharp.Lang.AST;
23 using AspectSharp.Lang.Steps;
24 using AspectSharp.Lang.Steps.Semantic;
26 /// <summary>
27 /// Summary description for SemanticAnalizerTestCase.
28 /// </summary>
29 [TestFixture]
30 public class SemanticAnalizerTestCase : ParserTestCaseBase
32 [Test]
33 public void InvalidMixinsDeclaration()
35 String content = "mixins [ \"\" : MyType in MyAssemblye ]";
37 Analize( CreateEngineConfiguration( content ) );
38 Assert.IsTrue(_context.HasErrors);
39 AssertOutput("A key must be specified to identify the type in the map;");
42 [Test]
43 public void InvalidInterceptorsDeclaration()
45 String content = "interceptors [ \"\" : MyType in MyAssemblye ]";
47 Analize( CreateEngineConfiguration( content ) );
48 Assert.IsTrue(_context.HasErrors);
49 AssertOutput("A key must be specified to identify the type in the map;");
52 [Test]
53 public void AspectsWithSameName()
55 String content = "aspect McBrother for X end aspect McBrother for Y end";
57 Analize( CreateEngineConfiguration( content ) );
58 Assert.IsTrue(_context.HasErrors);
59 AssertOutput("The name given to an aspect must be unique;");
62 [Test]
63 public void IncludingTheSameMixinTwice()
65 String content = "aspect McBrother for X " +
66 "include Customer " +
67 "include Author " +
68 "include Customer " +
69 "end";
71 Analize( CreateEngineConfiguration( content ) );
72 Assert.IsTrue(_context.HasErrors);
73 AssertOutput("You shouldn't include the same mixin more than one time;");
76 [Test]
77 public void CorrectIncludeUsage()
79 String content = "aspect McBrother for X " +
80 "include Customer " +
81 "include Author " +
82 "end";
84 Analize( CreateEngineConfiguration( content ) );
85 Assert.IsFalse(_context.HasErrors);
88 [Test]
89 public void DuplicatePointcuts()
91 String content = "aspect McBrother for X " +
92 " pointcut method(*) " +
93 " end " +
94 " " +
95 " pointcut method(*) " +
96 " end " +
97 "end";
99 Analize( CreateEngineConfiguration( content ) );
100 Assert.IsTrue(_context.HasErrors);
101 AssertOutput("Duplicated pointcut definition found;");
104 [Test]
105 public void DuplicatePointcutsWithName()
107 String content = "aspect McBrother for X " +
108 " pointcut method(* Name) " +
109 " end " +
110 " " +
111 " pointcut method(* Name) " +
112 " end " +
113 "end";
115 Analize( CreateEngineConfiguration( content ) );
116 Assert.IsTrue(_context.HasErrors);
117 AssertOutput("Duplicated pointcut definition found;");
120 [Test]
121 public void DuplicatePointcutsWithNameAndRetType()
123 String content = "aspect McBrother for X " +
124 " pointcut method(string Name) " +
125 " end " +
126 " " +
127 " pointcut method(String Name) " +
128 " end " +
129 "end";
131 Analize( CreateEngineConfiguration( content ) );
132 Assert.IsTrue(_context.HasErrors);
133 AssertOutput("Duplicated pointcut definition found;");
136 [Test]
137 public void DuplicatePointcutsWithNameArgumentsAndRetType()
139 String content = "aspect McBrother for X " +
140 " pointcut method(string Name(string, int)) " +
141 " end " +
142 " " +
143 " pointcut method(String Name(string, int)) " +
144 " end " +
145 "end";
147 Analize( CreateEngineConfiguration( content ) );
148 Assert.IsTrue(_context.HasErrors);
149 AssertOutput("Duplicated pointcut definition found;");
152 [Test]
153 public void ValidPointcutsWithNameArgumentsAndRetType()
155 String content = "aspect McBrother for X " +
156 " pointcut method(string Name(string, int)) " +
157 " end " +
158 " " +
159 " pointcut method(String Name(int, int)) " +
160 " end " +
161 "end";
163 Analize( CreateEngineConfiguration( content ) );
164 Assert.IsFalse(_context.HasErrors);
167 [Test]
168 public void ValidPointcutsWithName()
170 String content = "aspect McBrother for X " +
171 " pointcut method(* Name(string, int)) " +
172 " end " +
173 " " +
174 " pointcut method(* Name()) " +
175 " end " +
176 "end";
178 Analize( CreateEngineConfiguration( content ) );
179 Assert.IsFalse(_context.HasErrors);
182 [Test]
183 public void InvalidPointcutDeclaration()
185 String content = "aspect McBrother for X " +
186 " pointcut property|propertyread(*) " +
187 " end " +
188 "end";
190 Analize( CreateEngineConfiguration( content ) );
191 Assert.IsTrue(_context.HasErrors);
192 AssertOutput("Meaningless declaration. A pointcut to a property can't be combined with property read or write. This is implied;");
195 [Test]
196 public void DuplicateInterceptorsInPointcut()
198 String content = "aspect McBrother for X " +
199 " pointcut property(* Name) " +
200 " " +
201 " advice(Interceptors.SecurityInterceptor in MyAssembly) " +
202 " advice(Interceptors.SecurityInterceptor in MyAssembly) " +
203 " " +
204 " end " +
205 "end";
207 Analize( CreateEngineConfiguration( content ) );
208 Assert.IsTrue(_context.HasErrors);
209 AssertOutput("Duplicated advices found;");
212 protected EngineConfiguration CreateEngineConfiguration(String content)
214 AspectParser parser = base.CreateParser(content);
215 return parser.Parse();
218 protected SemanticAnalizerStep Analize(EngineConfiguration conf)
220 return Analize(conf, null);
223 protected SemanticAnalizerStep Analize(EngineConfiguration conf, IStep next)
225 SemanticAnalizerStep analizer = new SemanticAnalizerStep();
226 analizer.Next = next;
227 _context = new Context();
228 _context.Error += new ErrorDelegate(OnError);
229 analizer.Process(_context, conf);
230 return analizer;