Author: iainmc
Date: 2005-07-17 10:05:44 -0400 (Sun, 17 Jul 2005)
New Revision: 47365
Modified:
trunk/mcs/class/PresentationFramework/ChangeLog
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs
trunk/mcs/class/PresentationFramework/Test/XamlParser.cs
Log:
2005-07-17 Iain McCoy <[EMAIL PROTECTED]>
* Test/XamlParser.cs: add a bunch of tests
* Mono.Windows.Serialization/XamlParser.cs: improve error reporting,
don't accept elements without namespaces
Modified: trunk/mcs/class/PresentationFramework/ChangeLog
===================================================================
--- trunk/mcs/class/PresentationFramework/ChangeLog 2005-07-17 13:34:46 UTC
(rev 47364)
+++ trunk/mcs/class/PresentationFramework/ChangeLog 2005-07-17 14:05:44 UTC
(rev 47365)
@@ -1,3 +1,9 @@
+2005-07-17 Iain McCoy <[EMAIL PROTECTED]>
+
+ * Test/XamlParser.cs: add a bunch of tests
+ * Mono.Windows.Serialization/XamlParser.cs: improve error reporting,
+ don't accept elements without namespaces
+
2005-07-16 Iain McCoy <[EMAIL PROTECTED]>
* Test/XamlParser.cs: fix a bug in property tests, add tests for
Modified:
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs
===================================================================
---
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs
2005-07-17 13:34:46 UTC (rev 47364)
+++
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs
2005-07-17 14:05:44 UTC (rev 47365)
@@ -79,7 +79,7 @@
{
while (reader.Read()) {
Debug.WriteLine("NOW PARSING: " +
reader.NodeType + "; " + reader.Name + "; " + reader.Value);
- if (begun && currentState == null &&
reader.NodeType != XmlNodeType.Whitespace)
+ if (begun && currentState == null &&
reader.NodeType != XmlNodeType.Whitespace && reader.NodeType !=
XmlNodeType.Comment)
throw new Exception("Too far: " +
reader.NodeType + ", " + reader.Name);
if (currentState != null && currentState.type
== CurrentType.Code)
{
@@ -124,6 +124,8 @@
void parseElement()
{
+ if (reader.NamespaceURI == "")
+ throw new Exception("No xml namespace
specified.");
if (reader.LocalName == "Code" && reader.NamespaceURI
== XAML_NAMESPACE) {
parseCodeElement();
return;
@@ -192,9 +194,7 @@
PropertyInfo prop =
currentType.GetProperty(propertyName);
if (prop == null) {
- Console.WriteLine("Property " + propertyName +
" not found on " + currentType.Name);
- return;
- // TODO: exception
+ throw new Exception("Property '" + propertyName
+ "' not found on '" + currentType.Name + "'.");
}
push(CurrentType.Property, prop);
@@ -227,6 +227,8 @@
bool isEmpty = reader.IsEmptyElement;
parent = mapper.GetType(reader.NamespaceURI,
reader.Name);
+ if (parent == null)
+ throw new Exception("Class '" + reader.Name +
"' not found.");
if
(parent.GetInterface("System.Windows.Serialization.IAddChild") == null)
{} //TODO: throw exception
if (currentState == null) {
@@ -305,11 +307,8 @@
PropertyInfo prop =
currentType.GetProperty(propertyName);
if (parsedAsEventProperty(currentType, propertyName))
return;
- if (prop == null) {
- Console.WriteLine("Property " + propertyName +
" not found on " + currentType.Name);
- return;
- // TODO: throw exception
- }
+ if (prop == null)
+ throw new Exception ("Property '" +
propertyName + "' not found on '" + currentType.Name + "'.");
writer.CreateProperty(prop);
@@ -358,7 +357,7 @@
{
FieldInfo propField =
typeAttachedTo.GetField(propertyName + "Property");
if (propField == null)
- throw new Exception("Property " + propertyName
+ " does not exist on " + typeAttachedTo.Name);
+ throw new Exception("Property '" + propertyName
+ "' does not exist on '" + typeAttachedTo.Name + "'.");
return (DependencyProperty)propField.GetValue(null);
}
Modified: trunk/mcs/class/PresentationFramework/Test/XamlParser.cs
===================================================================
--- trunk/mcs/class/PresentationFramework/Test/XamlParser.cs 2005-07-17
13:34:46 UTC (rev 47364)
+++ trunk/mcs/class/PresentationFramework/Test/XamlParser.cs 2005-07-17
14:05:44 UTC (rev 47365)
@@ -9,6 +9,7 @@
using System;
using System.Diagnostics;
using System.IO;
+using System.Xml;
using System.Reflection;
using System.Windows;
using Mono.Windows.Serialization;
@@ -33,6 +34,42 @@
[Test]
public void TestTopLevel()
{
+ string s = "<ConsoleApp xmlns=\"console\"></ConsoleApp>";
+ ParserTester pt = new ParserTester(MAPPING + s,
+ new CreateTopLevelHappening(typeof(ConsoleApp),
null),
+ new EndObjectHappening(),
+ new FinishHappening());
+ pt.Test();
+ }
+
+ [Test]
+ [ExpectedException(typeof(Exception), "Class 'ConsoleApple' not
found.")]
+ public void TestTopLevelWithIncorrectClassName()
+ {
+ string s = "<ConsoleApple xmlns=\"console\"></ConsoleApple>";
+ ParserTester pt = new ParserTester(MAPPING + s,
+ new CreateTopLevelHappening(typeof(ConsoleApp),
null),
+ new EndObjectHappening(),
+ new FinishHappening());
+ pt.Test();
+ }
+
+ [Test]
+ [ExpectedException(typeof(XmlException))]
+ public void TestTopLevelWithWrongEndingTag()
+ {
+ string s = "<ConsoleApp xmlns=\"console\"></ConsoleApple>";
+ ParserTester pt = new ParserTester(MAPPING + s,
+ new CreateTopLevelHappening(typeof(ConsoleApp),
null),
+ new EndObjectHappening(),
+ new FinishHappening());
+ pt.Test();
+ }
+
+ [Test]
+ [ExpectedException(typeof(Exception), "No xml namespace specified.")]
+ public void TestTopLevelWithoutNamespace()
+ {
string s = "<ConsoleApp></ConsoleApp>";
ParserTester pt = new ParserTester(MAPPING + s,
new CreateTopLevelHappening(typeof(ConsoleApp),
null),
@@ -40,10 +77,11 @@
new FinishHappening());
pt.Test();
}
+
[Test]
- public void TestTopLevelWithClass()
+ public void TestTopLevelWithClassName()
{
- string s = "<ConsoleApp
xmlns:x=\"http://schemas.microsoft.com/winfx/xaml/2005\" x:Class=\"nnn\">\n"+
+ string s = "<ConsoleApp xmlns=\"console\"
xmlns:x=\"http://schemas.microsoft.com/winfx/xaml/2005\" x:Class=\"nnn\">\n"+
"</ConsoleApp>";
ParserTester pt = new ParserTester(MAPPING + s,
new CreateTopLevelHappening(typeof(ConsoleApp),
"nnn"),
@@ -53,10 +91,10 @@
}
[Test]
- [ExpectedException(typeof(Exception))]
+ [ExpectedException(typeof(Exception), "The XAML Name attribute can not
be applied to top level elements\nDo you mean the Class attribute?")]
public void TestTopLevelWithName()
{
- string s = "<ConsoleApp
xmlns:x=\"http://schemas.microsoft.com/winfx/xaml/2005\" x:Name=\"nnn\">\n"+
+ string s = "<ConsoleApp xmlns=\"console\"
xmlns:x=\"http://schemas.microsoft.com/winfx/xaml/2005\" x:Name=\"nnn\">\n"+
"</ConsoleApp>";
ParserTester pt = new ParserTester(MAPPING + s,
new CreateTopLevelHappening(typeof(ConsoleApp),
"nnn"), // this is a lie, actually we expect
@@ -69,7 +107,7 @@
[Test]
public void TestSimplestAddChild()
{
- string s = "<ConsoleApp
xmlns:x=\"http://schemas.microsoft.com/winfx/xaml/2005\">\n"+
+ string s = "<ConsoleApp xmlns=\"console\"
xmlns:x=\"http://schemas.microsoft.com/winfx/xaml/2005\">\n"+
"<ConsoleWriter></ConsoleWriter>" +
"</ConsoleApp>";
ParserTester pt = new ParserTester(MAPPING + s,
@@ -82,9 +120,26 @@
}
[Test]
+ [ExpectedException(typeof(Exception), "Class 'ConsoleWritttter' not
found.")]
+ public void TestSimplestAddChildWithIncorrectName()
+ {
+ string s = "<ConsoleApp xmlns=\"console\"
xmlns:x=\"http://schemas.microsoft.com/winfx/xaml/2005\">\n"+
+ "<ConsoleWritttter></ConsoleWritttter>" +
+ "</ConsoleApp>";
+ ParserTester pt = new ParserTester(MAPPING + s,
+ new CreateTopLevelHappening(typeof(ConsoleApp),
null),
+ new
CreateObjectHappening(typeof(ConsoleWriter), null),
+ new EndObjectHappening(),
+ new EndObjectHappening(),
+ new FinishHappening());
+ pt.Test();
+ }
+
+
+ [Test]
public void TestSimplestAddChildAndText()
{
- string s = "<ConsoleApp
xmlns:x=\"http://schemas.microsoft.com/winfx/xaml/2005\">\n"+
+ string s = "<ConsoleApp xmlns=\"console\"
xmlns:x=\"http://schemas.microsoft.com/winfx/xaml/2005\">\n"+
"<ConsoleWriter>Hello</ConsoleWriter>" +
"</ConsoleApp>";
ParserTester pt = new ParserTester(MAPPING + s,
@@ -100,7 +155,7 @@
[Test]
public void TestTextProperty()
{
- string s = "<ConsoleApp
xmlns:x=\"http://schemas.microsoft.com/winfx/xaml/2005\">\n"+
+ string s = "<ConsoleApp xmlns=\"console\"
xmlns:x=\"http://schemas.microsoft.com/winfx/xaml/2005\">\n"+
"<ConsoleWriter Text=\"Hello\" />" +
"</ConsoleApp>";
ParserTester pt = new ParserTester(MAPPING + s,
@@ -114,10 +169,30 @@
new FinishHappening());
pt.Test();
}
+
[Test]
+ [ExpectedException(typeof(Exception), "Property 'Texxxt' not found on
'ConsoleWriter'.")]
+ public void TestTextPropertyWithIncorrectName()
+ {
+ string s = "<ConsoleApp xmlns=\"console\"
xmlns:x=\"http://schemas.microsoft.com/winfx/xaml/2005\">\n"+
+ "<ConsoleWriter Texxxt=\"Hello\" />" +
+ "</ConsoleApp>";
+ ParserTester pt = new ParserTester(MAPPING + s,
+ new CreateTopLevelHappening(typeof(ConsoleApp),
null),
+ new
CreateObjectHappening(typeof(ConsoleWriter), null),
+ new
CreatePropertyHappening(typeof(ConsoleWriter).GetProperty("Text")),
+ new CreatePropertyTextHappening("Hello",
typeof(ConsoleValue)),
+ new EndPropertyHappening(),
+ new EndObjectHappening(), //ConsoleWriter
+ new EndObjectHappening(), //ConsoleApp
+ new FinishHappening());
+ pt.Test();
+ }
+
+ [Test]
public void TestTextPropertyAsElement()
{
- string s = "<ConsoleApp
xmlns:x=\"http://schemas.microsoft.com/winfx/xaml/2005\">\n"+
+ string s = "<ConsoleApp xmlns=\"console\"
xmlns:x=\"http://schemas.microsoft.com/winfx/xaml/2005\">\n"+
"<ConsoleWriter><ConsoleWriter.Text>Hello</ConsoleWriter.Text></ConsoleWriter>\n"
+
"</ConsoleApp>";
ParserTester pt = new ParserTester(MAPPING + s,
@@ -133,9 +208,28 @@
}
[Test]
- public void testDependencyProperty()
+ [ExpectedException(typeof(Exception), "Property 'Texxxt' not found on
'ConsoleWriter'.")]
+ public void TestTextPropertyAsElementWithIncorrectName()
{
- string s = "<ConsoleApp
xmlns:x=\"http://schemas.microsoft.com/winfx/xaml/2005\">\n"+
+ string s = "<ConsoleApp xmlns=\"console\"
xmlns:x=\"http://schemas.microsoft.com/winfx/xaml/2005\">\n"+
+
"<ConsoleWriter><ConsoleWriter.Texxxt>Hello</ConsoleWriter.Text></ConsoleWriter>\n"
+
+ "</ConsoleApp>";
+ ParserTester pt = new ParserTester(MAPPING + s,
+ new CreateTopLevelHappening(typeof(ConsoleApp),
null),
+ new
CreateObjectHappening(typeof(ConsoleWriter), null),
+ new
CreatePropertyHappening(typeof(ConsoleWriter).GetProperty("Text")),
+ new CreatePropertyTextHappening("Hello",
typeof(ConsoleValue)),
+ new EndPropertyHappening(),
+ new EndObjectHappening(), //ConsoleWriter
+ new EndObjectHappening(), //ConsoleApp
+ new FinishHappening());
+ pt.Test();
+ }
+
+ [Test]
+ public void TestDependencyProperty()
+ {
+ string s = "<ConsoleApp xmlns=\"console\"
xmlns:x=\"http://schemas.microsoft.com/winfx/xaml/2005\">\n"+
"<ConsoleWriter ConsoleApp.Repetitions=\"3\" />" +
"</ConsoleApp>";
ParserTester pt = new ParserTester(MAPPING + s,
@@ -149,11 +243,31 @@
new FinishHappening());
pt.Test();
}
+
+ [Test]
+ [ExpectedException(typeof(Exception), "Property 'Reps' does not exist
on 'ConsoleApp'.")]
+ public void TestDependencyPropertyWithIncorrectName()
+ {
+ string s = "<ConsoleApp xmlns=\"console\"
xmlns:x=\"http://schemas.microsoft.com/winfx/xaml/2005\">\n"+
+ "<ConsoleWriter ConsoleApp.Reps=\"3\" />" +
+ "</ConsoleApp>";
+ ParserTester pt = new ParserTester(MAPPING + s,
+ new CreateTopLevelHappening(typeof(ConsoleApp),
null),
+ new
CreateObjectHappening(typeof(ConsoleWriter), null),
+ new
CreateDependencyPropertyHappening(typeof(ConsoleApp), "Repetitions",
typeof(int)),
+ new CreateDependencyPropertyTextHappening("3"),
+ new EndDependencyPropertyHappening(),
+ new EndObjectHappening(), // ConsoleWriter
+ new EndObjectHappening(), // ConsoleApp
+ new FinishHappening());
+ pt.Test();
+ }
+
[Test]
- public void testDependencyPropertyAsChildElement()
+ public void TestDependencyPropertyAsChildElement()
{
- string s = "<ConsoleApp
xmlns:x=\"http://schemas.microsoft.com/winfx/xaml/2005\">\n"+
+ string s = "<ConsoleApp xmlns=\"console\"
xmlns:x=\"http://schemas.microsoft.com/winfx/xaml/2005\">\n"+
"<ConsoleWriter><ConsoleApp.Repetitions>3</ConsoleApp.Repetitions></ConsoleWriter>"
+
"</ConsoleApp>";
ParserTester pt = new ParserTester(MAPPING + s,
@@ -167,9 +281,31 @@
new FinishHappening());
pt.Test();
}
- public void testObjectAsPropertyValue()
+
+ [Test]
+ [ExpectedException(typeof(Exception), "Property 'Reps' does not exist
on 'ConsoleApp'.")]
+ public void TestDependencyPropertyAsChildElementWithIncorrectName()
{
- string s = "<ConsoleApp
xmlns:x=\"http://schemas.microsoft.com/winfx/xaml/2005\">\n"+
+ string s = "<ConsoleApp xmlns=\"console\"
xmlns:x=\"http://schemas.microsoft.com/winfx/xaml/2005\">\n"+
+
"<ConsoleWriter><ConsoleApp.Reps>3</ConsoleApp.Reps></ConsoleWriter>" +
+ "</ConsoleApp>";
+ ParserTester pt = new ParserTester(MAPPING + s,
+ new CreateTopLevelHappening(typeof(ConsoleApp),
null),
+ new
CreateObjectHappening(typeof(ConsoleWriter), null),
+ new
CreateDependencyPropertyHappening(typeof(ConsoleApp), "Repetitions",
typeof(int)),
+ new CreateDependencyPropertyTextHappening("3"),
+ new EndDependencyPropertyHappening(),
+ new EndObjectHappening(), // ConsoleWriter
+ new EndObjectHappening(), // ConsoleApp
+ new FinishHappening());
+ pt.Test();
+ }
+
+
+ [Test]
+ public void TestObjectAsPropertyValue()
+ {
+ string s = "<ConsoleApp xmlns=\"console\"
xmlns:x=\"http://schemas.microsoft.com/winfx/xaml/2005\">\n"+
"<ConsoleReader>\n" +
"<ConsoleReader.Prompt><ConsoleWriter
/></ConsoleReader.Prompt>\n" +
"</ConsoleReader>\n" +
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches