New test.
[mono.git] / mcs / class / Microsoft.Build.Engine / Test / Microsoft.Build.BuildEngine / BuildPropertyTest.cs
1 //
2 // BuildPropertyTest.cs
3 //
4 // Author:
5 //   Marek Sieradzki (marek.sieradzki@gmail.com)
6 //
7 // (C) 2006 Marek Sieradzki
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
28 using System;
29 using System.Collections;
30 using Microsoft.Build.BuildEngine;
31 using Microsoft.Build.Framework;
32 using Microsoft.Build.Utilities;
33 using NUnit.Framework;
34
35 namespace MonoTests.Microsoft.Build.BuildEngine {
36         [TestFixture]
37         public class BuildPropertyTest {
38                 
39                 BuildProperty   bp;
40                 string          binPath;
41                 Engine          engine;
42                 Project         project;
43                 
44                 [SetUp]
45                 public void SetUp ()
46                 {
47                         binPath = "../../tools/xbuild/xbuild";
48                 }
49                 
50                 [Test]
51                 public void TestCtor1 ()
52                 {
53                         string name = "name";
54                         string value = "value";
55                 
56                         bp = new BuildProperty (name, value);
57                         
58                         Assert.AreEqual (name, bp.Name, "A1");
59                         Assert.AreEqual (value, bp.Value, "A2");
60                         Assert.AreEqual (String.Empty, bp.Condition, "A3");
61                         Assert.AreEqual (value, bp.FinalValue, "A4");
62                         Assert.AreEqual (false, bp.IsImported, "A5");
63                         Assert.AreEqual (value, bp.ToString (), "A6");
64                 
65                         name = "name";
66                         value = "$(AnotherProperty)";
67                 
68                         bp = new BuildProperty (name, value);
69                         
70                         Assert.AreEqual (name, bp.Name, "A7");
71                         Assert.AreEqual (value, bp.Value, "A8");
72                         Assert.AreEqual (String.Empty, bp.Condition, "A9");
73                         Assert.AreEqual (value, bp.FinalValue, "A10");
74                         Assert.AreEqual (false, bp.IsImported, "A11");
75                         Assert.AreEqual (value, bp.ToString (), "A12");
76                 }
77                 
78                 [Test]
79                 [ExpectedException (typeof (ArgumentNullException),
80                         "Parameter \"propertyName\" cannot be null.")]
81                 public void TestCtor2 ()
82                 {
83                         bp = new BuildProperty (null, "value");
84                         
85                 }
86                 
87                 [Test]
88                 [ExpectedException (typeof (ArgumentNullException),
89                         "Parameter \"propertyValue\" cannot be null.")]
90                 public void TestCtor3 ()
91                 {
92                         bp = new BuildProperty ("name", null);
93                         
94                 }
95
96                 [Test]
97                 [ExpectedException (typeof (InvalidOperationException),
98                         "A shallow clone of this object cannot be created.")]
99                 public void TestClone1 ()
100                 {
101                         bp = new BuildProperty ("name", "value");
102                         
103                         bp.Clone (false);
104                 }
105
106                 [Test]
107                 public void TestClone2 ()
108                 {
109                         bp = new BuildProperty ("name", "value");
110                         
111                         bp.Clone (true);
112                 }
113                 
114                 [Test]
115                 public void TestClone3 ()
116                 {
117                         BuildProperty a,b;
118                         
119                         string documentString = @"
120                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
121                                         <PropertyGroup>
122                                                 <Name>Value</Name>
123                                         </PropertyGroup>
124                                 </Project>
125                         ";
126
127                         engine = new Engine (binPath);
128
129                         project = engine.CreateNewProject ();
130                         project.LoadXml (documentString);
131
132                         a = project.EvaluatedProperties ["Name"];
133                         Assert.AreEqual ("Value", a.Value, "A1");
134                         
135                         b = a.Clone (false);
136                         
137                         b.Value = "AnotherValue";
138                         Assert.AreEqual ("Value", a.Value, "A2");
139                 }
140
141                 [Test]
142                 public void TestClone4 ()
143                 {
144                         BuildProperty a,b;
145                         
146                         string documentString = @"
147                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
148                                         <PropertyGroup>
149                                                 <Name>Value</Name>
150                                         </PropertyGroup>
151                                 </Project>
152                         ";
153
154                         engine = new Engine (binPath);
155
156                         project = engine.CreateNewProject ();
157                         project.LoadXml (documentString);
158
159                         a = project.EvaluatedProperties ["Name"];
160                         Assert.AreEqual ("Value", a.Value, "A1");
161                         
162                         b = a.Clone (true);
163                         
164                         b.Value = "AnotherValue";
165                         Assert.AreEqual ("Value", a.Value, "A2");
166                 }
167
168                 [Test]
169                 public void TestClone5 ()
170                 {
171                         BuildProperty a,b;
172                         IList properties = new ArrayList ();
173                         
174                         string documentString = @"
175                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
176                                         <PropertyGroup>
177                                                 <Name>Value</Name>
178                                         </PropertyGroup>
179                                 </Project>
180                         ";
181
182                         engine = new Engine (binPath);
183
184                         project = engine.CreateNewProject ();
185                         project.LoadXml (documentString);
186
187                         foreach (BuildPropertyGroup bpg in project.PropertyGroups)
188                                 foreach (BuildProperty bpr in bpg)
189                                         properties.Add (bpr);
190                         
191                         a = (BuildProperty) properties [0];
192                         Assert.AreEqual ("Value", a.Value, "A1");
193                         
194                         b = a.Clone (false);
195                         
196                         b.Value = "AnotherValue";
197                         Assert.AreEqual ("Value", a.Value, "A2");
198                 }
199
200                 [Test]
201                 public void TestClone6 ()
202                 {
203                         BuildProperty a,b;
204                         IList properties = new ArrayList ();
205                         
206                         string documentString = @"
207                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
208                                         <PropertyGroup>
209                                                 <Name>Value</Name>
210                                         </PropertyGroup>
211                                 </Project>
212                         ";
213
214                         engine = new Engine (binPath);
215
216                         project = engine.CreateNewProject ();
217                         project.LoadXml (documentString);
218
219                         foreach (BuildPropertyGroup bpg in project.PropertyGroups)
220                                 foreach (BuildProperty bpr in bpg)
221                                         properties.Add (bpr);
222                         
223                         a = (BuildProperty) properties [0];
224                         Assert.AreEqual ("Value", a.Value, "A1");
225                         
226                         b = a.Clone (true);
227                         
228                         b.Value = "AnotherValue";
229                         Assert.AreEqual ("Value", a.Value, "A2");
230                 }
231                 
232                 [Test]
233                 public void TestOpExplicit ()
234                 {
235                         bp = new BuildProperty ("name", "value");
236                         
237                         Assert.AreEqual ("value", (string) bp, "A1");
238                 }
239                 
240                 [Test]
241                 public void TestToString ()
242                 {
243                         bp = new BuildProperty ("name", "a;b");
244                         Assert.AreEqual ("a;b", bp.ToString ());
245                 }
246         }
247 }