2008-05-12 Atsushi Enomoto <atsushi@ximian.com>
authorAtsushi Eno <atsushieno@gmail.com>
Mon, 12 May 2008 08:48:54 +0000 (08:48 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Mon, 12 May 2008 08:48:54 +0000 (08:48 -0000)
* XStreamingElement.cs : couple of fixes:
  - object[] args are params.
  - Fixed WriteContents(object[],XmlWriter) wrong iteration.
  - do not write xmldecl when it does not exist (OmitXmlDeclaration).

* XStreamingElementTest.cs : new test.

* System.Xml.Linq_test.dll.sources : added XStreamingElementTest.cs.

svn path=/trunk/mcs/; revision=102986

mcs/class/System.Xml.Linq/ChangeLog
mcs/class/System.Xml.Linq/System.Xml.Linq/ChangeLog
mcs/class/System.Xml.Linq/System.Xml.Linq/XStreamingElement.cs
mcs/class/System.Xml.Linq/System.Xml.Linq_test.dll.sources
mcs/class/System.Xml.Linq/Test/System.Xml.Linq/ChangeLog
mcs/class/System.Xml.Linq/Test/System.Xml.Linq/XStreamingElementTest.cs [new file with mode: 0755]

index e0a2f0ac32b8836daa8dbc8f6218d8d8d261800d..394691f77efc84d0b1696f9a28c3874ba451f9c7 100644 (file)
@@ -1,3 +1,7 @@
+2008-05-12  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * System.Xml.Linq_test.dll.sources : added XStreamingElementTest.cs.
+
 2008-04-06  Roei Erez  <roeie@mainsoft.com>
 
        * System.Xml.Linq.csproj: some modifications to the project file.
index 64d7e34d8574361c91f69fb2e04047cad324e401..f119680d619b510261ce6312d096415417bbc7a6 100644 (file)
@@ -1,3 +1,10 @@
+2008-05-12  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * XStreamingElement.cs : couple of fixes:
+         - object[] args are params.
+         - Fixed WriteContents(object[],XmlWriter) wrong iteration.
+         - do not write xmldecl when it does not exist (OmitXmlDeclaration).
+
 2008-04-30  Atsushi Enomoto  <atsushi@ximian.com>
 
        * XElement.cs, XNode.cs : XNode.ReadFrom() should not reuse
index 97238eec9f41703cc09f762a1838c169d632d56f..4a637eaab335193de7a01660420a0431de732ff8 100644 (file)
@@ -43,7 +43,7 @@ namespace System.Xml.Linq
                        Add (content);
                }
 
-               public XStreamingElement (XName name, object [] content)
+               public XStreamingElement (XName name, params object [] content)
                        : this (name)
                {
                        Add (content);
@@ -68,7 +68,7 @@ namespace System.Xml.Linq
                        contents.Add (content);
                }
 
-               public void Add (object [] content)
+               public void Add (params object [] content)
                {
                        if (contents == null)
                                contents = new List<object> ();
@@ -100,6 +100,7 @@ namespace System.Xml.Linq
                public void Save (TextWriter textWriter, SaveOptions options)
                {
                        XmlWriterSettings s = new XmlWriterSettings ();
+                       s.OmitXmlDeclaration = true;
                        s.Indent = options != SaveOptions.DisableFormatting;
                        using (XmlWriter w = XmlWriter.Create (textWriter, s))
                                Save (w);
@@ -126,7 +127,7 @@ namespace System.Xml.Linq
 
                void WriteContents (IEnumerable<object> items, XmlWriter w)
                {
-                       foreach (object o in contents) {
+                       foreach (object o in items) {
                                if (o == null)
                                        continue;
                                else if (o is object [])
index 6bcad49ff3781fbc2935393e48154721b89dbf67..e932781bbfcf5753034d9a443a1c48e79b6a81ff 100644 (file)
@@ -11,4 +11,5 @@ System.Xml.Linq/XNodeReaderTest.cs
 System.Xml.Linq/XNodeWriterTest.cs
 System.Xml.Linq/XObjectTest.cs
 System.Xml.Linq/XProcessingInstructionTest.cs
+System.Xml.Linq/XStreamingElementTest.cs
 System.Xml.Linq/XTextTest.cs
index bdc1c9d821e52da9280a4d827745d66155fd1404..5d9f0464bcf6206f0bd2c2c51e7d16fec2062b33 100644 (file)
@@ -1,3 +1,7 @@
+2008-05-12  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * XStreamingElementTest.cs : new test.
+
 2008-04-30  Atsushi Enomoto  <atsushi@ximian.com>
 
        * XNodeReaderTest.cs : added CreateReader3().
diff --git a/mcs/class/System.Xml.Linq/Test/System.Xml.Linq/XStreamingElementTest.cs b/mcs/class/System.Xml.Linq/Test/System.Xml.Linq/XStreamingElementTest.cs
new file mode 100755 (executable)
index 0000000..e144dbc
--- /dev/null
@@ -0,0 +1,58 @@
+//
+// Authors:
+//   Atsushi Enomoto
+//
+// Copyright 2007 Novell (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.IO;
+using System.Xml;
+using System.Xml.Linq;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.Xml.Linq
+{
+       [TestFixture]
+       public class XStreamingElementTest
+       {
+               [Test]
+               public void ToString ()
+               {
+                       var el = new XStreamingElement ("foo",
+                               new XAttribute ("bar", "baz"),
+                               "text");
+                       Assert.AreEqual ("<foo bar=\"baz\">text</foo>", el.ToString ());
+               }
+
+               [Test]
+               [ExpectedException (typeof (InvalidOperationException))]
+               public void ToStringAttributeAfterText ()
+               {
+                       var el = new XStreamingElement ("foo",
+                               "text",
+                               new XAttribute ("bar", "baz"));
+                       el.ToString ();
+               }
+       }
+}