Example #1
0
        private static void CacheProperties()
        {
            if (null == cachedProperties)
            {
                cachedProperties = new StringProperties();
            }

            cachedProperties.UnicodeRanges.Clear();
            if (0 != properties.UnicodeRanges.Count)
            {
                foreach (UnicodeRange range in properties.UnicodeRanges)
                {
                    cachedProperties.UnicodeRanges.Add(range);
                }
            }

            cachedProperties.HasNumbers                            = properties.HasNumbers;
            cachedProperties.IsBidirectional                       = properties.IsBidirectional;
            cachedProperties.NormalizationForm                     = properties.NormalizationForm;
            cachedProperties.MinNumberOfCombiningMarks             = properties.MinNumberOfCombiningMarks;
            cachedProperties.MinNumberOfCodePoints                 = properties.MinNumberOfCodePoints;
            cachedProperties.MaxNumberOfCodePoints                 = properties.MaxNumberOfCodePoints;
            cachedProperties.MinNumberOfEndUserDefinedCodePoints   = properties.MinNumberOfEndUserDefinedCodePoints;
            cachedProperties.MinNumberOfLineBreaks                 = properties.MinNumberOfLineBreaks;
            cachedProperties.MinNumberOfSurrogatePairs             = properties.MinNumberOfSurrogatePairs;
            cachedProperties.MinNumberOfTextSegmentationCodePoints = properties.MinNumberOfTextSegmentationCodePoints;
        }
Example #2
0
 /// <summary>
 /// Create property objects according to string properties
 /// </summary>
 public PropertyFactory(StringProperties properties, UnicodeRangeDatabase unicodeDb, UnicodeRange expectedRange)
 {
     bidiProperty              = null;
     combiningMarksProperty    = null;
     eudcProperty              = null;
     lineBreakProperty         = null;
     numberProperty            = null;
     surrogatePairProperty     = null;
     textNormalizationProperty = null;
     textSegmentationProperty  = null;
     minNumOfCodePoint         = 0;
     propertyDictionary        = new Dictionary <PropertyFactory.PropertyName, IStringProperty>();
     CreateProperties(properties, unicodeDb, expectedRange);
 }
Example #3
0
        private static void CacheProperties()
        {
            if (null == cachedProperties)
            {
                cachedProperties = new StringProperties();
            }

            if (null != properties.UnicodeRange)
            {
                cachedProperties.UnicodeRange = new UnicodeRange(properties.UnicodeRange.StartOfUnicodeRange, properties.UnicodeRange.EndOfUnicodeRange);
            }

            cachedProperties.HasNumbers                            = properties.HasNumbers;
            cachedProperties.IsBidirectional                       = properties.IsBidirectional;
            cachedProperties.NormalizationForm                     = properties.NormalizationForm;
            cachedProperties.MinNumberOfCombiningMarks             = properties.MinNumberOfCombiningMarks;
            cachedProperties.MinNumberOfCodePoints                 = properties.MinNumberOfCodePoints;
            cachedProperties.MaxNumberOfCodePoints                 = properties.MaxNumberOfCodePoints;
            cachedProperties.MinNumberOfEndUserDefinedCodePoints   = properties.MinNumberOfEndUserDefinedCodePoints;
            cachedProperties.MinNumberOfLineBreaks                 = properties.MinNumberOfLineBreaks;
            cachedProperties.MinNumberOfSurrogatePairs             = properties.MinNumberOfSurrogatePairs;
            cachedProperties.MinNumberOfTextSegmentationCodePoints = properties.MinNumberOfTextSegmentationCodePoints;
        }
