* roottypes.cs: Rename from tree.cs.
[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                 // FIXME: split it to several tests and add more tests
55                 public void TestItems1 ()
56                 {
57                         Engine engine = new Engine (Consts.BinPath);
58                         Project proj = engine.CreateNewProject ();
59
60                         string documentString = @"
61                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
62                                         <ItemGroup>
63                                                 <Item0 Include=""A"" />
64                                                 <Item1 Include=""A;B;C"" />
65                                                 <Item2 Include=""@(Item1);A;D"" />
66                                                 <Item3 Include=""@(Item2)"" Exclude=""A"" />
67                                                 <Item4 Include=""@(Item1);Q"" Exclude=""@(Item2)"" />
68                                                 <Item5 Include=""@(Item1)"" Exclude=""@(Item2)"" />
69                                                 <Item6 Include=""@(Item2)"" Exclude=""@(Item1)"" />
70
71                                                 <ItemOrig Include=""A\B.txt;A\C.txt;B\B.zip;B\C.zip"" />
72                                                 <ItemT1 Include=""@(Item1->'%(Identity)')"" />
73                                                 <ItemT2 Include=""@(Item1->'%(Identity)%(Identity)')"" />
74                                                 <ItemT3 Include=""@(Item1->'(-%(Identity)-)')"" />
75                                                 <ItemT4 Include=""@(ItemOrig->'%(Extension)')"" />
76                                                 <ItemT5 Include=""@(ItemOrig->'%(Filename)/%(Extension)')"" />
77                                                 <ItemT6 Include=""@(ItemOrig->'%(RelativeDir)X/%(Filename)')"" />
78                                                 
79                                                 <ItemS1 Include=""@(Item1,'-')"" />
80                                                 <ItemS2 Include=""@(Item1,'xx')"" />
81                                                 <ItemS3 Include=""@(Item1, '-')"" />
82                                         </ItemGroup>
83                                 </Project>
84                         ";
85
86                         proj.LoadXml (documentString);
87                         Assert.AreEqual ("A", GetItems (proj, "Item0"), "A1");
88                         Assert.AreEqual ("A;B;C", GetItems (proj, "Item1"), "A2");
89                         Assert.AreEqual ("A;B;C;A;D", GetItems (proj, "Item2"), "A3");
90                         Assert.AreEqual ("B;C;D", GetItems (proj, "Item3"), "A4");
91                         Assert.AreEqual ("Q", GetItems (proj, "Item4"), "A5");
92                         Assert.AreEqual ("", GetItems (proj, "Item5"), "A6");
93                         Assert.AreEqual ("D", GetItems (proj, "Item6"), "A7");
94
95                         Assert.AreEqual ("A;B;C", GetItems (proj, "ItemT1"), "A8");
96                         Assert.AreEqual ("AA;BB;CC", GetItems (proj, "ItemT2"), "A9");
97                         Assert.AreEqual ("(-A-);(-B-);(-C-)", GetItems (proj, "ItemT3"), "A10");
98                         Assert.AreEqual (".txt;.txt;.zip;.zip", GetItems (proj, "ItemT4"), "A11");
99                         Assert.AreEqual ("B/.txt;C/.txt;B/.zip;C/.zip", GetItems (proj, "ItemT5"), "A12");
100                         Assert.AreEqual (@"A\X/B;A\X/C;B\X/B;B\X/C", GetItems (proj, "ItemT6"), "A13");
101
102                         Assert.AreEqual ("A-B-C", GetItems (proj, "ItemS1"), "A14");
103                         Assert.AreEqual ("AxxBxxC", GetItems (proj, "ItemS2"), "A15");
104                         // Will fail.
105                         Assert.AreEqual ("A-B-C", GetItems (proj, "ItemS3"), "A16");
106                 }
107         }
108 }