Merge pull request #1624 from esdrubal/getprocesstimes
[mono.git] / mcs / class / System.Data / Test / System.Data / DataSetReadXmlTest.cs
index 63c05088fec39f12a027e1856653089c2ad5e4e5..ff5caaf20c7ead9613d4547f77f8c91eb7305d09 100644 (file)
@@ -4,37 +4,37 @@
 // Author:\r
 //     Atsushi Enomoto <atsushi@ximian.com>\r
 //\r
-
-//
-// Copyright (C) 2004 Novell, Inc (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.
-//
 \r
+//\r
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)\r
+//\r
+// Permission is hereby granted, free of charge, to any person obtaining\r
+// a copy of this software and associated documentation files (the\r
+// "Software"), to deal in the Software without restriction, including\r
+// without limitation the rights to use, copy, modify, merge, publish,\r
+// distribute, sublicense, and/or sell copies of the Software, and to\r
+// permit persons to whom the Software is furnished to do so, subject to\r
+// the following conditions:\r
+// \r
+// The above copyright notice and this permission notice shall be\r
+// included in all copies or substantial portions of the Software.\r
+// \r
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+//\r
 \r
 using System;\r
-using System.IO;\r
 using System.Data;\r
+using System.IO;\r
 using System.Text;\r
 using System.Xml;\r
 using System.Xml.Serialization;\r
+\r
 using NUnit.Framework;\r
 \r
 namespace MonoTests.System.Data\r
@@ -42,7 +42,6 @@ namespace MonoTests.System.Data
        [TestFixture]\r
        public class DataSetReadXmlTest : DataSetAssertion\r
        {\r
-\r
                const string xml1 = "";\r
                const string xml2 = "<root/>";\r
                const string xml3 = "<root></root>";\r
@@ -579,7 +578,7 @@ namespace MonoTests.System.Data
 \r
                        AssertReadXml (ds, "SimpleTable", xml6,\r
                                XmlReadMode.Auto, XmlReadMode.InferSchema,\r
-                               "root", 1); // not NewDataSet unlike standalone load\r
+                               "NewDataSet", 1);\r
                        AssertDataTable ("seq1", ds.Tables [0], "root", 1, 1, 0, 0, 0, 0);\r
                }\r
 \r
@@ -595,7 +594,7 @@ namespace MonoTests.System.Data
 \r
                        AssertReadXml (ds, "SimpleTable2", xml7,\r
                                XmlReadMode.Auto, XmlReadMode.InferSchema,\r
-                               "root", 1); // dataset name will not be overwritten\r
+                               "NewDataSet", 1);\r
                        AssertDataTable ("#1", ds.Tables [0], "root", 2, 1, 0, 0, 0, 0);\r
 \r
                        // simple table -> simple dataset\r
@@ -639,15 +638,15 @@ namespace MonoTests.System.Data
                        dt.Columns.Add ("col");\r
                        ds.ReadXml (new StringReader (xml1), XmlReadMode.IgnoreSchema);\r
                        AssertDataSet ("ds", ds, "NewDataSet", 1, 0);\r
-                       AssertEquals ("wrapper element", 1, dt.Rows.Count);\r
+                       Assert.AreEqual (1, dt.Rows.Count, "wrapper element");\r
                        dt.Clear ();\r
 \r
                        ds.ReadXml (new StringReader (xml2), XmlReadMode.IgnoreSchema);\r
-                       AssertEquals ("no wrapper element", 1, dt.Rows.Count);\r
+                       Assert.AreEqual (1, dt.Rows.Count, "no wrapper element");\r
                        dt.Clear ();\r
 \r
                        ds.ReadXml (new StringReader (xml3), XmlReadMode.IgnoreSchema);\r
-                       AssertEquals ("no such table", 0, dt.Rows.Count);\r
+                       Assert.AreEqual (0, dt.Rows.Count, "no such table");\r
                }\r
 \r
                // bug #60118\r
@@ -666,7 +665,134 @@ namespace MonoTests.System.Data
 \r
                        DataSet ds = new DataSet ();\r
                        ds.ReadXml (new StringReader (xml));\r
