public string GetSimpleInvalidXml()
 {
     string invalidCharString = StringGen.GetIllegalXmlString(10, true);
     ManagedNodeWriter mn = new ManagedNodeWriter();
     mn.PutDecl();
     mn.OpenElement("�");
     mn.CloseElement();
     mn.PutText(invalidCharString);
     mn.PutEndElement();
     return mn.GetNodes();
 }
Beispiel #2
0
        public int v100()
        {
            ManagedNodeWriter mnw = new ManagedNodeWriter();
            mnw.PutPattern("X");
            do
            {
                mnw.OpenElement();
                mnw.CloseElement();
            }
            while (mnw.GetNodes().Length < 4096);

            mnw.Finish();

            ReloadSource(new StringReader(mnw.GetNodes()));

            DataReader.PositionOnElement("ELEMENT_2");

            XmlReader r = DataReader.ReadSubtree();
            while (r.Read()) ;

            DataReader.Read();

            CError.Compare(DataReader.Name, "ELEMENT_1", "Main name doesnt match");
            CError.Compare(DataReader.Value, "", "Main value doesnt match");
            CError.Compare(DataReader.NodeType.ToString().ToUpperInvariant(), "ENDELEMENT", "Main nodetype doesnt match");

            DataReader.Close();
            return TEST_PASS;
        }
        public object[] GetAllPri0ConformanceTestXmlStrings()
        {
            /*
            The following XML Strings will be created :
            
            1 Text at Top Level
            2 More than one element at top level
            3 WhiteSpace at Top level
            4 Top Level Attribute
            5 Multiple Contiguous Text Nodes.
            6 Same Prefix declared twice.
            7 xml:space contains wrong value
            8 Invalid Name for element
            9 Invalid Name for attribute
            10 Prefix Xml matched with wrong namespace URI.
            11 prefix Xml missing Namepace URI
            12 prefix or localname xmlns matches with wrong namespace URI
            13 prefix or localname xmlns missing namespace uri.

            */

            List<string> list = new List<string>();
            ManagedNodeWriter mn = null;

            list.Add(GetPatternXml("T")); //1
            list.Add(GetPatternXml("XEMEM"));//2
            list.Add(GetPatternXml("WEM"));//3
            list.Add(GetPatternXml("TPT"));//4
            list.Add(GetPatternXml("A"));//5

            //6
            mn = new ManagedNodeWriter();
            mn.PutPattern("XE");
            mn.PutAttribute("xmlns:a", "http://www.foo.com");
            mn.PutAttribute("xmlns:a", "http://www.foo.com");
            mn.PutPattern("M");
            CError.WriteLine(mn.GetNodes());
            list.Add(mn.GetNodes());
            mn.Close();

            //7
            mn = new ManagedNodeWriter();
            mn.PutPattern("XE");
            mn.PutAttribute("xml:space", "rubbish");
            mn.PutPattern("M");
            CError.WriteLine(mn.GetNodes());
            list.Add(mn.GetNodes());
            mn.Close();

            //8
            mn = new ManagedNodeWriter();
            mn.PutPattern("X");
            mn.OpenElement(UnicodeCharHelper.GetInvalidCharacters(CharType.XmlChar));
            mn.PutPattern("M");
            CError.WriteLine(mn.GetNodes());
            list.Add(mn.GetNodes());
            mn.Close();

            //9
            mn = new ManagedNodeWriter();
            mn.PutPattern("XE");
            mn.PutAttribute(UnicodeCharHelper.GetInvalidCharacters(CharType.XmlChar), UnicodeCharHelper.GetInvalidCharacters(CharType.XmlChar));
            mn.PutPattern("M");
            CError.WriteLine(mn.GetNodes());
            list.Add(mn.GetNodes());
            mn.Close();

            //10
            mn = new ManagedNodeWriter();
            mn.PutPattern("XE");
            mn.PutAttribute("xmlns:xml", "http://wrong");
            mn.PutPattern("M");
            CError.WriteLine(mn.GetNodes());
            list.Add(mn.GetNodes());
            mn.Close();

            //11
            mn = new ManagedNodeWriter();
            mn.PutPattern("XE");
            mn.PutAttribute("xml:space", "default");
            mn.PutPattern("M");
            CError.WriteLine(mn.GetNodes());
            list.Add(mn.GetNodes());
            mn.Close();

            return list.ToArray();
        }
        //[Variation("Default Reader, Check Characters On and pass invalid characters in text", Pri = 0, Params = new object[] { "CoreValidatingReader" })]
        //[Variation("Default Reader, Check Characters On and pass invalid characters in text", Pri = 0, Params = new object[] { "CoreReader" })]
        public int v5()
        {
            string readerType = (string)this.CurVariation.Params[0];
            bool exceptionThrown = false;

            ManagedNodeWriter mn = new ManagedNodeWriter();
            mn.PutDecl();
            mn.OpenElement();
            mn.CloseElement();
            mn.PutText("&#xd800;"); //This is invalid char in XML.
            mn.PutEndElement();
            string invalidCharXml = mn.GetNodes();

            XmlReaderSettings rs = new XmlReaderSettings();
            rs.CheckCharacters = true;

            XmlReader reader = ReaderHelper.CreateReader(readerType, new StringReader(invalidCharXml), false, null, rs);
            try
            {
                while (reader.Read()) ;
            }
            catch (XmlException xe)
            {
                CError.WriteIgnore(invalidCharXml);
                CError.WriteLine(xe.Message);
                CError.WriteLine(xe.StackTrace);
                exceptionThrown = true;
            }

            mn.Close();
            reader.Dispose();

            if (!exceptionThrown)
                return TEST_FAIL;

            return TEST_PASS;
        }
        //[Variation("Default Reader, Check Characters Off and pass invalid characters in element", Pri = 0, Params = new object[] { "CoreValidatingReader" })]
        //[Variation("Default Reader, Check Characters Off and pass invalid characters in element", Pri = 0, Params = new object[] {"CoreReader"})]
        public int v4()
        {
            string readerType = (string)this.CurVariation.Params[0];
            bool exceptionThrown = false;

            ManagedNodeWriter mn = new ManagedNodeWriter();
            mn.PutDecl();
            mn.OpenElement("&#xd800;");
            mn.CloseEmptyElement();

            XmlReaderSettings rs = new XmlReaderSettings();
            rs.CheckCharacters = false;
            XmlReader reader = ReaderHelper.CreateReader(readerType, new StringReader(mn.GetNodes()), false, null, rs);
            try
            {
                while (reader.Read()) ;
            }
            catch (XmlException xe)
            {
                CError.WriteIgnore(xe.Message + "\n");
                exceptionThrown = true;
            }

            mn.Close();
            reader.Dispose();

            if (!exceptionThrown)
                return TEST_FAIL;

            return TEST_PASS;
        }