public void writeNode_XmlReader28(XmlWriterUtils utils)
        {
            string    strxml = "<?xml version=\"1.0\" standalone=\"yes\"?><Root />";
            XmlReader xr     = CreateReader(new StringReader(strxml));

            xr.Read();
            if (xr.NodeType != XmlNodeType.XmlDeclaration)
            {
                CError.WriteLine("Reader positioned on {0}", xr.NodeType);
                xr.Dispose();
                return;
            }

            XmlWriterSettings ws = new XmlWriterSettings();

            ws.OmitXmlDeclaration = false;
            XmlWriter w = utils.CreateWriter(ws);

            w.WriteNode(xr, false);
            w.WriteStartElement("Root");
            w.WriteEndElement();
            xr.Dispose();
            w.Dispose();
            strxml = utils.IsIndent() ? "<?xml version=\"1.0\" standalone=\"yes\"?>" + Environment.NewLine + "<Root />" : strxml;
            Assert.True(utils.CompareString(strxml));
        }
Esempio n. 2
0
 public void writeAttributes_4(XmlWriterUtils utils)
 {
     using (XmlWriter w = utils.CreateWriter())
     {
         using (XmlReader xr = CreateReader("XmlReader.xml"))
         {
             while (xr.Read())
             {
                 if (xr.LocalName == "AttributesGeneric")
                 {
                     do
                     {
                         xr.Read();
                     } while (xr.LocalName != "node");
                     break;
                 }
             }
             if (xr.NodeType != XmlNodeType.Element)
             {
                 CError.WriteLine("Reader not positioned element");
                 CError.WriteLine(xr.LocalName);
                 xr.Dispose();
                 w.Dispose();
                 Assert.True(false);
             }
             w.WriteStartElement("Root");
             w.WriteAttributes(xr, false);
             w.WriteEndElement();
         }
     }
     Assert.True(utils.CompareReader("<Root a=\"b\" c=\"d\" e=\"f\" />"));
 }
Esempio n. 3
0
        public void indent_39(XmlWriterUtils utils, ConformanceLevel conformanceLevel)
        {
            XmlWriterSettings wSettings = new XmlWriterSettings();

            wSettings.OmitXmlDeclaration = true;
            wSettings.Indent             = true;
            wSettings.ConformanceLevel   = conformanceLevel;

            using (XmlWriter w = utils.CreateWriter(wSettings))
            {
                w.WriteProcessingInstruction("piname1", "pitext1");
                w.WriteComment("comment1");
                w.WriteProcessingInstruction("piname2", "pitext2");
                w.WriteStartElement("root");
                w.WriteStartElement("e1");
                w.WriteStartElement("e2");
                w.WriteStartElement("e3");
                w.WriteStartElement("e4");
                w.WriteEndElement();
                w.WriteString("text1");
                w.WriteProcessingInstruction("piname3", "pitext3");
                w.WriteEndElement();
                w.WriteComment("comment2");
                w.WriteCData("cdata1");
                w.WriteString("text2");
                w.WriteProcessingInstruction("piname4", "pitext4");
                w.WriteCData("cdata2");
                w.WriteComment("comment3");
                w.WriteProcessingInstruction("piname5", "pitext5");
                w.WriteEndElement();
                w.WriteEndElement();
            }
            CError.Compare(utils.CompareString("<?piname1 pitext1?>" + wSettings.NewLineChars + "<!--comment1-->" + wSettings.NewLineChars + "<?piname2 pitext2?>" + wSettings.NewLineChars + "<root>" + wSettings.NewLineChars + "  <e1>" + wSettings.NewLineChars + "    <e2>" + wSettings.NewLineChars + "      <e3>" + wSettings.NewLineChars + "        <e4 />text1<?piname3 pitext3?></e3>" + wSettings.NewLineChars + "      <!--comment2--><![CDATA[cdata1]]>text2<?piname4 pitext4?><![CDATA[cdata2]]><!--comment3--><?piname5 pitext5?></e2>" + wSettings.NewLineChars + "  </e1>" + wSettings.NewLineChars + "</root>"), "");
            return;
        }
