コード例 #1
0
ファイル: ReadBinHex.cs プロジェクト: rsumner31/corefx2
                //[Variation("ReadBinHex Element on CDATA", Priority = 0)]
                public void TestReadBinHex_4()
                {
                    int BinHexlen = 0;

                    byte[] BinHex = new byte[3];

                    string    xmlStr     = "<root><![CDATA[ABCDEF]]></root>";
                    XmlReader DataReader = GetReader(new StringReader(xmlStr));

                    PositionOnElement(DataReader, "root");
                    DataReader.Read();
                    if (!DataReader.CanReadBinaryContent)
                    {
                        return;
                    }

                    BinHexlen = DataReader.ReadContentAsBinHex(BinHex, 0, BinHex.Length);
                    TestLog.Compare(BinHexlen, 3, "BinHex");
                    BinHexlen = DataReader.ReadContentAsBinHex(BinHex, 0, BinHex.Length);
                    TestLog.Compare(BinHexlen, 0, "BinHex");

                    DataReader.Read();
                    TestLog.Compare(DataReader.NodeType, XmlNodeType.None, "Not on none");
                }
コード例 #2
0
        public void LoadOptionsBU()
        {
            string fileName = @"NoExternals.xml";
            var    how      = CurrentChild.Param as string;

            XDocument doc = GetXDocument(fileName, LoadOptions.SetBaseUri, how);

            foreach (XObject node in doc.DescendantNodes().OfType <object>().Concat2(doc.Descendants().Attributes().OfType <object>()))
            {
                string baseUri = node.BaseUri;
                // fail when use stream replace file
                if (!String.IsNullOrWhiteSpace(baseUri))
                {
                    TestLog.Compare(new Uri(baseUri), new Uri(GetFullTestPath(fileName)), "base uri failed");
                }
            }

            doc = GetXDocument(fileName, LoadOptions.None, how);
            foreach (XObject node in doc.DescendantNodes().OfType <object>().Concat2(doc.Descendants().Attributes().OfType <object>()))
            {
                string baseUri = node.BaseUri;
                TestLog.Compare(baseUri, "", "base uri failed");
            }
        }
コード例 #3
0
        public void ElementOtherTypes()
        {
            object[] nodeset = { "text", new XProcessingInstruction("pi", "data"), new XComment("comm"), new XElement("single"), new XElement("complex", new XElement("a1"), new XElement("a2")) };

            XElement e   = XElement.Parse("<A/>");
            int      pos = ((bool)Param) ? 0 : nodeset.Length - 1;

            foreach (var combination in nodeset.PositionCombinations(pos))
            {
                e.Add(combination);
                XNode ret = ((bool)Param) ? e.FirstNode : e.LastNode;

                if (combination[pos] is string)
                {
                    TestLog.Compare(ret is XText, "text node");
                    TestLog.Compare((ret as XText).Value, combination[pos], "text node value");
                }
                else
                {
                    TestLog.Compare(ret.Equals(combination[pos]), "Node not OK");
                }
                e.RemoveAll();
            }
        }
コード例 #4
0
ファイル: ReadBinHex.cs プロジェクト: rsumner31/corefx2
                //[Variation("ReadBinHex Element multiple into same buffer (using offset), Priority=0")]
                public void TestReadBinHex_13()
                {
                    int BinHexlen = 10;

                    byte[] BinHex = new byte[BinHexlen];

                    XmlReader DataReader = GetReader(pBinHexXml);

                    PositionOnElement(DataReader, ST_ELEM_NAME4);
                    DataReader.Read();
                    if (!DataReader.CanReadBinaryContent)
                    {
                        return;
                    }

                    string strActbinhex = "";

                    for (int i = 0; i < BinHexlen; i = i + 2)
                    {
                        DataReader.ReadContentAsBinHex(BinHex, i, 2);
                        strActbinhex = (System.BitConverter.ToChar(BinHex, i)).ToString();
                        TestLog.Compare(String.Compare(strActbinhex, 0, strTextBinHex, i / 2, 1), 0, "Compare All Valid Base64");
                    }
                }
コード例 #5
0
 public void InvalidAddIntoXDocument5()
 {
     _runWithEvents = (bool)Params[0];
     foreach (object o in new object[] { new XCData("CD"), new XAttribute("a1", "avalue"), "text1", new XText("text2"), new XDocument() })
     {
         try
         {
             var doc = new XDocument(new XElement("A"));
             if (_runWithEvents)
             {
                 _eHelper = new EventsHelper(doc);
             }
             doc.AddFirst(o);
             if (_runWithEvents)
             {
                 _eHelper.Verify(XObjectChange.Add, o);
             }
             TestLog.Compare(false, "Exception expected");
         }
         catch (ArgumentException)
         {
         }
     }
 }
