示例#1
0
        /// <summary>
        /// Returns a string of valid characters
        /// </summary>
        /// <param name="charType">type form CharType class</param>
        /// <returns>string of characters</returns>
        public string GetValidCharacters(string charType)
        {
            string chars = string.Empty;

            switch (charType)
            {
            case "NCNameStartChar":
                chars = UnicodeCharHelper.GetValidCharacters(CharType.NCNameStartChar);
                break;

            case "NCNameChar":
                chars = UnicodeCharHelper.GetValidCharacters(CharType.NCNameChar);
                break;

            case "NameStartSurrogateHighChar":
                chars = UnicodeCharHelper.GetValidCharacters(CharType.NameStartSurrogateHighChar);
                break;

            case "NameStartSurrogateLowChar":
                chars = UnicodeCharHelper.GetValidCharacters(CharType.NameStartSurrogateLowChar);
                break;

            case "NameSurrogateHighChar":
                chars = UnicodeCharHelper.GetValidCharacters(CharType.NameSurrogateHighChar);
                break;

            case "NameSurrogateLowChar":
                chars = UnicodeCharHelper.GetValidCharacters(CharType.NameSurrogateLowChar);
                break;

            default:
                break;
            }
            return(chars);
        }
示例#2
0
        private IEnumerable <string> FuzzNames(bool useInvalidCharacters, CharType charType, int namesCount)
        {
            string chars =
                useInvalidCharacters ?
                UnicodeCharHelper.GetInvalidCharacters(charType) :
                UnicodeCharHelper.GetValidCharacters(charType);

            for (int i = 0; i < namesCount; i++)
            {
                yield return(GenerateString(chars[_rand.Next(chars.Length)], charType));
            }
        }
示例#3
0
        public void CreateElementsAndAttributesUsingXsltAndXPath(object param0, object param1)
        {
            bool     isValidChar = (bool)param0;
            CharType charType    = (CharType)param1;
            var      startChars  = new CharType[] { CharType.NameStartChar, CharType.NameStartSurrogateHighChar, CharType.NameStartSurrogateLowChar };

            string charsToChooseFrom = isValidChar ? UnicodeCharHelper.GetValidCharacters(charType) : UnicodeCharHelper.GetInvalidCharacters(charType);

            Assert.True(charsToChooseFrom.Length > 0);

            foreach (bool enableDebug in new bool[] { /*true,*/ false }) // XSLT debugging not supported in Core
            {
                XslCompiledTransform transf = new XslCompiledTransform(enableDebug);
                using (XmlReader r = XmlReader.Create(new StringReader(createElementsXsltAndXpath))) transf.Load(r);

                for (int i = 0; i < charsToChooseFrom.Length; i++)
                {
                    XsltArgumentList arguments = new XsltArgumentList();
                    arguments.AddParam("mode", "", Array.Exists(startChars, x => x == charType) ? "start" : "middle");
                    string strToInject = GenerateStringToInject(charsToChooseFrom, i, charType);
                    if (strToInject[0] == ':')
                    {
                        continue;
                    }
                    arguments.AddParam("char", "", strToInject);
                    StringBuilder sb = new StringBuilder();

                    try
                    {
                        using (XmlReader r = XmlReader.Create(new StringReader("<root/>"))) transf.Transform(r, arguments, new StringWriter(sb));
                        Assert.True(isValidChar);
                        // TODO: verification for valid case
                    }
                    catch (Exception)
                    {
                        if (isValidChar)
                        {
                            throw;
                        }
                        else
                        {
                            continue;  //exception expected -> continue
                        }
                    }
                }
            }
            return;
        }
示例#4
0
        public void CreateElementsAndAttributesUsingXsltInline(object param0, object param1)
        {
            int      numOfRepeat = 300; // from the test case
            bool     isValidChar = (bool)param0;
            CharType charType    = (CharType)param1;
            var      startChars  = new CharType[] { CharType.NameStartChar, CharType.NameStartSurrogateHighChar, CharType.NameStartSurrogateLowChar };

            string charsToChooseFrom = isValidChar ? UnicodeCharHelper.GetValidCharacters(charType) : UnicodeCharHelper.GetInvalidCharacters(charType);

            Assert.True(charsToChooseFrom.Length > 0);

            foreach (bool enableDebug in new bool[] { /*true,*/ false }) // XSLT debugging not supported in Core
            {
                foreach (string name in FuzzNames(!isValidChar, charType, numOfRepeat))
                {
                    XslCompiledTransform transf = new XslCompiledTransform(enableDebug);

                    try
                    {
                        using (XmlReader r = XmlReader.Create(new StringReader(String.Format(createElementsXsltInline, name)))) transf.Load(r);
                        Assert.True(isValidChar);
                    }
                    catch (Exception)
                    {
                        if (isValidChar)
                        {
                            throw;
                        }
                        else
                        {
                            continue;  //exception expected -> continue
                        }
                    }

                    // if loading of the stylesheet passed, then we should be able to provide
                    StringBuilder sb = new StringBuilder();
                    using (XmlReader r = XmlReader.Create(new StringReader("<root/>"))) transf.Transform(r, null, new StringWriter(sb));
                    // TODO: verification for valid case
                }
            }
            return;
        }
示例#5
0
        private int v3()
        {
            var param = (int)CurVariation.Param;

            for (int i = 0; i <= 0xFFFF; i++)
            {
                char c = Convert.ToChar(i);

                string actName    = String.Format("abc{0}", c);
                string expName    = null;
                bool   bException = false;

                try
                {
                    switch (param)
                    {
                    case 1:
                        expName = XmlConvert.VerifyNMTOKEN(actName);
                        break;

                    case 2:
                        expName = XmlConvert.VerifyName(actName);
                        break;

                    case 3:
                        expName = XmlConvert.VerifyNCName(actName);
                        break;

                    case 5:
                        expName = XmlConvert.VerifyXmlChars(actName);
                        break;

                    case 6:
                        expName = XmlConvert.VerifyPublicId(actName);
                        break;

                    case 7:
                        expName = XmlConvert.VerifyWhitespace(actName);
                        break;
                    }
                }
                catch (XmlException)
                {
                    bException = true;
                }

                bool bIsValid = false;
                switch (param)
                {
                case 1:
                    bIsValid = UnicodeCharHelper.IsW3C_NameChar(c);
                    break;

                case 2:
                    bIsValid = UnicodeCharHelper.IsW3C_NameChar(c);
                    break;

                case 3:
                    bIsValid = UnicodeCharHelper.IsW3C_NCNameChar(c);
                    break;

                case 4:
                    bIsValid = !(UnicodeCharHelper.IsW3C_WhitespaceChar(c));
                    break;

                case 5:
                    bIsValid = UnicodeCharHelper.IsW3C_XmlChar(c);
                    break;

                case 6:
                    bIsValid = UnicodeCharHelper.IsW3C_PubidChar(c);
                    break;

                case 7:
                    bIsValid = false;
                    break;     //always false - other characters are not whitespaces
                }
                if (bIsValid)
                {
                    CError.Compare(expName, actName, "Name");
                }
                else
                {
                    CError.Compare(bException, string.Format("Exception expected for char: 0x{0:x}", (int)c));
                }
            }
            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());
        }