X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2FSystem.XML%2FTest%2FSystem.Xml%2FXmlReaderCommonTests.cs;h=16c46b496f4ce7a996bdbf568db76d706bd7e52a;hb=0b4bc83e79ca3057693089dc7f926004bb9d9592;hp=1f6ee9bb39a8fc5c061b77b491600d4c0cd7290b;hpb=0900c61969ca862b0bcc967b4413e539acf07dbb;p=mono.git diff --git a/mcs/class/System.XML/Test/System.Xml/XmlReaderCommonTests.cs b/mcs/class/System.XML/Test/System.Xml/XmlReaderCommonTests.cs index 1f6ee9bb39a..16c46b496f4 100644 --- a/mcs/class/System.XML/Test/System.Xml/XmlReaderCommonTests.cs +++ b/mcs/class/System.XML/Test/System.Xml/XmlReaderCommonTests.cs @@ -15,6 +15,10 @@ using System.Text; using System.Xml; using System.Xml.Schema; using System.Xml.XPath; +#if NET_4_5 +using System.Threading; +using System.Threading.Tasks; +#endif using NUnit.Framework; @@ -197,14 +201,12 @@ namespace MonoTests.System.Xml document.LoadXml (xml); xnr = new XmlNodeReader (document); method (xnr); -#if NET_2_0 /* // XPathNavigatorReader tests System.Xml.XPath.XPathDocument doc = new System.Xml.XPath.XPathDocument (new StringReader (xml)); XmlReader xpr = doc.CreateNavigator ().ReadSubtree (); method (xpr); */ -#endif } @@ -1344,6 +1346,7 @@ namespace MonoTests.System.Xml [Test] [Category ("NotDotNet")] + [Ignore ("Bug in Microsoft referencesource")] public void IndexerAndAttributes () { string xml = @""; @@ -1509,7 +1512,6 @@ namespace MonoTests.System.Xml reader.Read (); // silently returns false } -#if NET_2_0 [Test] public void CreateSimple () { @@ -1536,7 +1538,7 @@ namespace MonoTests.System.Xml // a bit revised version of bug #78706 public void CreateFromUrlClose () { - string file = "Test/XmlFiles/78706.xml"; + string file = Path.Combine (Path.GetTempPath (), "78706.xml"); try { if (!File.Exists (file)) File.Create (file).Close (); @@ -1556,7 +1558,7 @@ namespace MonoTests.System.Xml // a bit revised version of bug #385638 public void CreateFromUrlClose2 () { - string file = "Test/XmlFiles/385638.xml"; + string file = Path.Combine (Path.GetTempPath (), "385638.xml"); try { if (File.Exists (file)) File.Delete (file); @@ -1723,6 +1725,48 @@ namespace MonoTests.System.Xml reader.ReadToNextSibling ("book"); // should not result in an infinite loop } + // bug #676020 + [Test] + public void ReadToNextSibling4 () + { + string xml = @" + + + + + +"; + + var reader = XmlReader.Create (new StringReader (xml)); + + Assert.IsTrue (reader.ReadToDescendant ("SerializableStringDictionary"), "#1"); + Assert.IsTrue (reader.ReadToDescendant ("DictionaryEntry"), "#2"); + + int count = 0; + do { + reader.MoveToAttribute ("Key"); + var key = reader.ReadContentAsString (); + reader.MoveToAttribute ("Value"); + var value = reader.ReadContentAsString (); + count++; + } + while (reader.ReadToNextSibling ("DictionaryEntry")); + Assert.AreEqual (3, count, "#3"); + } + + [Test, Category("NotWorking")] + public void ReadToNextSiblingInInitialReadState () + { + var xml = ""; + var ms = new MemoryStream(Encoding.Default.GetBytes(xml)); + var xtr = XmlReader.Create(ms); + + Assert.AreEqual(xtr.ReadState, ReadState.Initial); + xtr.ReadToNextSibling("Text"); + + Assert.AreEqual("hello", xtr.GetAttribute("name")); + } + [Test] public void ReadSubtree () { @@ -2201,7 +2245,7 @@ namespace MonoTests.System.Xml Assert.AreEqual (XmlNodeType.Text, reader.NodeType, "#2"); bytesRead = reader.ReadElementContentAsBase64 (fixedSizeBuffer, 0, fixedSizeBuffer.Length); Assert.AreEqual (0, bytesRead, "#3"); - Assert.AreEqual (XmlNodeType.EndElement, reader.NodeType, "#4"); + Assert.AreEqual (XmlNodeType.None, reader.NodeType, "#4"); } [Test] @@ -2218,6 +2262,91 @@ namespace MonoTests.System.Xml var q = (XmlQualifiedName) xr.ReadElementContentAs (typeof (XmlQualifiedName), xr as IXmlNamespaceResolver); Assert.AreEqual ("urn:foo", q.Namespace, "#1"); } + + [Test] + public void ReadElementContentAsArray () + { + var sw = new StringWriter (); + var xw = XmlWriter.Create (sw); + xw.WriteStartElement ("root"); + xw.WriteAttributeString ("xmlns", "b", "http://www.w3.org/2000/xmlns/", "urn:bar"); + var arr = new XmlQualifiedName [] { new XmlQualifiedName ("foo"), new XmlQualifiedName ("bar", "urn:bar") }; + xw.WriteValue (arr); + xw.Close (); + var xr = XmlReader.Create (new StringReader (sw.ToString ())); + xr.MoveToContent (); + var ret = xr.ReadElementContentAs (typeof (XmlQualifiedName []), null) as XmlQualifiedName []; + Assert.IsNotNull (ret, "#1"); + Assert.AreEqual (arr [0], ret [0], "#2"); + Assert.AreEqual (arr [1], ret [1], "#3"); + } + + [Test] + public void ReadContentAs () + { + var xr = XmlReader.Create (new StringReader ("")); + xr.Read (); + xr.MoveToAttribute ("a"); + + Assert.AreEqual ((Byte) 1, xr.ReadContentAs (typeof (Byte), null), "#1"); + Assert.AreEqual ((SByte) 1, xr.ReadContentAs (typeof (SByte), null), "#2"); + Assert.AreEqual ((Int16) 1, xr.ReadContentAs (typeof (Int16), null), "#3"); + Assert.AreEqual ((UInt16) 1, xr.ReadContentAs (typeof (UInt16), null), "#4"); + Assert.AreEqual ((Int32) 1, xr.ReadContentAs (typeof (Int32), null), "#5"); + Assert.AreEqual ((UInt32) 1, xr.ReadContentAs (typeof (UInt32), null), "#6"); + Assert.AreEqual ((Int64) 1, xr.ReadContentAs (typeof (Int64), null), "#7"); + Assert.AreEqual ((UInt64) 1, xr.ReadContentAs (typeof (UInt64), null), "#8"); + } + +#if NET_4_5 + [Test] + [ExpectedException(typeof(InvalidOperationException))] + public void MustSetAsyncFlag () + { + var r = XmlReader.Create (new StringReader ("")); + r.ReadAsync (); + } + + Exception RunAsync (Action action) + { + var task = Task.Run (async () => { + try { + action (); + return null; + } catch (Exception ex) { + return ex; + } + }); + task.Wait (); + Assert.That (task.IsCompleted); + return task.Result; + } + + [Test] + public void SimpleAsync () + { + var xml = ""; + var task = Task.Run (async () => { + try { + var s = new XmlReaderSettings (); + s.Async = true; + var r = XmlReader.Create (new StringReader (xml), s); + + Assert.That (await r.ReadAsync ()); + Assert.That (r.MoveToFirstAttribute ()); + + Assert.AreEqual (await r.GetValueAsync (), "monkey"); + r.Close (); + return null; + } catch (Exception ex) { + return ex; + } + }); + task.Wait (); + Assert.That (task.IsCompleted); + if (task.Result != null) + throw task.Result; + } #endif } }