コード例 #6
0
                //[Variation("ReadValue with multiple different inner nodes")]
                public void TestReadChar14()
                {
                    string strExpected = "somevalue";

                    char[]    buffer     = new char[strExpected.Length];
                    string    strxml     = "<ROOT>somevalue<![CDATA[somevalue]]>somevalue</ROOT>";
                    XmlReader DataReader = GetReaderStr(strxml);

                    PositionOnElement(DataReader, "ROOT");

                    DataReader.Read();
                    if (!DataReader.CanReadValueChunk)
                    {
                        try
                        {
                            DataReader.ReadValueChunk(buffer, 0, 5);
                            throw new TestException(TestResult.Failed, "");
                        }
                        catch (NotSupportedException)
                        {
                            return;
                        }
                    }
                    TestLog.Compare(DataReader.ReadValueChunk(buffer, 0, buffer.Length), strExpected.Length, "ReadValue1");
                    TestLog.Compare(new string(buffer), strExpected, "str1");

                    // Now on CDATA.
                    DataReader.Read();
                    TestLog.Compare(DataReader.ReadValueChunk(buffer, 0, buffer.Length), strExpected.Length, "ReadValue2");
                    TestLog.Compare(new string(buffer), strExpected, "str2");

                    // Now back on Text
                    DataReader.Read();
                    TestLog.Compare(DataReader.ReadValueChunk(buffer, 0, buffer.Length), strExpected.Length, "ReadValue3");
                    TestLog.Compare(new string(buffer), strExpected, "str3");
                }
コード例 #7
0
ファイル: XElement_Value.cs プロジェクト: wuyou201400/corefx
                //[Variation(Priority = 1, Desc = "SET:  XText content, Empty string content", Params = new object[] { "<X>t0<A xml:space='preserve'>orig</A>t00</X>", "" })]
                //[Variation(Priority = 1, Desc = "SET:  XText content, string content", Params = new object[] { "<X>t0<A>orig</A>t00</X>", "\tt1 " })]
                //[Variation(Priority = 1, Desc = "SET:  CDATA content, Empty string content", Params = new object[] { "<X>t0<A><![CDATA[cdata]]></A>t00</X>", "" })]
                //[Variation(Priority = 1, Desc = "SET:  CDATA content, string content", Params = new object[] { "<X>t0<A><![CDATA[cdata]]></A>t00</X>", "\tt1 " })]
                //[Variation(Priority = 1, Desc = "SET:  Mixed content, Empty string content", Params = new object[] { "<X>t0<A xmlns:p='p'>t1<p:Y/></A>t00</X>", "" })]
                //[Variation(Priority = 0, Desc = "SET:  Mixed content, string content", Params = new object[] { "<X>t0<A is='is'><![CDATA[cdata]]>orig<C/><!--comment--></A>t00</X>", "\tt1 " })]
                //[Variation(Priority = 1, Desc = "SET:  Mixed content (comment only), string content", Params = new object[] { "<X>t0<A is='is'><!--comment--></A>t00</X>", "\tt1 " })]
                //[Variation(Priority = 1, Desc = "SET:  Mixed content (PI only), string content", Params = new object[] { "<X>t0<A is='is'><?PI aaa?></A>t00</X>", "\tt1 " })]
                public void Value_Set_WithNodes()
                {
                    _runWithEvents = (bool)Params[0];
                    string xml    = Variation.Params[0] as string;
                    string newVal = Variation.Params[1] as string;

                    XElement e              = XElement.Parse(xml, LoadOptions.PreserveWhitespace).Element("A");
                    var      origNodes      = e.Nodes().ToList();
                    var      origAttributes = e.Attributes().ToList();

                    if (_runWithEvents)
                    {
                        _eHelper = new EventsHelper(e);
                    }
                    e.Value = newVal;
                    // Not sure how to verify this yet( what possible events and in what order)
                    //if (runWithEvents) eHelper.Verify(XObjectChange.Value);

                    TestLog.Compare(e.Value, newVal, "value");
                    TestLog.Compare(e.Parent.Value, "t0" + newVal + "t00", "parent value");
                    TestLog.Compare(!e.IsEmpty, "!e.IsEmpty");
                    TestLog.Compare(origNodes.Where(n => n.Parent != null || n.Document != null).IsEmpty(), "origNodes.Where(n=>n.Parent!=null || n.Document!=null).IsEmpty()");
                    TestLog.Compare(origAttributes.SequenceEqual(e.Attributes()), "origAttributes.SequenceEqual(e.Attributes())");
                }
