// // Items.cs // // Author: // Marek Sieradzki (marek.sieradzki@gmail.com) // // (C) 2006 Marek Sieradzki // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the // "Software"), to deal in the Software without restriction, including // without limitation the rights to use, copy, modify, merge, publish, // distribute, sublicense, and/or sell copies of the Software, and to // permit persons to whom the Software is furnished to do so, subject to // the following conditions: // // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. using System; using System.IO; using System.Xml; using Microsoft.Build.BuildEngine; using NUnit.Framework; namespace MonoTests.Microsoft.Build.BuildEngine.Various { [TestFixture] public class Items { private string GetItems (Project proj, string name) { BuildItemGroup big = proj.GetEvaluatedItemsByName (name); string str = String.Empty; if (big == null) return str; foreach (BuildItem bi in big) { if (str == String.Empty) str = bi.FinalItemSpec; else str += ";" + bi.FinalItemSpec; } return str; } [Test] public void TestItems1 () { Engine engine = new Engine (Consts.BinPath); Project proj = engine.CreateNewProject (); string documentString = @" "; proj.LoadXml (documentString); Assert.AreEqual ("A", GetItems (proj, "Item0"), "A1"); Assert.AreEqual ("A;B;C", GetItems (proj, "Item1"), "A2"); Assert.AreEqual ("A;B;C;A;D", GetItems (proj, "Item2"), "A3"); Assert.AreEqual ("B;C;D", GetItems (proj, "Item3"), "A4"); Assert.AreEqual ("Q", GetItems (proj, "Item4"), "A5"); Assert.AreEqual (String.Empty, GetItems (proj, "Item5"), "A6"); Assert.AreEqual ("D", GetItems (proj, "Item6"), "A7"); Assert.AreEqual (String.Empty, GetItems (proj, "Item7"), "A8"); } [Test] public void TestItems2 () { Engine engine = new Engine (Consts.BinPath); Project proj = engine.CreateNewProject (); string documentString = @" "; proj.LoadXml (documentString); Assert.AreEqual ("A-B-C", GetItems (proj, "Item2"), "A1"); Assert.AreEqual ("AxxBxxC", GetItems (proj, "Item3"), "A2"); } [Test] public void TestItems3 () { Engine engine = new Engine (Consts.BinPath); Project proj = engine.CreateNewProject (); string documentString = @" "; proj.LoadXml (documentString); Assert.AreEqual ("A-B-C", GetItems (proj, "Item2"), "A1"); } [Test] public void TestItems4 () { Engine engine = new Engine (Consts.BinPath); Project proj = engine.CreateNewProject (); string documentString = @" '%(Identity)')"" /> '%(Identity)%(Identity)')"" /> '(-%(Identity)-)')"" /> '%(Extension)')"" /> '%(Filename)/%(Extension)')"" /> "; proj.LoadXml (documentString); Assert.AreEqual ("A;B;C", GetItems (proj, "ItemT1"), "A1"); Assert.AreEqual ("AA;BB;CC", GetItems (proj, "ItemT2"), "A2"); Assert.AreEqual ("(-A-);(-B-);(-C-)", GetItems (proj, "ItemT3"), "A3"); Assert.AreEqual (".txt;.txt;.zip;.zip", GetItems (proj, "ItemT4"), "A4"); Assert.AreEqual (string.Format ("B{0}.txt;C{0}.txt;B{0}.zip;C{0}.zip", Path.DirectorySeparatorChar), GetItems (proj, "ItemT5"), "A5"); } [Test] [Category ("NotWorking")] public void TestItems5 () { Engine engine = new Engine (Consts.BinPath); Project proj = engine.CreateNewProject (); string documentString = @" '%(RelativeDir)X/%(Filename)')"" /> "; proj.LoadXml (documentString); Assert.AreEqual (@"A\X/B;A\X/C;B\X/B;B\X/C", GetItems (proj, "ItemT"), "A1"); } [Test] [Category ("NotWorking")] public void TestItems6 () { Engine engine = new Engine (Consts.BinPath); Project proj = engine.CreateNewProject (); string documentString = @" A '%(Filename)')"" /> "; proj.LoadXml (documentString); Assert.AreEqual ("%(A.B)", GetItems (proj, "Item2"), "A1"); Assert.AreEqual (String.Empty, GetItems (proj, "Item3"), "A2"); Assert.AreEqual ("AABAC", GetItems (proj, "Item4"), "A3"); Assert.AreEqual ("A%(A)B%(A)C", GetItems (proj, "Item5"), "A4"); Assert.AreEqual ("A@(A)B@(A)C", GetItems (proj, "Item6"), "A6"); Assert.AreEqual ("A;B;C", GetItems (proj, "Item7"), "A6"); } [Test] [ExpectedException (typeof (InvalidProjectFileException), "The expression \"@(Item1, '@(A,'')')\" cannot be used in this context. " + "Item lists cannot be concatenated with other strings where an item list is expected. " + "Use a semicolon to separate multiple item lists. ")] [Category ("NotWorking")] public void TestItems7 () { Engine engine = new Engine (Consts.BinPath); Project proj = engine.CreateNewProject (); string documentString = @" "; proj.LoadXml (documentString); } [Test] [ExpectedException (typeof (InvalidProjectFileException), "The expression \"@(Item1, '@(A->'')')\" cannot be used in this context. " + "Item lists cannot be concatenated with other strings where an item list is expected. " + "Use a semicolon to separate multiple item lists. ")] [Category ("NotWorking")] public void TestItems8 () { Engine engine = new Engine (Consts.BinPath); Project proj = engine.CreateNewProject (); string documentString = @" '')')"" /> "; proj.LoadXml (documentString); } [Test] [ExpectedException (typeof (InvalidProjectFileException), "The expression \"@(Item1, '@(A->'','')')\" cannot be used in this context. " + "Item lists cannot be concatenated with other strings where an item list is expected. " + "Use a semicolon to separate multiple item lists. ")] [Category ("NotWorking")] public void TestItems9 () { Engine engine = new Engine (Consts.BinPath); Project proj = engine.CreateNewProject (); string documentString = @" '','')')"" /> "; proj.LoadXml (documentString); } [Test] public void TestItemsInTarget1 () { Engine engine = new Engine (Consts.BinPath); Project proj = engine.CreateNewProject (); string documentString = @" A "; proj.LoadXml (documentString); Assert.IsTrue (proj.Build ("1"), "A0, Build failed"); Assert.AreEqual ("A;B;C", proj.GetEvaluatedProperty ("P1"), "A1"); Assert.AreEqual ("ABC", proj.GetEvaluatedProperty ("P2"), "A2"); Assert.AreEqual ("A@(A)B@(A)C", proj.GetEvaluatedProperty ("P3"), "A3"); Assert.AreEqual ("AABAC", proj.GetEvaluatedProperty ("P4"), "A4"); Assert.AreEqual ("@(A,'ABC')", proj.GetEvaluatedProperty ("P5"), "A5"); Assert.AreEqual ("A;B;C", GetItems (proj, "I1"), "A6"); Assert.AreEqual ("A A;B B;C C", GetItems (proj, "I2"), "A7"); } [Test] [Category ("NotWorking")] public void TestItemsInTarget2 () { Engine engine = new Engine (Consts.BinPath); Project proj = engine.CreateNewProject (); string documentString = @" "; proj.LoadXml (documentString); Assert.IsFalse (proj.Build ("1"), "A1"); } [Test] [Category ("NotWorking")] public void TestItemsInTarget3 () { Engine engine = new Engine (Consts.BinPath); Project proj = engine.CreateNewProject (); string documentString = @" A A;B A; "; proj.LoadXml (documentString); proj.Build ("1"); Assert.AreEqual ("AA", GetItems (proj, "I0"), "A1"); Assert.AreEqual ("A;BA;B", GetItems (proj, "I1"), "A2"); Assert.AreEqual (3, proj.GetEvaluatedItemsByName ("I1").Count, "A3"); Assert.AreEqual ("A", GetItems (proj, "I2"), "A4"); Assert.AreEqual (1, proj.GetEvaluatedItemsByName ("I2").Count, "A5"); Assert.AreEqual ("A;A", GetItems (proj, "I3"), "A6"); Assert.AreEqual (2, proj.GetEvaluatedItemsByName ("I3").Count, "A7"); Assert.AreEqual ("A;B;C;A", GetItems (proj, "I4"), "A8"); Assert.AreEqual (4, proj.GetEvaluatedItemsByName ("I4").Count, "A9"); Assert.AreEqual ("A;B;C;A;B;C", GetItems (proj, "I5"), "A10"); Assert.AreEqual (6, proj.GetEvaluatedItemsByName ("I5").Count, "A11"); } [Test] [Category ("NotWorking")] public void TestItemsInTarget4 () { Engine engine = new Engine (Consts.BinPath); Project proj = engine.CreateNewProject (); string documentString = @" "; proj.LoadXml (documentString); Assert.IsFalse (proj.Build ("1")); } [Test] [Category ("NotWorking")] public void TestItemsInTarget5 () { Engine engine = new Engine (Consts.BinPath); Project proj = engine.CreateNewProject (); string documentString = @" "; proj.LoadXml (documentString); Assert.IsFalse (proj.Build ("1")); } [Test] [Category ("NotWorking")] public void TestItemsInTarget6 () { Engine engine = new Engine (Consts.BinPath); Project proj = engine.CreateNewProject (); string documentString = @" A "; proj.LoadXml (documentString); Assert.IsFalse (proj.Build ("1")); } } }