Example #4
0
        /// <summary>
        /// Returns a string, conforming to the <see cref="StringProperties"/> provided.
        /// </summary>
        /// <param name="stringProperties">The properties of the strings to be generated by the factory.</param>
        /// <param name="seed">The random number generator seed.</param>
        /// <returns>A string, conforming to the previously specified properties.</returns>
        public static string GenerateRandomString(StringProperties stringProperties, int seed)
        {
            if (null == properties || IsPropertyChanged(stringProperties))
            {
                properties = stringProperties;
                // Make a deep copy of stringProperties to cache it. If user changes any property and calls this API again,
                // InitializeProperties() is triggered. Otherwise, no need to re initialize properties for optimization.
                CacheProperties();
                InitializeProperties();
            }

            string retStr = string.Empty;
            Random rand   = new Random(seed);

            numOfCodePoints = rand.Next(minNumCodePoints, maxNumCodePoints);

            int numberOfProperties = propertyFactory.PropertyDictionary.Count;

            if (0 == numberOfProperties)
            {
                for (int i = 0; i < numOfCodePoints; i++)
                {
                    retStr += TextUtil.IntToString(GetNextCodePoint(rand, seed));
                }
                return(retStr);
            }

            int quote = numOfCodePoints / propertyFactory.MinNumOfCodePoint;

            if (0 == quote)
            {
                throw new ArgumentOutOfRangeException(
                          "StringFactory, MinNumberOfCodePoints needs to be at least " + numberOfProperties * propertyFactory.MinNumOfCodePoint + ".");
            }

            Dictionary <PropertyFactory.PropertyName, IStringProperty> .KeyCollection keyColl = propertyFactory.PropertyDictionary.Keys;
            foreach (PropertyFactory.PropertyName name in keyColl)
            {
                if (PropertyFactory.PropertyName.Bidi == name)
                {
                    retStr += GenerateBidiString(quote * BidiProperty.MINNUMOFCODEPOINT, seed);
                }
                else if (PropertyFactory.PropertyName.CombiningMarks == name)
                {
                    retStr += GenerateCombiningMarkString(quote * CombiningMarksProperty.MINNUMOFCODEPOINT * (int)properties.MinNumberOfCombiningMarks, seed);
                }
                else if (PropertyFactory.PropertyName.Eudc == name)
                {
                    retStr += GenerateStringWithEudc(quote * EudcProperty.MINNUMOFCODEPOINT * (int)properties.MinNumberOfEndUserDefinedCodePoints, seed);
                }
                else if (PropertyFactory.PropertyName.LineBreak == name)
                {
                    retStr += GenerateStringWithLineBreak(quote * LineBreakProperty.MINNUMOFCODEPOINT * (int)properties.MinNumberOfLineBreaks, seed);
                }
                else if (PropertyFactory.PropertyName.Number == name)
                {
                    retStr += GenerateStringWithNumber(quote * NumberProperty.MINNUMOFCODEPOINT, seed);
                }
                else if (PropertyFactory.PropertyName.Surrogate == name)
                {
                    retStr += GenerateStringWithSurrogatePair(quote * SurrogatePairProperty.MINNUMOFCODEPOINT * (int)properties.MinNumberOfSurrogatePairs, seed);
                }
                else if (PropertyFactory.PropertyName.TextNormalization == name)
                {
                    retStr += GenerateNormalizedString(quote * TextNormalizationProperty.MINNUMOFCODEPOINT, seed);
                }
                else if (PropertyFactory.PropertyName.TextSegmentation == name)
                {
                    retStr += GenerateStringWithSegmentation(
                        quote * TextSegmentationProperty.MINNUMOFCODEPOINT * (int)properties.MinNumberOfTextSegmentationCodePoints,
                        seed);
                }
            }

            if (numOfCodePoints > 0)
            {
                for (int i = 0; i < numOfCodePoints; i++)
                {
                    retStr += TextUtil.IntToString(GetNextCodePoint(rand, seed));
                }
            }

            if (null != properties.NormalizationForm)
            {
                retStr = retStr.Normalize((NormalizationForm)properties.NormalizationForm);
            }

            return(retStr);
        }