コード例 #8
0
                //[Variation("ReadValue entire value in one call", Priority = 0)]
                public void TestReadValue2()
                {
                    Char[] buffer = new Char[10];

                    XmlReader DataReader = GetReader();

                    PositionOnElement(DataReader, ST_TEST_NAME);
                    DataReader.Read();
                    if (!DataReader.CanReadValueChunk)
                    {
                        try
                        {
                            DataReader.ReadValueChunk(buffer, 0, 5);
                            throw new TestException(TestResult.Failed, "");
                        }
                        catch (NotSupportedException)
                        {
                            return;
                        }
                    }

                    TestLog.Compare(DataReader.ReadValueChunk(buffer, 0, 10), 10, "Didnt read 10");
                    TestLog.Compare("0123456789", new string(buffer), "Strings don't match");
                }
コード例 #9
0
                //[Variation("ReadValue with combination Text, CDATA and SignificantWhitespace")]
                public void TestReadChar12()
                {
                    string    strExpected = "AB";
                    XmlReader DataReader  = GetReader();

                    PositionOnElement(DataReader, "CATMIXED");
                    DataReader.Read();
                    char[] buffer = new char[strExpected.Length];
                    if (!DataReader.CanReadValueChunk)
                    {
                        try
                        {
                            DataReader.ReadValueChunk(buffer, 0, 5);
                            throw new TestException(TestResult.Failed, "");
                        }
                        catch (NotSupportedException)
                        {
                            return;
                        }
                    }

                    TestLog.Compare(DataReader.ReadValueChunk(buffer, 0, buffer.Length), strExpected.Length, "ReadValue");
                    TestLog.Compare(new string(buffer), strExpected, "str");
                }
コード例 #10
0
ファイル: ReadBinHex.cs プロジェクト: rsumner31/corefx2
                protected void TestInvalidNodeType(XmlNodeType nt)
                {
                    XmlReader DataReader = GetReader(pBinHexXml);

                    PositionOnNodeType(DataReader, nt);
                    string name  = DataReader.Name;
                    string value = DataReader.Value;

                    byte[] buffer = new byte[1];
                    if (!DataReader.CanReadBinaryContent)
                    {
                        return;
                    }

                    try
                    {
                        int nBytes = DataReader.ReadContentAsBinHex(buffer, 0, 1);
                    }
                    catch (InvalidOperationException)
                    {
                        return;
                    }
                    TestLog.Compare(false, "Invalid OP exception not thrown on wrong nodetype");
                }
コード例 #11
0
ファイル: ReadBinHex.cs プロジェクト: rsumner31/corefx2
                //[Variation("ReadBinHex Element with all valid Text value")]
                public void TestReadBinHex_3()
                {
                    int BinHexlen = 0;

                    byte[] BinHex = new byte[1000];

                    XmlReader DataReader = GetReader(pBinHexXml);

                    PositionOnElement(DataReader, ST_ELEM_NAME4);
                    if (!DataReader.CanReadBinaryContent)
                    {
                        return;
                    }

                    BinHexlen = DataReader.ReadElementContentAsBinHex(BinHex, 0, BinHex.Length);

                    string strActBinHex = "";

                    for (int i = 0; i < BinHexlen; i = i + 2)
                    {
                        strActBinHex += System.BitConverter.ToChar(BinHex, i);
                    }
                    TestLog.Compare(strActBinHex, strTextBinHex, "Compare All Valid BinHex");
                }
コード例 #12
0
                //[Variation("ReadValue", Priority = 0)]
                public void TestReadValuePri0()
                {
                    char[]    buffer     = new char[5];
                    XmlReader DataReader = GetReader(new StringReader("<root>value</root>"));

                    PositionOnElement(DataReader, "root");
                    DataReader.Read();

                    if (!DataReader.CanReadValueChunk)
                    {
                        try
                        {
                            DataReader.ReadValueChunk(buffer, 0, 5);
                            throw new TestException(TestResult.Failed, "");
                        }
                        catch (NotSupportedException)
                        {
                            return;
                        }
                    }

                    TestLog.Compare(DataReader.ReadValueChunk(buffer, 0, 5), 5, "Didnt read 5 chars");
                    TestLog.Compare("value", new string(buffer), "Strings don't match");
                }