-                       AssertNotNull (ds.Tables ["PriceListDetails"]);\r
+                       Assert.IsNotNull (ds.Tables ["PriceListDetails"]);\r
+               }\r
+\r
+               [Test] // bug #80045\r
+               public void ColumnOrder ()\r
+               {\r
+                       string xml = "<?xml version=\"1.0\" standalone=\"yes\"?>" +\r
+                               "<NewDataSet>" +\r
+                               "  <Table>" +\r
+                               "    <Name>Miguel</Name>" +\r
+                               "    <FirstName>de Icaza</FirstName>" +\r
+                               "    <Income>4000</Income>" +\r
+                               "  </Table>" +\r
+                               "  <Table>" +\r
+                               "    <Name>25</Name>" +\r
+                               "    <FirstName>250</FirstName>" +\r
+                               "    <Address>Belgium</Address>" +\r
+                               "    <Income>5000</Income>" +\r
+                               "</Table>" +\r
+                               "</NewDataSet>";\r
+\r
+                       DataSet ds = new DataSet ();\r
+                       ds.ReadXml (new StringReader (xml));\r
+                       Assert.AreEqual (1, ds.Tables.Count, "#1");\r
+                       Assert.AreEqual ("Table", ds.Tables [0].TableName, "#2");\r
+                       Assert.AreEqual (4, ds.Tables [0].Columns.Count, "#3");\r
+                       Assert.AreEqual ("Name", ds.Tables [0].Columns [0].ColumnName, "#4a");\r
+                       Assert.AreEqual (0, ds.Tables [0].Columns [0].Ordinal, "#4b");\r
+                       Assert.AreEqual ("FirstName", ds.Tables [0].Columns [1].ColumnName, "#5a");\r
+                       Assert.AreEqual (1, ds.Tables [0].Columns [1].Ordinal, "#5b");\r
+                       Assert.AreEqual ("Address", ds.Tables [0].Columns [2].ColumnName, "#6a");\r
+                       Assert.AreEqual (2, ds.Tables [0].Columns [2].Ordinal, "#6b");\r
+                       Assert.AreEqual ("Income", ds.Tables [0].Columns [3].ColumnName, "#7a");\r
+                       Assert.AreEqual (3, ds.Tables [0].Columns [3].Ordinal, "#7b");\r
+               }\r
+\r
+               [Test] // bug #80048\r
+               public void XmlSpace ()\r
+               {\r
+                       string xml = "<?xml version=\"1.0\" standalone=\"yes\"?>" +\r
+                               "<NewDataSet>" +\r
+                               "  <Table>" +\r
+                               "    <Name>Miguel</Name>" +\r
+                               "    <FirstName xml:space=\"preserve\"> de Icaza</FirstName>" +\r
+                               "    <Income>4000</Income>" +\r
+                               "  </Table>" +\r
+                               "  <Table>" +\r
+                               "    <Name>Chris</Name>" +\r
+                               "    <FirstName xml:space=\"preserve\">Toshok </FirstName>" +\r
+                               "    <Income>3000</Income>" +\r
+                               "  </Table>" +\r
+                               "</NewDataSet>";\r
+\r
+                       DataSet ds = new DataSet ();\r
+                       ds.ReadXml (new StringReader (xml));\r
+                       Assert.AreEqual (1, ds.Tables.Count, "#1");\r
+                       Assert.AreEqual ("Table", ds.Tables [0].TableName, "#2");\r
+                       Assert.AreEqual (3, ds.Tables [0].Columns.Count, "#3");\r
+                       Assert.AreEqual ("Name", ds.Tables [0].Columns [0].ColumnName, "#4a");\r
+                       Assert.AreEqual (0, ds.Tables [0].Columns [0].Ordinal, "#4b");\r
+                       Assert.AreEqual ("FirstName", ds.Tables [0].Columns [1].ColumnName, "#5a");\r
+                       Assert.AreEqual (1, ds.Tables [0].Columns [1].Ordinal, "#5b");\r
+                       Assert.AreEqual ("Income", ds.Tables [0].Columns [2].ColumnName, "#6a");\r
+                       Assert.AreEqual (2, ds.Tables [0].Columns [2].Ordinal, "#6b");\r
+               }\r
+\r
+               public void TestSameParentChildName ()\r
+               {\r
+                       string xml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><resource type=\"parent\">" +\r
+                                    "<resource type=\"child\" /></resource>";\r
+                       DataSet ds = new DataSet ();\r
+                       ds.ReadXml (new StringReader (xml));\r
+\r
+                       AssertReadXml (ds, "SameNameParentChild", xml,\r
+                               XmlReadMode.Auto, XmlReadMode.IgnoreSchema,\r
+                               "NewDataSet", 1);\r
+               }\r
+\r
+               public void TestSameColumnName ()\r
+               {\r
+                       string xml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><resource resource_Id_0=\"parent\">" +\r
+                                    "<resource resource_Id_0=\"child\" /></resource>";\r
+                       DataSet ds = new DataSet ();\r
+                       ds.ReadXml (new StringReader (xml));\r
+\r
+                       AssertReadXml (ds, "SameColumnName", xml,\r
+                               XmlReadMode.Auto, XmlReadMode.IgnoreSchema,\r
+                               "NewDataSet", 1);\r
+               }\r
+               \r
+               [Test]\r
+               public void DataSetExtendedPropertiesTest()\r
+               {\r
+                       DataSet dataSet1 = new DataSet();\r
+                       dataSet1.ExtendedProperties.Add("DS1", "extended0");\r
+                       DataTable table = new DataTable("TABLE1");\r
+                       table.ExtendedProperties.Add("T1", "extended1");\r
+                       table.Columns.Add("C1", typeof(int));\r
+                       table.Columns.Add("C2", typeof(string));\r
+                       table.Columns[1].MaxLength = 20;\r
+                       table.Columns[0].ExtendedProperties.Add("C1Ext1", "extended2");\r
+                       table.Columns[1].ExtendedProperties.Add("C2Ext1", "extended3");\r
+                       dataSet1.Tables.Add(table);\r
+                       table.LoadDataRow(new object[]{1, "One"}, false);\r
+                       table.LoadDataRow(new object[]{2, "Two"}, false);\r
+                       string file = Path.Combine (Path.GetTempPath (), "schemas-test.xml");\r
+                       try {\r
+                               dataSet1.WriteXml (file, XmlWriteMode.WriteSchema);\r
+                       }\r
+                       catch (Exception ex) {\r
+                               Assert.Fail ("DSExtPropTest failed: WriteXml failed with : "+ex.Message);\r
+                       } finally {\r
+                               File.Delete (file);\r
+                       }\r
+                       \r
+                       DataSet dataSet2 = new DataSet();\r
+                       dataSet2.ReadXml("Test/System.Data/schemas/b582732.xml", XmlReadMode.ReadSchema);\r
+                       Assert.AreEqual (dataSet1.ExtendedProperties["DS1"], dataSet2.ExtendedProperties["DS1"],\r
+                                        "DSExtProp#1: DS extended properties mismatch");\r
+                                               \r
+                       Assert.AreEqual (dataSet1.Tables[0].ExtendedProperties["T1"], dataSet2.Tables[0].ExtendedProperties["T1"],\r
+                                        "DSExtProp#2: DS Table extended properties mismatch");\r
+                       Assert.AreEqual (dataSet1.Tables[0].Columns[0].ExtendedProperties["C1Ext1"], \r
+                                        dataSet2.Tables[0].Columns[0].ExtendedProperties["C1Ext1"],\r
+                                        "DSExtProp#3: DS Table Column 1 extended properties mismatch");\r
+                       Assert.AreEqual (dataSet1.Tables[0].Columns[1].ExtendedProperties["C2Ext1"], \r
+                                        dataSet2.Tables[0].Columns[1].ExtendedProperties["C2Ext1"],\r
+                                        "DSExtProp#4: DS Table Column 2 extended properties mismatch");\r
                }\r
        }\r
 }\r