Esempio n. 4
0
        public void standalone_2(XmlWriterUtils utils)
        {
            XmlWriterSettings wSettings = new XmlWriterSettings();

            wSettings.ConformanceLevel = ConformanceLevel.Document;
            wSettings.CloseOutput      = false;

            XmlWriter w = utils.CreateWriter(wSettings);

            w.WriteStartDocument(false);
            w.WriteStartElement("Root");
            w.WriteEndElement();
            w.WriteEndDocument();
            w.Dispose();

            bool ret = false;

            if (utils.WriterType == WriterType.UnicodeWriter)
            {
                ret = utils.CompareReader("<?xml version=\"1.0\" encoding=\"unicode\" standalone=\"no\"?><Root />");
            }
            else
            {
                ret = utils.CompareReader("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?><Root />");
            }

            Assert.True(ret);
        }
Esempio n. 5
0
        public void indent_29(XmlWriterUtils utils)
        {
            // The output should be the same for ConformanceLevel.Document/Auto
            int i;

            for (i = 0; i < 2; i++)
            {
                XmlWriterSettings wSettings = new XmlWriterSettings();
                wSettings.OmitXmlDeclaration = false;
                wSettings.Indent             = true;
                wSettings.ConformanceLevel   = (i % 2) == 0 ? ConformanceLevel.Auto : ConformanceLevel.Document;
                CError.WriteLine("ConformanceLevel: {0}", wSettings.ConformanceLevel.ToString());

                XmlWriter w        = utils.CreateWriter(wSettings);
                Encoding  encoding = w.Settings.Encoding;
                if (wSettings.ConformanceLevel == ConformanceLevel.Auto)
                {
                    // Write the decl as PI - since WriteStartDocument would switch to Document mode
                    w.WriteProcessingInstruction("xml", string.Format("version=\"1.0\" encoding=\"{0}\"", encoding.WebName));
                }
                else
                {
                    w.WriteStartDocument();
                }
                w.WriteStartElement("root");
                w.Dispose();
                string expectedResult = string.Format("<?xml version=\"1.0\" encoding=\"{0}\"?>" + wSettings.NewLineChars + "<root />", encoding.WebName);
                CError.Compare(utils.CompareString(expectedResult), "");
            }
        }
Esempio n. 6
0
        public void var_4(XmlWriterUtils utils)
        {
            using (XmlWriter w = utils.CreateWriter())
            {
                try
                {
                    w.WriteStartDocument();
                    w.WriteEndDocument();
                }
                catch (ArgumentException e)
                {
                    CError.WriteLineIgnore("Exception: " + e.ToString());

                    Assert.True(false);
                }
                catch (InvalidOperationException e)
                {
                    CError.WriteLineIgnore("Exception: " + e.ToString());
                    CError.Compare(w.WriteState, WriteState.Error, "WriteState should be Error");
                    return;
                }
            }
            CError.WriteLine("Did not throw exception");
            Assert.True(false);
        }
Esempio n. 7
0
        public void XmlDecl_1(XmlWriterUtils utils)
        {
            XmlWriterSettings wSettings = new XmlWriterSettings();

            wSettings.ConformanceLevel = ConformanceLevel.Document;

            XmlWriter w = utils.CreateWriter(wSettings);

            CError.Compare(w.Settings.ConformanceLevel, ConformanceLevel.Document, "Mismatch in CL");
            w.WriteStartElement("root");
            w.WriteEndElement();
            w.Dispose();

            XmlReader xr = utils.GetReader();

            // First node should be XmlDeclaration
            xr.Read();
            if (xr.NodeType != XmlNodeType.XmlDeclaration)
            {
                CError.WriteLine("Did not write XmlDecl when OmitXmlDecl was FALSE. NodeType = {0}", xr.NodeType.ToString());
                xr.Dispose();
                Assert.True(false);
            }
            else if (xr.NodeType == XmlNodeType.XmlDeclaration)
            {
                xr.Dispose();
                return;
            }
            else
            {
                xr.Dispose();
                Assert.True(false);
            }
        }
