Sfoglia il codice sorgente

2006-04-05 Atsushi Enomoto <[email protected]>

	* XmlWriter.cs : Create(StringBuilder,XmlWriterSettings) was missing
	  settings argument to pass another .ctor().
	* XmlWriterSettings.cs : set_NewLineChars() should reject null.

	* XmlWriterSettingsTest.cs : added tests on set_Encoding(),
	  set_NewLineChars() and OmitXmlDeclaration.


svn path=/trunk/mcs/; revision=59061
Atsushi Eno 20 anni fa
parent
commit
ac928fb2a9

+ 6 - 0
mcs/class/System.XML/System.Xml/ChangeLog

@@ -1,3 +1,9 @@
+2006-04-05  Atsushi Enomoto <[email protected]>
+
+	* XmlWriter.cs : Create(StringBuilder,XmlWriterSettings) was missing
+	  settings argument to pass another .ctor().
+	* XmlWriterSettings.cs : set_NewLineChars() should reject null.
+
 2006-04-03	Boris Kirzner <[email protected]>
 	* XmlException.cs: fix .net soap serialization compatibility.
 

+ 1 - 8
mcs/class/System.XML/System.Xml/XmlWriter.cs

@@ -116,35 +116,28 @@ namespace System.Xml
 			return Create (builder, null);
 		}
 
-		[MonoTODO ("NewLineHandling/OutputMethod")]
 		public static XmlWriter Create (Stream stream, XmlWriterSettings settings)
 		{
-			// FIXME: this might result in encoding null reference
 			Encoding enc = settings != null ? settings.Encoding : Encoding.UTF8;
 			return Create (new StreamWriter (stream, enc), settings);
 		}
 
-		[MonoTODO ("NewLineHandling/OutputMethod")]
 		public static XmlWriter Create (string file, XmlWriterSettings settings)
 		{
-			// FIXME: this might result in encoding null reference
 			Encoding enc = settings != null ? settings.Encoding : Encoding.UTF8;
 			return Create (new StreamWriter (file, false, enc), settings);
 		}
 
-		[MonoTODO ("NewLineHandling/OutputMethod")]
 		public static XmlWriter Create (StringBuilder builder, XmlWriterSettings settings)
 		{
-			return Create (new StringWriter (builder), null);
+			return Create (new StringWriter (builder), settings);
 		}
 
-		[MonoTODO ("NewLineHandling/OutputMethod")]
 		public static XmlWriter Create (TextWriter writer, XmlWriterSettings settings)
 		{
 			return CreateTextWriter (writer, settings);
 		}
 
-		[MonoTODO ("NewLineHandling/OutputMethod")]
 		public static XmlWriter Create (XmlWriter writer, XmlWriterSettings settings)
 		{
 			if (settings == null)

+ 5 - 1
mcs/class/System.XML/System.Xml/XmlWriterSettings.cs

@@ -130,7 +130,11 @@ namespace System.Xml
 		// It affects only on XmlTextWriter
 		public string NewLineChars {
 			get { return newLineChars; }
-			set { newLineChars = value; }
+			set {
+				if (value == null)
+					throw new ArgumentNullException ("value");
+				newLineChars = value;
+			}
 		}
 
 		// It affects only on XmlTextWriter

+ 5 - 0
mcs/class/System.XML/Test/System.Xml/ChangeLog

@@ -1,3 +1,8 @@
+2006-04-05  Atsushi Enomoto <[email protected]>
+
+	* XmlWriterSettingsTest.cs : added tests on set_Encoding(),
+	  set_NewLineChars() and OmitXmlDeclaration.
+
 2006-03-08  Atsushi Enomoto <[email protected]>
 
 	* XmlReaderCommonTests.cs : Added tests for ReadContentAsString() and

+ 31 - 0
mcs/class/System.XML/Test/System.Xml/XmlWriterSettingsTests.cs

@@ -137,6 +137,37 @@ namespace MonoTests.System.Xml
 			w.Close ();
 			AssertEquals (output, sw.ToString ());
 		}
+
+		[Test]
+		public void SetEncodingNull ()
+		{
+			// null is allowed.
+			new XmlWriterSettings ().Encoding = null;
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentNullException))]
+		public void NewLineCharsNull ()
+		{
+			new XmlWriterSettings ().NewLineChars = null;
+		}
+
+		[Test]
+		public void CreateOmitXmlDeclaration ()
+		{
+			StringBuilder sb = new StringBuilder ();
+			// Even if XmlWriter is allowed to write fragment,
+			// DataContractSerializer never allows it to write
+			// content in contentOnly mode.
+			XmlWriterSettings settings = new XmlWriterSettings ();
+			settings.OmitXmlDeclaration = true;
+			//settings.ConformanceLevel = ConformanceLevel.Fragment;
+			XmlWriter w = XmlWriter.Create (sb, settings);
+			w.WriteStartElement ("root");
+			w.WriteEndElement ();
+			w.Flush ();
+			AssertEquals ("<root />", sb.ToString ());
+		}
 	}
 }
 #endif