Added new tests
authorCrestez Dan Leonard <cdleonard@mono-cvs.ximian.com>
Mon, 27 Mar 2006 21:40:29 +0000 (21:40 -0000)
committerCrestez Dan Leonard <cdleonard@mono-cvs.ximian.com>
Mon, 27 Mar 2006 21:40:29 +0000 (21:40 -0000)
svn path=/trunk/mcs/; revision=58622

mcs/class/Microsoft.Build.Engine/Test/Microsoft.Build.BuildEngine/ChangeLog
mcs/class/Microsoft.Build.Engine/Test/Microsoft.Build.BuildEngine/EngineTest.cs
mcs/class/Microsoft.Build.Engine/Test/Microsoft.Build.BuildEngine/ProjectTest.cs

index 4bb2e9d02940958422fcf3a68012537b53fca2f3..50cb099b334f901f98e373b5ef6d3fba78081228 100644 (file)
@@ -1,3 +1,7 @@
+2006-03-27  Crestez Leonard  <cdleonard@gmail.com>
+
+       * ProjectTest.cs, EngineTest.cs: Added new tests.
+
 2006-03-23  Marek Sieradzki  <marek.sieradzki@gmail.com>
 
        * Microsoft.Build.Engine.Test.csproj: Updated.
index edd38e366fef92230a97ab78ecb1ff3e1e87cd59..a287fac2b3de8020aa3cd6f58c92518127808079 100644 (file)
@@ -83,15 +83,52 @@ namespace MonoTests.Microsoft.Build.BuildEngine {
                        Assert.AreEqual (false, engine.OnlyLogCriticalEvents, "A1");
                }
 
+               private static string GetPropValue (BuildPropertyGroup bpg, string name)
+               {
+                       foreach (BuildProperty bp in bpg) {
+                               if (bp.Name == name) {
+                                       return bp.FinalValue;
+                               }
+                       }
+                       return String.Empty;
+               }
+
                [Test]
                public void TestGlobalProperties ()
                {
                        engine = new Engine (binPath);
+                       Project project;
 
                        Assert.IsNotNull (engine.GlobalProperties, "A1");
                        Assert.AreEqual (0, engine.GlobalProperties.Count, "A2");
                        Assert.AreEqual (String.Empty, engine.GlobalProperties.Condition, "A3");
                        Assert.IsFalse (engine.GlobalProperties.IsImported, "A4");
+                       
+                       engine.GlobalProperties.SetProperty ("GlobalA", "value1");
+                       Assert.AreEqual (1, engine.GlobalProperties.Count, "A5");
+                       engine.GlobalProperties.SetProperty ("GlobalB", "value1");
+                       Assert.AreEqual (2, engine.GlobalProperties.Count, "A6");
+                       engine.GlobalProperties.SetProperty ("GlobalA", "value2");
+                       Assert.AreEqual (2, engine.GlobalProperties.Count, "A7");
+
+                       project = engine.CreateNewProject ();
+                       Assert.AreEqual (2, project.GlobalProperties.Count, "A8");
+                       project.GlobalProperties.SetProperty ("GlobalC", "value3");
+                       Assert.AreEqual (3, project.GlobalProperties.Count, "A9");
+                       Assert.AreEqual (2, engine.GlobalProperties.Count, "A10");
+
+                       project.GlobalProperties.SetProperty ("GlobalA", "value3");
+                       Assert.AreEqual ("value2", GetPropValue(engine.GlobalProperties, "GlobalA"), "A11");
+                       engine.GlobalProperties.SetProperty ("GlobalB", "value3");
+                       Assert.AreEqual ("value1", GetPropValue(project.GlobalProperties, "GlobalB"), "A12");
+
+                       engine.GlobalProperties.SetProperty ("GlobalC", "value4");
+                       engine.GlobalProperties.SetProperty ("GlobalD", "value5");
+                       Assert.AreEqual (4, engine.GlobalProperties.Count, "A13");
+                       Assert.AreEqual (3, project.GlobalProperties.Count, "A14");
+
+                       project = new Project (engine);
+                       Assert.AreEqual (4, project.GlobalProperties.Count, "A15");
                }
        }
 }
