From 9dce0c5ea7de2824efa4f6199fde11cb13ad35d0 Mon Sep 17 00:00:00 2001 From: Iain McCoy Date: Mon, 25 Jul 2005 13:43:42 +0000 Subject: 2005-07-25 Iain McCoy * Test/XamlParser.cs: added tests for correct catching of non-existent processing instructions, attempting to set a dependency property on an object that is not a dependency object and for code elements. * Test/CodeWriter.cs: added tests for partial class generation and for giving a specific name to an object to be stored as a property value * Mono.Windows.Serialization/XamlParser.cs: be more paranoid about children of code elements, have better punctuation if objecting to an incorrect mapping and throw exceptions on unknown property types. svn path=/trunk/mcs/; revision=47644 --- mcs/class/PresentationFramework/ChangeLog | 11 ++++ .../Mono.Windows.Serialization/XamlParser.cs | 6 +- mcs/class/PresentationFramework/Test/CodeWriter.cs | 76 ++++++++++++++++++++++ mcs/class/PresentationFramework/Test/XamlParser.cs | 70 ++++++++++++++++++-- 4 files changed, 157 insertions(+), 6 deletions(-) (limited to 'mcs/class/PresentationFramework') diff --git a/mcs/class/PresentationFramework/ChangeLog b/mcs/class/PresentationFramework/ChangeLog index a718caf9fdd..3b7e6c28f0e 100644 --- a/mcs/class/PresentationFramework/ChangeLog +++ b/mcs/class/PresentationFramework/ChangeLog @@ -1,3 +1,14 @@ +2005-07-25 Iain McCoy + + * Test/XamlParser.cs: added tests for correct catching of non-existent + processing instructions, attempting to set a dependency property on an + object that is not a dependency object and for code elements. + * Test/CodeWriter.cs: added tests for partial class generation and for + giving a specific name to an object to be stored as a property value + * Mono.Windows.Serialization/XamlParser.cs: be more paranoid about + children of code elements, have better punctuation if objecting to an + incorrect mapping and throw exceptions on unknown property types. + 2005-07-24 Iain McCoy * Test/XamlParser.cs, diff --git a/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs b/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs index 732a873527b..b486bc66528 100644 --- a/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs +++ b/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs @@ -104,7 +104,7 @@ namespace Mono.Windows.Serialization { // skip whitespace and comments break; default: - Console.Out.WriteLine("Unknown element type " + reader.NodeType); + throw new Exception("Unknown element type " + reader.NodeType); break; } } @@ -115,6 +115,8 @@ namespace Mono.Windows.Serialization { reader.LocalName == "Code" && reader.NamespaceURI == XAML_NAMESPACE) { parseEndElement(); + } else if (reader.NodeType != XmlNodeType.CDATA && reader.NodeType != XmlNodeType.Text) { + throw new Exception("Code element children must be either text or CDATA nodes."); } else { currentState.obj = (string)currentState.obj + reader.Value; } @@ -134,7 +136,7 @@ namespace Mono.Windows.Serialization { void parsePI() { if (reader.Name != "Mapping") - throw new Exception("Unknown processing instruction"); + throw new Exception("Unknown processing instruction."); mapper.AddMappingProcessingInstruction(reader.Value); } diff --git a/mcs/class/PresentationFramework/Test/CodeWriter.cs b/mcs/class/PresentationFramework/Test/CodeWriter.cs index a7c8eaaf040..742dccc9d46 100644 --- a/mcs/class/PresentationFramework/Test/CodeWriter.cs +++ b/mcs/class/PresentationFramework/Test/CodeWriter.cs @@ -74,6 +74,54 @@ public class CodeWriterTest { ); } +#if NET_2_0 + [Test] + public void TestPartialTopLevel() + { + // we duplicate the setup code here, with the one change that + // the third parameter (determining partialness) of CodeWriter's + // constructor is set to true + ICodeGenerator generator = (new Microsoft.CSharp.CSharpCodeProvider()).CreateGenerator(); + w = new StringWriter(); + cw = new CodeWriter(generator, w, true); + cw.CreateTopLevel(typeof(ConsoleApp), null); + cw.EndObject(); + cw.Finish(); + compare( + "namespace DefaultNamespace {\n"+ + " public partial class derivedConsoleApp: Xaml.TestVocab.Console.ConsoleApp {\n" + + " private derivedConsoleApp() {\n"+ + " }\n" + + " }\n" + + "}" + ); + } +#else + [ExpectedException(typeof(Exception), "Cannot create partial class")] + [Test] + public void TestPartialTopLevel() + { + // we duplicate the setup code here, with the one change that + // the third parameter (determining partialness) of CodeWriter's + // constructor is set to true + ICodeGenerator generator = (new Microsoft.CSharp.CSharpCodeProvider()).CreateGenerator(); + w = new StringWriter(); + cw = new CodeWriter(generator, w, true); + cw.CreateTopLevel(typeof(ConsoleApp), null); + cw.EndObject(); + cw.Finish(); + compare( + "namespace DefaultNamespace {\n"+ + " public partial class derivedConsoleApp: Xaml.TestVocab.Console.ConsoleApp {\n" + + " private derivedConsoleApp() {\n"+ + " }\n" + + " }\n" + + "}" + ); + } +#endif + + [Test] public void TestTopLevelWithClassName() { @@ -247,6 +295,34 @@ public class CodeWriterTest { ); } + [Test] + public void TestObjectAsPropertyValueWithSpecifiedName() + { + cw.CreateTopLevel(typeof(ConsoleApp), null); + cw.CreateObject(typeof(ConsoleReader), null); + cw.CreateProperty(typeof(ConsoleReader).GetProperty("Prompt")); + cw.CreatePropertyObject(typeof(ConsoleWriter), "prompt"); + cw.EndPropertyObject(typeof(ConsoleWriter)); + cw.EndProperty(); + cw.EndObject(); + cw.EndObject(); + cw.Finish(); + compare( + "namespace DefaultNamespace {\n"+ + " public class derivedConsoleApp: Xaml.TestVocab.Console.ConsoleApp {\n" + + " private Xaml.TestVocab.Console.ConsoleWriter prompt = new Xaml.TestVocab.Console.ConsoleWriter();\n"+ + " private derivedConsoleApp() {\n"+ + " Xaml.TestVocab.Console.ConsoleReader consoleReader1 = new Xaml.TestVocab.Console.ConsoleReader();\n"+ + " this.AddChild(consoleReader1);\n" + +// " Xaml.TestVocab.Console.ConsoleWriter consoleWriter1 = new Xaml.TestVocab.Console.ConsoleWriter();\n"+ + " consoleReader1.Prompt = prompt;\n" + + + " }\n" + + " }\n" + + "}" + ); + } + [Test] public void TestEvent() { diff --git a/mcs/class/PresentationFramework/Test/XamlParser.cs b/mcs/class/PresentationFramework/Test/XamlParser.cs index a7986f4d307..79c81293ea4 100644 --- a/mcs/class/PresentationFramework/Test/XamlParser.cs +++ b/mcs/class/PresentationFramework/Test/XamlParser.cs @@ -73,6 +73,19 @@ public class XamlParserTest : Assertion { [TearDown] public void Clean() {} + [Test] + [ExpectedException(typeof(Exception), "Unknown processing instruction.")] + public void TestIncorrectPIName() + { + string s = "\n"; + ParserTester pt = new ParserTester(s, + new CreateTopLevelHappening(typeof(ConsoleApp), null), + new EndObjectHappening(), + new FinishHappening()); + pt.Test(); + + } + [Test] public void TestTopLevel() { @@ -342,7 +355,26 @@ public class XamlParserTest : Assertion { new FinishHappening()); pt.Test(); } - + + [Test] + [ExpectedException(typeof(Exception), "Dependency properties can only be set on DependencyObjects (not ConsoleValueString)")] + public void TestDependencyPropertyOnNotDependencyObject() + { + string s = "\n"+ + "" + + ""; + ParserTester pt = new ParserTester(MAPPING + s, + new CreateTopLevelHappening(typeof(ConsoleApp), null), + new CreateObjectHappening(typeof(ConsoleValueString), null), + new CreateDependencyPropertyHappening(typeof(ConsoleApp), "Repetitions", typeof(int)), + new CreateDependencyPropertyTextHappening("3", typeof(int)), + new EndDependencyPropertyHappening(), + new EndObjectHappening(), // ConsoleWriter + new EndObjectHappening(), // ConsoleApp + new FinishHappening()); + pt.Test(); + } + [Test] [ExpectedException(typeof(Exception), "Property 'Reps' does not exist on 'ConsoleApp'.")] public void TestDependencyPropertyWithIncorrectName() @@ -452,20 +484,20 @@ public class XamlParserTest : Assertion { { string s = "\n"+ "\n" + - "xyz" + + "ABC" + "\n" + ""; ParserTester pt = new ParserTester(MAPPING + s, new CreateTopLevelHappening(typeof(ConsoleApp), null), new CreateObjectHappening(typeof(ConsoleValueString), null), - new CreateObjectTextHappening("xyz"), + new CreateObjectHappening(typeof(ConsoleWriter), null), new EndObjectHappening(), new EndObjectHappening(), new EndObjectHappening(), new FinishHappening()); pt.Test(); } - + [Test] public void TestEvent() { @@ -499,6 +531,36 @@ public class XamlParserTest : Assertion { pt.Test(); } + [Test] + public void TestCode() + { + string s = "\n"+ + " here there everywhere]]>\n"+ + ""; + ParserTester pt = new ParserTester(MAPPING + s, + new CreateTopLevelHappening(typeof(ConsoleApp), null), + new CreateCodeHappening("Hi there here there everywhere"), + new EndObjectHappening(), + new FinishHappening()); + pt.Test(); + } + + + [Test] + [ExpectedException(typeof(Exception), "Code element children must be either text or CDATA nodes.")] + public void TestCodeWithIncorrectChildren() + { + string s = "\n"+ + "Hi there here there everywhere\n"+ + ""; + ParserTester pt = new ParserTester(MAPPING + s, + new CreateTopLevelHappening(typeof(ConsoleApp), null), + new CreateCodeHappening("Hi there here there everywhere"), + new EndObjectHappening(), + new FinishHappening()); + pt.Test(); + } + } -- cgit v1.2.3