Ejemplo n.º 1
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);
            }
        }
Ejemplo n.º 2
0
        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, "Couldnt go to Descendant");
            int depth = DataReader.Depth;

            CError.Compare(DataReader.ReadToNextSibling("b"), true, "Couldnt 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);
        }
Ejemplo n.º 3
0
        public bool CompareString(string strExpected)
        {
            string strActual = this.GetString();

            if (strExpected != strActual)
            {
                int expLen = (strExpected == null ? 0 : strExpected.Length);
                int actLen = (strActual == null ? 0 : strActual.Length);

                int minLen = (expLen < actLen ? expLen : actLen);

                // find the first different character
                int i;
                for (i = 0; i < minLen; i++)
                {
                    if (strExpected[i] != strActual[i])
                    {
                        CError.WriteLine("Position:" + i);
                        CError.WriteLine("Expected char:'" + strExpected[i] + "'(" + Convert.ToInt32(strExpected[i]) + ")");
                        CError.WriteLine("Actual char:'" + strActual[i] + "'(" + Convert.ToInt32(strActual[i]) + ")");
                        break;
                    }
                }
                if (i == minLen)
                {
                    // one string contains the other
                    CError.WriteLine("Expected length:" + expLen + " Actual length:" + actLen);
                    return(false);
                }
                CError.WriteLine("Expected string:" + strExpected);
                CError.WriteLine("Actual string:" + strActual);
                CError.Compare(false, "CompareString failed");
                return(false);
            }
            return(true);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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");
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
0
 public int TestNameTable()
 {
     ReloadSource();
     CError.Compare(DataReader.NameTable != null, "nt");
     return(TEST_PASS);
 }
Ejemplo n.º 10
0
 public int HelperThisName()
 {
     ReloadSource();
     CError.Compare(DataReader[s_ATTR], null, "Compare the GetAttribute");
     return(TEST_PASS);
 }
Ejemplo n.º 11
0
 public int GetAttributeEmptyNameNamespace()
 {
     CError.Compare(DataReader.GetAttribute(String.Empty, String.Empty), null, "Compare the GetAttribute");
     return(TEST_PASS);
 }
Ejemplo n.º 12
0
 public int GetAttributeNameNamespace()
 {
     CError.Compare(DataReader.GetAttribute(s_ATTR, s_NS), null, "Compare the GetAttribute");
     return(TEST_PASS);
 }
Ejemplo n.º 13
0
        //[Variation("Read on descendant with same names", Pri = 1, Params = new object[] { "NNS" })]
        //[Variation("Read on descendant with same names", Pri = 1, Params = new object[] { "DNS" })]
        //[Variation("Read on descendant with same names", Pri = 1, Params = new object[] { "NS" })]
        public int v3()
        {
            string type = CurVariation.Params[0].ToString();

            CError.WriteLine("Test Type : " + type);

            ReloadSource(new StringReader(_xmlStr));
            DataReader.PositionOnElement("root");

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

                return(TEST_PASS);

            case "DNS":
                DataReader.ReadToDescendant("elem", "elem");
                if (DataReader.HasAttributes)
                {
                    if (DataReader.GetAttribute("xmlns") == null)
                    {
                        CError.WriteLine("Positioned on wrong element, not on DNS");
                        return(TEST_FAIL);
                    }
                }
                CError.Compare(DataReader.ReadToDescendant("elem", "elem"), false, "There are no more descendants");
                CError.Compare(DataReader.NodeType, XmlNodeType.EndElement, "Wrong node type");
                while (DataReader.Read())
                {
                    ;
                }
                DataReader.Close();

                return(TEST_PASS);

            case "NS":
                DataReader.ReadToDescendant("e:elem");
                if (DataReader.HasAttributes)
                {
                    if (DataReader.GetAttribute("xmlns:e") == null)
                    {
                        CError.WriteLine("Positioned on wrong element, not on DNS");
                        return(TEST_FAIL);
                    }
                }
                CError.Compare(DataReader.ReadToDescendant("e:elem"), false, "There are no more descendants");
                CError.Compare(DataReader.NodeType, XmlNodeType.EndElement, "Wrong node type");
                while (DataReader.Read())
                {
                    ;
                }
                DataReader.Close();

                return(TEST_PASS);

            default:
                throw new CTestFailedException("Error in Test type");
            }
        }
Ejemplo n.º 14
0
 public int GetXmlReaderLocalName()
 {
     CError.Compare(DataReader.LocalName, String.Empty, CurVariation.Desc);
     CError.Compare(DataReader.LocalName, String.Empty, CurVariation.Desc);
     return(TEST_PASS);
 }
Ejemplo n.º 15
0
 public int IsEmptyElement()
 {
     CError.Compare(DataReader.IsEmptyElement, false, CurVariation.Desc);
     CError.Compare(DataReader.IsEmptyElement, false, CurVariation.Desc);
     return(TEST_PASS);
 }
Ejemplo n.º 16
0
 public int IsDefault()
 {
     CError.Compare(DataReader.IsDefault, false, CurVariation.Desc);
     CError.Compare(DataReader.IsDefault, false, CurVariation.Desc);
     return(TEST_PASS);
 }
Ejemplo n.º 17
0
 public int GetDepth()
 {
     CError.Compare(DataReader.Depth, 0, CurVariation.Desc);
     CError.Compare(DataReader.Depth, 0, CurVariation.Desc);
     return(TEST_PASS);
 }
Ejemplo n.º 18
0
 public int Prefix()
 {
     CError.Compare(DataReader.Prefix, String.Empty, CurVariation.Desc);
     CError.Compare(DataReader.Prefix, String.Empty, CurVariation.Desc);
     return(TEST_PASS);
 }
Ejemplo n.º 19
0
 public int Namespace()
 {
     CError.Compare(DataReader.NamespaceURI, String.Empty, CurVariation.Desc);
     CError.Compare(DataReader.NamespaceURI, String.Empty, CurVariation.Desc);
     return(TEST_PASS);
 }
Ejemplo n.º 20
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);
        }
Ejemplo n.º 21
0
        protected void CheckException(string expectedCode, Exception e)
        {
            string actualCode = expectedCode;

            CError.Compare(actualCode, expectedCode, "Error Code" + e.Message);
        }
Ejemplo n.º 22
0
 public int GetXmlSpace()
 {
     CError.Compare(DataReader.XmlSpace, XmlSpace.None, CurVariation.Desc);
     CError.Compare(DataReader.XmlSpace, XmlSpace.None, CurVariation.Desc);
     return(TEST_PASS);
 }
Ejemplo n.º 23
0
        //[Variation("Simple positive test 1", Pri = 0, Params = new object[] { "NNS" })]
        //[Variation("Simple positive test 2", Pri = 0, Params = new object[] { "DNS" })]
        //[Variation("Simple positive test 3", Pri = 0, Params = new object[] { "NS" })]
        public int v()
        {
            string type = CurVariation.Params[0].ToString();

            CError.WriteLine("Test Type : " + type);

            ReloadSource(new StringReader(_xmlStr));
            DataReader.PositionOnElement("root");

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

                if (DataReader.HasAttributes)
                {
                    CError.Compare(DataReader.GetAttribute("att"), "1", "Not the expected attribute");
                }
                else
                {
                    CError.WriteLine("Positioned on wrong element");
                    DumpStat();
                    return(TEST_FAIL);
                }
                while (DataReader.Read())
                {
                    ;
                }
                DataReader.Close();
                return(TEST_PASS);

            case "DNS":
                DataReader.ReadToDescendant("elem", "elem");
                DataReader.ReadToNextSibling("elem", "elem");
                if (DataReader.HasAttributes)
                {
                    if (DataReader.GetAttribute("att") == null)
                    {
                        CError.WriteLine("Positioned on wrong element, not on DNS");
                        return(TEST_FAIL);
                    }
                }
                else
                {
                    CError.WriteLine("Positioned on wrong element");
                    DumpStat();
                    return(TEST_FAIL);
                }
                while (DataReader.Read())
                {
                    ;
                }
                DataReader.Close();
                return(TEST_PASS);

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

                if (DataReader.HasAttributes)
                {
                    if (DataReader.GetAttribute("xmlns:e") == null)
                    {
                        CError.WriteLine("Positioned on wrong element, not on DNS");
                        return(TEST_FAIL);
                    }
                }
                else
                {
                    CError.WriteLine("Positioned on wrong element");
                    DumpStat();
                    return(TEST_FAIL);
                }

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

            default:
                throw new CTestFailedException("Error in Test type");
            }
        }