Esempio n. 8
0
        public void writeAttributes_13(XmlWriterUtils utils)
        {
            string strxml = "<E a=\"&gt;&lt;&quot;&apos;&amp;\" />";

            using (XmlReader xr = CreateReader(new StringReader(strxml)))
            {
                xr.Read();
                xr.MoveToFirstAttribute();

                if (xr.NodeType != XmlNodeType.Attribute)
                {
                    CError.WriteLine("Reader positioned on {0}", xr.NodeType.ToString());
                    xr.Dispose();
                    Assert.True(false);
                }

                using (XmlWriter w = utils.CreateWriter())
                {
                    w.WriteStartElement("Root");
                    w.WriteAttributes(xr, false);
                    w.WriteEndElement();
                }
            }
            Assert.True(utils.CompareReader("<Root a=\"&gt;&lt;&quot;&apos;&amp;\" />"));
        }
Esempio n. 9
0
        public void auto_6(XmlWriterUtils utils, string tokenType)
        {
            XmlWriter w = utils.CreateWriter(ConformanceLevel.Auto);

            switch (tokenType)
            {
            case "PI":
                w.WriteProcessingInstruction("pi", "text");
                break;

            case "Comment":
                w.WriteComment("text");
                break;

            case "WS":
                w.WriteWhitespace("   ");
                break;

            default:
                CError.Compare(false, "Invalid param in testcase");
                break;
            }
            CError.Compare(w.Settings.ConformanceLevel, ConformanceLevel.Auto, "Error");
            w.WriteDocType("ROOT", "publicid", "sysid", "<!ENTITY e 'abc'>");
            CError.Compare(w.Settings.ConformanceLevel, ConformanceLevel.Document, "Error");
            w.Dispose();
            return;
        }
Esempio n. 10
0
 public void writeAttributes_8(XmlWriterUtils utils)
 {
     if (IsXPathDataModelReader())
     {
         CError.WriteLine("{0} does not support XmlDecl node", readerType);
         return;
     }
     using (XmlWriter w = utils.CreateWriter())
     {
         using (XmlReader xr = CreateReader("Simple.xml"))
         {
             xr.Read();
             if (xr.NodeType != XmlNodeType.XmlDeclaration)
             {
                 CError.WriteLine("Reader not positioned on XmlDeclaration");
                 CError.WriteLine(xr.LocalName);
                 xr.Dispose();
                 w.Dispose();
                 Assert.True(false);
             }
             w.WriteStartElement("Root");
             w.WriteAttributes(xr, false);
             w.WriteEndElement();
         }
     }
     Assert.True(utils.CompareReader("<Root version=\"1.0\" standalone=\"yes\" />"));
 }
Esempio n. 11
0
        public void docType_4(XmlWriterUtils utils, string param)
        {
            String docName = "";

            if (param == "String.Empty")
            {
                docName = String.Empty;
            }
            else if (param == "null")
            {
                docName = null;
            }
            using (XmlWriter w = utils.CreateWriter())
            {
                try
                {
                    w.WriteDocType(docName, null, null, "test1");
                }
                catch (ArgumentException e)
                {
                    CError.WriteLineIgnore(e.ToString());
                    CError.Compare(w.WriteState, (utils.WriterType == WriterType.CharCheckingWriter) ? WriteState.Start : WriteState.Error, "WriteState should be Error");
                    return;
                }
                catch (NullReferenceException e)
                {
                    CError.WriteLineIgnore(e.ToString());
                    CError.Compare(w.WriteState, (utils.WriterType == WriterType.CharCheckingWriter) ? WriteState.Start : WriteState.Error, "WriteState should be Error");
                    return;
                }
            }
            CError.WriteLine("Did not throw exception");
            Assert.True(false);
        }
Esempio n. 12
0
        public void indent_28(XmlWriterUtils utils)
        {
            // The output should be the same for ConformanceLevel.Document/Auto
            //   and with WriteStartDocument called or not
            int i;

            for (i = 0; i < 4; i++)
            {
                XmlWriterSettings wSettings = new XmlWriterSettings();
                wSettings.OmitXmlDeclaration = true;
                wSettings.Indent             = true;
                wSettings.ConformanceLevel   = (i % 2) == 0 ? ConformanceLevel.Auto : ConformanceLevel.Document;
                CError.WriteLine("ConformanceLevel: {0}", wSettings.ConformanceLevel.ToString());

                using (XmlWriter w = utils.CreateWriter(wSettings))
                {
                    if (i > 1)
                    {
                        CError.WriteLine("WriteStartDocument called.");
                        w.WriteStartDocument();
                    }
                    else
                    {
                        CError.WriteLine("WriteStartDocument not called.");
                    }
                    w.WriteStartElement("root");
                }
                CError.Compare(utils.CompareString("<root />"), "");
            }
            return;
        }