Example #5
0
        private static bool IsPropertyChanged(StringProperties stringProperties)
        {
            if ((0 == cachedProperties.UnicodeRanges.Count && 0 != stringProperties.UnicodeRanges.Count) ||
                (0 != cachedProperties.UnicodeRanges.Count && 0 == stringProperties.UnicodeRanges.Count))
            {
                return(true);
            }
            else if (0 != cachedProperties.UnicodeRanges.Count && 0 != stringProperties.UnicodeRanges.Count)
            {
                if (cachedProperties.UnicodeRanges.Count != stringProperties.UnicodeRanges.Count)
                {
                    return(true);
                }

                int i = 0;
                foreach (UnicodeRange range in cachedProperties.UnicodeRanges)
                {
                    if (range.StartOfUnicodeRange != stringProperties.UnicodeRanges[i].StartOfUnicodeRange)
                    {
                        return(true);
                    }

                    if (range.EndOfUnicodeRange != stringProperties.UnicodeRanges[i++].EndOfUnicodeRange)
                    {
                        return(true);
                    }
                }
            }

            if (cachedProperties.HasNumbers != stringProperties.HasNumbers)
            {
                return(true);
            }

            if (cachedProperties.IsBidirectional != stringProperties.IsBidirectional)
            {
                return(true);
            }

            if (cachedProperties.NormalizationForm != stringProperties.NormalizationForm)
            {
                return(true);
            }

            if (cachedProperties.MinNumberOfCombiningMarks != stringProperties.MinNumberOfCombiningMarks)
            {
                return(true);
            }

            if (cachedProperties.MinNumberOfCodePoints != stringProperties.MinNumberOfCodePoints)
            {
                return(true);
            }

            if (cachedProperties.MaxNumberOfCodePoints != stringProperties.MaxNumberOfCodePoints)
            {
                return(true);
            }

            if (cachedProperties.MinNumberOfEndUserDefinedCodePoints != stringProperties.MinNumberOfEndUserDefinedCodePoints)
            {
                return(true);
            }

            if (cachedProperties.MinNumberOfLineBreaks != stringProperties.MinNumberOfLineBreaks)
            {
                return(true);
            }

            if (cachedProperties.MinNumberOfSurrogatePairs != stringProperties.MinNumberOfSurrogatePairs)
            {
                return(true);
            }

            if (cachedProperties.MinNumberOfTextSegmentationCodePoints != stringProperties.MinNumberOfTextSegmentationCodePoints)
            {
                return(true);
            }

            return(false);
        }
Example #6
0
 /// <summary>
 /// Returns an array of predefined strings, interesting from a text testing point of view, with the specified properties.
 /// <font color="red">NOT IMPLEMENTED.</font>
 /// </summary>
 /// <param name="stringProperties">The properties of the generated string.</param>
 /// <returns>An array of predefined strings with the specified properties.</returns>
 public static string[] GetPredefinedStrings(StringProperties stringProperties)
 {
     throw new NotImplementedException();
 }
Example #7
0
 /// <summary>
 /// Generates a random string, with the specified properties.
 /// <font color="red">NOT IMPLEMENTED.</font>
 /// </summary>
 /// <param name="stringProperties">The properties of the generated string.</param>
 /// <param name="seed">A number used to calculate a starting value for the pseudo-random number sequence. If a negative number is specified, the absolute value of the number is used.</param>
 /// <returns>A random string with the specified properties.</returns>
 public static string GenerateRandomString(StringProperties stringProperties, int seed)
 {
     throw new NotImplementedException();
 }