index d82b5cb8f852bdb8454ad383c54c5da9a294c0d8..76097f24bd05d56d3bda06d87585249759f4125e 100644 (file)
@@ -34,13 +34,13 @@ namespace MonoTests.Microsoft.Build.BuildEngine {
        [TestFixture]
        public class ProjectTest {
 
-       string binPath;
+               string binPath;
 
-       [SetUp]
-       public void SetUp ()
-       {
-               binPath = "binPath";
-       }
+               [SetUp]
+               public void SetUp ()
+               {
+                   binPath = "binPath";
+               }
 
                // Clones a project by reloading from original.Xml
                private Project CloneProject (Project original)
@@ -56,7 +56,7 @@ namespace MonoTests.Microsoft.Build.BuildEngine {
                [Test]
                [ExpectedException (typeof (InvalidProjectFileException),
                @"The default XML namespace of the project must be the MSBuild XML namespace." + 
-               " If the project is authored in the MSBuild 2003 format, please add " +
+               " If the project is authored in the MSBuild 2003 format, please add " +
                "xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\" to the <Project> element. " +
                "If the project has been authored in the old 1.0 or 1.2 format, please convert it to MSBuild 2003 format.  ")]
                public void TestAssignment ()
@@ -78,9 +78,9 @@ namespace MonoTests.Microsoft.Build.BuildEngine {
                        Project proj;
                        Project cproj;
                        string documentString = @"
-                <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" DefaultTargets=""Build;Compile"">
-                </Project>
-            ";
+                       <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" DefaultTargets=""Build;Compile"">
+                       </Project>
+                       ";
                        
                        engine = new Engine (binPath);
                        proj = engine.CreateNewProject ();
@@ -94,7 +94,7 @@ namespace MonoTests.Microsoft.Build.BuildEngine {
                }
 
                [Test]
-               public void TestListProperties ()
+               public void TestProperties ()
                {
                        Engine engine = new Engine (binPath);
                        Project proj = engine.CreateNewProject ();
@@ -102,13 +102,88 @@ namespace MonoTests.Microsoft.Build.BuildEngine {
                        string documentString = @"
                                <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
                                        <PropertyGroup>
-                                               <Prop1>value1</Prop1>
+                                               <Config>debug</Config>
+                                               <ExpProp>$(Config)-$(Config)</ExpProp>
                                        </PropertyGroup>
                                </Project>
                        ";
 
                        proj.LoadXml (documentString);
-                       Assert.AreEqual (proj.PropertyGroups.Count, 1, "A1");
+                       Assert.AreEqual (1, proj.PropertyGroups.Count, "A1");
+                       Assert.AreEqual ("debug", proj.GetEvaluatedProperty ("Config"), "A2");
+                       Assert.AreEqual ("debug-debug", proj.GetEvaluatedProperty ("ExpProp"), "A3");
+               }
+
+               // Get all items with a specific name, separated by ;
+               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 TestItems ()
+               {
+                       Engine engine = new Engine ();
+                       Project proj = engine.CreateNewProject ();
+
+                       string documentString = @"
+                               <Project>
+                                       <ItemGroup>
+                                               <Item0 Include=""A"" />
+                                               <Item1 Include=""A;B;C"" />
+                                               <Item2 Include=""@(Item1);A;D"" />
+                                               <Item3 Include=""@(Item2)"" Exclude=""A"" />
+                                               <Item4 Include=""@(Item1);Q"" Exclude=""@(Item2)"" />
+                                               <Item5 Include=""@(Item1)"" Exclude=""@(Item2)"" />
+                                               <Item6 Include=""@(Item2)"" Exclude=""@(Item1)"" />
+
+                                               <ItemOrig Include=""A/B.txt;A/C.txt;B/B.zip;B/C.zip"" />
+                                               <ItemT1 Include=""@(Item1->'%(Identity)')"" />
+                                               <ItemT2 Include=""@(Item1->'%(Identity)%(Identity)')"" />
+                                               <ItemT3 Include=""@(Item1->'(-%(Identity)-)')"" />
+                                               <ItemT4 Include=""@(ItemOrig->'%(Extension)')"" />
+                                               <ItemT5 Include=""@(ItemOrig->'%(Filename)/%(Extension)')"" />
+                                               <ItemT6 Include=""@(ItemOrig->'%(RelativeDir)/X/%(Filename)')"" />
+                                               
+                                               <ItemS1 Include=""@(Item1,'-')"" />
+                                               <ItemS2 Include=""@(Item1,'xx')"" />
+                                               <ItemS3 Include=""@(Item1, '-')"" />
+                                       </ItemGroup>
+                               </Project>
+                       ";
+
+                       proj.LoadXml (documentString);
+                       Assert.AreEqual ("A", GetItems (proj, "Item0"), "Item0");
+                       Assert.AreEqual ("A;B;C", GetItems (proj, "Item1"), "Item1");
+                       Assert.AreEqual ("A;B;C;A;D", GetItems (proj, "Item2"), "Item2");
+                       Assert.AreEqual ("B;C;D", GetItems (proj, "Item3"), "Item3");
+                       Assert.AreEqual ("Q", GetItems (proj, "Item4"), "Item4");
+                       Assert.AreEqual ("", GetItems (proj, "Item5"), "Item5");
+                       Assert.AreEqual ("D", GetItems (proj, "Item6"), "Item6");
+
+                       Assert.AreEqual ("A;B;C", GetItems (proj, "ItemT1"), "ItemT1");
+                       Assert.AreEqual ("AA;BB;CC", GetItems (proj, "ItemT2"), "ItemT2");
+                       Assert.AreEqual ("(-A-);(-B-);(-C-)", GetItems (proj, "ItemT3"), "ItemT3");
+                       Assert.AreEqual (".txt;.txt;.zip;.zip", GetItems (proj, "ItemT4"), "ItemT4");
+                       Assert.AreEqual ("B/.txt;C/.txt;B/.zip;C/.zip", GetItems (proj, "ItemT5"), "ItemT5");
+                       Assert.AreEqual ("A/X/B;A/X/C;B/X/B;B/X/C", GetItems (proj, "ItemT6"), "ItemT6");
+
+                       Assert.AreEqual ("A-B-C", GetItems (proj, "ItemS1"), "ItemS1");
+                       Assert.AreEqual ("AxxBxxC", GetItems (proj, "ItemS2"), "ItemS2");
+                       // Will fail.
+                       Assert.AreEqual ("A-B-C", GetItems (proj, "ItemS3"), "ItemS3");
                }
        }
 }