public int Variation_18()
        {
            ReloadSource();

            string strEmpty = string.Empty;

            object objAdded  = DataReader.NameTable.Add(strEmpty);
            object objAdded1 = DataReader.NameTable.Add(strEmpty.ToCharArray(), 0, strEmpty.Length);

            object objActual1 = DataReader.NameTable.Get(strEmpty.ToCharArray(), 0, strEmpty.Length);
            object objActual2 = DataReader.NameTable.Get(strEmpty);

            CError.WriteLine("String " + DataReader.NameTable.Get(strEmpty));
            CError.WriteLine("String " + objAdded1 + " String2 " + objAdded1);
            if (objAdded != objAdded1)
            {
                CError.WriteLine("HERE");
            }
            CError.Compare(objActual1, objActual2, CurVariation.Desc);
            VerifyNameTable(objActual1, strEmpty, strEmpty.ToCharArray(), 0, 0);

            return(TEST_PASS);
        }
        public void v6(object param0)
        {
            Initialize();
            XmlSchemaSet xss = new XmlSchemaSet();

            xss.XmlResolver             = new XmlUrlResolver();
            xss.ValidationEventHandler += ValidationCallback;
            var reader = new XmlTextReader(Path.Combine(TestData._Root, param0.ToString()));

            reader.XmlResolver = new XmlUrlResolver();
            XmlSchema schema = XmlSchema.Read(reader, ValidationCallback);

#pragma warning disable 0618
            schema.Compile(ValidationCallback);
#pragma warning restore 0618

            xss.Add(schema);

            // expect a validation warning for unresolvable schema location
            CError.Compare(warningCount, 0, "Warning Count mismatch");
            CError.Compare(errorCount, 0, "Error Count mismatch");
            return;
        }
Example #3
0
        public int v101()
        {
            string xml = @"<a xmlns:f='urn:foobar' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>" +
                         "<b><c xsi:type='f:mytype'>some content</c></b></a>";

            ReloadSourceStr(xml);

            DataReader.Read(); CError.Compare(DataReader.Name, "a", "a");
            DataReader.Read(); CError.Compare(DataReader.Name, "b", "b");
            using (XmlReader subtree = DataReader.ReadSubtree())
            {
                subtree.Read(); CError.Compare(subtree.Name, "b", "b2");
                subtree.Read(); CError.Compare(subtree.Name, "c", "c");
                subtree.MoveToAttribute("type", "http://www.w3.org/2001/XMLSchema-instance");
                CError.Compare(subtree.Value, "f:mytype", "value");
                string ns = subtree.LookupNamespace("f");
                if (ns == null)
                {
                    return(TEST_PASS);
                }
            }
            return(TEST_FAIL);
        }