Example #8
0
        private void CreateProperties(StringProperties properties, UnicodeRangeDatabase unicodeDb, UnicodeRange expectedRange)
        {
            if (null != properties.HasNumbers)
            {
                if ((bool)properties.HasNumbers)
                {
                    numberProperty     = new NumberProperty(unicodeDb, expectedRange);
                    minNumOfCodePoint += NumberProperty.MINNUMOFCODEPOINT;
                    propertyDictionary.Add(PropertyName.Number, numberProperty);
                }
            }

            if (null != properties.IsBidirectional)
            {
                if ((bool)properties.IsBidirectional)
                {
                    bidiProperty       = new BidiProperty(unicodeDb, expectedRange);
                    minNumOfCodePoint += BidiProperty.MINNUMOFCODEPOINT;
                    propertyDictionary.Add(PropertyName.Bidi, bidiProperty);
                }
            }

            if (null != properties.NormalizationForm)
            {
                textNormalizationProperty = new TextNormalizationProperty(unicodeDb, expectedRange);
                minNumOfCodePoint        += TextNormalizationProperty.MINNUMOFCODEPOINT;
                propertyDictionary.Add(PropertyName.TextNormalization, textNormalizationProperty);
            }

            if (null != properties.MinNumberOfCombiningMarks)
            {
                if (0 != properties.MinNumberOfCombiningMarks)
                {
                    combiningMarksProperty = new CombiningMarksProperty(unicodeDb, expectedRange);
                    minNumOfCodePoint     += CombiningMarksProperty.MINNUMOFCODEPOINT * (int)properties.MinNumberOfCombiningMarks;
                    propertyDictionary.Add(PropertyName.CombiningMarks, combiningMarksProperty);
                }
            }

            if (null != properties.MinNumberOfEndUserDefinedCodePoints)
            {
                if (0 != properties.MinNumberOfEndUserDefinedCodePoints)
                {
                    eudcProperty       = new EudcProperty(unicodeDb, expectedRange);
                    minNumOfCodePoint += EudcProperty.MINNUMOFCODEPOINT * (int)properties.MinNumberOfEndUserDefinedCodePoints;
                    propertyDictionary.Add(PropertyName.Eudc, eudcProperty);
                }
            }

            if (null != properties.MinNumberOfLineBreaks)
            {
                if (0 != properties.MinNumberOfLineBreaks)
                {
                    lineBreakProperty  = new LineBreakProperty(expectedRange);
                    minNumOfCodePoint += LineBreakProperty.MINNUMOFCODEPOINT * (int)properties.MinNumberOfLineBreaks;
                    propertyDictionary.Add(PropertyName.LineBreak, lineBreakProperty);
                }
            }

            if (null != properties.MinNumberOfSurrogatePairs)
            {
                if (0 != properties.MinNumberOfSurrogatePairs)
                {
                    surrogatePairProperty = new SurrogatePairProperty(unicodeDb, expectedRange);
                    minNumOfCodePoint    += SurrogatePairProperty.MINNUMOFCODEPOINT * (int)properties.MinNumberOfSurrogatePairs;
                    propertyDictionary.Add(PropertyName.Surrogate, surrogatePairProperty);
                }
            }

            if (null != properties.MinNumberOfTextSegmentationCodePoints)
            {
                if (0 != properties.MinNumberOfTextSegmentationCodePoints)
                {
                    textSegmentationProperty = new TextSegmentationProperty(unicodeDb, expectedRange);
                    minNumOfCodePoint       += TextSegmentationProperty.MINNUMOFCODEPOINT * (int)properties.MinNumberOfTextSegmentationCodePoints;
                    propertyDictionary.Add(PropertyName.TextSegmentation, textSegmentationProperty);
                }
            }
        }
Example #9
0
        private static bool IsPropertyChanged(StringProperties stringProperties)
        {
            if ((null == cachedProperties.UnicodeRange && null != stringProperties.UnicodeRange) ||
                (null != cachedProperties.UnicodeRange && null == stringProperties.UnicodeRange))
            {
                return(true);
            }
            else if (null != cachedProperties.UnicodeRange && null != stringProperties.UnicodeRange)
            {
                if (cachedProperties.UnicodeRange.StartOfUnicodeRange != stringProperties.UnicodeRange.StartOfUnicodeRange)
                {
                    return(true);
                }

                if (cachedProperties.UnicodeRange.EndOfUnicodeRange != stringProperties.UnicodeRange.EndOfUnicodeRange)
                {
                    return(true);
                }
            }

            if (cachedProperties.HasNumbers != stringProperties.HasNumbers)
            {
                return(true);
            }

            if (cachedProperties.IsBidirectional != stringProperties.IsBidirectional)
            {
                return(true);
            }

            if (cachedProperties.NormalizationForm != stringProperties.NormalizationForm)
            {
                return(true);
            }

            if (cachedProperties.MinNumberOfCombiningMarks != stringProperties.MinNumberOfCombiningMarks)
            {
                return(true);
            }

            if (cachedProperties.MinNumberOfCodePoints != stringProperties.MinNumberOfCodePoints)
            {
                return(true);
            }

            if (cachedProperties.MaxNumberOfCodePoints != stringProperties.MaxNumberOfCodePoints)
            {
                return(true);
            }

            if (cachedProperties.MinNumberOfEndUserDefinedCodePoints != stringProperties.MinNumberOfEndUserDefinedCodePoints)
            {
                return(true);
            }

            if (cachedProperties.MinNumberOfLineBreaks != stringProperties.MinNumberOfLineBreaks)
            {
                return(true);
            }

            if (cachedProperties.MinNumberOfSurrogatePairs != stringProperties.MinNumberOfSurrogatePairs)
            {
                return(true);
            }

            if (cachedProperties.MinNumberOfTextSegmentationCodePoints != stringProperties.MinNumberOfTextSegmentationCodePoints)
            {
                return(true);
            }

            return(false);
        }