diff options
author | Iain McCoy <iainmc@mono-cvs.ximian.com> | 2005-07-24 11:51:26 +0400 |
---|---|---|
committer | Iain McCoy <iainmc@mono-cvs.ximian.com> | 2005-07-24 11:51:26 +0400 |
commit | 714512257f487dae12f2dcc4aeff902bd458e4fb (patch) | |
tree | 30882231f44400a4ddb57331df3aaaa9aad672b1 /mcs/class/PresentationFramework | |
parent | 32de363917ad562cbbbf57259a4f02f3645e9bc5 (diff) | |
parent | 43b0dc2bcd858355110814ac244bb3678f8beea0 (diff) |
2005-07-24 Iain McCoy <iain@mccoy.id.au>
* Test/XamlParser.cs,
Mono.Windows.Serialization/XamlParser.cs: added a test for
inappropriate usage of the Class attribute and fixed bug revealed by
the test
* Test/ObjectWriter.cs,
PresentationFramework_test.dll.sources: added tests for object
builder (based on tests for code generator)
* demo/TestVocab/ConsoleWriter.cs,
demo/TestVocab/ConsoleReader.cs,
demo/TestVocab/ConsoleApp.cs: fix up definitions of Equals methods
so that the object builder's tests work.
svn path=/trunk/mcs/; revision=47599
Diffstat (limited to 'mcs/class/PresentationFramework')
6 files changed, 243 insertions, 0 deletions
diff --git a/mcs/class/PresentationFramework/ChangeLog b/mcs/class/PresentationFramework/ChangeLog index f7e2da8cb5c..a718caf9fdd 100644 --- a/mcs/class/PresentationFramework/ChangeLog +++ b/mcs/class/PresentationFramework/ChangeLog @@ -1,3 +1,14 @@ +2005-07-24 Iain McCoy <iain@mccoy.id.au> + + * Test/XamlParser.cs, + Mono.Windows.Serialization/XamlParser.cs: added a test for + inappropriate usage of the Class attribute and fixed bug revealed by + the test + * Test/ObjectWriter.cs, + PresentationFramework_test.dll.sources: added tests for object + builder (based on tests for code generator) + + 2005-07-23 Iain McCoy <iain@mccoy.id.au> * Test/XamlParser.cs: added test for events and delegates as property diff --git a/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs b/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs index 0d2d6f4af11..732a873527b 100644 --- a/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs +++ b/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs @@ -293,6 +293,9 @@ namespace Mono.Windows.Serialization { void parseChildObjectElement(Type parent) { + if (reader.GetAttribute("Class", XAML_NAMESPACE) != null) + throw new Exception("The XAML Class attribute can not be applied to child elements\n"+ + "Do you mean the Name attribute?"); string name = reader.GetAttribute("Name", XAML_NAMESPACE); if (name == null) name = reader.GetAttribute("Name", reader.NamespaceURI); diff --git a/mcs/class/PresentationFramework/PresentationFramework_test.dll.sources b/mcs/class/PresentationFramework/PresentationFramework_test.dll.sources index 56fd45e2566..2e9a5223c95 100644 --- a/mcs/class/PresentationFramework/PresentationFramework_test.dll.sources +++ b/mcs/class/PresentationFramework/PresentationFramework_test.dll.sources @@ -1,2 +1,3 @@ XamlParser.cs CodeWriter.cs +ObjectWriter.cs diff --git a/mcs/class/PresentationFramework/Test/CodeWriter.cs b/mcs/class/PresentationFramework/Test/CodeWriter.cs index 4c3ce769058..a7c8eaaf040 100644 --- a/mcs/class/PresentationFramework/Test/CodeWriter.cs +++ b/mcs/class/PresentationFramework/Test/CodeWriter.cs @@ -297,11 +297,13 @@ public class CodeWriterTest { int i, j; string[] actualLines = w.ToString().Split('\n'); for (i = 0; i < actualLines.Length; i++) { + // set commented-out lines to null if (actualLines[i].StartsWith("//")) { actualLines[i] = null; continue; } + // set lines containing only whitespace to null j = 0; while (j < actualLines[i].Length && Char.IsWhiteSpace(actualLines[i][j])) { @@ -312,6 +314,7 @@ public class CodeWriterTest { continue; } } + // shift all null elements to end of list and join all non-null elements j = 0; for (i = 0; i < actualLines.Length; i++) { if (actualLines[i] != null) diff --git a/mcs/class/PresentationFramework/Test/ObjectWriter.cs b/mcs/class/PresentationFramework/Test/ObjectWriter.cs new file mode 100644 index 00000000000..aa2f0e80cd5 --- /dev/null +++ b/mcs/class/PresentationFramework/Test/ObjectWriter.cs @@ -0,0 +1,209 @@ +// +// ObjectWriter.cs - NUnit Test Cases for the xaml object builder +// +// Author: +// Iain McCoy (iain@mccoy.id.au) +// +// (C) 2005 Iain McCoy +// +// 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 NUnit.Framework; + +using System; +using System.Diagnostics; +using System.IO; +using System.Xml; +using System.Reflection; +using System.Windows; +using System.CodeDom.Compiler; +using Mono.Windows.Serialization; +using Xaml.TestVocab.Console; + +namespace MonoTests.System.Windows.Serialization +{ + +[TestFixture] +public class ObjectWriterTest { + ObjectWriter ow; + + [SetUp] + public void GetReady() + { + ow = new ObjectWriter(); + } + + [TearDown] + public void Clean() {} + + [Test] + public void TestTopLevel() + { + ow.CreateTopLevel(typeof(ConsoleApp), null); + ow.EndObject(); + ow.Finish(); + ConsoleApp app = new ConsoleApp(); + compare(app); + } + + [Test] + public void TestTopLevelWithClassName() + { + ow.CreateTopLevel(typeof(ConsoleApp), "MyConsoleApp"); + ow.EndObject(); + ow.Finish(); + ConsoleApp app = new ConsoleApp(); + compare(app); + } + + [Test] + public void TestTopLevelWithClassNameAndNamespace() + { + ow.CreateTopLevel(typeof(ConsoleApp), "Test.Thing.MyConsoleApp"); + ow.EndObject(); + ow.Finish(); + ConsoleApp app = new ConsoleApp(); + compare(app); + } + + [Test] + public void TestSimplestAddChild() + { + ow.CreateTopLevel(typeof(ConsoleApp), null); + ow.CreateObject(typeof(ConsoleWriter), null); + ow.EndObject(); + ow.EndObject(); + ow.Finish(); + + ConsoleApp app = new ConsoleApp(); + ConsoleWriter writer = new ConsoleWriter(); + app.AddChild(writer); + + compare(app); + } + + [Test] + public void TestSimplestAddChildWithInstanceName() + { + ow.CreateTopLevel(typeof(ConsoleApp), null); + ow.CreateObject(typeof(ConsoleWriter), "XX"); + ow.EndObject(); + ow.EndObject(); + ow.Finish(); + + ConsoleApp app = new ConsoleApp(); + ConsoleWriter writer = new ConsoleWriter(); + app.AddChild(writer); + + compare(app); + } + + + [Test] + public void TestSimplestAddChildAndText() + { + ow.CreateTopLevel(typeof(ConsoleApp), null); + ow.CreateObject(typeof(ConsoleWriter), null); + ow.CreateObjectText("Hello"); + ow.EndObject(); + ow.EndObject(); + ow.Finish(); + + ConsoleApp app = new ConsoleApp(); + ConsoleWriter writer = new ConsoleWriter(); + writer.AddText("Hello"); + app.AddChild(writer); + + compare(app); + } + + [Test] + public void TestTextProperty() + { + ow.CreateTopLevel(typeof(ConsoleApp), null); + ow.CreateObject(typeof(ConsoleWriter), null); + ow.CreateProperty(typeof(ConsoleWriter).GetProperty("Text")); + ow.CreatePropertyText("Hello", typeof(ConsoleValue)); + ow.EndProperty(); + ow.EndObject(); + ow.EndObject(); + ow.Finish(); + + ConsoleApp app = new ConsoleApp(); + ConsoleWriter writer = new ConsoleWriter(); + writer.Text = new ConsoleValueString("Hello"); + app.AddChild(writer); + + compare(app); + } + + [Test] + public void TestDependencyProperty() + { + ow.CreateTopLevel(typeof(ConsoleApp), null); + ow.CreateObject(typeof(ConsoleWriter), null); + ow.CreateDependencyProperty(typeof(ConsoleApp), "Repetitions", typeof(int)); + ow.CreateDependencyPropertyText("3", typeof(int)); + ow.EndDependencyProperty(); + ow.EndObject(); + ow.EndObject(); + ow.Finish(); + + ConsoleApp app = new ConsoleApp(); + ConsoleWriter writer = new ConsoleWriter(); + ConsoleApp.SetRepetitions(writer, 3); + app.AddChild(writer); + + compare(app); + } + + [Test] + public void TestObjectAsPropertyValue() + { + ow.CreateTopLevel(typeof(ConsoleApp), null); + ow.CreateObject(typeof(ConsoleReader), null); + ow.CreateProperty(typeof(ConsoleReader).GetProperty("Prompt")); + ow.CreatePropertyObject(typeof(ConsoleWriter), null); + ow.EndPropertyObject(typeof(ConsoleWriter)); + ow.EndProperty(); + ow.EndObject(); + ow.EndObject(); + ow.Finish(); + + ConsoleApp app = new ConsoleApp(); + ConsoleReader reader = new ConsoleReader(); + ConsoleWriter writer = new ConsoleWriter(); + reader.Prompt = writer; + app.AddChild(reader); + + compare(app); + } + + + private void compare(object expected) + { + Assert.AreEqual(expected, ow.instance); + } + +} + +} diff --git a/mcs/class/PresentationFramework/Test/XamlParser.cs b/mcs/class/PresentationFramework/Test/XamlParser.cs index 948c0927866..a7986f4d307 100644 --- a/mcs/class/PresentationFramework/Test/XamlParser.cs +++ b/mcs/class/PresentationFramework/Test/XamlParser.cs @@ -192,6 +192,22 @@ public class XamlParserTest : Assertion { new FinishHappening()); pt.Test(); } + + [Test] + [ExpectedException(typeof(Exception), "The XAML Class attribute can not be applied to child elements\nDo you mean the Name attribute?")] + public void TestSimplestAddChildWithWrongNamingAttribute() + { + string s = "<ConsoleApp xmlns=\"console\" xmlns:x=\"http://schemas.microsoft.com/winfx/xaml/2005\">\n"+ + "<ConsoleWriter x:Class=\"abc\"></ConsoleWriter>" + + "</ConsoleApp>"; + ParserTester pt = new ParserTester(MAPPING + s, + new CreateTopLevelHappening(typeof(ConsoleApp), null), + new CreateObjectHappening(typeof(ConsoleWriter), "abc"), + new EndObjectHappening(), + new EndObjectHappening(), + new FinishHappening()); + pt.Test(); + } [Test] |