2009-03-31 Atsushi Enomoto <atsushi@ximian.com>
authorAtsushi Eno <atsushieno@gmail.com>
Tue, 31 Mar 2009 14:17:05 +0000 (14:17 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Tue, 31 Mar 2009 14:17:05 +0000 (14:17 -0000)
* XmlBinaryDictionaryReader.cs, XmlDictionaryWriter.cs :
  a couple of fixes to reflect correct values for node properties
  on each read step.

* XmlBinaryDictionaryReaderTest.cs: make tests more doubtful on
  state.

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

mcs/class/System.Runtime.Serialization/System.Xml/ChangeLog
mcs/class/System.Runtime.Serialization/System.Xml/XmlBinaryDictionaryReader.cs
mcs/class/System.Runtime.Serialization/System.Xml/XmlDictionaryWriter.cs
mcs/class/System.Runtime.Serialization/Test/System.Xml/ChangeLog
mcs/class/System.Runtime.Serialization/Test/System.Xml/XmlBinaryDictionaryReaderTest.cs

index 1aa127b9534b5483fed516b3827fde4b9519736e..46f9a4951e7e3a3a61eed3189f6493a6d962c88d 100755 (executable)
@@ -1,3 +1,9 @@
+2009-03-31  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * XmlBinaryDictionaryReader.cs, XmlDictionaryWriter.cs :
+         a couple of fixes to reflect correct values for node properties
+         on each read step.
+
 2009-03-31  Atsushi Enomoto  <atsushi@ximian.com>
 
        * XmlBinaryDictionaryReader.cs, XmlBinaryFormat.cs :
index 22df6c81a73c7923242467f46a17622752431593..17a80719f0443baa2480d9f725a2d2e045efcca9 100644 (file)
@@ -42,8 +42,6 @@ namespace System.Xml
 {
        // FIXME:
        //      - support XmlDictionaryReaderQuotas.
-       //      - support XmlBinaryReaderSession.
-       //      - handle namespaces as expected.
 
        internal class XmlBinaryDictionaryReader : XmlDictionaryReader, IXmlNamespaceResolver
        {
@@ -114,9 +112,9 @@ namespace System.Xml
                        // 0 or more to fill later
                        public int NSSlot;
 
-                       string name;
-                       string local_name;
-                       string ns;
+                       string name = String.Empty;
+                       string local_name = String.Empty;
+                       string ns = String.Empty;
                        string value;
 
                        public string LocalName {
@@ -215,6 +213,7 @@ namespace System.Xml
                        {
                                base.Reset ();
                                ValueIndex = -1;
+                               NodeType = XmlNodeType.Attribute;
                        }
                }
 
@@ -310,7 +309,7 @@ namespace System.Xml
                }
 
                public override int Depth {
-                       get { return depth; }
+                       get { return current == node ? depth : NodeType == XmlNodeType.Attribute ? depth + 1 : depth + 2; }
                }
 
                public override bool EOF {
@@ -330,15 +329,16 @@ namespace System.Xml
                }
 
                public override string Prefix {
-                       get { return current.Prefix; }
+                       get { return current_attr >= 0 ? attributes [current_attr].Prefix : current.Prefix; }
                }
 
+               // looks like it may return attribute's name even if it is on its value node.
                public override string LocalName {
-                       get { return current.LocalName; }
+                       get { return current_attr >= 0 ? attributes [current_attr].LocalName : current.LocalName; }
                }
 
                public override string NamespaceURI {
-                       get { return current.NS; }
+                       get { return current_attr >= 0 ? attributes [current_attr].NS : current.NS; }
                }
 
                public override XmlNameTable NameTable {
@@ -475,12 +475,15 @@ namespace System.Xml
                                current = attr_values [start];
                                return true;
                        }
+                       // Actually there is no case for attribute whose value is split to more than two nodes. We could simplify the node structure.
+                       /*
                        for (int i = start; i < end; i++) {
                                if (current == attr_values [i] && i + 1 < end) {
                                        current = attr_values [i + 1];
                                        return true;
                                }
                        }
+                       */
                        return false;
                }
 
@@ -517,7 +520,6 @@ namespace System.Xml
                                }
                                else
                                        node = node_stack [depth];
-                               node.Reset ();
                                current = node;
                        }
 
@@ -526,7 +528,6 @@ namespace System.Xml
                                ProcessEndElement ();
                                return true;
                        }
-                       node.Reset ();
 
                        // process array node after preparing node stack.
                        switch (array_state) {
@@ -546,6 +547,9 @@ namespace System.Xml
                                }
                        }
 
+                       // array consumer does not expect Reset whlie it's on reading. So call it later than array check.
+                       node.Reset ();
+
                        int ident = next >= 0 ? next : source.ReadByte ();
                        next = -1;
 