Example #4
0
        public int TestTextReadValue26()
        {
            if (IsRoundTrippedReader())
            {
                return(TEST_SKIPPED);
            }

            char[] buffer = new char[5];
            ReloadSource(new StringReader("<root>value</notroot>"));
            DataReader.PositionOnElement("root");
            DataReader.Read(); //This takes to text node.
            if (!DataReader.CanReadValueChunk)
            {
                try
                {
                    DataReader.ReadValueChunk(buffer, 0, 5);
                    return(TEST_FAIL);
                }
                catch (NotSupportedException)
                {
                    return(TEST_PASS);
                }
            }

            CError.Compare(DataReader.ReadValueChunk(buffer, 0, 5), 5, "Didnt read 5 chars");
            CError.Compare("value", new string(buffer), "Strings dont match");

            try
            {
                DataReader.Read();
                return(TEST_FAIL);
            }
            catch (XmlException)
            {
                return(TEST_PASS);
            }
        }
        public int v2()
        {
            ManagedNodeWriter mnw = new ManagedNodeWriter();

            mnw.PutPattern("X");

            int count = 0;

            do
            {
                mnw.PutPattern("E/");
                count++;
            } while (mnw.GetNodes().Length < 4096);
            mnw.PutText("<a/><b/>");
            mnw.Finish();
            CError.WriteIgnore(mnw.GetNodes() + "\n");


            ReloadSource(new StringReader(mnw.GetNodes()));
            DataReader.PositionOnElement("ELEMENT_1");

            CError.Compare(DataReader.ReadToDescendant("a"), true, "Couldn't go to Descendant");
            int depth = DataReader.Depth;

            CError.Compare(DataReader.ReadToNextSibling("b"), true, "Couldn't go to NextSibling");

            CError.Compare(DataReader.Depth, depth, "Depth is not correct");
            CError.Compare(DataReader.NodeType, XmlNodeType.Element, "Nodetype is not correct");

            while (DataReader.Read())
            {
                ;
            }
            DataReader.Close();

            return(TEST_PASS);
        }
        public void writeNode_XmlReader21b(XmlWriterUtils utils)
        {
            string strxml = "<!DOCTYPE doc " +
                            "[<!ELEMENT doc ANY>" +
                            "<!ELEMENT test1 (#PCDATA)>" +
                            "<!ELEMENT test2 ANY>" +
                            "<!ELEMENT test3 (#PCDATA)>" +
                            "<!ENTITY e1 \"&e2;\">" +
                            "<!ENTITY e2 \"xmlns=\"x\"\">" +
                            "<!ATTLIST test3 a1 CDATA #IMPLIED>" +
                            "<!ATTLIST test3 a2 CDATA #IMPLIED>" +
                            "]>" +
                            "<doc>" +
                            "    &e2;" +
                            "    <test1>AA&e2;AA</test1>" +
                            "    <test2>BB&e1;BB</test2>" +
                            "    <test3 a1=\"&e2;\" a2=\"&e1;\">World</test3>" +
                            "</doc>";

            try
            {
                using (XmlWriter w = utils.CreateWriter())
                {
                    try
                    {
                        using (XmlReader xr = CreateReader(new StringReader(strxml)))
                        {
                            w.WriteNode(xr, true);
                            CError.Compare(false, "Failed");
                        }
                    }
                    catch (XmlException xe) { CError.WriteLine(xe.Message); return; }
                }
            }
            catch (ObjectDisposedException e) { CError.WriteLine(e.Message); return; }
            Assert.True(false);
        }
Example #7
0
        public void v13(object param0)
        {
            Initialize();
            XmlSchemaSet xss = new XmlSchemaSet();

            xss.XmlResolver             = new XmlUrlResolver();
            xss.ValidationEventHandler += ValidationCallback;

            XmlReader r  = CreateReader(TestData._Root + param0.ToString(), false);
            XmlReader r2 = CreateReader(r, true);

            try
            {
                xss.Add(null, r2);
            }
            catch (XmlException)
            {
                Assert.True(false); //exepect a validation warning for unresolvable schema location
            }

            _output.WriteLine("Count: " + xss.Count);
            CError.Compare(warningCount, 1, "Warning Count mismatch");
            return;
        }
Example #8
0
        public void v5(object param0, object param1)
        {
            Initialize();
            XmlSchemaSet xss = new XmlSchemaSet();

            xss.XmlResolver             = new XmlUrlResolver();
            xss.ValidationEventHandler += ValidationCallback;
            XmlSchema schema = XmlSchema.Read(new StreamReader(new FileStream(TestData._Root + param0.ToString(), FileMode.Open, FileAccess.Read)), ValidationCallback);

#pragma warning disable 0618
            schema.Compile(ValidationCallback, new XmlUrlResolver());
#pragma warning restore 0618
            try
            {
                xss.Add(schema);
            }
            catch (XmlException)
            {
                Assert.True(false); //exepect a validation warning for unresolvable schema location
            }
            CError.Compare(warningCount, (int)param1, "Warning Count mismatch");
            CError.Compare(errorCount, 0, "Error Count mismatch");
            return;
        }