コード例 #13
0
                //[Variation("Call from different nodetypes", Priority = 1)]
                public void v12()
                {
                    XmlReader DataReader = GetReader(new StringReader(_xmlStr));

                    while (DataReader.Read())
                    {
                        if (DataReader.NodeType != XmlNodeType.Element)
                        {
                            TestLog.Compare(DataReader.ReadToDescendant("child1"), false, "Fails on node");
                        }
                        else
                        {
                            if (DataReader.HasAttributes)
                            {
                                while (DataReader.MoveToNextAttribute())
                                {
                                    TestLog.Compare(DataReader.ReadToDescendant("abc"), false, "Fails on attribute node");
                                }
                            }
                        }
                    }

                    DataReader.Dispose();
                }
コード例 #14
0
                //[Variation("Current node on multiple calls")]
                public void TestReadBase64_17()
                {
                    XmlReader DataReader = GetReader(pBase64Xml);

                    PositionOnElement(DataReader, "ElemNum");
                    DataReader.Read();
                    if (!DataReader.CanReadBinaryContent)
                    {
                        return;
                    }

                    byte[] buffer = new byte[30];

                    int nRead = DataReader.ReadContentAsBase64(buffer, 0, 2);

                    TestLog.Compare(nRead, 2, "0");

                    nRead = DataReader.ReadContentAsBase64(buffer, 0, 23);
                    TestLog.Compare(nRead, 22, "1");

                    DataReader.Read();
                    TestLog.Compare(DataReader.NodeType, XmlNodeType.Element, "Nodetype not end element");
                    TestLog.Compare(DataReader.Name, "ElemText", "Nodetype not end element");
                }
コード例 #15
0
                //[Variation("ReadBase64 Element multiple into same buffer (using offset), Priority=0")]
                public void TestReadBase64_13()
                {
                    int base64len = 20;

                    byte[] base64 = new byte[base64len];

                    XmlReader DataReader = GetReader(pBase64Xml);

                    PositionOnElement(DataReader, ST_ELEM_NAME4);
                    DataReader.Read();
                    if (!DataReader.CanReadBinaryContent)
                    {
                        return;
                    }

                    string strActbase64 = "";

                    for (int i = 0; i < base64len; i = i + 2)
                    {
                        DataReader.ReadContentAsBase64(base64, i, 2);
                        strActbase64 = (System.BitConverter.ToChar(base64, i)).ToString();
                        TestLog.Compare(String.Compare(strActbase64, 0, strTextBase64, i / 2, 1), 0, "Compare All Valid Base64");
                    }
                }
コード例 #16
0
                //[Variation("ReadBase64 with whitespaces in the mIddle")]
                public void TestTextReadBase64_26()
                {
                    byte[] buffer = new byte[1];
                    string strxml = "<abc> AQID  B            B  </abc>";
                    int    nRead;

                    XmlReader DataReader = GetReaderStr(strxml);

                    PositionOnElement(DataReader, "abc");
                    if (!DataReader.CanReadBinaryContent)
                    {
                        return;
                    }

                    for (int i = 0; i < 4; i++)
                    {
                        nRead = DataReader.ReadElementContentAsBase64(buffer, 0, 1);
                        TestLog.Compare(nRead, 1, "res" + i);
                        TestLog.Compare(buffer[0], (byte)(i + 1), "buffer " + i);
                    }

                    nRead = DataReader.ReadElementContentAsBase64(buffer, 0, 1);
                    TestLog.Compare(nRead, 0, "nRead 0");
                }
コード例 #17
0
                //[Variation("IsStartElement")]
                public void TestIsStartElement()
                {
                    XmlReader DataReader = ReloadSource();

                    TestLog.Compare(DataReader.IsStartElement(), true, Variation.Desc);
                }
コード例 #18
0
ファイル: EventsHelper.cs プロジェクト: rsumner31/corefx2
 // If all you care about is number of expected events and not the type
 public void Verify(int expectedCount)
 {
     TestLog.Compare(_events.Count, expectedCount, "Mismatch in expected number of events");
     _events.Clear();
 }