Esempio n. 13
0
        public void writeAttributes_12(XmlWriterUtils utils)
        {
            using (XmlWriter w = utils.CreateWriter())
            {
                using (XmlReader xr = CreateReader("XmlReader.xml"))
                {
                    while (xr.Read())
                    {
                        if (xr.LocalName == "OneHundredAttributes")
                        {
                            xr.MoveToFirstAttribute();
                            break;
                        }
                    }

                    if (xr.NodeType != XmlNodeType.Attribute)
                    {
                        CError.WriteLine("Reader positioned on {0}", xr.NodeType.ToString());
                        xr.Dispose();
                        Assert.True(false);
                    }
                    w.WriteStartElement("OneHundredAttributes");
                    w.WriteAttributes(xr, false);
                    w.WriteEndElement();
                }
            }
            Assert.True(utils.CompareBaseline("OneHundredAttributes.xml"));
        }
        public void writeNode_XmlReader26(XmlWriterUtils utils)
        {
            XmlReader xr = CreateReaderIgnoreWS("XmlReader.xml");

            while (xr.Read())
            {
                if (xr.LocalName == "CommentNode")
                {
                    xr.Read();
                    break;
                }
            }
            if (xr.NodeType != XmlNodeType.Comment)
            {
                CError.WriteLine("Reader positioned on {0}", xr.NodeType);
                xr.Dispose();
                Assert.True(false);
            }
            using (XmlWriter w = utils.CreateWriter())
            {
                w.WriteStartElement("root");
                w.WriteNode(xr, false);
                w.WriteEndElement();
            }
            xr.Dispose();
            Assert.True(utils.CompareReader("<root><!--Comment--></root>"));
        }