Example #9
0
        public int TRReadOuterXml28()
        {
            string strExpected;

            if (IsXsltReader() || IsXmlNodeReaderDataDoc() || IsCoreReader() || IsXPathNavigatorReader())
            {
                strExpected = "att1=\"xxx&lt;xxxAxxxCxxxNO_REFERENCEe1;xxx\"";
            }
            else
            {
                if (IsXmlNodeReader())
                {
                    strExpected = "att1=\"xxx&lt;xxxAxxxCxxxNO_REFERENCEe1;xxx\"";
                }
                else
                {
                    strExpected = "att1=\"xxx&lt;xxxAxxxCxxxNO_REFERENCEe1;xxx\"";
                }
            }

            ReloadSource();
            DataReader.PositionOnElement(s_ENT1);

            DataReader.MoveToAttribute(DataReader.AttributeCount / 2);
            CError.Compare(DataReader.ReadOuterXml(), strExpected, "outer");
            if (IsXmlTextReader())
            {
                CError.Compare(DataReader.VerifyNode(XmlNodeType.Attribute, "att1", ST_ENT1_ATT_EXPAND_CHAR_ENTITIES), true, "vn");
            }
            else
            {
                CError.Compare(DataReader.VerifyNode(XmlNodeType.Attribute, "att1", ST_ENT1_ATT_EXPAND_ENTITIES), true, "vn");
            }

            return(TEST_PASS);
        }
Example #10
0
        public void v4(object param0)
        {
            XmlSchemaSet sc = new XmlSchemaSet();

            sc.XmlResolver = new XmlUrlResolver();

            try
            {
                XmlSchema Schema1 = sc.Add(null, TestData._XsdAuthor);
                XmlSchema Schema2 = sc.Add(null, Path.Combine(TestData._Root, param0.ToString())); // param as filename

                sc.Compile();
                sc.Remove(Schema2);
                CError.Compare(sc.Count, 1, "Count");
                ICollection Col = sc.Schemas();
                CError.Compare(Col.Count, 1, "ICollection.Count");
            }
            catch (Exception)
            {
                Assert.True(false);
            }

            return;
        }
        public void v11(object param0)
        {
            XmlSchemaSet sc = new XmlSchemaSet();

            sc.XmlResolver = new XmlUrlResolver();

            sc.ValidationEventHandler += new ValidationEventHandler(ValidationCallback);
            bWarningCallback           = false;
            bErrorCallback             = false;
            try
            {
                //after compile
                XmlSchema Schema1 = sc.Add(null, Path.Combine(TestData._Root, param0.ToString()));
                sc.Compile();
                CError.Compare(sc.Count, 4, "Count");
                sc.RemoveRecursive(Schema1);
                sc.Compile();
                CError.Compare(sc.Count, 0, "Count");
                CError.Compare(sc.GlobalElements.Count, 0, "Global Elements Count");
                CError.Compare(sc.GlobalTypes.Count, 0, "Global Types Count");//should contain xs:anyType

                //before compile
                Schema1 = sc.Add(null, Path.Combine(TestData._Root, param0.ToString()));
                CError.Compare(sc.Count, 4, "Count");
                sc.RemoveRecursive(Schema1);
                CError.Compare(sc.Count, 0, "Count");
                CError.Compare(sc.GlobalElements.Count, 0, "Global Elements Count");
                CError.Compare(sc.GlobalTypes.Count, 0, "Global Types Count"); //should contain xs:anyType
            }
            catch (Exception e)
            {
                _output.WriteLine(e.ToString());
                Assert.True(false);
            }
            return;
        }
Example #12
0
        public int TestReadBinHex_13()
        {
            int BinHexlen = 10;

            byte[] BinHex = new byte[BinHexlen];

            ReloadSource(EREADER_TYPE.BINHEX_TEST);
            DataReader.PositionOnElement(ST_ELEM_NAME4);
            if (CheckCanReadBinaryContent())
            {
                return(TEST_PASS);
            }

            string strActbinhex = "";

            for (int i = 0; i < BinHexlen; i = i + 2)
            {
                DataReader.ReadElementContentAsBinHex(BinHex, i, 2);
                strActbinhex = (System.BitConverter.ToChar(BinHex, i)).ToString();
                CError.WriteLine("Actual: " + strActbinhex + " Exp: " + strTextBinHex);
                CError.Compare(string.Compare(strActbinhex, 0, strTextBinHex, i / 2, 1), 0, "Compare All Valid Base64");
            }
            return(TEST_PASS);
        }
