diff options
author | Iain McCoy <iainmc@mono-cvs.ximian.com> | 2005-08-26 15:15:34 +0400 |
---|---|---|
committer | Iain McCoy <iainmc@mono-cvs.ximian.com> | 2005-08-26 15:15:34 +0400 |
commit | ffb845b352dadf2a085b2b58aa3cb6c5d5ae4464 (patch) | |
tree | f0ddba31d0b847558ebeff6987331c461d544321 /mcs | |
parent | 4c35581a7e457b0efa9afd466d25e01736568433 (diff) | |
parent | 19538fbb905817793415b08ce15aea3894a75eb9 (diff) |
2005-08-26 Iain McCoy <iain@mccoy.id.au>
* demo/runtimetest.cs: use the newly-renamed Parser class instead of
the interim ObjectWriter
2005-08-24 Iain McCoy <iain@mccoy.id.au>
* Mono.Windows.Serialization/ObjectWriter.cs,
System.Windows.Serialization/Parser.cs: renamed ObjectWriter to
Parser, made interface more similar
* Test/ObjectWriter.cs: changed to test the new Parser class
2005-08-24 Iain McCoy <iain@mccoy.id.au>
* Mono.Windows.Serialization/XamlParser.cs: make internal
* Mono.Windows.Serialization/CodeWriter.cs: add private member so that
the tests can get at the type for XamlParser
* Test/XamlParser.cs: use reflection to get the XamlParser type out of
CodeWriter, create an instance of it and get nodes from it
svn path=/trunk/mcs/; revision=48885
Diffstat (limited to 'mcs')
-rw-r--r-- | mcs/class/PresentationFramework/ChangeLog | 15 | ||||
-rw-r--r-- | mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs | 2 | ||||
-rw-r--r-- | mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs | 2 | ||||
-rw-r--r-- | mcs/class/PresentationFramework/PresentationFramework.dll.sources | 2 | ||||
-rw-r--r-- | mcs/class/PresentationFramework/System.Windows.Serialization/Parser.cs (renamed from mcs/class/PresentationFramework/Mono.Windows.Serialization/ObjectWriter.cs) | 21 | ||||
-rw-r--r-- | mcs/class/PresentationFramework/Test/ObjectWriter.cs | 7 | ||||
-rw-r--r-- | mcs/class/PresentationFramework/Test/XamlParser.cs | 546 | ||||
-rw-r--r-- | mcs/tools/xamlc/ChangeLog | 5 | ||||
-rw-r--r-- | mcs/tools/xamlc/demo/runtimetest.cs | 3 |
9 files changed, 155 insertions, 448 deletions
diff --git a/mcs/class/PresentationFramework/ChangeLog b/mcs/class/PresentationFramework/ChangeLog index 77bc2be83da..4e73cfed51d 100644 --- a/mcs/class/PresentationFramework/ChangeLog +++ b/mcs/class/PresentationFramework/ChangeLog @@ -1,3 +1,18 @@ +2005-08-24 Iain McCoy <iain@mccoy.id.au> + + * Mono.Windows.Serialization/ObjectWriter.cs, + System.Windows.Serialization/Parser.cs: renamed ObjectWriter to + Parser, made interface more similar + * Test/ObjectWriter.cs: changed to test the new Parser class + +2005-08-24 Iain McCoy <iain@mccoy.id.au> + + * Mono.Windows.Serialization/XamlParser.cs: make internal + * Mono.Windows.Serialization/CodeWriter.cs: add private member so that + the tests can get at the type for XamlParser + * Test/XamlParser.cs: use reflection to get the XamlParser type out of + CodeWriter, create an instance of it and get nodes from it + 2005-08-23 Iain McCoy <iain@mccoy.id.au> * System.Windows.Serialization/XamlParser.cs: rearrange class so that diff --git a/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs b/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs index 244c321857c..cf34fe2098a 100644 --- a/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs +++ b/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs @@ -51,6 +51,8 @@ namespace Mono.Windows.Serialization { CodeTypeDeclaration type; CodeConstructor constructor; + private static readonly Type xamlParserType = typeof(XamlParser); + public static string Parse(XmlTextReader reader, ICodeGenerator generator, bool isPartial) { CodeWriter cw = new CodeWriter(reader, generator, isPartial); diff --git a/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs b/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs index 4a96b7e2482..b7702f792d5 100644 --- a/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs +++ b/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs @@ -37,7 +37,7 @@ using System.Windows; using System.Windows.Serialization; namespace Mono.Windows.Serialization { - public class XamlParser { + internal class XamlParser { public const string XAML_NAMESPACE = "http://schemas.microsoft.com/winfx/xaml/2005"; private Mapper mapper = new Mapper(new string[] { }); private XmlTextReader reader; diff --git a/mcs/class/PresentationFramework/PresentationFramework.dll.sources b/mcs/class/PresentationFramework/PresentationFramework.dll.sources index 796cdc5ace6..a76d924c5b2 100644 --- a/mcs/class/PresentationFramework/PresentationFramework.dll.sources +++ b/mcs/class/PresentationFramework/PresentationFramework.dll.sources @@ -1,11 +1,11 @@ System.Windows.Serialization/IAddChild.cs System.Windows.Serialization/Mapper.cs System.Windows.Serialization/NamespaceMapEntry.cs +System.Windows.Serialization/Parser.cs System.Windows.Serialization/XamlNodeType.cs System.Windows.Serialization/XamlParseMode.cs System.Windows.Serialization/BamlAttributeUsage.cs Mono.Windows.Serialization/CodeWriter.cs -Mono.Windows.Serialization/ObjectWriter.cs Mono.Windows.Serialization/Exceptions.cs Mono.Windows.Serialization/XamlParser.cs Mono.Windows.Serialization/IXamlWriter.cs diff --git a/mcs/class/PresentationFramework/Mono.Windows.Serialization/ObjectWriter.cs b/mcs/class/PresentationFramework/System.Windows.Serialization/Parser.cs index c078cb0763e..3b50d5c8dd2 100644 --- a/mcs/class/PresentationFramework/Mono.Windows.Serialization/ObjectWriter.cs +++ b/mcs/class/PresentationFramework/System.Windows.Serialization/Parser.cs @@ -35,20 +35,25 @@ using System.CodeDom.Compiler; using System.ComponentModel; using System.Diagnostics; using System.Windows; -using System.Windows.Serialization; +using Mono.Windows.Serialization; using System.Xml; -namespace Mono.Windows.Serialization { - public class ObjectWriter { - public object instance; +namespace System.Windows.Serialization { + public class Parser { + private object instance; ArrayList objects = new ArrayList(); - public static object Parse(XmlTextReader reader) + public static object LoadXml(Stream s) { - ObjectWriter ow = new ObjectWriter(reader); - return ow.instance; + return LoadXml(new XmlTextReader(s)); } - private ObjectWriter(XmlTextReader reader) + // TODO: this should take a XmlReader in order to be same as MSFT + public static object LoadXml(XmlTextReader reader) + { + Parser r = new Parser(reader); + return r.instance; + } + private Parser(XmlTextReader reader) { XamlParser p = new XamlParser(reader); XamlNode n; diff --git a/mcs/class/PresentationFramework/Test/ObjectWriter.cs b/mcs/class/PresentationFramework/Test/ObjectWriter.cs index 73618b8c251..887ae575d4f 100644 --- a/mcs/class/PresentationFramework/Test/ObjectWriter.cs +++ b/mcs/class/PresentationFramework/Test/ObjectWriter.cs @@ -1,5 +1,5 @@ // -// ObjectWriter.cs - NUnit Test Cases for the xaml object builder +// Parser.cs - NUnit Test Cases for the xaml object builder // // Author: // Iain McCoy (iain@mccoy.id.au) @@ -37,13 +37,14 @@ using System.Reflection; using System.Windows; using System.CodeDom.Compiler; using Mono.Windows.Serialization; +using System.Windows.Serialization; using Xaml.TestVocab.Console; namespace MonoTests.System.Windows.Serialization { [TestFixture] -public class ObjectWriterTest { +public class ParserTest { string code; [SetUp] @@ -179,7 +180,7 @@ public class ObjectWriterTest { private void compare(object expected) { string mapping = "<?Mapping ClrNamespace=\"Xaml.TestVocab.Console\" Assembly=\"./TestVocab.dll\" XmlNamespace=\"console\" ?>\n"; - object o = ObjectWriter.Parse(new XmlTextReader(new StringReader(mapping + code))); + object o = Parser.LoadXml(new XmlTextReader(new StringReader(mapping + code))); Assert.AreEqual(expected, o); } diff --git a/mcs/class/PresentationFramework/Test/XamlParser.cs b/mcs/class/PresentationFramework/Test/XamlParser.cs index d70bce4e17f..68b75684c7b 100644 --- a/mcs/class/PresentationFramework/Test/XamlParser.cs +++ b/mcs/class/PresentationFramework/Test/XamlParser.cs @@ -56,9 +56,10 @@ public class XamlParserTest { private void makeGoBang(string s) { XamlNode n; - XamlParser p = new XamlParser(new StringReader(s)); + object p = buildParser(new StringReader(s)); do { - n = p.GetNextNode(); + n = getNextNode(p); +// Process.Start("xmessage " + n.GetType()); } while (!(n is XamlDocumentEndNode)); } @@ -75,20 +76,20 @@ public class XamlParserTest { { string s = "<ConsoleApp xmlns=\"console\"></ConsoleApp>"; XamlNode n; - XamlParser p = new XamlParser(new StringReader(MAPPING + s)); + object p = buildParser(new StringReader(MAPPING + s)); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlDocumentStartNode, "A1"); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlElementStartNode, "B1"); Assert.AreEqual(0, n.Depth, "B2"); Assert.AreEqual(((XamlElementStartNode)n).ElementType, typeof(ConsoleApp), "B3"); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlElementEndNode, "C1"); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlDocumentEndNode, "D1"); } @@ -125,21 +126,21 @@ public class XamlParserTest { string s = "<ConsoleApp xmlns=\"console\" xmlns:x=\"http://schemas.microsoft.com/winfx/xaml/2005\" x:Class=\"nnn\">\n"+ "</ConsoleApp>"; XamlNode n; - XamlParser p = new XamlParser(new StringReader(MAPPING + s)); + object p = buildParser(new StringReader(MAPPING + s)); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlDocumentStartNode, "A1"); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlElementStartNode, "B1"); Assert.AreEqual(0, n.Depth, "B2"); Assert.AreEqual("nnn", ((XamlElementStartNode)n).name, "B3"); Assert.AreEqual(((XamlElementStartNode)n).ElementType, typeof(ConsoleApp), "B4"); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlElementEndNode, "C1"); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlDocumentEndNode, "D1"); } @@ -160,28 +161,28 @@ public class XamlParserTest { "</ConsoleApp>"; XamlNode n; - XamlParser p = new XamlParser(new StringReader(MAPPING + s)); + object p = buildParser(new StringReader(MAPPING + s)); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlDocumentStartNode); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlElementStartNode); Assert.AreEqual(n.Depth, 0); Assert.AreEqual(((XamlElementStartNode)n).ElementType, typeof(ConsoleApp)); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlElementStartNode); Assert.AreEqual(n.Depth, 1); Assert.AreEqual(((XamlElementStartNode)n).ElementType, typeof(ConsoleWriter)); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlElementEndNode); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlElementEndNode); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlDocumentEndNode); } @@ -194,29 +195,29 @@ public class XamlParserTest { "</ConsoleApp>"; XamlNode n; - XamlParser p = new XamlParser(new StringReader(MAPPING + s)); + object p = buildParser(new StringReader(MAPPING + s)); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlDocumentStartNode, "A1"); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlElementStartNode, "B1"); Assert.AreEqual(n.Depth, 0, "B2"); Assert.AreEqual(((XamlElementStartNode)n).ElementType, typeof(ConsoleApp), "B3"); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlElementStartNode, "C1"); Assert.AreEqual(1, n.Depth, "C2"); Assert.AreEqual("XXX", ((XamlElementStartNode)n).name, "C3"); Assert.AreEqual(((XamlElementStartNode)n).ElementType, typeof(ConsoleWriter), "C4"); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlElementEndNode, "D1"); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlElementEndNode, "E1"); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlDocumentEndNode, "F1"); } @@ -251,32 +252,32 @@ public class XamlParserTest { "</ConsoleApp>"; XamlNode n; - XamlParser p = new XamlParser(new StringReader(MAPPING + s)); + object p = buildParser(new StringReader(MAPPING + s)); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlDocumentStartNode); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlElementStartNode); Assert.AreEqual(n.Depth, 0); Assert.AreEqual(((XamlElementStartNode)n).ElementType, typeof(ConsoleApp)); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlElementStartNode); Assert.AreEqual(n.Depth, 1); Assert.AreEqual(((XamlElementStartNode)n).ElementType, typeof(ConsoleWriter)); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlTextNode); Assert.AreEqual(((XamlTextNode)n).TextContent, "Hello"); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlElementEndNode); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlElementEndNode); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlDocumentEndNode); } @@ -289,7 +290,7 @@ public class XamlParserTest { "</ConsoleApp>"; XamlNode n; - XamlParser p = new XamlParser(new StringReader(MAPPING + s)); + object p = buildParser(new StringReader(MAPPING + s)); basicPropertyTestStream(p, 0); } @@ -302,45 +303,45 @@ public class XamlParserTest { "<ConsoleWriter.Text>Hello</ConsoleWriter.Text>\n" + "</ConsoleWriter>\n" + "</ConsoleApp>"; - XamlParser p = new XamlParser(new StringReader(MAPPING + s)); + object p = buildParser(new StringReader(MAPPING + s)); basicPropertyTestStream(p, 1); } - private void basicPropertyTestStream(XamlParser p, int depthIncreaseForProperty) + private void basicPropertyTestStream(object p, int depthIncreaseForProperty) { XamlNode n; - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlDocumentStartNode, "A1"); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlElementStartNode, "B1"); Assert.AreEqual(0, n.Depth, "B2"); Assert.AreEqual(((XamlElementStartNode)n).ElementType, typeof(ConsoleApp), "B3"); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlElementStartNode, "C1"); Assert.AreEqual(1, n.Depth, "C2"); Assert.AreEqual(((XamlElementStartNode)n).ElementType, typeof(ConsoleWriter), "C3"); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlPropertyNode, "D1"); Assert.AreEqual(1 + depthIncreaseForProperty, n.Depth, "D2"); Assert.AreEqual(((XamlPropertyNode)n).PropInfo, typeof(ConsoleWriter).GetProperty("Text"), "D3"); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlTextNode, "E1"); Assert.AreEqual(((XamlTextNode)n).TextContent, "Hello", "E2"); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlElementEndNode, "F1"); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlElementEndNode, "F2"); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlDocumentEndNode, "F3"); } @@ -387,36 +388,36 @@ public class XamlParserTest { "</ConsoleApp>"; XamlNode n; - XamlParser p = new XamlParser(new StringReader(MAPPING + s)); + object p = buildParser(new StringReader(MAPPING + s)); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlDocumentStartNode); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlElementStartNode); Assert.AreEqual(n.Depth, 0); Assert.AreEqual(((XamlElementStartNode)n).ElementType, typeof(ConsoleApp)); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlElementStartNode); Assert.AreEqual(n.Depth, 1); Assert.AreEqual(((XamlElementStartNode)n).ElementType, typeof(ConsoleWriter)); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlPropertyNode); Assert.AreEqual(((XamlPropertyNode)n).DP, ConsoleApp.RepetitionsProperty); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlTextNode); Assert.AreEqual(((XamlTextNode)n).TextContent, "3"); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlElementEndNode); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlElementEndNode); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlDocumentEndNode); } @@ -452,37 +453,37 @@ public class XamlParserTest { "</ConsoleApp>"; XamlNode n; - XamlParser p = new XamlParser(new StringReader(MAPPING + s)); + object p = buildParser(new StringReader(MAPPING + s)); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlDocumentStartNode); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlElementStartNode); Assert.AreEqual(n.Depth, 0); Assert.AreEqual(((XamlElementStartNode)n).ElementType, typeof(ConsoleApp)); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlElementStartNode); Assert.AreEqual(n.Depth, 1); Assert.AreEqual(((XamlElementStartNode)n).ElementType, typeof(ConsoleWriter)); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlPropertyNode); Assert.AreEqual(n.Depth, 2); Assert.AreEqual(((XamlPropertyNode)n).DP, ConsoleApp.RepetitionsProperty); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlTextNode); Assert.AreEqual(((XamlTextNode)n).TextContent, "3"); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlElementEndNode); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlElementEndNode); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlDocumentEndNode); } @@ -508,44 +509,44 @@ public class XamlParserTest { "<ConsoleReader.Prompt><ConsoleWriter /></ConsoleReader.Prompt>\n" + "</ConsoleReader>\n" + "</ConsoleApp>"; - XamlParser p = new XamlParser(new StringReader(MAPPING + s)); + object p = buildParser(new StringReader(MAPPING + s)); XamlNode n; - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlDocumentStartNode, "A1"); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlElementStartNode, "B1"); Assert.AreEqual(n.Depth, 0, "B2"); Assert.AreEqual(((XamlElementStartNode)n).ElementType, typeof(ConsoleApp), "B3"); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlElementStartNode, "C1"); Assert.AreEqual(1, n.Depth, "C2"); Assert.AreEqual(((XamlElementStartNode)n).ElementType, typeof(ConsoleReader), "C3"); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlPropertyNode, "D1"); Assert.AreEqual(2, n.Depth, "D3"); Assert.AreEqual(((XamlPropertyNode)n).PropInfo, typeof(ConsoleReader).GetProperty("Prompt"), "D2"); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlElementStartNode, "E1" + n.GetType()); Assert.AreEqual(3, n.Depth, "E2"); Assert.AreEqual(((XamlElementStartNode)n).ElementType, typeof(ConsoleWriter), "E3"); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlElementEndNode, "F1" + n.GetType()); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlPropertyComplexEndNode, "G1"); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlElementEndNode, "H1"); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlElementEndNode, "I1"); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlDocumentEndNode, "J1"); } @@ -579,25 +580,25 @@ public class XamlParserTest { { string s = "<ConsoleApp xmlns=\"console\" xmlns:x=\"http://schemas.microsoft.com/winfx/xaml/2005\" SomethingHappened=\"handleSomething\">\n"+ "</ConsoleApp>"; - XamlParser p = new XamlParser(new StringReader(MAPPING + s)); + object p = buildParser(new StringReader(MAPPING + s)); XamlNode n; - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlDocumentStartNode, "A1"); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlElementStartNode, "B1"); Assert.AreEqual(n.Depth, 0, "B2"); Assert.AreEqual(((XamlElementStartNode)n).ElementType, typeof(ConsoleApp), "B3"); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlClrEventNode, "C1"); Assert.AreEqual(((XamlClrEventNode)n).EventMember, typeof(ConsoleApp).GetEvent("SomethingHappened"), "C2"); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlElementEndNode, "D1"); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlDocumentEndNode, "E1"); } @@ -607,39 +608,39 @@ public class XamlParserTest { string s = "<ConsoleApp xmlns=\"console\" xmlns:x=\"http://schemas.microsoft.com/winfx/xaml/2005\">\n"+ "<ConsoleWriter Filter=\"filterfilter\" />\n"+ "</ConsoleApp>"; - XamlParser p = new XamlParser(new StringReader(MAPPING + s)); + object p = buildParser(new StringReader(MAPPING + s)); XamlNode n; - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlDocumentStartNode, "A1"); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlElementStartNode, "B1"); Assert.AreEqual(n.Depth, 0, "B2"); Assert.AreEqual(((XamlElementStartNode)n).ElementType, typeof(ConsoleApp), "B3"); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlElementStartNode, "C1"); Assert.AreEqual(n.Depth, 1, "C2"); Assert.AreEqual(((XamlElementStartNode)n).ElementType, typeof(ConsoleWriter), "C3"); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlPropertyNode, "D1"); Assert.AreEqual(n.Depth, 1, "D2"); Assert.AreEqual(((XamlPropertyNode)n).PropInfo, typeof(ConsoleWriter).GetProperty("Filter"), "D3"); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlClrEventNode, "E1"); Assert.AreEqual((MemberInfo)((XamlClrEventNode)n).EventMember, typeof(ConsoleWriter).GetProperty("Filter"), "E2"); Assert.AreEqual(((XamlClrEventNode)n).Value, "filterfilter", "E3"); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlElementEndNode, "F1"); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlElementEndNode, "G1"); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlDocumentEndNode, "H1"); } @@ -649,24 +650,24 @@ public class XamlParserTest { string s = "<ConsoleApp xmlns=\"console\" xmlns:x=\"http://schemas.microsoft.com/winfx/xaml/2005\">\n"+ "<x:Code><![CDATA[Hi there <thing /> here there everywhere]]></x:Code>\n"+ "</ConsoleApp>"; - XamlParser p = new XamlParser(new StringReader(MAPPING + s)); + object p = buildParser(new StringReader(MAPPING + s)); XamlNode n; - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlDocumentStartNode, "A1"); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlElementStartNode, "B1"); Assert.AreEqual(((XamlElementStartNode)n).ElementType, typeof(ConsoleApp), "B3"); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlLiteralContentNode, "C1"); Assert.AreEqual("Hi there <thing /> here there everywhere", ((XamlLiteralContentNode)n).Content, "C2"); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlElementEndNode, "D1"); - n = p.GetNextNode(); + n = getNextNode(p); Assert.IsTrue(n is XamlDocumentEndNode, "E1"); } @@ -682,351 +683,30 @@ public class XamlParserTest { makeGoBang(MAPPING + s); } -} - - - -abstract class Happening { - // this space deliberately left blank -} - -class CreateTopLevelHappening : Happening -{ - public Type parent; - public string className; - public CreateTopLevelHappening(Type parent, string name) { - this.parent = parent; - this.className = name; - } -} - -class CreateObjectHappening : Happening -{ - public Type type; - public string objectName; - public CreateObjectHappening(Type type, string name) { - this.type = type; - this.objectName = name; - } -} - -class CreateObjectTextHappening : Happening -{ - public string text; - public CreateObjectTextHappening(string text) { - this.text = text; - } -} - -class EndObjectHappening : Happening -{ - // this space deliberately left blank -} - -class CreatePropertyHappening : Happening -{ - public PropertyInfo property; - public CreatePropertyHappening(PropertyInfo property){ - this.property = property; - } -} - -class CreatePropertyTextHappening : Happening -{ - public string text; - public Type propertyType; - public CreatePropertyTextHappening(string text, Type propertyType){ - this.text = text; - this.propertyType = propertyType; - } -} - -class CreatePropertyObjectHappening : Happening -{ - public Type type; - public string objectName; - - public CreatePropertyObjectHappening(Type type, string objectName) { - this.type = type; - this.objectName = objectName; - } -} -class EndPropertyObjectHappening : Happening -{ - public Type type; - - public EndPropertyObjectHappening(Type type) { - this.type = type; - } -} -class CreatePropertyDelegateHappening : Happening -{ - public string functionName; - public Type propertyType; - - public CreatePropertyDelegateHappening(string functionName, Type propertyType) { - this.functionName = functionName; - this.propertyType = propertyType; - } -} - -class EndPropertyHappening : Happening -{ - // this space deliberately left blank -} - -class CreateEventHappening : Happening -{ - public EventInfo evt; - public CreateEventHappening(EventInfo evt) { - this.evt = evt; - } -} - -class CreateEventDelegateHappening : Happening -{ - public string functionName; - public Type eventDelegateType; - public CreateEventDelegateHappening(string functionName, Type eventDelegateType) { - this.functionName = functionName; - this.eventDelegateType = eventDelegateType; - } -} - -class EndEventHappening : Happening -{ - // this space deliberately left blank -} - -class CreateDependencyPropertyHappening : Happening -{ - public Type attachedTo; - public string propertyName; - public Type propertyType; - public CreateDependencyPropertyHappening(Type attachedTo, string propertyName, Type propertyType) { - this.attachedTo = attachedTo; - this.propertyName = propertyName; - this.propertyType = propertyType; - } -} - -class CreateDependencyPropertyTextHappening : Happening -{ - public string text; - public Type propertyType; - public CreateDependencyPropertyTextHappening(string text, Type propertyType) { - this.text = text; - this.propertyType = propertyType; - } -} - -class EndDependencyPropertyHappening : Happening -{ - // this space deliberately left blank -} - -class CreateCodeHappening : Happening -{ - public string code; - public CreateCodeHappening(string code) { - this.code = code; - } -} - -class FinishHappening : Happening -{ - // this space deliberately left blank -} - - -class ParserTester : IXamlWriter { - string document; - Happening[] happenings; - int c; - public ParserTester(string document, params Happening[] happenings) - { - this.document = document; - this.happenings = happenings; - this.c = 0; - } - public void Test() - { -/* XamlParser p = new XamlParser(new StringReader(document), - this); - p.Parse(); - // if this fails, then we haven't consumed all the happenings - Assert.AreEqual(happenings.Length, c);*/ - Assert.IsTrue(false); - } - Happening getHappening() + XamlNode getNextNode(object p) { - Assert.IsFalse(c >= happenings.Length, "not enough happenings in list"); - return happenings[c++]; + MethodInfo getter = p.GetType().GetMethod("GetNextNode"); + Assert.IsTrue(getter != null, "Couldn't get next-node-getter"); + try { + XamlNode n = (XamlNode)getter.Invoke(p, null); + Assert.IsTrue(n != null, "Couldn't get next node"); + return n; + } catch (TargetInvocationException ex) { + throw ex.InnerException; + } } - private void AssertSubclass(Type parent, bool consume) - { - Assert.IsFalse(c >= happenings.Length, "not enough happenings in list"); - Happening child = happenings[c]; - - Debug.WriteLine("WRITER CURRENT EXPECTED THING: " + child.GetType()); -// - if (child.GetType() != parent) - Assert.Fail("The method called was a " + parent + ", but was expecting a " + child.GetType()); - if (consume) - c++; - } - private void d(string step) + object buildParser(TextReader input) { - Debug.WriteLine("WRITER IN STEP" + step); + Type xamlParserType = (Type)typeof(Mono.Windows.Serialization.CodeWriter).GetField("xamlParserType", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null); + Assert.IsTrue(xamlParserType != null, "couldn't get type of parser"); + object p = Activator.CreateInstance(xamlParserType, new object[] { input}); + Assert.IsTrue(p != null, "couldn't get instance of parser"); + return p; } - - public void CreateTopLevel(Type parent, string className) - { - d("CreateTopLevel"); - AssertSubclass(typeof(CreateTopLevelHappening), false); - - CreateTopLevelHappening h = (CreateTopLevelHappening)getHappening(); - Assert.AreEqual(h.parent, parent); - Assert.AreEqual(h.className, className); - } - - public void CreateObject(Type type, string objectName){ - d("CreateObject"); - AssertSubclass(typeof(CreateObjectHappening), false); - - CreateObjectHappening h = (CreateObjectHappening)getHappening(); - Assert.AreEqual(h.type, type); - Assert.AreEqual(h.objectName, objectName); - } - - public void CreateObjectText(string text){ - d("CreateObjectText"); - AssertSubclass(typeof(CreateObjectTextHappening), false); - - CreateObjectTextHappening h = (CreateObjectTextHappening)getHappening(); - Assert.AreEqual(h.text, text); - } - - public void EndObject(){ - d("EndObject"); - AssertSubclass(typeof(EndObjectHappening), true); - } - - public void CreateProperty(PropertyInfo property){ - d("CreateProperty"); - AssertSubclass(typeof(CreatePropertyHappening), false); - - CreatePropertyHappening h = (CreatePropertyHappening)getHappening(); - Assert.AreEqual(h.property, property); - } - - public void CreatePropertyObject(Type type, string objectName){ - d("CreatePropertyObject"); - AssertSubclass(typeof(CreatePropertyObjectHappening), false); - - CreatePropertyObjectHappening h = (CreatePropertyObjectHappening)getHappening(); - Assert.AreEqual(h.type, type); - Assert.AreEqual(h.objectName, objectName); - } - public void EndPropertyObject(Type type) { - d("EndPropertyObject"); - AssertSubclass(typeof(EndPropertyObjectHappening), false); - - EndPropertyObjectHappening h = (EndPropertyObjectHappening)getHappening(); - Assert.AreEqual(h.type, type); - } - - public void CreatePropertyText(string text, Type propertyType){ - d("CreatePropertyText"); - AssertSubclass(typeof(CreatePropertyTextHappening), false); - - CreatePropertyTextHappening h = (CreatePropertyTextHappening)getHappening(); - Assert.AreEqual(h.text, text); - Assert.AreEqual(h.propertyType, propertyType); - } - - public void CreatePropertyDelegate(string functionName, Type propertyType){ - d("CreatePropertyDelegate"); - AssertSubclass(typeof(CreatePropertyDelegateHappening), false); - - CreatePropertyDelegateHappening h = (CreatePropertyDelegateHappening)getHappening(); - Assert.AreEqual(h.functionName, functionName); - Assert.AreEqual(h.propertyType, propertyType); - } - - public void EndProperty(){ - d("EndProperty"); - AssertSubclass(typeof(EndPropertyHappening), true); - } - - - public void CreateEvent(EventInfo evt){ - d("CreateEvent"); - AssertSubclass(typeof(CreateEventHappening), false); - - CreateEventHappening h = (CreateEventHappening)getHappening(); - Assert.AreEqual(h.evt, evt); - } - - public void CreateEventDelegate(string functionName, Type eventDelegateType){ - d("CreateEventDelegate"); - AssertSubclass(typeof(CreateEventDelegateHappening), false); - - CreateEventDelegateHappening h = (CreateEventDelegateHappening)getHappening(); - Assert.AreEqual(h.functionName, functionName); - Assert.AreEqual(h.eventDelegateType, eventDelegateType); - } - - public void EndEvent(){ - d("EndEvent"); - AssertSubclass(typeof(EndEventHappening), true); - } - - - public void CreateDependencyProperty(Type attachedTo, string propertyName, Type propertyType){ - d("CreateDependencyProperty"); - AssertSubclass(typeof(CreateDependencyPropertyHappening), false); - - CreateDependencyPropertyHappening h = (CreateDependencyPropertyHappening)getHappening(); - Assert.AreEqual(h.attachedTo, attachedTo); - Assert.AreEqual(h.propertyName, propertyName); - Assert.AreEqual(h.propertyType, propertyType); - } - - public void CreateDependencyPropertyText(string text, Type propertyType){ - d("CreateDependencyPropertyText"); - AssertSubclass(typeof(CreateDependencyPropertyTextHappening), false); - - CreateDependencyPropertyTextHappening h = (CreateDependencyPropertyTextHappening)getHappening(); - Assert.AreEqual(h.text, text); - Assert.AreEqual(h.propertyType, propertyType); - } - - public void EndDependencyProperty(){ - d("EndDependencyProperty"); - AssertSubclass(typeof(EndDependencyPropertyHappening), true); - } - - - public void CreateCode(string code){ - d("CreateCode"); - AssertSubclass(typeof(CreateCodeHappening), false); - - CreateCodeHappening h = (CreateCodeHappening)getHappening(); - Assert.AreEqual(h.code, code); - } - - - public void Finish() - { - d("Finish"); - AssertSubclass(typeof(FinishHappening), true); - } - - } + } diff --git a/mcs/tools/xamlc/ChangeLog b/mcs/tools/xamlc/ChangeLog index c7c1823b8bd..5d60c92a12e 100644 --- a/mcs/tools/xamlc/ChangeLog +++ b/mcs/tools/xamlc/ChangeLog @@ -1,3 +1,8 @@ +2005-08-26 Iain McCoy <iain@mccoy.id.au> + + * demo/runtimetest.cs: use the newly-renamed Parser class instead of + the interim ObjectWriter + 2005-08-23 Iain McCoy <iain@mccoy.id.au> * xamlc.cs: consume the new CodeWriter interface diff --git a/mcs/tools/xamlc/demo/runtimetest.cs b/mcs/tools/xamlc/demo/runtimetest.cs index fc310b6e712..e8c20e16a06 100644 --- a/mcs/tools/xamlc/demo/runtimetest.cs +++ b/mcs/tools/xamlc/demo/runtimetest.cs @@ -1,11 +1,10 @@ using Xaml.TestVocab.Console; using System.Xml; using System.Windows.Serialization; -using Mono.Windows.Serialization; class RuntimeTest { public static void Main(string[] args) { - ConsoleApp c = (ConsoleApp)ObjectWriter.Parse(new XmlTextReader("runtimetest.xaml")); + ConsoleApp c = (ConsoleApp)Parser.LoadXml(new XmlTextReader("runtimetest.xaml")); c.Run(); } |