[System] Fixes UdpClient.Receive with IPv6 endpoint
[mono.git] / mcs / class / Microsoft.Build.Engine / Test / various / Properties.cs
1 //
2 // Properties.cs
3 //
4 // Authors:
5 //   Marek Sieradzki (marek.sieradzki@gmail.com)
6 //   Marek Safar (marek.safar@gmail.com)
7 //
8 // (C) 2006 Marek Sieradzki
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 using System;
30 using System.Xml;
31 using Microsoft.Build.BuildEngine;
32 using NUnit.Framework;
33
34 namespace MonoTests.Microsoft.Build.BuildEngine.Various {
35         [TestFixture]
36         public class Properties {
37
38                 Project proj;
39
40                 [SetUp]
41                 public void Setup ()
42                 {
43                         Engine engine = new Engine (Consts.BinPath);
44                         proj = engine.CreateNewProject ();
45                 }
46
47                 [Test]
48                 public void PropertyReference ()
49                 {
50                         string documentString = @"
51                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
52                                         <PropertyGroup>
53                                                 <Config>debug</Config>
54                                                 <ExpProp>$(Config)-$(Config)</ExpProp>
55                                                 <ExpProp2> $(Config) $(Config) </ExpProp2>
56                                                 <InvProp1>$(Config-$(Config)</InvProp1>
57                                         </PropertyGroup>
58                                 </Project>
59                         ";
60
61                         proj.LoadXml (documentString);
62                         Assert.AreEqual (1, proj.PropertyGroups.Count, "A1");
63                         Assert.AreEqual ("debug", proj.GetEvaluatedProperty ("Config"), "A2");
64                         Assert.AreEqual ("debug-debug", proj.GetEvaluatedProperty ("ExpProp"), "A3");
65                         Assert.AreEqual (" debug debug ", proj.GetEvaluatedProperty ("ExpProp2"), "A4");        
66                         Assert.AreEqual ("$(Config-$(Config)", proj.GetEvaluatedProperty ("InvProp1"), "A5");
67                 }
68
69                 [Test]
70                 [Category ("NotDotNet")]
71                 public void PropertyReference2 ()
72                 {
73                         string documentString = @"
74                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
75                                         <UsingTask TaskName='StringTestTask' AssemblyFile='Test\resources\TestTasks.dll' />
76                                         <PropertyGroup>
77                                                 <A>A</A>
78                                                 <B>B</B>
79                                         </PropertyGroup>
80
81                                         <Target Name='Main' >
82                                                 <StringTestTask Array='$(A)$(B)'>
83                                                         <Output TaskParameter='Array' ItemName='Out' />
84                                                 </StringTestTask>
85                                         </Target>
86                                 </Project>
87                         ";
88
89                         proj.LoadXml (documentString);
90                         proj.Build ("Main");
91                         Assert.AreEqual (1, proj.GetEvaluatedItemsByName ("Out").Count, "A1");
92                         Assert.AreEqual ("AB", proj.GetEvaluatedItemsByName ("Out") [0].Include, "A2");
93                 }
94
95                 [Test]
96                 public void StringInstanceProperties ()
97                 {
98                         string documentString = @"
99                                         <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
100                                                 <PropertyGroup>
101                                                         <Config>debug</Config>
102                                                         <NullValue>null</NullValue>
103                                                         <TargetValue>  </TargetValue>
104                                                         <Prop1>$(Config.Substring(0,3)) </Prop1>
105                                                         <Prop2>$(Config.Length )</Prop2>
106                                                         <Prop3>$(Config.StartsWith ('DE', System.StringComparison.OrdinalIgnoreCase))</Prop3>
107                                                         <Prop4>$(NullValue.StartsWith ('Te', StringComparison.OrdinalIgnoreCase))</Prop4>
108                                                         <Prop5>$(TargetValue.Trim('\\'))</Prop5>
109                                                 </PropertyGroup>
110                                         </Project>
111                                 ";
112
113                         proj.LoadXml (documentString);
114                         Assert.AreEqual ("deb ", proj.GetEvaluatedProperty ("Prop1"), "#1");
115                         Assert.AreEqual ("5", proj.GetEvaluatedProperty ("Prop2"), "#2");
116                         Assert.AreEqual ("True", proj.GetEvaluatedProperty ("Prop3"), "#3");
117                         Assert.AreEqual ("False", proj.GetEvaluatedProperty ("Prop4"), "#4");
118                         Assert.AreEqual ("", proj.GetEvaluatedProperty ("Prop5"), "#5");
119                 }
120
121                 [Test]
122                 public void AllowedFrameworkMembers ()
123                 {
124                         string documentString = @"
125                                         <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
126                                                 <PropertyGroup>
127                                                         <Prop1>$([System.Byte]::MaxValue)</Prop1>
128                                                         <Prop2>$([System.math]::Abs (-4.2) )</Prop2>
129                                                         <Prop3>$([System.DateTime]::Today )</Prop3>
130                                                         <Prop4>$([System.Char]::GetNumericValue('3'))</Prop4>
131                                                         <Prop5>$([System.String]::Compare (Null, nUll))</Prop5>
132                                                         <Prop6>$([System.Environment]::GetLogicalDrives ( ))</Prop6>
133                                                         <Prop7>$([System.String]::Concat (`,`, `n`, `,`))</Prop7>
134                                                 </PropertyGroup>
135                                         </Project>
136                                 ";
137
138                         proj.LoadXml (documentString);
139                         Assert.AreEqual ("255", proj.GetEvaluatedProperty ("Prop1"), "#1");
140                         Assert.AreEqual ("4.2", proj.GetEvaluatedProperty ("Prop2"), "#2");
141                         Assert.AreEqual (DateTime.Today.ToString (), proj.GetEvaluatedProperty ("Prop3"), "#3");
142                         Assert.AreEqual ("3", proj.GetEvaluatedProperty ("Prop4"), "#4");
143                         Assert.AreEqual ("0", proj.GetEvaluatedProperty ("Prop5"), "#5");
144                         Assert.AreEqual (string.Join (";", Environment.GetLogicalDrives ()), proj.GetEvaluatedProperty ("Prop6"), "#6");
145                         Assert.AreEqual (",n,", proj.GetEvaluatedProperty ("Prop7"), "#7");
146                 }
147
148                 [Test]
149                 public void InstanceMethodOnStaticProperty ()
150                 {
151                         string documentString = @"
152                                         <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
153                                                 <PropertyGroup>
154                                                         <Prop1>$([System.DateTime]::Now.ToString(""yyyy.MM.dd""))</Prop1>
155                                                 </PropertyGroup>
156                                         </Project>
157                                 ";
158
159                         proj.LoadXml (documentString);
160                         Assert.AreEqual (DateTime.Now.ToString ("yyyy.MM.dd"), proj.GetEvaluatedProperty ("Prop1"), "#1");
161                 }
162
163                 [Test]
164                 public void InstanceMemberOnStaticProperty ()
165                 {
166                         string documentString = @"
167                                         <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
168                                                 <PropertyGroup>
169                                                         <Prop1>$([System.DateTime]::Now.Year)</Prop1>
170                                                 </PropertyGroup>
171                                         </Project>
172                                 ";
173
174                         proj.LoadXml (documentString);
175                         Assert.AreEqual (DateTime.Now.Year.ToString (), proj.GetEvaluatedProperty ("Prop1"), "#1");
176                 }
177
178                 [Test]
179                 public void InstanceMembersOnStaticMethod ()
180                 {
181                         string documentString = @"
182                                         <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
183                                                 <PropertyGroup>
184                                                         <Prop1>$([System.String]::Concat('a', 'bb', 'c').Length.GetHashCode ())</Prop1>
185
186                                                 </PropertyGroup>
187                                         </Project>
188                                 ";
189
190                         proj.LoadXml (documentString);
191                         Assert.AreEqual (4.GetHashCode ().ToString (), proj.GetEvaluatedProperty ("Prop1"), "#1");
192                 }
193
194                 [Test]
195                 public void MSBuildPropertyFunctions ()
196                 {
197                         string documentString = @"
198                                         <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
199                                                 <PropertyGroup>
200                                                         <NumberOne>0.6</NumberOne>
201                                                         <NumberTwo>6</NumberTwo>
202                                                         <Prop1>$([MSBuild]::Add($(NumberOne), $(NumberTwo)))</Prop1>
203                                                 </PropertyGroup>
204                                         </Project>
205                                 ";
206
207                         proj.LoadXml (documentString);
208                         Assert.AreEqual ("6.6", proj.GetEvaluatedProperty ("Prop1"), "#1");
209                 }
210
211                 [Test]
212                 public void Constructor ()
213                 {
214                         string documentString = @"
215                                         <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
216                                                 <PropertyGroup>
217                                                         <NumberOne>0.6</NumberOne>
218                                                         <NumberTwo>6</NumberTwo>
219                                                         <Prop1>$([System.String]::new('value').EndsWith ('ue'))</Prop1>
220                                                 </PropertyGroup>
221                                         </Project>
222                                 ";
223
224                         proj.LoadXml (documentString);
225                         Assert.AreEqual ("True", proj.GetEvaluatedProperty ("Prop1"), "#1");
226                 }
227         }
228 }