Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIain McCoy <iainmc@mono-cvs.ximian.com>2005-07-25 17:43:42 +0400
committerIain McCoy <iainmc@mono-cvs.ximian.com>2005-07-25 17:43:42 +0400
commit9dce0c5ea7de2824efa4f6199fde11cb13ad35d0 (patch)
tree8b157442c33370552095f423c9f9a6f37fcfe61c /mcs/class/PresentationFramework
parent9191e0c5db18025221d390981ae2335c17bbd345 (diff)
2005-07-25 Iain McCoy <iain@mccoy.id.au>
* 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
Diffstat (limited to 'mcs/class/PresentationFramework')
-rw-r--r--mcs/class/PresentationFramework/ChangeLog11
-rw-r--r--mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs6
-rw-r--r--mcs/class/PresentationFramework/Test/CodeWriter.cs76
-rw-r--r--mcs/class/PresentationFramework/Test/XamlParser.cs70
4 files changed, 157 insertions, 6 deletions
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 <iain@mccoy.id.au>
+
+ * 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 <iain@mccoy.id.au>
* 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()
{
@@ -248,6 +296,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()
{
cw.CreateTopLevel(typeof(ConsoleApp), null);
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
@@ -74,6 +74,19 @@ public class XamlParserTest : Assertion {
public void Clean() {}
[Test]
+ [ExpectedException(typeof(Exception), "Unknown processing instruction.")]
+ public void TestIncorrectPIName()
+ {
+ string s = "<?Mapppping ClrNamespace=\"Xaml.TestVocab.Console\" Assembly=\"./TestVocab.dll\" XmlNamespace=\"console\" ?>\n";
+ ParserTester pt = new ParserTester(s,
+ new CreateTopLevelHappening(typeof(ConsoleApp), null),
+ new EndObjectHappening(),
+ new FinishHappening());
+ pt.Test();
+
+ }
+
+ [Test]
public void TestTopLevel()
{
string s = "<ConsoleApp xmlns=\"console\"></ConsoleApp>";
@@ -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 = "<ConsoleApp xmlns=\"console\" xmlns:x=\"http://schemas.microsoft.com/winfx/xaml/2005\">\n"+
+ "<ConsoleValueString ConsoleApp.Repetitions=\"3\" />" +
+ "</ConsoleApp>";
+ 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 = "<ConsoleApp xmlns=\"console\" xmlns:x=\"http://schemas.microsoft.com/winfx/xaml/2005\">\n"+
"<ConsoleValueString>\n" +
- "xyz" +
+ "ABC" +
"</ConsoleValueString>\n" +
"</ConsoleApp>";
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 = "<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>";
+ ParserTester pt = new ParserTester(MAPPING + s,
+ new CreateTopLevelHappening(typeof(ConsoleApp), null),
+ new CreateCodeHappening("Hi there <thing /> 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 = "<ConsoleApp xmlns=\"console\" xmlns:x=\"http://schemas.microsoft.com/winfx/xaml/2005\">\n"+
+ "<x:Code>Hi there <thing /> here there everywhere</x:Code>\n"+
+ "</ConsoleApp>";
+ ParserTester pt = new ParserTester(MAPPING + s,
+ new CreateTopLevelHappening(typeof(ConsoleApp), null),
+ new CreateCodeHappening("Hi there <thing /> here there everywhere"),
+ new EndObjectHappening(),
+ new FinishHappening());
+ pt.Test();
+ }
+
}