Esempio n. 15
0
        public void writeAttributes_2(XmlWriterUtils utils)
        {
            using (XmlWriter w = utils.CreateWriter())
            {
                using (XmlReader xr = CreateReader("XmlReader.xml"))
                {
                    while (xr.Read())
                    {
                        if (xr.LocalName == "name")
                        {
                            xr.MoveToFirstAttribute();
                            break;
                        }
                    }
                    w.WriteStartElement("Root");
                    w.WriteAttributes(xr, false);
                    w.WriteEndElement();
                }
            }

            if (IsXPathDataModelReader())
            {
                // always sees default attributes
                Assert.True(utils.CompareReader("<Root a=\"b\" FIRST=\"KEVIN\" LAST=\"WHITE\" />"));
            }
            else
            {
                Assert.True(utils.CompareReader("<Root a=\"b\" />"));
            }
        }
        public void writeNode_XmlReader2(XmlWriterUtils utils)
        {
            using (XmlWriter w = utils.CreateWriter())
            {
                using (XmlReader xr = CreateReaderIgnoreWS("XmlReader.xml"))
                {
                    while (xr.Read())
                    {
                        if (xr.LocalName == "defattr")
                        {
                            xr.Read();
                            xr.MoveToFirstAttribute();
                            break;
                        }
                    }

                    if (xr.NodeType != XmlNodeType.Attribute)
                    {
                        CError.WriteLine("Reader positioned on {0}", xr.NodeType.ToString());
                        xr.Dispose();
                        w.Dispose();
                        Assert.True(false);
                    }
                    w.WriteStartElement("Root");
                    w.WriteNode(xr, false);
                    w.WriteEndElement();
                }
            }
            Assert.True(utils.CompareReader("<Root />"));
        }
        public void writeNode_XmlReader24(XmlWriterUtils utils)
        {
            if (IsXPathDataModelReader())
            {
                CError.WriteLine("XPath data model does not have CDATA node type, so {0} can not be positioned on CDATA", readerType);
                return;
            }

            XmlReader xr = CreateReaderIgnoreWS("XmlReader.xml");

            while (xr.Read())
            {
                if (xr.LocalName == "CDataNode")
                {
                    xr.Read();
                    break;
                }
            }
            if (xr.NodeType != XmlNodeType.CDATA)
            {
                CError.WriteLine("Reader positioned on {0}", xr.NodeType);
                xr.Dispose();
                Assert.True(false);
            }
            using (XmlWriter w = utils.CreateWriter())
            {
                w.WriteStartElement("root");
                w.WriteNode(xr, false);
                w.WriteEndElement();
            }
            xr.Dispose();

            Assert.True(utils.CompareReader("<root><![CDATA[cdata content]]></root>"));
        }
        public void writeNode_XmlReader16(XmlWriterUtils utils)
        {
            XmlReader xr = CreateReaderIgnoreWS("XmlReader.xml");

            while (xr.Read())
            {
                if (xr.LocalName == "DefaultAttributesTrue")
                {
                    xr.Read();
                    break;
                }
            }
            using (XmlWriter w = utils.CreateWriter())
            {
                w.WriteStartElement("Root");
                w.WriteNode(xr, false);
                w.WriteEndElement();
            }
            xr.Dispose();
            if (ReaderLoosesDefaultAttrInfo())
            {
                Assert.True(utils.CompareReader("<Root><name a='b' FIRST='KEVIN' LAST='WHITE'/></Root>"));
            }
            else
            {
                Assert.True(utils.CompareReader("<Root><name a='b' /></Root>"));
            }
        }
        public void writeNode_XmlReader10(XmlWriterUtils utils)
        {
            XmlReader xr = CreateReaderIgnoreWS("XmlReader.xml");

            while (xr.Read())
            {
                if (xr.LocalName == "MixedContent")
                {
                    xr.Read();
                    break;
                }
            }
            using (XmlWriter w = utils.CreateWriter())
            {
                w.WriteNode(xr, false);
            }

            // check reader position
            CError.Compare(xr.NodeType, XmlNodeType.EndElement, "Error");
            CError.Compare(xr.Name, "MixedContent", "Error");
            xr.Dispose();

            if (IsXPathDataModelReader())
            {
                Assert.True(utils.CompareReader("<node1><?PI Instruction?><!--Comment-->Textcdata</node1>"));
            }

            Assert.True(utils.CompareReader("<node1><?PI Instruction?><!--Comment-->Text<![CDATA[cdata]]></node1>"));
        }
Esempio n. 20
0
        public void default_1(XmlWriterUtils utils)
        {
            XmlWriterSettings wSettings = new XmlWriterSettings();

            CError.Compare(wSettings.Encoding, Encoding.UTF8, "Incorrect default value of Encoding");

            XmlWriter w = utils.CreateWriter();

            switch (utils.WriterType)
            {
            case WriterType.UTF8Writer:
            case WriterType.UTF8WriterIndent:
            case WriterType.CharCheckingWriter:
            case WriterType.WrappedWriter:
                CError.Compare(w.Settings.Encoding.WebName, "utf-8", "Incorrect default value of Encoding");
                break;

            case WriterType.UnicodeWriter:
            case WriterType.UnicodeWriterIndent:
                CError.Compare(w.Settings.Encoding.WebName, "utf-16", "Incorrect default value of Encoding");
                break;
            }
            w.Dispose();
            return;
        }
Esempio n. 21
0
        public void auto_2(XmlWriterUtils utils, bool writeStartDocument)
        {
            XmlWriter w = utils.CreateWriter(ConformanceLevel.Auto);

            CError.Compare(w.Settings.ConformanceLevel, ConformanceLevel.Auto, "Error");
            w.WriteStartDocument(writeStartDocument);

            // PROLOG
            CError.Compare(w.Settings.ConformanceLevel, ConformanceLevel.Document, "Error");
            w.WriteStartElement("root");
            // ELEMENT CONTENT
            CError.Compare(w.Settings.ConformanceLevel, ConformanceLevel.Document, "Error");
            // Inside Attribute
            w.WriteStartAttribute("attr");
            CError.Compare(w.Settings.ConformanceLevel, ConformanceLevel.Document, "Error");
            w.WriteEndElement();

            // Try writing another root element, should error
            try
            {
                w.WriteStartElement("root");
            }
            catch (InvalidOperationException)
            {
                return;
            }
            finally
            {
                w.Dispose();
            }
            CError.WriteLine("Conformance level = Document did not take effect");
            Assert.True(false);
        }