コード例 #19
0
                //[Variation("Simple positive test 1", Priority = 0, Params = new object[] { "NNS" })]
                //[Variation("Simple positive test 2", Priority = 0, Params = new object[] { "DNS" })]
                //[Variation("Simple positive test 3", Priority = 0, Params = new object[] { "NS" })]
                public void v()
                {
                    string type = Variation.Params[0].ToString();

                    XmlReader DataReader = GetReader(new StringReader(_xmlStr));

                    PositionOnElement(DataReader, "root");

                    switch (type)
                    {
                    case "NNS":
                        DataReader.ReadToDescendant("elem");
                        DataReader.ReadToNextSibling("elem");

                        if (DataReader.HasAttributes)
                        {
                            TestLog.Compare(DataReader.GetAttribute("att"), "1", "Not the expected attribute");
                        }
                        else
                        {
                            TestLog.WriteLine("Positioned on wrong element");
                            throw new TestException(TestResult.Failed, "");
                        }
                        while (DataReader.Read())
                        {
                            ;
                        }
                        DataReader.Dispose();
                        return;

                    case "DNS":
                        DataReader.ReadToDescendant("elem", "elem");
                        DataReader.ReadToNextSibling("elem", "elem");
                        if (DataReader.HasAttributes)
                        {
                            if (DataReader.GetAttribute("att") == null)
                            {
                                TestLog.WriteLine("Positioned on wrong element, not on DNS");
                                throw new TestException(TestResult.Failed, "");
                            }
                        }
                        else
                        {
                            TestLog.WriteLine("Positioned on wrong element");
                            throw new TestException(TestResult.Failed, "");
                        }
                        while (DataReader.Read())
                        {
                            ;
                        }
                        DataReader.Dispose();
                        return;

                    case "NS":
                        DataReader.ReadToDescendant("e:elem");
                        DataReader.ReadToNextSibling("e:elem");

                        if (DataReader.HasAttributes)
                        {
                            if (DataReader.GetAttribute("xmlns:e") == null)
                            {
                                TestLog.WriteLine("Positioned on wrong element, not on DNS");
                                throw new TestException(TestResult.Failed, "");
                            }
                        }
                        else
                        {
                            TestLog.WriteLine("Positioned on wrong element");
                            throw new TestException(TestResult.Failed, "");
                        }

                        while (DataReader.Read())
                        {
                            ;
                        }
                        DataReader.Dispose();
                        return;

                    default:
                        throw new TestFailedException("Error in Test type");
                    }
                }
コード例 #20
0
        //[Variation(Priority = 0, Desc = "XDocument - adding element cloned", Param = "XElement")]
        //[Variation(Priority = 1, Desc = "XDocument - adding PI cloned", Param = "XPI")]
        //[Variation(Priority = 1, Desc = "XDocument - adding XmlDecl cloned", Param = "XmlDecl")]
        //[Variation (Priority=1, Desc="XDocument - adding dot type")]
        //[Variation(Priority = 1, Desc = "XDocument - adding Comment cloned", Param = "XComment")]
        //[Variation(Priority = 1, Desc = "XDocument - combination off allowed types in correct order,  cloned", Param = "Mix1")]
        //[Variation(Priority = 1, Desc = "XDocument - combination off allowed types in correct order, without decl;  cloned", Param = "Mix2")]
        //[Variation(Priority = 2, Desc = "XDocument - adding string/whitespace", Param = "Whitespace")]
        public void XDocumentAddParamsCloning()
        {
            object[] paras     = null;
            var      paramType = Variation.Param as string;
            var      doc1      = new XDocument();

            switch (paramType)
            {
            case "XElement":
                var xe = new XElement("root");
                doc1.Add(xe);
                paras = new object[] { xe };
                break;

            case "XPI":
                var pi = new XProcessingInstruction("Click", "data");
                doc1.Add(pi);
                paras = new object[] { pi };
                break;

            case "XComment":
                var comm = new XComment("comment");
                doc1.Add(comm);
                paras = new object[] { comm };
                break;

            case "Whitespace":
                var txt = new XText(" ");
                doc1.Add(txt);
                paras = new object[] { txt };
                break;

            case "Mix1":
            {
                var a2 = new XComment("comment");
                doc1.Add(a2);
                var a3 = new XProcessingInstruction("Click", "data");
                doc1.Add(a3);
                var a4 = new XElement("root");
                doc1.Add(a4);
                var a5 = new XProcessingInstruction("Click2", "data2");
                doc1.Add(a5);
                paras = new object[] { a2, a3, a4, a5 };
            }
            break;

            case "Mix2":
            {
                var a2 = new XComment("comment");
                doc1.Add(a2);
                var a3 = new XProcessingInstruction("Click", "data");
                doc1.Add(a3);
                var a4 = new XElement("root");
                doc1.Add(a4);
                var a5 = new XProcessingInstruction("Click2", "data2");
                doc1.Add(a5);
                paras = new object[] { a2, a3, a4, a5 };
            }
            break;

            default:
                TestLog.Compare(false, "Test case: Wrong param");
                break;
            }

            var doc = new XDocument(paras);

            TestLog.Compare(doc != null, "doc!=null");
            TestLog.Compare(doc.Document == doc, "doc.Document property");
            int counter = 0;

            for (XNode node = doc.FirstNode; node.NextNode != null; node = node.NextNode)
            {
                TestLog.Compare(node != null, "node != null");
                var orig = paras[counter] as XNode;
                TestLog.Compare(node != orig, "Not the same instance, cloned");
                TestLog.Compare(orig.Document, doc1, "Orig Document");
                TestLog.Compare(XNode.DeepEquals(node, orig), "node equals param");
                TestLog.Compare(node.Document, doc, "Document property");
                counter++;
            }
        }
