Author: atsushi
Date: 2007-05-03 13:23:15 -0400 (Thu, 03 May 2007)
New Revision: 76630
Added:
trunk/olive/class/System.Xml.Linq/Test/System.Xml.Linq/XElementTest.cs
Modified:
trunk/olive/class/System.Xml.Linq/System.Xml.Linq/ChangeLog
trunk/olive/class/System.Xml.Linq/System.Xml.Linq/XContainer.cs
trunk/olive/class/System.Xml.Linq/System.Xml.Linq/XDeclaration.cs
trunk/olive/class/System.Xml.Linq/System.Xml.Linq/XDocument.cs
trunk/olive/class/System.Xml.Linq/System.Xml.Linq/XElement.cs
trunk/olive/class/System.Xml.Linq/System.Xml.Linq/XName.cs
trunk/olive/class/System.Xml.Linq/System.Xml.Linq/XNamespace.cs
trunk/olive/class/System.Xml.Linq/System.Xml.Linq/XNode.cs
trunk/olive/class/System.Xml.Linq/System.Xml.Linq_test.dll.sources
trunk/olive/class/System.Xml.Linq/Test/System.Xml.Linq/ChangeLog
trunk/olive/class/System.Xml.Linq/Test/System.Xml.Linq/XDocumentTest.cs
trunk/olive/class/System.Xml.Linq/Test/System.Xml.Linq/XNamespaceTest.cs
Log:
2007-05-03 Atsushi Enomoto <[EMAIL PROTECTED]>
* XNode.cs
XElement.cs
XDocument.cs
XContainer.cs : some basic tree implementation.
Removed list-based code. Fixed erroneous reader settings.
* XDeclaration.cs : removed extra space in ToString().
* XNamespace.cs : added operator overloads.
* XName.cs : implemented ToString().
* XElementTest.cs : new test.
* XNamespaceTest.cs
XDocumentTest.cs : some tests for simple tree structure.
Modified: trunk/olive/class/System.Xml.Linq/System.Xml.Linq/ChangeLog
===================================================================
--- trunk/olive/class/System.Xml.Linq/System.Xml.Linq/ChangeLog 2007-05-03
16:49:42 UTC (rev 76629)
+++ trunk/olive/class/System.Xml.Linq/System.Xml.Linq/ChangeLog 2007-05-03
17:23:15 UTC (rev 76630)
@@ -1,5 +1,16 @@
2007-05-03 Atsushi Enomoto <[EMAIL PROTECTED]>
+ * XNode.cs
+ XElement.cs
+ XDocument.cs
+ XContainer.cs : some basic tree implementation.
+ Removed list-based code. Fixed erroneous reader settings.
+ * XDeclaration.cs : removed extra space in ToString().
+ * XNamespace.cs : added operator overloads.
+ * XName.cs : implemented ToString().
+
+2007-05-03 Atsushi Enomoto <[EMAIL PROTECTED]>
+
yuck, I was updating things based on March CTP, not Beta1 ...
* LoadOptions.cs
SaveOptions.cs
Modified: trunk/olive/class/System.Xml.Linq/System.Xml.Linq/XContainer.cs
===================================================================
--- trunk/olive/class/System.Xml.Linq/System.Xml.Linq/XContainer.cs
2007-05-03 16:49:42 UTC (rev 76629)
+++ trunk/olive/class/System.Xml.Linq/System.Xml.Linq/XContainer.cs
2007-05-03 17:23:15 UTC (rev 76630)
@@ -13,35 +13,26 @@
{
}
-#if LIST_BASED
- List <object> list = new List <object> ();
+ XNode first;
+ XNode last;
public XNode FirstNode {
- get { return list.Count > 0 ? (XNode) list [0] : null; }
+ get { return first; }
+ internal set { first = value; }
}
- public XNode LastNode{
- get { return list.Count > 0 ? (XNode) list [list.Count
- 1] : null; }
- }
-#else
- XNode lastChild;
-
- public XNode FirstNode {
- get { return lastChild != null ? lastChild.InternalNext
: null; }
- }
-
public XNode LastNode {
- get { return lastChild; }
+ get { return last; }
+ internal set { last = value; }
}
-#endif
- void CheckChildType (object o)
+ void CheckChildType (object o, bool addFirst)
{
if (o == null || o is string || o is XNode)
return;
if (o is IEnumerable) {
foreach (object oc in ((IEnumerable) o))
- CheckChildType (oc);
+ CheckChildType (oc, addFirst);
return;
}
else
@@ -66,24 +57,18 @@
// AddAttribute ((XAttribute) content);
// return;
// }
- CheckChildType (content);
-#if LIST_BASED
- if (content is XNode)
- ((XNode) content).Parent = this as XElement;
- list.Add (content);
-#else
+
XNode n = XUtil.ToNode (content);
+ CheckChildType (n, false);
+ OnAdded (n, false);
n.Parent = this as XElement;
- if (lastChild == null) {
- lastChild = n;
- n.InternalNext = n;
- }
+ if (first == null)
+ last = first = n;
else {
- XNode firstChild = lastChild != null ?
lastChild.InternalNext : null;
- lastChild.UpdateTree (this, n);
- n.UpdateTree (this, firstChild);
+ last.NextNode = n;
+ n.PreviousNode = last;
+ last = n;
}
-#endif
}
public void Add (params object [] content)
@@ -100,23 +85,17 @@
// AddAttribute ((XAttribute) content);
// return;
// }
- CheckChildType (content);
-#if LIST_BASED
- if (content is XNode)
- ((XNode) content).Parent = this as XElement;
- list.Insert (0, content);
-#else
XNode n = XUtil.ToNode (content);
+ OnAdded (n, true);
+ CheckChildType (n, true);
n.Parent = this as XElement;
- if (lastChild == null) {
- lastChild = n;
- n.InternalNext = n;
- }
+ if (first == null)
+ first = last = n;
else {
- n.UpdateTree (this, lastChild.InternalNext);
- lastChild.UpdateTree (this, n);
+ n.NextNode = first;
+ first.PreviousNode = n;
+ first = n;
}
-#endif
}
public void AddFirst (params object [] content)
@@ -131,81 +110,11 @@
throw new NotImplementedException ();
}
-#if LIST_BASED
- internal object GetNextSibling (object target)
- {
- int i = list.IndexOf (target);
- return i + 1 == list.Count ? null : list [i + 1];
- }
-
- internal void InsertBefore (object from, object target)
- {
-// if (target is XAttribute) {
-// AddAttribute ((XAttribute) target);
-// return;
-// }
- CheckChildType (target);
- int index = list.IndexOf (from);
- if (target is XNode)
- ((XNode) target).Parent = this as XElement;
- list.Insert (index, target);
- }
-
- internal void InsertBefore (object from, params object []
target)
- {
- foreach (object o in target)
- CheckChildType (o);
- if (target.Length == 0)
- return;
- int index = list.IndexOf (from);
- if (index == 0) {
- List <object> tmp = list;
- list = new List <object> (list.Count +
target.Length);
- Add (target);
- list.AddRange (tmp);
- } else {
- InsertAfter (list [index - 1], target);
- }
- }
-
- internal void InsertAfter (object from, object target)
- {
-// if (target is XAttribute) {
-// AddAttribute ((XAttribute) target);
-// return;
-// }
- CheckChildType (target);
- int index = list.IndexOf (from);
- if (target is XNode)
- ((XNode) target).Parent = this as XElement;
- list.Insert (index + 1, target);
- }
-
- internal void InsertAfter (object from, params object [] target)
- {
- for (int i = 0; i < target.Length; i++) {
- CheckChildType (target [i]);
- InsertAfter (from, target [i]);
- from = target [i];
- }
- }
-
- internal void RemoveChild (object target)
- {
- list.Remove (target);
- }
-#endif
-
public IEnumerable <XNode> Nodes ()
{
-#if LIST_BASED
- foreach (XNode n in list)
- yield return n;
-#else
//return new XChildrenIterator (this);
for (XNode n = FirstNode; n != null; n = n.NextNode)
yield return n;
-#endif
}
public IEnumerable<XNode> DescendantNodes ()
@@ -259,37 +168,20 @@
return null;
}
- /*
- public void ReadContentFrom (XmlReader reader)
+ internal void ReadContentFrom (XmlReader reader)
{
- if (reader.IsEmptyElement)
- reader.Read ();
- else {
- reader.Read ();
- do {
- if (reader.NodeType ==
XmlNodeType.EndElement)
- // end of the element.
- break;
- if (reader.NodeType == XmlNodeType.Text)
- Add (reader.Value);
- else
- Add (XNode.ReadFrom (reader));
- } while (reader.Read ());
- reader.Read ();
+ while (!reader.EOF) {
+ if (reader.NodeType == XmlNodeType.EndElement)
+ // end of the element.
+ break;
+ Add (XNode.ReadFrom (reader));
}
}
- */
public void RemoveNodes ()
{
-#if LIST_BASED
- foreach (object o in list)
- if (o is XNode)
- ((XNode) o).Parent = null;
-#else
foreach (XNode n in Nodes ())
n.Remove ();
-#endif
}
public void ReplaceNodes (object content)
@@ -317,5 +209,9 @@
}
}
*/
+
+ internal virtual void OnAdded (XNode item, bool addFirst)
+ {
+ }
}
}
Modified: trunk/olive/class/System.Xml.Linq/System.Xml.Linq/XDeclaration.cs
===================================================================
--- trunk/olive/class/System.Xml.Linq/System.Xml.Linq/XDeclaration.cs
2007-05-03 16:49:42 UTC (rev 76629)
+++ trunk/olive/class/System.Xml.Linq/System.Xml.Linq/XDeclaration.cs
2007-05-03 17:23:15 UTC (rev 76630)
@@ -51,10 +51,16 @@
public override string ToString ()
{
- return String.Concat ("<?xml ",
- version != null ? "version=\"" + version + "\"
" : null,
- encoding != null ? "encoding=\"" + encoding +
"\" " : null,
- standalone != null ? "standalone=\"" +
standalone + "\" " : null,
+ return String.Concat ("<?xml",
+ version != null ? " version=\"" : null,
+ version != null ? version : null,
+ version != null ? "\"" : null,
+ encoding != null ? " encoding=\"" : null,
+ encoding != null ? encoding : null,
+ encoding != null ? "\"" : null,
+ standalone != null ? " standalone=\"" : null,
+ standalone != null ? standalone : null,
+ standalone != null ? "\"" : null,
"?>");
}
Modified: trunk/olive/class/System.Xml.Linq/System.Xml.Linq/XDocument.cs
===================================================================
--- trunk/olive/class/System.Xml.Linq/System.Xml.Linq/XDocument.cs
2007-05-03 16:49:42 UTC (rev 76629)
+++ trunk/olive/class/System.Xml.Linq/System.Xml.Linq/XDocument.cs
2007-05-03 17:23:15 UTC (rev 76630)
@@ -94,7 +94,7 @@
public static XDocument Load (XmlReader reader, LoadOptions
options)
{
- XmlReaderSettings s = new XmlReaderSettings ();
+ XmlReaderSettings s = reader.Settings.Clone ();
s.IgnoreWhitespace = (options &
LoadOptions.PreserveWhitespace) == 0;
using (XmlReader r = XmlReader.Create (reader, s)) {
return LoadCore (r);
@@ -113,24 +113,23 @@
reader.GetAttribute ("standalone"));
reader.Read ();
}
- /*
- if (reader.NodeType == XmlNodeType.DocumentType) {
- doc.Add (new XDocumentType (
- reader.Name,
- reader.GetAttribute ("PUBLIC"),
- reader.GetAttribute ("SYSTEM"),
- reader.Value));
- reader.Read ();
- }
- */
- for (; !reader.EOF; reader.Read ())
- if (reader.NodeType == XmlNodeType.Text)
- doc.Add (reader.Value);
- else
- doc.Add (XNode.ReadFrom (reader));
+ doc.ReadContentFrom (reader);
+ if (doc.Root == null)
+ throw new InvalidOperationException ("The
document element is missing.");
return doc;
}
+ static void ValidateWhitespace (string s)
+ {
+ for (int i = 0; i < s.Length; i++)
+ switch (s [i]) {
+ case ' ': case '\t': case '\n': case '\r':
+ continue;
+ default:
+ throw new ArgumentException
("Non-whitespace text appears directly in the document.");
+ }
+ }
+
public static XDocument Parse (string s)
{
return Parse (s, LoadOptions.None);
@@ -195,5 +194,26 @@
foreach (XNode node in Nodes ())
node.WriteTo (w);
}
+
+ internal override void OnAdded (XNode node, bool addFirst)
+ {
+ if (node == null)
+ throw new InvalidOperationException ("Only a
node is allowed here");
+
+ if (node is XText)
+ ValidateWhitespace (((XText) node).Value);
+ else if (node is XDocumentType) {
+ if (DocumentType != null)
+ throw new InvalidOperationException
("There already is another document type declaration");
+ if (Root != null && !addFirst)
+ throw new InvalidOperationException ("A
document type cannot be added after the document element");
+ }
+ else if (node is XElement) {
+ if (Root != null)
+ throw new InvalidOperationException
("There already is another document element");
+ if (DocumentType != null && addFirst)
+ throw new InvalidOperationException
("An element cannot be added before the document type declaration");
+ }
+ }
}
}
Modified: trunk/olive/class/System.Xml.Linq/System.Xml.Linq/XElement.cs
===================================================================
--- trunk/olive/class/System.Xml.Linq/System.Xml.Linq/XElement.cs
2007-05-03 16:49:42 UTC (rev 76629)
+++ trunk/olive/class/System.Xml.Linq/System.Xml.Linq/XElement.cs
2007-05-03 17:23:15 UTC (rev 76630)
@@ -33,20 +33,6 @@
Add (source.Nodes ());
}
- // for Load()
- XElement (XmlReader source)
- {
- if (source.NodeType != XmlNodeType.Element)
- throw new InvalidOperationException ();
- name = XName.Get (source.LocalName,
source.NamespaceURI);
- if (source.MoveToFirstAttribute ()) {
- do {
- SetAttributeValue (XName.Get
(source.LocalName, source.NamespaceURI), source.Value);
- } while (source.MoveToNextAttribute ());
- source.MoveToElement ();
- }
- }
-
public XElement (XName name)
{
this.name = name;
@@ -241,7 +227,7 @@
public static XElement Load (XmlReader reader, LoadOptions
options)
{
- XmlReaderSettings s = new XmlReaderSettings ();
+ XmlReaderSettings s = reader.Settings.Clone ();
s.IgnoreWhitespace = (options &
LoadOptions.PreserveWhitespace) == 0;
using (XmlReader r = XmlReader.Create (reader, s)) {
return LoadCore (r);
@@ -250,27 +236,27 @@
static XElement LoadCore (XmlReader r)
{
- XElement e = new XElement (r);
- using (XmlWriter w = e.CreateWriter ()) {
- if (r.ReadState == ReadState.Initial) {
- while (!r.EOF)
- w.WriteNode (r, false);
- }
- else
- w.WriteNode (r, false);
+ r.MoveToContent ();
+ if (r.NodeType != XmlNodeType.Element)
+ throw new InvalidOperationException ("The
XmlReader must be positioned at an element");
+ XName name = XName.Get (r.LocalName, r.NamespaceURI);
+ XElement e = new XElement (name);
+ if (r.MoveToFirstAttribute ()) {
+ do {
+ e.SetAttributeValue (XName.Get
(r.LocalName, r.NamespaceURI), r.Value);
+ } while (r.MoveToNextAttribute ());
+ r.MoveToElement ();
}
+ if (!r.IsEmptyElement) {
+ r.Read ();
+ e.ReadContentFrom (r);
+ r.ReadEndElement ();
+ }
+ else
+ r.Read ();
return e;
}
- /*
- public static explicit operator bool (XElement e)
- {
- return e.Value == "true";
- }
-
- // FIXME: similar operator overloads should go here.
- */
-
public static XElement Parse (string s)
{
return Parse (s, LoadOptions.None);
@@ -290,8 +276,9 @@
public void RemoveAttributes ()
{
if (attributes != null)
+ // FIXME: should avoid modification?
foreach (XAttribute a in attributes)
- a.Parent = null;
+ a.Remove ();
attributes = null;
}
@@ -483,5 +470,11 @@
{
throw new NotImplementedException ();
}
+
+ internal override void OnAdded (XNode node, bool addFirst)
+ {
+ if (node is XDocument || node is XDocumentType)
+ throw new ArgumentException (String.Format ("A
node of type {0} cannot be added as a content", node.GetType ()));
+ }
}
}
Modified: trunk/olive/class/System.Xml.Linq/System.Xml.Linq/XName.cs
===================================================================
--- trunk/olive/class/System.Xml.Linq/System.Xml.Linq/XName.cs 2007-05-03
16:49:42 UTC (rev 76629)
+++ trunk/olive/class/System.Xml.Linq/System.Xml.Linq/XName.cs 2007-05-03
17:23:15 UTC (rev 76630)
@@ -108,11 +108,11 @@
return ! (n1 == n2);
}
- [MonoTODO]
public override string ToString ()
{
- return base.ToString ();
- //return ExpandedName;
+ if (ns == XNamespace.Blank)
+ return local;
+ return String.Concat ("{", ns.NamespaceName, "}",
local);
}
[MonoTODO]
Modified: trunk/olive/class/System.Xml.Linq/System.Xml.Linq/XNamespace.cs
===================================================================
--- trunk/olive/class/System.Xml.Linq/System.Xml.Linq/XNamespace.cs
2007-05-03 16:49:42 UTC (rev 76629)
+++ trunk/olive/class/System.Xml.Linq/System.Xml.Linq/XNamespace.cs
2007-05-03 17:23:15 UTC (rev 76630)
@@ -1,5 +1,3 @@
-#if NET_2_0
-
using System;
using System.Collections;
using System.Collections.Generic;
@@ -7,8 +5,6 @@
using System.Text;
using System.Xml;
-using XPI = System.Xml.Linq.XProcessingInstruction;
-
namespace System.Xml.Linq
{
public sealed class XNamespace
@@ -60,6 +56,16 @@
return ns != null && uri == ns.uri;
}
+ public static bool operator == (XNamespace o1, XNamespace o2)
+ {
+ return (object) o1 != null ? o1.Equals (o2) : (object)
o2 == null;
+ }
+
+ public static bool operator != (XNamespace o1, XNamespace o2)
+ {
+ return ! (o1 == o2);
+ }
+
public override int GetHashCode ()
{
return uri.GetHashCode ();
@@ -72,5 +78,3 @@
}
}
}
-
-#endif
Modified: trunk/olive/class/System.Xml.Linq/System.Xml.Linq/XNode.cs
===================================================================
--- trunk/olive/class/System.Xml.Linq/System.Xml.Linq/XNode.cs 2007-05-03
16:49:42 UTC (rev 76629)
+++ trunk/olive/class/System.Xml.Linq/System.Xml.Linq/XNode.cs 2007-05-03
17:23:15 UTC (rev 76630)
@@ -5,6 +5,8 @@
using System.Text;
using System.Xml;
+using XPI = System.Xml.Linq.XProcessingInstruction;
+
namespace System.Xml.Linq
{
public abstract class XNode : XObject
@@ -21,14 +23,14 @@
throw new NotImplementedException ();
}
-#if !LIST_BASED
- XNode next;
-#endif
static XNodeEqualityComparer eq_comparer =
new XNodeEqualityComparer ();
static XNodeDocumentOrderComparer order_comparer =
new XNodeDocumentOrderComparer ();
+ XNode previous;
+ XNode next;
+
internal XNode ()
{
}
@@ -42,51 +44,15 @@
}
public XNode PreviousNode {
- get {
- if (Parent == null || object.ReferenceEquals
(Parent.FirstNode, this))
- return null;
-#if LIST_BASED
- IEnumerator e = Parent.Nodes ().GetEnumerator
();
- for (object o = null; e.MoveNext (); o =
e.Current)
- if (object.ReferenceEquals (e.Current,
this))
- return (XNode) o;
- return null;
-#else
- for (XNode n = Parent.LastNode.next; n != null;
n = n.next)
- if (n.next == this)
- return n;
- return null;
-#endif
- }
+ get { return previous; }
+ internal set { previous = value; }
}
public XNode NextNode {
- get {
- if (Parent == null || object.ReferenceEquals
(Parent.LastNode, this))
- return null;
-#if LIST_BASED
- return (XNode) Parent.GetNextSibling (this);
-#else
- return next;
-#endif
- }
- }
-
-#if !LIST_BASED
- internal XNode InternalNext {
get { return next; }
- set { next = value; }
+ internal set { next = value; }
}
-#endif
-#if !LIST_BASED
- internal void UpdateTree (XContainer parent, XNode next)
- {
- this.Parent = parent as XElement;
- this.next = next;
- }
-#endif
-
public string ToString (SaveOptions options)
{
StringWriter sw = new StringWriter ();
@@ -107,72 +73,40 @@
{
if (Parent == null)
throw new InvalidOperationException ();
-#if LIST_BASED
- Parent.InsertAfter (this, content);
-#else
- /*
XNode n = XUtil.ToNode (content);
n.Parent = Parent;
- n.next = next;
+ n.previous = this;
next = n;
- if (Parent.LastNode == null || object.ReferenceEquals
(Parent.LastNode, this))
+ if (Parent.LastNode == this)
Parent.LastNode = n;
- */
- throw new NotImplementedException ();
-#endif
}
public void AddAfterSelf (params object [] content)
{
if (Parent == null)
throw new InvalidOperationException ();
-#if LIST_BASED
- Parent.InsertAfter (this, content);
-#else
- /*
- foreach (object o in new XFilterIterator <object>
(content, null))
+ foreach (object o in content)
AddAfterSelf (o);
- */
- throw new NotImplementedException ();
-#endif
}
public void AddBeforeSelf (object content)
{
if (Parent == null)
throw new InvalidOperationException ();
-#if LIST_BASED
- Parent.InsertBefore (this, content);
-#else
- /*
XNode n = XUtil.ToNode (content);
n.Parent = Parent;
n.next = this;
- XNode p = PreviousSibling;
- if (p != null)
- PreviousSibling.next = n;
- else
- Parent.LastChild.next = this;
- if (Parent.LastChild == null || object.ReferenceEquals
(Parent.LastChild, this))
- Parent.LastChild = n;
- */
- throw new NotImplementedException ();
-#endif
+ previous = n;
+ if (Parent.FirstNode == this)
+ Parent.FirstNode = n;
}
public void AddBeforeSelf (params object [] content)
{
if (Parent == null)
throw new InvalidOperationException ();
-#if LIST_BASED
- Parent.InsertBefore (this, content);
-#else
- /*
- foreach (object o in new XFilterIterator <object>
(content, null))
- AddBeforeSelf (o);
- */
- throw new NotImplementedException ();
-#endif
+ for (int i = content.Length - 1; i >= 0; i--)
+ AddBeforeSelf (content [i]);
}
public static XNode ReadFrom (XmlReader r)
@@ -180,32 +114,42 @@
switch (r.NodeType) {
case XmlNodeType.Element:
return XElement.Load (r);
+ case XmlNodeType.Whitespace:
+ case XmlNodeType.SignificantWhitespace:
case XmlNodeType.Text:
- throw new InvalidOperationException ();
+ XText t = new XText (r.Value);
+ r.Read ();
+ return t;
case XmlNodeType.CDATA:
- return new XCData (r.Value);
+ XCData c = new XCData (r.Value);
+ r.Read ();
+ return c;
case XmlNodeType.ProcessingInstruction:
- return new XProcessingInstruction (r.Name,
r.Value);
+ XPI pi = new XPI (r.Name, r.Value);
+ r.Read ();
+ return pi;
case XmlNodeType.Comment:
- return new XComment (r.Value);
+ XComment cm = new XComment (r.Value);
+ r.Read ();
+ return cm;
case XmlNodeType.DocumentType:
- return new XDocumentType (r.Name,
+ XDocumentType d = new XDocumentType (r.Name,
r.GetAttribute ("PUBLIC"),
r.GetAttribute ("System"),
r.Value);
+ r.Read ();
+ return d;
default:
- throw new NotSupportedException ();
+ throw new NotSupportedException (String.Format
("Node type {0} is not supported", r.NodeType));
}
}
public void Remove ()
{
-#if LIST_BASED
- Parent.RemoveChild (this);
-#else
PreviousNode.next = NextNode;
+ previous = null;
+ next = null;
Parent = null;
-#endif
}
public override string ToString ()
@@ -215,16 +159,17 @@
public abstract void WriteTo (XmlWriter w);
- [MonoTODO]
public IEnumerable<XElement> Ancestors ()
{
- throw new NotImplementedException ();
+ for (XElement el = Parent; el != null; el = el.Parent)
+ yield return el;
}
- [MonoTODO]
public IEnumerable<XElement> Ancestors (XName name)
{
- throw new NotImplementedException ();
+ foreach (XElement el in Ancestors ())
+ if (el.Name == name)
+ yield return el;
}
[MonoTODO]
Modified: trunk/olive/class/System.Xml.Linq/System.Xml.Linq_test.dll.sources
===================================================================
--- trunk/olive/class/System.Xml.Linq/System.Xml.Linq_test.dll.sources
2007-05-03 16:49:42 UTC (rev 76629)
+++ trunk/olive/class/System.Xml.Linq/System.Xml.Linq_test.dll.sources
2007-05-03 17:23:15 UTC (rev 76630)
@@ -1,3 +1,4 @@
System.Xml.Linq/XDocumentTest.cs
+System.Xml.Linq/XElementTest.cs
System.Xml.Linq/XNameTest.cs
System.Xml.Linq/XNamespaceTest.cs
Modified: trunk/olive/class/System.Xml.Linq/Test/System.Xml.Linq/ChangeLog
===================================================================
--- trunk/olive/class/System.Xml.Linq/Test/System.Xml.Linq/ChangeLog
2007-05-03 16:49:42 UTC (rev 76629)
+++ trunk/olive/class/System.Xml.Linq/Test/System.Xml.Linq/ChangeLog
2007-05-03 17:23:15 UTC (rev 76630)
@@ -1,5 +1,11 @@
2007-05-03 Atsushi Enomoto <[EMAIL PROTECTED]>
+ * XElementTest.cs : new test.
+ * XNamespaceTest.cs
+ XDocumentTest.cs : some tests for simple tree structure.
+
+2007-05-03 Atsushi Enomoto <[EMAIL PROTECTED]>
+
* XDocumentTest.cs
XNameTest.cs
XNamespaceTest.cs : initial commit.
Modified:
trunk/olive/class/System.Xml.Linq/Test/System.Xml.Linq/XDocumentTest.cs
===================================================================
--- trunk/olive/class/System.Xml.Linq/Test/System.Xml.Linq/XDocumentTest.cs
2007-05-03 16:49:42 UTC (rev 76629)
+++ trunk/olive/class/System.Xml.Linq/Test/System.Xml.Linq/XDocumentTest.cs
2007-05-03 17:23:15 UTC (rev 76630)
@@ -22,6 +22,50 @@
Assert.IsNull (doc.NextNode, "#3");
Assert.IsNull (doc.PreviousNode, "#4");
Assert.AreEqual (1, new List<XNode> (doc.Nodes
()).Count, "#5");
+ Assert.IsNull (doc.FirstNode.Parent, "#6");
+ Assert.AreEqual (doc.FirstNode, doc.LastNode, "#7");
+ Assert.AreEqual (XmlNodeType.Document, doc.NodeType,
"#8");
+ Assert.AreEqual (doc.FirstNode, doc.Root, "#7");
}
+
+ [Test]
+ [ExpectedException (typeof (ArgumentException))]
+ public void LoadInvalid ()
+ {
+ string xml = "text";
+ XmlReaderSettings s = new XmlReaderSettings ();
+ s.ConformanceLevel = ConformanceLevel.Fragment;
+
+ XDocument.Load (XmlReader.Create (new StringReader
(xml), s));
+ }
+
+ [Test]
+ [ExpectedException (typeof (InvalidOperationException))]
+ public void LoadWhitespaces ()
+ {
+ string xml = " ";
+ XmlReaderSettings s = new XmlReaderSettings ();
+ s.ConformanceLevel = ConformanceLevel.Fragment;
+
+ XDocument.Load (XmlReader.Create (new StringReader
(xml), s));
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentException))]
+ public void AddTextToDocument ()
+ {
+ XDocument doc = new XDocument ();
+ doc.Add ("test");
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentException))]
+ public void AddXDeclarationToDocument ()
+ {
+ XDocument doc = new XDocument ();
+ // XDeclaration is treated as a general object and
+ // hence converted to a string -> error
+ doc.Add (new XDeclaration ("1.0", null, null));
+ }
}
}
Added: trunk/olive/class/System.Xml.Linq/Test/System.Xml.Linq/XElementTest.cs
===================================================================
--- trunk/olive/class/System.Xml.Linq/Test/System.Xml.Linq/XElementTest.cs
2007-05-03 16:49:42 UTC (rev 76629)
+++ trunk/olive/class/System.Xml.Linq/Test/System.Xml.Linq/XElementTest.cs
2007-05-03 17:23:15 UTC (rev 76630)
@@ -0,0 +1,108 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Xml;
+using System.Xml.Linq;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.Xml.Linq
+{
+ [TestFixture]
+ public class XElementTest
+ {
+ [Test] // xml declaration is skipped.
+ public void LoadWithXmldecl ()
+ {
+ string xml = "<?xml version='1.0'?><root />";
+ XElement.Load (new StringReader (xml));
+ }
+
+ [Test]
+ public void Load1 ()
+ {
+ string xml = "<root><foo/></root>";
+
+ XElement el = XElement.Load (new StringReader (xml));
+ XElement first = el.FirstNode as XElement;
+ Assert.IsNotNull (first, "#1");
+ Assert.IsTrue (el.LastNode is XElement, "#2");
+ Assert.IsNull (el.NextNode, "#3");
+ Assert.IsNull (el.PreviousNode, "#4");
+ Assert.AreEqual (1, new List<XNode> (el.Nodes
()).Count, "#5");
+ Assert.AreEqual (el, first.Parent, "#6");
+ Assert.AreEqual (first, el.LastNode, "#7");
+
+ Assert.AreEqual ("root", el.Name.ToString (), "#8");
+ Assert.AreEqual ("foo", first.Name.ToString (), "#9");
+ Assert.IsFalse (el.Attributes ().GetEnumerator
().MoveNext (), "#10");
+ }
+
+ [Test]
+ [ExpectedException (typeof (InvalidOperationException))]
+ public void LoadInvalid ()
+ {
+ string xml = "text";
+ XmlReaderSettings s = new XmlReaderSettings ();
+ s.ConformanceLevel = ConformanceLevel.Fragment;
+
+ XElement.Load (XmlReader.Create (new StringReader
(xml), s));
+ }
+
+ [Test]
+ public void PrecedingWhitespaces ()
+ {
+ string xml = " <root/>";
+ XmlReaderSettings s = new XmlReaderSettings ();
+ s.ConformanceLevel = ConformanceLevel.Fragment;
+
+ XElement.Load (XmlReader.Create (new StringReader
(xml), s));
+ }
+
+ [Test]
+ public void PrecedingWhitespaces2 ()
+ {
+ string xml = " <root/>";
+ XmlReaderSettings s = new XmlReaderSettings ();
+ s.ConformanceLevel = ConformanceLevel.Fragment;
+
+ XmlReader r = XmlReader.Create (new StringReader (xml),
s);
+ r.Read (); // at whitespace
+ XElement.Load (r);
+ }
+
+ [Test]
+ public void Load2 ()
+ {
+ string xml = "<root>foo</root>";
+
+ XElement el = XElement.Load (new StringReader (xml));
+ XText first = el.FirstNode as XText;
+ Assert.IsNotNull (first, "#1");
+ Assert.IsTrue (el.LastNode is XText, "#2");
+ Assert.AreEqual (1, new List<XNode> (el.Nodes
()).Count, "#3");
+ Assert.AreEqual (el, first.Parent, "#4");
+ Assert.AreEqual (first, el.LastNode, "#5");
+
+ Assert.AreEqual ("foo", first.Value, "#6");
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentException))]
+ public void AddDocumentTypeToElement ()
+ {
+ XElement el = new XElement (XName.Get ("foo"));
+ el.Add (new XDocumentType ("foo", null, null, null));
+ }
+
+ [Test]
+ public void AddXDeclarationToElement ()
+ {
+ XElement el = new XElement (XName.Get ("foo"));
+ // XDeclaration is treated as a general object and
+ // hence converted to a string. No error here.
+ el.Add (new XDeclaration ("1.0", null, null));
+ Assert.AreEqual ("<?xml version=\"1.0\"?>", ((XText)
el.FirstNode).Value, "#1");
+ }
+ }
+}
Modified:
trunk/olive/class/System.Xml.Linq/Test/System.Xml.Linq/XNamespaceTest.cs
===================================================================
--- trunk/olive/class/System.Xml.Linq/Test/System.Xml.Linq/XNamespaceTest.cs
2007-05-03 16:49:42 UTC (rev 76629)
+++ trunk/olive/class/System.Xml.Linq/Test/System.Xml.Linq/XNamespaceTest.cs
2007-05-03 17:23:15 UTC (rev 76630)
@@ -71,5 +71,14 @@
Assert.AreEqual
("http://www.w3.org/XML/1998/namespace", XNamespace.Xml.NamespaceName, "#1");
Assert.AreEqual ("http://www.w3.org/2000/xmlns/",
XNamespace.Xmlns.NamespaceName, "#2");
}
+
+ [Test]
+ public void Equals ()
+ {
+ Assert.IsTrue (XNamespace.Blank.Equals (XNamespace.Get
("")), "#1");
+ Assert.IsTrue (XNamespace.Blank == XNamespace.Get (""),
"#2");
+ Assert.IsFalse (XNamespace.Blank.Equals (XNamespace.Get
(" ")), "#3");
+ Assert.IsFalse (XNamespace.Blank == XNamespace.Get ("
"), "#4");
+ }
}
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches