genstrings.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // Authors:
  2. // Rafael Mizrahi <[email protected]>
  3. // Erez Lotan <[email protected]>
  4. // Oren Gurfinkel <[email protected]>
  5. // Ofer Borstein
  6. //
  7. // Copyright (c) 2004 Mainsoft Co.
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. using System;
  29. using System.IO;
  30. using System.Globalization;
  31. using System.Text;
  32. using System.Collections;
  33. using Microsoft.VisualBasic;
  34. namespace GenStrings
  35. {
  36. public class IntlStrings
  37. {
  38. //Random generator used to generate the random numbers.
  39. private Random rand;
  40. //*-------------------------------------------------------------------------------------------------
  41. // Name : IntlStrings ( constructor )
  42. // Purpose : Creates a random genrator and loads the default resources.
  43. //*-------------------------------------------------------------------------------------------------
  44. public IntlStrings()
  45. {
  46. //Create a random object.
  47. rand = new Random(10);//'cint(DateTime.Now.Ticks));
  48. }
  49. public IntlStrings(long lSeed):this(){}
  50. //*--------------------------------------------------------------------------------------------------
  51. // Name : GetRandString
  52. // Purpose : Generates a string composed of valid characters for the current locale ID.
  53. // String is retrieved from TEXT block in the resouce file.
  54. // Inputs : iMaxChar -- int maximum number of unicode character to be generated.
  55. // : bAbsolute -- if set true, exact number (iMaxChar) will be generated,
  56. // if set false, number of generated chars will be random.
  57. // : bValidate -- boolean, if true, verify generated characters are valid
  58. // if false, does not verify generated characters
  59. // Outputs : Random generated string
  60. //*--------------------------------------------------------------------------------------------------
  61. public string GetString(int iMaxChar, bool bAbsolute, bool bValidate, bool bNoLeadNum)
  62. {
  63. string strTemp ;
  64. if ( iMaxChar <= 0 ) // If the string length is zero, return an empty string
  65. {
  66. return String.Empty;
  67. }
  68. //'If (Not bAbsolute ) Then
  69. //' iMaxChar = rand.Next( 1 , iMaxChar )
  70. //'End If
  71. strTemp = GetString(iMaxChar, true, true);
  72. //Include all the intestring characters.
  73. //rafi strTemp = InsertInterestingChars( strTemp );
  74. return strTemp;
  75. }
  76. public string GetString(int iMaxChar, bool bAbsolute, bool bValidate)
  77. {
  78. int idx;
  79. char[] chr_arr = new char[iMaxChar] ;
  80. for (idx = 0 ;idx < iMaxChar ;idx++) //'GetString must return exact size of iMaxChar
  81. { //genstring must be random, otherwise ,if generated strings will be repeated, tests will fail.
  82. chr_arr[idx] = System.Convert.ToChar(64 + (System.DateTime.Now.Ticks + idx) % 60) ;
  83. }
  84. //'return strBuffer
  85. return new string(chr_arr);
  86. }
  87. }
  88. }