コード例 #21
0
                //[Variation("IsStartElement(String.Empty,String.Empty)")]
                public void TestIsStartElementNameNs2()
                {
                    XmlReader DataReader = ReloadSource();

                    TestLog.Compare(DataReader.IsStartElement(string.Empty, string.Empty), false, Variation.Desc);
                }
コード例 #22
0
                //[Variation("IsStartElement(name, ns)")]
                public void TestIsStartElementNameNs()
                {
                    XmlReader DataReader = ReloadSource();

                    TestLog.Compare(DataReader.IsStartElement(pNAME, pNS), false, Variation.Desc);
                }
コード例 #23
0
                //[Variation(Id = 1, Desc = "CheckChars=true, invalid XML test WriteEntityRef", Priority = 1, Param = "EntityRef")]
                //[Variation(Id = 2, Desc = "CheckChars=true, invalid XML test WriteSurrogateCharEntity", Priority = 1, Param = "SurrogateCharEntity")]
                //[Variation(Id = 3, Desc = "CheckChars=true, invalid XML test WriteWhitespace", Priority = 1, Param = "Whitespace")]
                //[Variation(Id = 4, Desc = "CheckChars=true, invalid name chars WriteDocType(name)", Priority = 1, Param = "WriteDocTypeName")]
                public void checkChars_1()
                {
                    char[] invalidXML = { '\u0000', '\u0008', '\u000B', '\u000C', '\u000E', '\u001F', '\uFFFE', '\uFFFF' };

                    XElement  d = new XElement("a");
                    XmlWriter w = d.CreateWriter();

                    try
                    {
                        switch (Variation.Param.ToString())
                        {
                        case "WriteDocTypeName":
                            w.WriteDocType(":badname", "sysid", "pubid", "subset");
                            break;

                        case "WriteDocTypeSysid":
                            w.WriteDocType("name", invalidXML[1].ToString(), "pubid", "subset");
                            break;

                        case "WriteDocTypePubid":
                            w.WriteDocType("name", "sysid", invalidXML[1].ToString(), "subset");
                            break;

                        case "String":
                            w.WriteString(invalidXML[0].ToString());
                            break;

                        case "CData":
                            w.WriteCData(invalidXML[1].ToString());
                            break;

                        case "Comment":
                            w.WriteComment(invalidXML[2].ToString());
                            break;

                        case "CharEntity":
                            w.WriteCharEntity(invalidXML[3]);
                            break;

                        case "EntityRef":
                            w.WriteEntityRef(invalidXML[4].ToString());
                            break;

                        case "SurrogateCharEntity":
                            w.WriteSurrogateCharEntity(invalidXML[5], invalidXML[1]);
                            break;

                        case "PI":
                            w.WriteProcessingInstruction("pi", invalidXML[6].ToString());
                            break;

                        case "Whitespace":
                            w.WriteWhitespace(invalidXML[7].ToString());
                            break;

                        case "Chars":
                            w.WriteChars(invalidXML, 1, 5);
                            break;

                        case "RawString":
                            w.WriteRaw(invalidXML[4].ToString());
                            break;

                        case "RawChars":
                            w.WriteRaw(invalidXML, 6, 2);
                            break;

                        case "WriteValue":
                            w.WriteValue(invalidXML[3].ToString());
                            break;

                        default:
                            TestLog.Compare(false, "Invalid param value");
                            break;
                        }
                    }
                    catch (XmlException)
                    {
                        TestLog.Compare(w.WriteState, WriteState.Error, "WriteState should be Error");
                        return;
                    }
                    catch (ArgumentException)
                    {
                        TestLog.Compare(w.WriteState, WriteState.Error, "WriteState should be Error");
                        return;
                    }
                    finally
                    {
                        w.Dispose();
                    }
                    throw new TestException(TestResult.Failed, "");
                }