index 8dcd2731cdab62ad6afecf522e3a121f6be4e997..84f7e62aba8a7c75c0b4ccb99300703f8a600132 100644 (file)
@@ -152,8 +152,6 @@ namespace System.Xml
                        throw new NotSupportedException ();
                }
 
-               // FIXME: add Write*Array() overloads.
-
                public void WriteAttributeString (
                        XmlDictionaryString localName,
                        XmlDictionaryString namespaceUri,
index 883eb7115f9ec2a5670cb6c662f9ca413926f018..1c4a0f5f5f1ee91cb18094cb92d8e4cf13250f27 100644 (file)
@@ -1,3 +1,8 @@
+2009-03-31  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * XmlBinaryDictionaryReaderTest.cs: make tests more doubtful on
+         state.
+
 2009-03-31  Atsushi Enomoto  <atsushi@ximian.com>
 
        * XmlBinaryDictionaryReaderTest.cs: test array reader.
index eff339ed17004e5d80be8a145c59648646ff94a2..9a2f763d0c68c1fae3b16739ebdb199a32feb4a4 100644 (file)
@@ -44,6 +44,20 @@ namespace MonoTests.System.Xml
 
                        while (!reader.EOF)
                                reader.Read ();
+                       // FIXME: use this instead; right now some tests are broken.
+                       //XmlDocument doc = new XmlDocument ();
+                       //doc.AppendChild (doc.CreateElement ("root"));
+                       //while (!reader.EOF)
+                       //      doc.DocumentElement.AppendChild (doc.ReadNode (reader));
+               }
+
+               void AssertNode (XmlNodeType nodeType, string localName, string ns, string value, int depth, XmlReader reader, string label)
+               {
+                       Assert.AreEqual (nodeType, reader.NodeType, label + ".Node");
+                       Assert.AreEqual (localName, reader.LocalName, label + ".LocalName");
+                       Assert.AreEqual (ns, reader.NamespaceURI, label + ".NS");
+                       Assert.AreEqual (value, reader.Value, label + ".Value");
+                       Assert.AreEqual (depth, reader.Depth, label + ".Depth");
                }
 
                [Test]
@@ -303,6 +317,17 @@ namespace MonoTests.System.Xml
                                };
 
                        Read (bytes);
+
+                       XmlDictionaryReader reader = XmlDictionaryReader.CreateBinaryReader (new MemoryStream (bytes), new XmlDictionaryReaderQuotas ());
+                       Assert.IsTrue (reader.Read (), "#1-1");
+                       AssertNode (XmlNodeType.Element, "root", "urn:bar", "", 0, reader, "#1");
+                       reader.MoveToAttribute (0);
+                       if (reader.LocalName != "a")
+                               reader.MoveToAttribute (1);
+                       AssertNode (XmlNodeType.Attribute, "a", "", "", 1, reader, "#2");
+                       Assert.IsTrue (reader.ReadAttributeValue (), "#3");
+                       AssertNode (XmlNodeType.Text, "a", "", "", 2, reader, "#4");
+                       Assert.IsFalse (reader.ReadAttributeValue (), "#5");
                }
 
                [Test]
@@ -339,7 +364,25 @@ namespace MonoTests.System.Xml
                [Test]
                public void ReadInt16Array ()
                {
-                       Read (array_int16);
+                       Read (array_int32);
+
+                       XmlDictionaryReader reader = XmlDictionaryReader.CreateBinaryReader (new MemoryStream (array_int16), new XmlDictionaryReaderQuotas ());
+                       Assert.IsTrue (reader.Read (), "#1-1");
+                       AssertNode (XmlNodeType.Element, "el", "", "", 0, reader, "#1-2");
+                       Assert.IsTrue (reader.Read (), "#2-1");
+                       AssertNode (XmlNodeType.Text, "", "", "4", 1, reader, "#2-2");
+                       Assert.IsTrue (reader.Read (), "#3-1");
+                       AssertNode (XmlNodeType.EndElement, "el", "", "", 0, reader, "#3-2");
+                       Assert.IsTrue (reader.Read (), "#4-1");
+                       AssertNode (XmlNodeType.Element, "el", "", "", 0, reader, "#4-2");
+                       Assert.IsTrue (reader.Read (), "#5-1");
+                       AssertNode (XmlNodeType.Text, "", "", "6", 1, reader, "#5-2");
+                       Assert.IsTrue (reader.Read (), "#6-1");
+                       AssertNode (XmlNodeType.EndElement, "el", "", "", 0, reader, "#6-2");
+                       for (int i = 0; i < 3; i++) // 6, 8, 10
+                               for (int j = 0; j < 3; j++) // el / text / endel
+                                       Assert.IsTrue (reader.Read (), "#x-" + i + j);
+                       Assert.IsFalse (reader.Read (), "End");
                }
 
                static readonly byte [] array_int16 = {