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                 [Ignore ("Not implemented")]
116                 public void TestClone3 ()
117                 {
118                         BuildProperty a,b;
119                         
120                         string documentString = @"
121                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
122                                         <PropertyGroup>
123                                                 <Name>Value</Name>
124                                         </PropertyGroup>
125                                 </Project>
126                         ";
127
128                         engine = new Engine (binPath);
129
130                         project = engine.CreateNewProject ();
131                         project.LoadXml (documentString);
132
133                         a = project.EvaluatedProperties ["Name"];
134                         Assert.AreEqual ("Value", a.Value, "A1");
135                         
136                         b = a.Clone (false);
137                         
138                         b.Value = "AnotherValue";
139                         Assert.AreEqual ("Value", a.Value, "A2");
140                 }
141
142                 [Test]
143                 [Ignore ("Not implemented")]
144                 public void TestClone4 ()
145                 {
146                         BuildProperty a,b;
147                         
148                         string documentString = @"
149                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
150                                         <PropertyGroup>
151                                                 <Name>Value</Name>
152                                         </PropertyGroup>
153                                 </Project>
154                         ";
155
156                         engine = new Engine (binPath);
157
158                         project = engine.CreateNewProject ();
159                         project.LoadXml (documentString);
160
161                         a = project.EvaluatedProperties ["Name"];
162                         Assert.AreEqual ("Value", a.Value, "A1");
163                         
164                         b = a.Clone (true);
165                         
166                         b.Value = "AnotherValue";
167                         Assert.AreEqual ("Value", a.Value, "A2");
168                 }
169
170                 [Test]
171                 [Ignore ("Not implemented")]
172                 public void TestClone5 ()
173                 {
174                         BuildProperty a,b;
175                         IList properties = new ArrayList ();
176                         
177                         string documentString = @"
178                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
179                                         <PropertyGroup>
180                                                 <Name>Value</Name>
181                                         </PropertyGroup>
182                                 </Project>
183                         ";
184
185                         engine = new Engine (binPath);
186
187                         project = engine.CreateNewProject ();
188                         project.LoadXml (documentString);
189
190                         foreach (BuildPropertyGroup bpg in project.PropertyGroups)
191                                 foreach (BuildProperty bpr in bpg)
192                                         properties.Add (bpr);
193                         
194                         a = (BuildProperty) properties [0];
195                         Assert.AreEqual ("Value", a.Value, "A1");
196                         
197                         b = a.Clone (false);
198                         
199                         b.Value = "AnotherValue";
200                         Assert.AreEqual ("Value", a.Value, "A2");
201                 }
202
203                 [Test]
204                 [Ignore ("Not implemented")]
205                 public void TestClone6 ()
206                 {
207                         BuildProperty a,b;
208                         IList properties = new ArrayList ();
209                         
210                         string documentString = @"
211                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
212                                         <PropertyGroup>
213                                                 <Name>Value</Name>
214                                         </PropertyGroup>
215                                 </Project>
216                         ";
217
218                         engine = new Engine (binPath);
219
220                         project = engine.CreateNewProject ();
221                         project.LoadXml (documentString);
222
223                         foreach (BuildPropertyGroup bpg in project.PropertyGroups)
224                                 foreach (BuildProperty bpr in bpg)
225                                         properties.Add (bpr);
226                         
227                         a = (BuildProperty) properties [0];
228                         Assert.AreEqual ("Value", a.Value, "A1");
229                         
230                         b = a.Clone (true);
231                         
232                         b.Value = "AnotherValue";
233                         Assert.AreEqual ("Value", a.Value, "A2");
234                 }
235                 
236                 [Test]
237                 public void TestOpExplicit ()
238                 {
239                         bp = new BuildProperty ("name", "value");
240                         
241                         Assert.AreEqual ("value", (string) bp, "A1");
242                 }
243                 
244                 [Test]
245                 public void TestToString ()
246                 {
247                         bp = new BuildProperty ("name", "a;b");
248                         Assert.AreEqual ("a;b", bp.ToString ());
249                 }
250         }
251 }