Example #13
0
        protected void TestInvalidNodeType(XmlNodeType nt)
        {
            ReloadSource();

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

            byte[] buffer = new byte[1];
            if (CheckCanReadBinaryContent())
            {
                return;
            }

            try
            {
                int nBytes = DataReader.ReadContentAsBinHex(buffer, 0, 1);
            }
            catch (InvalidOperationException)
            {
                return;
            }
            CError.Compare(false, "Invalid OP exception not thrown on wrong nodetype");
        }
Example #14
0
        public int Variation_10()
        {
            ReloadSource();

            // Add string
            object objAdded = DataReader.NameTable.Add(strVal);

            // Look for permutations of strings, should be null.
            for (int i = 0; i < strPerValCase.Length; i++)
            {
                char[] ach = strPerValCase[i].ToCharArray();

                object objActual  = DataReader.NameTable.Add(ach, 0, ach.Length);
                object objActual1 = DataReader.NameTable.Add(ach, 0, ach.Length);

                CError.Compare(objActual, objActual1, CurVariation.Desc);
                VerifyNameTable(objActual1, strPerValCase[i], ach, 0, ach.Length);
                if (objAdded == objActual)
                {
                    throw new Exception("\n Object are the same for " + strVal + " and " + strPerValCase[i]);
                }
            }
            return(TEST_PASS);
        }
Example #15
0
        public void document_6(XmlWriterUtils utils)
        {
            using (XmlWriter w = utils.CreateWriter())
            {
                try
                {
                    w.WriteStartDocument();
                    w.WriteStartElement("Root");
                    w.WriteEndElement();
                    w.WriteEndDocument();

                    w.WriteStartDocument();
                    w.WriteEndDocument();
                }
                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);
        }
Example #16
0
        public void v23()
        {
            Initialize();
            XmlSchemaSet xss = new XmlSchemaSet();

            xss.ValidationEventHandler += ValidationCallback;
            xss.Add(null, TestData._Root + "bug356711_root.xsd");

            try
            {
                XmlReader r1 = CreateReader(TestData._Root + "bug356711_1.xml", true);
                XmlReader r2 = CreateReader(r1, xss, false);
                while (r2.Read())
                {
                    ;
                }
            }
            catch (XmlException)
            {
                Assert.True(false);
            }
            CError.Compare(errorCount, 0, "ProhibitDTD did not work with schemaLocation");
            return;
        }
Example #17
0
        public int TestReadChar14()
        {
            string strExpected = "somevalue";

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

            ReloadSourceStr(strxml);
            DataReader.PositionOnElement("ROOT");

            DataReader.Read();
            if (!DataReader.CanReadValueChunk)
            {
                try
                {
                    DataReader.ReadValueChunk(buffer, 0, 5);
                    return(TEST_FAIL);
                }
                catch (NotSupportedException)
                {
                    return(TEST_PASS);
                }
            }
            CError.Compare(DataReader.ReadValueChunk(buffer, 0, buffer.Length), strExpected.Length, "ReadValue1");
            CError.Compare(new string(buffer), strExpected, "str1");

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

            DataReader.Read();//Now back on Text
            CError.Compare(DataReader.ReadValueChunk(buffer, 0, buffer.Length), strExpected.Length, "ReadValue3");
            CError.Compare(new string(buffer), strExpected, "str3");

            return(TEST_PASS);
        }
