示例#1
0
        public static string GenerateASCIINameWithInvalidCharacters(int length, char[] InvalidChars = null)
        {
            if (null == InvalidChars)
            {
                InvalidChars = InvalidFileNameCharacters;
            }

            int           numberOfInavlidCharacters = RandomGen.Next(1, length);
            int           numberOfValidCharacters   = length - numberOfInavlidCharacters;
            StringBuilder sb = new StringBuilder(GenerateNameFromRange(numberOfValidCharacters, ValidASCIIRange));
            var           invalidCharList = new List <char>(InvalidFileNameCharacters);

            if (AgentFactory.GetLanguage() == Language.NodeJS)
            {
                invalidCharList.Remove('"');
                invalidCharList.Remove('\'');
            }

            if (AgentFactory.GetOSType() != OSType.Windows)
            {
                // remove bash control characters
                invalidCharList.Remove('(');
                invalidCharList.Remove('$');
            }

            for (int i = 0; i < numberOfInavlidCharacters; i++)
            {
                int  position         = RandomGen.Next(sb.Length);
                char invalidCharacter = invalidCharList[RandomGen.Next(invalidCharList.Count)];
                sb.Insert(position, invalidCharacter);
            }

            return(sb.ToString());
        }
        public void CreateDirectoryWith255Unicodes()
        {
            if (OSType.Windows != AgentFactory.GetOSType())
            {
                return;
            }

            foreach (var dirName in FileNamingGenerator.GenerateValidateUnicodeName(FileNamingGenerator.MaxFileNameLength))
            {
                this.CreateDirectoryInternal(dirName, traceCommand: false);
                CommandAgent.Clear();
            }
        }
示例#3
0
        public static IEnumerable <string> GenerateValidateUnicodeName(UnicodeGenerator[] generators, int length)
        {
            if (AgentFactory.GetOSType() != OSType.Windows)
            {
                yield break;
            }

            foreach (var generator in generators)
            {
                string str = generator.GenerateRandomString(length);

                StringBuilder sb = new StringBuilder();
                foreach (var ch in str)
                {
                    sb.Append("\\u");
                    sb.Append(((int)ch).ToString("x4"));
                }

                Test.Verbose("Generated unicode name by {0}: {1}", generator.GetType().Name, sb.ToString());

                yield return(str);
            }
        }