Esempio n. 22
0
        public void XmlDecl_3(XmlWriterUtils utils)
        {
            XmlWriterSettings wSettings = new XmlWriterSettings();

            wSettings.ConformanceLevel   = ConformanceLevel.Document;
            wSettings.OmitXmlDeclaration = true;

            XmlWriter w = utils.CreateWriter(wSettings);

            w.WriteStartDocument(true);
            w.WriteStartElement("root");
            w.WriteEndElement();
            w.WriteEndDocument();
            w.Dispose();


            XmlReader xr = utils.GetReader();

            // Should not read XmlDeclaration
            while (xr.Read())
            {
                if (xr.NodeType == XmlNodeType.XmlDeclaration)
                {
                    CError.WriteLine("Wrote XmlDecl when OmitXmlDecl was TRUE");
                    xr.Dispose();
                    Assert.True(false);
                }
            }
            xr.Dispose();
            return;
        }
Esempio n. 23
0
        public void auto_3(XmlWriterUtils utils)
        {
            XmlWriter w = utils.CreateWriter(ConformanceLevel.Auto);

            w.WriteDocType("ROOT", "publicid", "sysid", "<!ENTITY e 'abc'>");
            // PROLOG
            CError.Compare(w.Settings.ConformanceLevel, ConformanceLevel.Document, "Should switch to Document from Auto when you write top level DTD");
            w.WriteStartElement("Root");
            w.WriteEndElement();

            // Try writing text at root level, should error
            try
            {
                w.WriteString("text");
            }
            catch (InvalidOperationException)
            {
                return;
            }
            finally
            {
                w.Dispose();
            }
            CError.WriteLine("Conformance level = Document did not take effect");
            Assert.True(false);
        }
Esempio n. 24
0
 public void writeAttributes_11(XmlWriterUtils utils)
 {
     using (XmlWriter w = utils.CreateWriter())
     {
         using (XmlReader xr = CreateReader("XmlReader.xml"))
         {
             while (xr.Read())
             {
                 if (xr.LocalName == "QuoteChar")
                 {
                     do
                     {
                         xr.Read();
                     } while (xr.LocalName != "node");
                     do
                     {
                         xr.Read();
                     } while (xr.LocalName != "node");
                     xr.MoveToFirstAttribute();
                     break;
                 }
             }
             w.WriteStartElement("Root");
             w.WriteAttributes(xr, false);
             w.WriteEndElement();
         }
     }
     Assert.True(utils.CompareReader("<Root a=\"b'c\" />"));
 }
        public void checkChars_3(XmlWriterUtils utils, string tokenType)
        {
            char[] invalidXML = { '\u0000', '\u0008', '\u000B', '\u000C', '\u000E', '\u001F', '\uFFFE', '\uFFFF' };

            XmlWriterSettings wSettings = new XmlWriterSettings();

            wSettings.OmitXmlDeclaration = true;
            wSettings.CheckCharacters    = false;
            wSettings.CloseOutput        = true;

            XmlWriter w = utils.CreateWriter(wSettings);

            CError.Compare(w.Settings.CheckCharacters, false, "Mismatch in CheckCharacters");
            w.WriteStartElement("Root");
            switch (tokenType)
            {
            case "Comment":
                w.WriteComment(invalidXML[2].ToString());
                w.WriteEndElement();
                w.Dispose();
                string exp = utils.IsIndent() ? "<Root>" + Environment.NewLine + "  <!--\u000B-->" + Environment.NewLine + "</Root>" : "<Root><!--\u000B--></Root>";
                Assert.True(utils.CompareString(exp));
                break;

            case "PI":
                w.WriteProcessingInstruction("pi", invalidXML[6].ToString());
                w.WriteEndElement();
                w.Dispose();
                exp = utils.IsIndent() ? "<Root>" + Environment.NewLine + "  <?pi \uFFFE?>" + Environment.NewLine + "</Root>" : "<Root><?pi \uFFFE?></Root>";
                Assert.True(utils.CompareString(exp));
                break;

            case "RawString":
                w.WriteRaw(invalidXML[4].ToString());
                w.WriteEndElement();
                w.Dispose();
                Assert.True(utils.CompareString("<Root>\u000E</Root>"));
                break;

            case "RawChars":
                w.WriteRaw(invalidXML, 6, 2);
                w.WriteEndElement();
                w.Dispose();
                Assert.True(utils.CompareString("<Root>\uFFFE\uFFFF</Root>"));
                break;

            case "CData":
                w.WriteCData(invalidXML[1].ToString());
                w.WriteEndElement();
                w.Dispose();
                Assert.True(utils.CompareString("<Root><![CDATA[\u0008]]></Root>"));
                break;

            default:
                CError.Compare(false, "Invalid param value");
                Assert.True(false);
                break;
            }
        }