コード例 #24
0
        /// <summary>
        /// XDocument:
        ///  - with content, empty
        ///  - adding valid nodes
        ///  - XDecl + XDocType (correct/incorrect order)
        /// </summary>
        public void AddIntoDocument()
        {
            _runWithEvents = (bool)Params[0];
            var    xml               = Variation.Params[0] as string;
            var    variationLength   = (int)Variation.Params[1];
            var    hasRoot           = (bool)Variation.Params[2];
            var    isConnected       = (bool)Variation.Params[3];
            string stringOnlyContent = Variation.Params.Length > 4 ? Variation.Params[4] as string : null;

            var rs = new XmlReaderSettings
            {
                ConformanceLevel = ConformanceLevel.Fragment,
                IgnoreWhitespace = false,
                DtdProcessing    = DtdProcessing.Ignore,
            };

            object[] nodes = { new XDocumentType("Q", null, null, "<!ENTITY e SYSTEM 'e.ent'!>"), new XDocumentType("A", null, null, "<!ENTITY e SYSTEM 'e.ent'!>"), new XElement("B", new XElement("C"), new XAttribute("a", "aa")), new XElement("B1", new XElement("C1"), new XAttribute("a1", "aa1")), new XProcessingInstruction("PI", "data"), new XProcessingInstruction("PI2", ""), new XComment("comment"), new XComment(""), new XText(""), new XText(" "), new XText("data"), // invalid
                               "text",                                                                                                                                                                                                                                                                                                                                                                                                                                                   // invalid
                               new XCData(""),                                                                                                                                                                                                                                                                                                                                                                                                                                           // invalid
                               "\n",                  "\t", " ",  "",                             null };

            if (isConnected)
            {
                foreach (XNode n in nodes.OfType <XNode>())
                {
                    if (n is XDocumentType)
                    {
                        new XDocument(n);
                        continue;
                    }
                    new XDocument(new XElement("dumma", n));
                }
            }

            foreach (var toInsert in nodes.NonRecursiveVariations(variationLength))
            {
                XDocument doc = null;
                if (hasRoot)
                {
                    doc = XDocument.Parse(xml, LoadOptions.PreserveWhitespace);
                }
                else
                {
                    doc = new XDocument();
                    using (XmlReader r = XmlReader.Create(new StringReader(xml), rs))
                    {
                        while (r.Read())
                        {
                            doc.Add(XNode.ReadFrom(r));
                        }
                    }
                }

                string stringOnlyContentCopy       = stringOnlyContent == null ? null : new string(stringOnlyContent.ToCharArray());
                List <ExpectedValue> expectedNodes = CalculateExpectedContent(doc, toInsert, stringOnlyContentCopy).ProcessNodes().ToList();

                bool shouldFail = expectedNodes.IsXDocValid();

                try
                {
                    if (_runWithEvents)
                    {
                        _eHelper = new EventsHelper(doc);
                    }
                    doc.Add(toInsert);
                    TestLog.Compare(!shouldFail, "exception was expected here");
                    TestLog.Compare(expectedNodes.EqualAll(doc.Nodes(), XNode.EqualityComparer), "AddFirst");
                }
                catch (ArgumentException)
                {
                    TestLog.Compare(shouldFail, "exception was NOT expected here");
                }
                catch (InvalidOperationException)
                {
                    TestLog.Compare(shouldFail, "exception was NOT expected here");
                }
                finally
                {
                    doc.RemoveNodes();
                }
            }
        }
コード例 #25
0
                //[Variation("Read on descendant with same names", Priority = 1, Params = new object[] { "NNS" })]
                //[Variation("Read on descendant with same names", Priority = 1, Params = new object[] { "DNS" })]
                //[Variation("Read on descendant with same names", Priority = 1, Params = new object[] { "NS" })]
                public void v3()
                {
                    string type = Variation.Params[0].ToString();

                    XmlReader DataReader = GetReader(new StringReader(_xmlStr));

                    PositionOnElement(DataReader, "root");

                    // Doing a sequential read.
                    switch (type)
                    {
                    case "NNS":
                        DataReader.ReadToDescendant("elem");
                        int depth = DataReader.Depth;
                        if (DataReader.HasAttributes)
                        {
                            TestLog.WriteLine("Positioned on wrong element");
                            throw new TestException(TestResult.Failed, "");
                        }
                        TestLog.Compare(DataReader.ReadToDescendant("elem"), false, "There are no more descendants");
                        TestLog.Compare(DataReader.NodeType, XmlNodeType.EndElement, "Wrong node type");
                        while (DataReader.Read())
                        {
                            ;
                        }
                        DataReader.Dispose();

                        return;

                    case "DNS":
                        DataReader.ReadToDescendant("elem", "elem");
                        if (DataReader.HasAttributes)
                        {
                            if (DataReader.GetAttribute("xmlns") == null)
                            {
                                TestLog.WriteLine("Positioned on wrong element, not on DNS");
                                throw new TestException(TestResult.Failed, "");
                            }
                        }
                        TestLog.Compare(DataReader.ReadToDescendant("elem", "elem"), false, "There are no more descendants");
                        TestLog.Compare(DataReader.NodeType, XmlNodeType.EndElement, "Wrong node type");
                        while (DataReader.Read())
                        {
                            ;
                        }
                        DataReader.Dispose();

                        return;

                    case "NS":
                        DataReader.ReadToDescendant("e:elem");
                        if (DataReader.HasAttributes)
                        {
                            if (DataReader.GetAttribute("xmlns:e") == null)
                            {
                                TestLog.WriteLine("Positioned on wrong element, not on DNS");
                                throw new TestException(TestResult.Failed, "");
                            }
                        }
                        TestLog.Compare(DataReader.ReadToDescendant("e:elem"), false, "There are no more descendants");
                        TestLog.Compare(DataReader.NodeType, XmlNodeType.EndElement, "Wrong node type");
                        while (DataReader.Read())
                        {
                            ;
                        }
                        DataReader.Dispose();

                        return;

                    default:
                        throw new TestFailedException("Error in Test type");
                    }
                }
