From 86e2fc2faad35a2cbe251f65f744a7aaaff16cda Mon Sep 17 00:00:00 2001 From: Atsushi Eno Date: Mon, 25 Oct 2010 16:17:53 +0900 Subject: [PATCH] Add a couple of writer tests (NotWorking) and fixed XamlServices to not omit xmldecl. --- mcs/class/System.Xaml/System.Xaml/XamlServices.cs | 6 +- .../Test/System.Xaml/XamlXmlWriterTest.cs | 110 +++++++++++++++++++++ 2 files changed, 114 insertions(+), 2 deletions(-) diff --git a/mcs/class/System.Xaml/System.Xaml/XamlServices.cs b/mcs/class/System.Xaml/System.Xaml/XamlServices.cs index b70f876cc05..5de7b6cacbb 100644 --- a/mcs/class/System.Xaml/System.Xaml/XamlServices.cs +++ b/mcs/class/System.Xaml/System.Xaml/XamlServices.cs @@ -79,12 +79,14 @@ namespace System.Xaml public static void Save (Stream stream, object instance) { - Save (new XamlXmlWriter (stream, new XamlSchemaContext ()), instance); + using (var xw = XmlWriter.Create (stream, new XmlWriterSettings () { OmitXmlDeclaration = true })) + Save (xw, instance); } public static void Save (TextWriter textWriter, object instance) { - Save (new XamlXmlWriter (textWriter, new XamlSchemaContext ()), instance); + using (var xw = XmlWriter.Create (textWriter, new XmlWriterSettings () { OmitXmlDeclaration = true })) + Save (xw, instance); } public static void Save (XmlWriter xmlWriter, object instance) diff --git a/mcs/class/System.Xaml/Test/System.Xaml/XamlXmlWriterTest.cs b/mcs/class/System.Xaml/Test/System.Xaml/XamlXmlWriterTest.cs index 78544df1b7c..ab844427d27 100644 --- a/mcs/class/System.Xaml/Test/System.Xaml/XamlXmlWriterTest.cs +++ b/mcs/class/System.Xaml/Test/System.Xaml/XamlXmlWriterTest.cs @@ -25,6 +25,7 @@ using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.IO; +using System.Linq; using System.Reflection; using System.Windows.Markup; using System.Xaml; @@ -631,6 +632,115 @@ namespace MonoTests.System.Xaml xw.Close (); string xml = String.Format (@"", GetType ().Assembly.GetName ().Name); } + + string ReadXml (string name) + { + return File.ReadAllText ("Test/XmlFiles/" + name).Trim ().Replace ("\r\n", "\n").Replace ("\n", Environment.NewLine); + } + + [Test] + public void Write_String () + { + Assert.AreEqual (ReadXml ("String.xml"), XamlServices.Save ("foo"), "#1"); + } + + [Test] + public void Write_Int32 () + { + Assert.AreEqual (ReadXml ("Int32.xml"), XamlServices.Save (5), "#1"); + } + + [Test] + public void Write_DateTime () + { + Assert.AreEqual (ReadXml ("DateTime.xml"), XamlServices.Save (new DateTime (2010, 4, 14)), "#1"); + } + + [Test] + public void Write_TimeSpan () + { + Assert.AreEqual (ReadXml ("TimeSpan.xml"), XamlServices.Save (TimeSpan.FromMinutes (7)), "#1"); + } + + [Test] + [Category ("NotWorking")] + public void Write_Null () + { + Assert.AreEqual (ReadXml ("NullExtension.xml"), XamlServices.Save (null), "#1"); + } + + [Test] + [Category ("NotWorking")] + public void Write_NullExtension () + { + Assert.AreEqual (ReadXml ("NullExtension.xml"), XamlServices.Save (new NullExtension ()), "#1"); + } + + [Test] + [Category ("NotWorking")] + public void Write_Type () + { + Assert.AreEqual (ReadXml ("Type.xml").Trim (), XamlServices.Save (typeof (int)), "#1"); + } + + [Test] + public void Write_Guid () + { + Assert.AreEqual (ReadXml ("Guid.xml").Trim (), XamlServices.Save (Guid.Parse ("9c3345ec-8922-4662-8e8d-a4e41f47cf09")), "#1"); + } + + [Test] + [Category ("NotWorking")] + public void Write_StaticExtension () + { + Assert.AreEqual (ReadXml ("StaticExtension.xml").Trim (), XamlServices.Save (new StaticExtension ("FooBar")), "#1"); + } + + [Test] + [Category ("NotWorking")] + public void Write_Reference () + { + Assert.AreEqual (ReadXml ("Reference.xml").Trim (), XamlServices.Save (new Reference ("FooBar")), "#1"); + } + + [Test] + [Category ("NotWorking")] + public void Write_ArrayInt32 () + { + Assert.AreEqual (ReadXml ("Array_Int32.xml").Trim (), XamlServices.Save (new int [] {4, -5, 0, 255, int.MaxValue}), "#1"); + } + + [Test] + [Category ("NotWorking")] + public void Write_ListInt32 () + { + Assert.AreEqual (ReadXml ("List_Int32.xml").Trim (), XamlServices.Save (new int [] {4, -5, 0, 255, int.MaxValue}.ToList ()), "#1"); + } + + [Test] + [Category ("NotWorking")] + public void Write_DictionaryInt32String () + { + var dic = new Dictionary (); + dic.Add (0, "foo"); + dic.Add (5, "bar"); + dic.Add (-2, "baz"); + Assert.AreEqual (ReadXml ("Dictionary_Int32_String.xml").Trim (), XamlServices.Save (dic), "#1"); + } + + [Test] + [Category ("NotWorking")] + public void Write_DictionaryStringType () + { + var dic = new Dictionary (); + dic.Add ("t1", typeof (int)); + dic.Add ("t2", typeof (int [])); + dic.Add ("t3", typeof (int?)); + dic.Add ("t4", typeof (List)); + dic.Add ("t5", typeof (Dictionary)); + dic.Add ("t6", typeof (List>)); + Assert.AreEqual (ReadXml ("Dictionary_String_Type.xml").Trim (), XamlServices.Save (dic), "#1"); + } } public class TestXmlWriterClass1 -- 2.11.4.GIT