Esempio n. 26
0
        public void close_2(XmlWriterUtils utils)
        {
            XmlWriter w = utils.CreateWriter();

            w.Dispose();
            CError.Equals(w.Settings.Indent, utils.IsIndent(), "Incorrect default value of Indent");
            CError.Equals(w.Settings.CheckCharacters, true, "Incorrect default value of CheckCharacters");
        }
Esempio n. 27
0
 public void element_3(XmlWriterUtils utils)
 {
     using (XmlWriter w = utils.CreateWriter())
     {
         w.WriteStartElement("Root", "http://my.com");
         w.WriteEndElement();
     }
     Assert.True(utils.CompareReader("<Root xmlns=\"http://my.com\" />"));
 }
Esempio n. 28
0
        public void VerifyInvalidWrite(XmlWriterUtils utils, string methodName, int iBufferSize, int iIndex, int iCount, Type exceptionType)
        {
            byte[] byteBuffer = new byte[iBufferSize];
            for (int i = 0; i < iBufferSize; i++)
            {
                byteBuffer[i] = (byte)(i + '0');
            }

            char[] charBuffer = new char[iBufferSize];
            for (int i = 0; i < iBufferSize; i++)
            {
                charBuffer[i] = (char)(i + '0');
            }

            XmlWriter w = utils.CreateWriter();

            w.WriteStartElement("root");
            try
            {
                switch (methodName)
                {
                case "WriteBase64":
                    w.WriteBase64(byteBuffer, iIndex, iCount);
                    break;

                case "WriteRaw":
                    w.WriteRaw(charBuffer, iIndex, iCount);
                    break;

                case "WriteBinHex":
                    w.WriteBinHex(byteBuffer, iIndex, iCount);
                    break;

                case "WriteChars":
                    w.WriteChars(charBuffer, iIndex, iCount);
                    break;

                default:
                    CError.Compare(false, "Unexpected method name " + methodName);
                    break;
                }
            }
            catch (Exception e)
            {
                CError.WriteLineIgnore("Exception: " + e.ToString());
                if (exceptionType.FullName.Equals(e.GetType().FullName))
                {
                    return;
                }
                else
                {
                    CError.WriteLine("Did not throw exception of type {0}", exceptionType);
                }
            }
            w.Flush();
            Assert.True(false, "Expected exception");
        }
Esempio n. 29
0
 public void element_1(XmlWriterUtils utils)
 {
     using (XmlWriter w = utils.CreateWriter())
     {
         w.WriteStartElement("Root");
         w.WriteEndElement();
     }
     Assert.True(utils.CompareReader("<Root />"));
 }
Esempio n. 30
0
 public void attribute_20(XmlWriterUtils utils)
 {
     using (XmlWriter w = utils.CreateWriter())
     {
         w.WriteStartElement("Root");
         w.WriteAttributeString("a", null, "< > &");
         w.WriteEndElement();
     }
     Assert.True(utils.CompareReader("<Root a=\"&lt; &gt; &amp;\" />"));
 }