コード例 #26
0
                //[Variation("NameTable")]
                public void TestNameTable()
                {
                    XmlReader DataReader = ReloadSource();

                    TestLog.Compare(DataReader.NameTable != null, "nt");
                }
コード例 #27
0
                public override TestResult Execute()
                {
                    var node = CreateContainer();

                    switch (_testType)
                    {
                    case ExplicitCastTestType.RoundTrip:
                        if (_nodeType.Name.Equals("XElement"))
                        {
                            var retData = Explicit(_retType, (XElement)node);
                            TestLog.Compare(retData, _data, "XElement (" + _retType + ")");
                        }
                        else
                        {
                            var retData = Explicit(_retType, (XAttribute)node);
                            TestLog.Compare(retData, _data, "XElement (" + _retType + ")");
                        }
                        break;

                    case ExplicitCastTestType.XmlConvert:
                        string xmlConv = "";
                        switch (_data.GetType().Name)
                        {
                        case "Boolean":
                            xmlConv = XmlConvert.ToString((Boolean)_data);
                            break;

                        case "Int32":
                            xmlConv = XmlConvert.ToString((Int32)_data);
                            break;

                        case "UInt32":
                            xmlConv = XmlConvert.ToString((UInt32)_data);
                            break;

                        case "Int64":
                            xmlConv = XmlConvert.ToString((Int64)_data);
                            break;

                        case "UInt64":
                            xmlConv = XmlConvert.ToString((UInt64)_data);
                            break;

                        case "Single":
                            xmlConv = XmlConvert.ToString((Single)_data);
                            break;

                        case "Double":
                            xmlConv = XmlConvert.ToString((Double)_data);
                            break;

                        case "Decimal":
                            xmlConv = XmlConvert.ToString((Decimal)_data);
                            break;

                        case "DateTime":
                            TestLog.Skip("DateTime Convert include +8:00");
                            break;

                        case "DateTimeOffset":
                            xmlConv = XmlConvert.ToString((DateTimeOffset)_data);
                            break;

                        case "TimeSpan":
                            xmlConv = XmlConvert.ToString((TimeSpan)_data);
                            break;

                        case "Guid":
                            xmlConv = XmlConvert.ToString((Guid)_data);
                            break;

                        default:
                            TestLog.Skip("No XmlConvert.ToString (" + _data.GetType().Name + ")");
                            break;
                        }
                        string value = node is XElement ? ((XElement)node).Value : ((XAttribute)node).Value;
                        TestLog.Compare(value == xmlConv, "XmlConvert verification");
                        break;

                    default:
                        TestLog.Compare(false, "Test failed: wrong test type");
                        break;
                    }
                    return(TestResult.Passed);
                }
コード例 #28
0
                //[Variation("MoveToContent")]
                public void TestMoveToContent()
                {
                    XmlReader DataReader = ReloadSource();

                    TestLog.Compare(DataReader.MoveToContent(), XmlNodeType.Element, Variation.Desc);
                }
コード例 #29
0
                //[Variation("ReadInnerXml on EndEntity")]
                public void TestTextReadInnerXml5()
                {
                    XmlReader DataReader = GetReader();

                    TestLog.Compare(DataReader.ReadInnerXml(), string.Empty, Variation.Desc);
                }
コード例 #30
0
                //[Variation("this[name]")]
                public void HelperThisName()
                {
                    XmlReader DataReader = ReloadSource();

                    TestLog.Compare(DataReader[pATTR], null, "Compare the GetAttribute");
                }