2006-12-04 Marek Sieradzki <marek.sieradzki@gmail.com>
[mono.git] / mcs / class / Microsoft.Build.Engine / Test / various / Items.cs
1 //
2 // Items.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.Xml;
30 using Microsoft.Build.BuildEngine;
31 using NUnit.Framework;
32
33 namespace MonoTests.Microsoft.Build.BuildEngine.Various {
34         [TestFixture]
35         public class Items {
36                 private string GetItems (Project proj, string name)
37                 {
38                         BuildItemGroup big = proj.GetEvaluatedItemsByName (name);
39                         string str = String.Empty;
40                         if (big == null)
41                                 return str;
42                         
43                         foreach (BuildItem bi in big) {
44                                 if (str == String.Empty)
45                                         str = bi.FinalItemSpec;
46                                 else 
47                                         str += ";" + bi.FinalItemSpec;
48                         }
49                         
50                         return str;
51                 }
52
53                 [Test]
54                 public void TestItems1 ()
55                 {
56                         Engine engine = new Engine (Consts.BinPath);
57                         Project proj = engine.CreateNewProject ();
58
59                         string documentString = @"
60                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
61                                         <ItemGroup>
62                                                 <Item0 Include='A' />
63                                                 <Item1 Include='A;B;C' />
64                                                 <Item2 Include='@(Item1);A;D' />
65                                                 <Item3 Include='@(Item2)' Exclude='A' />
66                                                 <Item4 Include='@(Item1);Q' Exclude='@(Item2)' />
67                                                 <Item5 Include='@(Item1)' Exclude='@(Item2)' />
68                                                 <Item6 Include='@(Item2)' Exclude='@(Item1)' />
69
70                                         </ItemGroup>
71                                 </Project>
72                         ";
73
74                         proj.LoadXml (documentString);
75                         Assert.AreEqual ("A", GetItems (proj, "Item0"), "A1");
76                         Assert.AreEqual ("A;B;C", GetItems (proj, "Item1"), "A2");
77                         Assert.AreEqual ("A;B;C;A;D", GetItems (proj, "Item2"), "A3");
78                         Assert.AreEqual ("B;C;D", GetItems (proj, "Item3"), "A4");
79                         Assert.AreEqual ("Q", GetItems (proj, "Item4"), "A5");
80                         Assert.AreEqual ("", GetItems (proj, "Item5"), "A6");
81                         Assert.AreEqual ("D", GetItems (proj, "Item6"), "A7");
82                 }
83
84                 [Test]
85                 public void TestItems2 ()
86                 {
87                         Engine engine = new Engine (Consts.BinPath);
88                         Project proj = engine.CreateNewProject ();
89
90                         string documentString = @"
91                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
92                                         <ItemGroup>
93                                                 <Item1 Include='A;B;C' />
94                                                 <Item2 Include=""@(Item1,'-')"" />
95                                                 <Item3 Include=""@(Item1,'xx')"" />
96                                         </ItemGroup>
97                                 </Project>
98                         ";
99
100                         proj.LoadXml (documentString);
101
102                         Assert.AreEqual ("A-B-C", GetItems (proj, "Item2"), "A1");
103                         Assert.AreEqual ("AxxBxxC", GetItems (proj, "Item3"), "A2");
104                 }
105
106                 // Will fail on xbuild
107                 [Test]
108                 [Platform ("NET-2.0")]
109                 public void TestItems3 ()
110                 {
111                         Engine engine = new Engine (Consts.BinPath);
112                         Project proj = engine.CreateNewProject ();
113
114                         string documentString = @"
115                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
116                                         <ItemGroup>
117                                                 <Item1 Include='A;B;C' />
118                                                 <Item2 Include=""@(Item1, '-')"" />
119                                         </ItemGroup>
120                                 </Project>
121                         ";
122
123                         proj.LoadXml (documentString);
124
125                         Assert.AreEqual ("A-B-C", GetItems (proj, "Item2"), "A1");
126                 }
127         
128                 [Test]
129                 public void TestItems4 ()
130                 {
131                         Engine engine = new Engine (Consts.BinPath);
132                         Project proj = engine.CreateNewProject ();
133
134                         string documentString = @"
135                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
136                                         <ItemGroup>
137                                                 <Item1 Include='A;B;C' />
138                                                 <Item2 Include=""A\B.txt;A\C.txt;B\B.zip;B\C.zip"" />
139                                                 <ItemT1 Include=""@(Item1->'%(Identity)')"" />
140                                                 <ItemT2 Include=""@(Item1->'%(Identity)%(Identity)')"" />
141                                                 <ItemT3 Include=""@(Item1->'(-%(Identity)-)')"" />
142                                                 <ItemT4 Include=""@(Item2->'%(Extension)')"" />
143                                                 <ItemT5 Include=""@(Item2->'%(Filename)/%(Extension)')"" />
144                                                 <ItemT6 Include=""@(Item2->'%(RelativeDir)X/%(Filename)')"" />
145                                         </ItemGroup>
146                                 </Project>
147                         ";
148
149                         proj.LoadXml (documentString);
150
151                         Assert.AreEqual ("A;B;C", GetItems (proj, "ItemT1"), "A8");
152                         Assert.AreEqual ("AA;BB;CC", GetItems (proj, "ItemT2"), "A9");
153                         Assert.AreEqual ("(-A-);(-B-);(-C-)", GetItems (proj, "ItemT3"), "A10");
154                         Assert.AreEqual (".txt;.txt;.zip;.zip", GetItems (proj, "ItemT4"), "A11");
155                         Assert.AreEqual ("B/.txt;C/.txt;B/.zip;C/.zip", GetItems (proj, "ItemT5"), "A12");
156                         Assert.AreEqual (@"A\X/B;A\X/C;B\X/B;B\X/C", GetItems (proj, "ItemT6"), "A13");
157
158                 }
159         }
160 }