Example #18
0
        public int TestTextReadBinHex_22()
        {
            byte[] buffer = new byte[1];
            string strxml = "<abc>11B</abc>";

            ReloadSource(new StringReader(strxml));
            DataReader.PositionOnElement("abc");
            if (CheckCanReadBinaryContent())
            {
                return(TEST_PASS);
            }
            int result = 0;
            int nRead;

            while ((nRead = DataReader.ReadElementContentAsBinHex(buffer, 0, 1)) > 0)
            {
                result += nRead;
            }

            CError.Compare(result, 1, "res");
            CError.Compare(buffer[0], (byte)17, "buffer[0]");

            return(TEST_PASS);
        }
        public void v8(object param0)
        {
            XmlSchemaSet sc = new XmlSchemaSet();

            sc.XmlResolver = new XmlUrlResolver();

            try
            {
                //after compile
                XmlSchema Schema1 = sc.Add(null, Path.Combine(TestData._Root, param0.ToString()));
                sc.Compile();
                CError.Compare(sc.Count, 4, "Count");
                sc.RemoveRecursive(Schema1);
                CError.Compare(sc.Count, 0, "Count");
                CError.Compare(sc.Contains("ns-d"), false, "Contains");
                CError.Compare(sc.Contains("ns-c"), false, "Contains");
                CError.Compare(sc.Contains("ns-b"), false, "Contains");
                CError.Compare(sc.Contains("ns-a"), false, "Contains");

                //before compile
                Schema1 = sc.Add(null, Path.Combine(TestData._Root, param0.ToString()));
                CError.Compare(sc.Count, 4, "Count");
                sc.RemoveRecursive(Schema1);
                CError.Compare(sc.Count, 0, "Count");
                CError.Compare(sc.Contains("ns-d"), false, "Contains");
                CError.Compare(sc.Contains("ns-c"), false, "Contains");
                CError.Compare(sc.Contains("ns-b"), false, "Contains");
                CError.Compare(sc.Contains("ns-a"), false, "Contains");
            }
            catch (Exception e)
            {
                _output.WriteLine(e.ToString());
                Assert.True(false);
            }
            return;
        }
        public void writeNode_XmlReader8(XmlWriterUtils utils)
        {
            XmlReader xr = CreateReaderIgnoreWS("XmlReader.xml");

            while (xr.Read())
            {
                if (xr.LocalName == "EmptyElement")
                {
                    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, "EmptyElement", "Error");
            xr.Dispose();

            Assert.True(utils.CompareReader("<node1 />"));
        }
Example #21
0
        public void v11(object param0, object param1)
        {
            XmlSchemaSet sc = new XmlSchemaSet();

            sc.XmlResolver = new XmlUrlResolver();

            try
            {
                XmlSchema Schema1 = sc.Add(null, Path.Combine(TestData._Root, param0.ToString())); // param as filename
                XmlSchema Schema2 = sc.Add(null, Path.Combine(TestData._Root, param1.ToString())); // param as filename
                sc.Compile();
                CError.Compare(sc.Count, 2, "Count");
                sc.Remove(Schema2);
                sc.Compile();
                CError.Compare(sc.Count, 1, "Count");
                CError.Compare(sc.GlobalElements.Count, 2, "GlobalElems Count");
            }
            catch (Exception e)
            {
                _output.WriteLine(e.ToString());
                Assert.True(false);
            }
            return;
        }
Example #22
0
        public int TestTextReadInnerXml16()
        {
            if (IsXsltReader() || IsXPathNavigatorReader() || IsSubtreeReader())
            {
                return(TEST_SKIPPED);
            }

            ReloadSource();
            DataReader.PositionOnNodeType(XmlNodeType.XmlDeclaration);
            DataReader.MoveToAttribute(DataReader.AttributeCount / 2);

            if (IsBinaryReader())
            {
                CError.Compare(DataReader.ReadInnerXml(), "utf-8", "inner");
                CError.Compare(DataReader.VerifyNode(XmlNodeType.Attribute, "encoding", "utf-8"), true, "vn");
            }
            else
            {
                CError.Compare(DataReader.ReadInnerXml(), "UTF-8", "inner");
                CError.Compare(DataReader.VerifyNode(XmlNodeType.Attribute, "encoding", "UTF-8"), true, "vn");
            }

            return(TEST_PASS);
        }
        public void v12()
        {
            bWarningCallback = false;
            bErrorCallback   = false;

            XmlSchemaSet sc = new XmlSchemaSet();

            sc.XmlResolver = new XmlUrlResolver();

            sc.ValidationEventHandler += new ValidationEventHandler(ValidationCallback);
            XmlSchema Schema1 = sc.Add(null, Path.Combine(TestData._Root, "include_v1_a.xsd"));

            CError.Compare(sc.Count, 1, "Count after add");
            CError.Compare(sc.Contains(Schema1), true, "Contains after add");

            sc.Compile();
            CError.Compare(sc.Count, 1, "Count after add/comp");
            CError.Compare(sc.Contains(Schema1), true, "Contains after add/comp");
            ///edit
            XmlSchemaInclude inc = new XmlSchemaInclude();

            inc.SchemaLocation = "include_v2.xsd";
            Schema1.Includes.Add(inc);

            sc.Reprocess(Schema1);
            ValidateSchemaSet(sc, 1, false, 1, 0, 0, "Validation after edit/reprocess");
            CError.Compare(bWarningCallback, false, "Warning repr");
            CError.Compare(bErrorCallback, true, "Error repr");

            sc.Compile();
            ValidateSchemaSet(sc, 1, false, 1, 0, 0, "Validation after comp/reprocess");
            CError.Compare(bWarningCallback, false, "Warning comp");
            CError.Compare(bErrorCallback, true, "Error comp");
            CError.Compare(Schema1.IsCompiled, false, "IsCompiled on SOM");
            return;
        }
Example #24
0
        public void v22(object param0)
        {
            Initialize();
            XmlSchemaSet xss = new XmlSchemaSet();

            xss.XmlResolver             = new XmlUrlResolver();
            xss.ValidationEventHandler += ValidationCallback;
            xss.Add(null, TestData._Root + "bug356711_root.xsd");

            try
            {
                XmlReader reader = CreateReader(TestData._Root + param0.ToString(), xss, false);
                while (reader.Read())
                {
                    ;
                }
            }
            catch (XmlException)
            {
                Assert.True(false);
            }
            CError.Compare(errorCount, 0, "ProhibitDTD did not work with schemaLocation");
            return;
        }
Example #25
0
        public int TestNormalization16()
        {
            string strxml             = "<e a='a&#xD;\r\n \r&#xA;b&#xD;&#x20;&#x9;&#x41;'/>";
            string expNormalizedValue = "a\r   \nb\r \tA";

            ReloadSourceStr(strxml);
            DataReader.Read();

            // use different ways of getting the value
            string valueGet = DataReader.GetAttribute("a");

            DataReader.MoveToAttribute("a");

            string valueMove = DataReader.Value;

            DataReader.ReadAttributeValue();

            string valueRead = DataReader.Value;

            CError.Compare(valueGet, expNormalizedValue, "Wrong normalization (GetAttributeValue)");
            CError.Compare(valueMove, expNormalizedValue, "Wrong normalization (MoveToAttribute)");
            CError.Compare(valueRead, expNormalizedValue, "Wrong normalization (ReadAttributeValue)");
            return(TEST_PASS);
        }
Example #26
0
        public void writeAttributes_9(XmlWriterUtils utils, string tokenType)
        {
            string strxml = "";

            switch (tokenType)
            {
            case "DocumentType":
                if (IsXPathDataModelReader())
                {
                    CError.WriteLine("{0} does not support DocumentType node", readerType);
                    return;
                }
                strxml = "<!DOCTYPE Root[]><Root/>";
                break;

            case "CDATA":
                if (IsXPathDataModelReader())
                {
                    CError.WriteLine("{0} does not support CDATA node", readerType);
                    return;
                }
                strxml = "<root><![CDATA[Test]]></root>";
                break;

            case "Text":
                strxml = "<root>Test</root>";
                break;

            case "ProcessingInstruction":
                strxml = "<root><?pi test?></root>";
                break;

            case "Comment":
                strxml = "<root><!-- comment --></root>";
                break;

            case "EntityReference":
                if (!ReaderSupportsEntityRef())
                {
                    CError.WriteLine("{0} does not support EntityRef node", readerType);
                    return;
                }
                strxml = "<!DOCTYPE root[<!ENTITY e \"Test Entity\"> ]><root>&e;</root>";
                break;

            case "SignificantWhitespace":
                strxml = "<root xml:space=\"preserve\">			 </root>";
                break;

            case "Whitespace":
                if (ReaderStripsWhitespace())
                {
                    CError.WriteLine("{0} strips whitespace nodes by default", readerType);
                    return;
                }
                strxml = "<root>			 </root>";
                break;
            }

            XmlReader xr;

            xr = CreateReader(new StringReader(strxml));

            do
            {
                xr.Read();
            }while ((xr.NodeType.ToString() != tokenType) && (xr.ReadState != ReadState.EndOfFile));

            if (xr.ReadState == ReadState.EndOfFile || xr.NodeType.ToString() != tokenType)
            {
                xr.Dispose();
                CError.WriteLine("Reader not positioned on correct node");
                CError.WriteLine("ReadState: {0}", xr.ReadState);
                CError.WriteLine("NodeType: {0}", xr.NodeType);
                Assert.True(false);
            }

            using (XmlWriter w = utils.CreateWriter())
            {
                try
                {
                    if (tokenType != "DocumentType")
                    {
                        w.WriteStartElement("root");
                    }
                    w.WriteAttributes(xr, false);
                }
                catch (XmlException e)
                {
                    CError.WriteLineIgnore(e.ToString());
                    CError.Compare(w.WriteState, (tokenType == "DocumentType") ? WriteState.Start : WriteState.Element, "WriteState should be Element");
                    return;
                }
                finally
                {
                    xr.Dispose();
                }
            }
            CError.WriteLine("Did not throw exception");
            Assert.True(false);
        }
Example #27
0
        public int InitReaderPointer()
        {
            int iRetVal = TEST_PASS;

            CError.WriteLine("InitReaderPointer:{0}", GetDescription());
            if (GetDescription() == "BeforeRead")
            {
                IntegrityVer = EINTEGRITY.BEFORE_READ;
                CError.Compare(DataReader.ReadState, ReadState.Initial, "ReadState=Initial");
                CError.Compare(DataReader.EOF, false, "EOF==false");
            }

            else if (GetDescription() == "AfterReadIsFalse")
            {
                IntegrityVer = EINTEGRITY.AFTER_READ_FALSE;
                while (DataReader.Read())
                {
                    ;
                }
                CError.Compare(DataReader.ReadState, ReadState.EndOfFile, "ReadState=EOF");
                CError.Compare(DataReader.EOF, true, "EOF==true");
            }

            else if (GetDescription() == "AfterClose")
            {
                IntegrityVer = EINTEGRITY.AFTER_CLOSE;
                while (DataReader.Read())
                {
                    ;
                }
                DataReader.Close();
                CError.Compare(DataReader.ReadState, ReadState.Closed, "ReadState=Closed");
                CError.Compare(DataReader.EOF, false, "EOF==true");
            }

            else if (GetDescription() == "AfterCloseInTheMiddle")
            {
                IntegrityVer = EINTEGRITY.CLOSE_IN_THE_MIDDLE;
                for (int i = 0; i < 1; i++)
                {
                    if (false == DataReader.Read())
                    {
                        iRetVal = TEST_FAIL;
                    }
                    CError.Compare(DataReader.ReadState, ReadState.Interactive, "ReadState=Interactive");
                }
                DataReader.Close();
                CError.Compare(DataReader.ReadState, ReadState.Closed, "ReadState=Closed");
                CError.Compare(DataReader.EOF, false, "EOF==true");
                CError.WriteLine("EOF = " + DataReader.EOF);
            }
            else if (GetDescription() == "AfterResetState")
            {
                IntegrityVer = EINTEGRITY.AFTER_RESETSTATE;

                // position the reader somewhere in the middle of the file
                DataReader.PositionOnElement("elem1");
                DataReader.ResetState();

                CError.Compare(DataReader.ReadState, ReadState.Initial, "ReadState=Initial");
            }


            CError.WriteLine("ReadState = " + (DataReader.ReadState).ToString());
            return(iRetVal);
        }
Example #28
0
 public int HelperThisName()
 {
     ReloadSource();
     CError.Compare(DataReader[s_ATTR], null, "Compare the GetAttribute");
     return(TEST_PASS);
 }
Example #29
0
 public int TestNameTable()
 {
     ReloadSource();
     CError.Compare(DataReader.NameTable != null, "nt");
     return(TEST_PASS);
 }
Example #30
0
 public int GetAttributeEmptyNameNamespace()
 {
     CError.Compare(DataReader.GetAttribute(String.Empty, String.Empty), null, "Compare the GetAttribute");
     return(TEST_PASS);
 }