Ejemplo n.º 24
0
        //[Variation("Read to next sibling with same names 1", Pri = 1, Params = new object[] { "NNS", "<root><a att='1'/><a att='2'/><a att='3'/></root>" })]
        //[Variation("Read on next sibling with same names 2", Pri = 1, Params = new object[] { "DNS", "<root xmlns='a'><a att='1'/><a att='2'/><a att='3'/></root>" })]
        //[Variation("Read on next sibling with same names 3", Pri = 1, Params = new object[] { "NS", "<root xmlns:a='a'><a:a att='1'/><a:a att='2'/><a:a att='3'/></root>" })]
        public int v3()
        {
            string type = CurVariation.Params[0].ToString();
            string xml  = CurVariation.Params[1].ToString();

            CError.WriteLine("Test Type : " + type);

            ReloadSource(new StringReader(xml));
            DataReader.Read();
            if (IsBinaryReader())
            {
                DataReader.Read();
            }

            //Doing a sequential read.
            switch (type)
            {
            case "NNS":
                DataReader.ReadToDescendant("a");
                DataReader.ReadToNextSibling("a");
                DataReader.ReadToNextSibling("a");
                CError.Compare(DataReader.GetAttribute("att"), "3", "Wrong node");

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

                return(TEST_PASS);

            case "DNS":
                DataReader.ReadToDescendant("a", "a");
                DataReader.ReadToNextSibling("a", "a");
                DataReader.ReadToNextSibling("a", "a");
                CError.Compare(DataReader.GetAttribute("att"), "3", "Wrong node");

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

                return(TEST_PASS);

            case "NS":
                DataReader.ReadToDescendant("a:a");
                DataReader.ReadToNextSibling("a:a");
                DataReader.ReadToNextSibling("a:a");
                CError.Compare(DataReader.GetAttribute("att"), "3", "Wrong node");

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

                return(TEST_PASS);

            default:
                throw new CTestFailedException("Error in Test type");
            }
        }
Ejemplo n.º 25
0
 public int AttributeCount()
 {
     CError.Compare(DataReader.AttributeCount, 0, CurVariation.Desc);
     CError.Compare(DataReader.AttributeCount, 0, CurVariation.Desc);
     return(TEST_PASS);
 }
Ejemplo n.º 26
0
        public override XmlReader Create(MyDict <string, object> options)
        {
            string tcDesc = (string)options[ReaderFactory.HT_CURDESC];
            string tcVar  = (string)options[ReaderFactory.HT_CURVAR];

            CError.Compare(tcDesc == "subtreereader", "Invalid testcase");

            XmlReaderSettings rs         = (XmlReaderSettings)options[ReaderFactory.HT_READERSETTINGS];
            Stream            stream     = (Stream)options[ReaderFactory.HT_STREAM];
            string            filename   = (string)options[ReaderFactory.HT_FILENAME];
            object            readerType = options[ReaderFactory.HT_READERTYPE];
            object            vt         = options[ReaderFactory.HT_VALIDATIONTYPE];
            string            fragment   = (string)options[ReaderFactory.HT_FRAGMENT];
            StringReader      sr         = (StringReader)options[ReaderFactory.HT_STRINGREADER];

            if (rs == null)
            {
                rs = new XmlReaderSettings();
            }

            rs.DtdProcessing = DtdProcessing.Ignore;
            if (sr != null)
            {
                CError.WriteLine("SubtreeReader String");

                XmlReader r = ReaderHelper.Create(sr, rs, string.Empty);
                while (r.Read())
                {
                    if (r.NodeType == XmlNodeType.Element)
                    {
                        break;
                    }
                }
                XmlReader wr = r.ReadSubtree();
                return(wr);
            }

            if (stream != null)
            {
                CError.WriteLine("SubtreeReader Stream");

                XmlReader r = ReaderHelper.Create(stream, rs, filename);
                while (r.Read())
                {
                    if (r.NodeType == XmlNodeType.Element)
                    {
                        break;
                    }
                }
                XmlReader wr = r.ReadSubtree();
                return(wr);
            }

            if (fragment != null)
            {
                CError.WriteLine("SubtreeReader Fragment");
                rs.ConformanceLevel = ConformanceLevel.Fragment;
                StringReader tr = new StringReader(fragment);

                XmlReader r = ReaderHelper.Create(tr, rs, (string)null);
                while (r.Read())
                {
                    if (r.NodeType == XmlNodeType.Element)
                    {
                        break;
                    }
                }
                XmlReader wr = r.ReadSubtree();
                return(wr);
            }

            if (filename != null)
            {
                CError.WriteLine("SubtreeReader Filename");

                Stream    fs = FilePathUtil.getStream(filename);
                XmlReader r  = ReaderHelper.Create(fs, rs, filename);
                while (r.Read())
                {
                    if (r.NodeType == XmlNodeType.Element)
                    {
                        break;
                    }
                }
                XmlReader wr = r.ReadSubtree();
                return(wr);
            }

            throw new CTestFailedException("SubtreeReader not created");
        }
Ejemplo n.º 27
0
 public int HasAttribute()
 {
     CError.Compare(DataReader.HasAttributes, false, CurVariation.Desc);
     CError.Compare(DataReader.HasAttributes, false, CurVariation.Desc);
     return(TEST_PASS);
 }
Ejemplo n.º 28
0
 public int GetXmlLang()
 {
     CError.Compare(DataReader.XmlLang, String.Empty, CurVariation.Desc);
     CError.Compare(DataReader.XmlLang, String.Empty, CurVariation.Desc);
     return(TEST_PASS);
 }
Ejemplo n.º 29
0
 public void CheckElementState(WriteState ws)
 {
     CError.Compare(ws, WriteState.Element, "WriteState should be Element");
 }