PageRenderTime 62ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Examples/test-suite/d/char_strings_runme.1.d

#
D | 151 lines | 119 code | 27 blank | 5 comment | 62 complexity | 64189047be8c117f5163163f4bb53eae MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. module char_strings_runme;
  2. import tango.text.convert.Integer;
  3. import char_strings.char_strings;
  4. const char[] CPLUSPLUS_MSG = "A message from the deep dark world of C++, where anything is possible.";
  5. const char[] OTHERLAND_MSG = "Little message from the safe world.";
  6. void main() {
  7. const uint count = 10000;
  8. uint i = 0;
  9. // get functions
  10. for (i=0; i<count; i++) {
  11. char[] str = GetCharHeapString();
  12. if (str != CPLUSPLUS_MSG)
  13. throw new Exception("Test char get 1 failed, iteration " ~ toString(i));
  14. DeleteCharHeapString();
  15. }
  16. for (i=0; i<count; i++) {
  17. char[] str = GetConstCharProgramCodeString();
  18. if (str != CPLUSPLUS_MSG)
  19. throw new Exception("Test char get 2 failed, iteration " ~ toString(i));
  20. DeleteCharHeapString();
  21. }
  22. for (i=0; i<count; i++) {
  23. char[] str = GetCharStaticString();
  24. if (str != CPLUSPLUS_MSG)
  25. throw new Exception("Test char get 3 failed, iteration " ~ toString(i));
  26. }
  27. for (i=0; i<count; i++) {
  28. char[] str = GetCharStaticStringFixed();
  29. if (str != CPLUSPLUS_MSG)
  30. throw new Exception("Test char get 4 failed, iteration " ~ toString(i));
  31. }
  32. for (i=0; i<count; i++) {
  33. char[] str = GetConstCharStaticStringFixed();
  34. if (str != CPLUSPLUS_MSG)
  35. throw new Exception("Test char get 5 failed, iteration " ~ toString(i));
  36. }
  37. // set functions
  38. for (i=0; i<count; i++) {
  39. if (!SetCharHeapString(OTHERLAND_MSG ~ toString(i), i))
  40. throw new Exception("Test char set 1 failed, iteration " ~ toString(i));
  41. }
  42. for (i=0; i<count; i++) {
  43. if (!SetCharStaticString(OTHERLAND_MSG ~ toString(i), i))
  44. throw new Exception("Test char set 2 failed, iteration " ~ toString(i));
  45. }
  46. for (i=0; i<count; i++) {
  47. if (!SetCharArrayStaticString(OTHERLAND_MSG ~ toString(i), i))
  48. throw new Exception("Test char set 3 failed, iteration " ~ toString(i));
  49. }
  50. for (i=0; i<count; i++) {
  51. if (!SetConstCharHeapString(OTHERLAND_MSG ~ toString(i), i))
  52. throw new Exception("Test char set 4 failed, iteration " ~ toString(i));
  53. }
  54. for (i=0; i<count; i++) {
  55. if (!SetConstCharStaticString(OTHERLAND_MSG ~ toString(i), i))
  56. throw new Exception("Test char set 5 failed, iteration " ~ toString(i));
  57. }
  58. for (i=0; i<count; i++) {
  59. if (!SetConstCharArrayStaticString(OTHERLAND_MSG ~ toString(i), i))
  60. throw new Exception("Test char set 6 failed, iteration " ~ toString(i));
  61. }
  62. for (i=0; i<count; i++) {
  63. if (!SetCharConstStaticString(OTHERLAND_MSG ~ toString(i), i))
  64. throw new Exception("Test char set 7 failed, iteration " ~ toString(i));
  65. }
  66. for (i=0; i<count; i++) {
  67. if (!SetConstCharConstStaticString(OTHERLAND_MSG ~ toString(i), i))
  68. throw new Exception("Test char set 8 failed, iteration " ~ toString(i));
  69. }
  70. // get set function
  71. for (i=0; i<count*10; i++) {
  72. char[] ping = OTHERLAND_MSG ~ toString(i);
  73. char[] pong = CharPingPong(ping);
  74. if (ping != pong)
  75. throw new Exception("Test PingPong 1 failed.\nExpected:" ~ ping ~ "\nReceived:" ~ pong);
  76. }
  77. // variables
  78. for (i=0; i<count; i++) {
  79. global_char = OTHERLAND_MSG ~ toString(i);
  80. if (global_char != OTHERLAND_MSG ~ toString(i))
  81. throw new Exception("Test variables 1 failed, iteration " ~ toString(i));
  82. }
  83. for (i=0; i<count; i++) {
  84. global_char_array1 = OTHERLAND_MSG ~ toString(i);
  85. if (global_char_array1 != OTHERLAND_MSG ~ toString(i))
  86. throw new Exception("Test variables 2 failed, iteration " ~ toString(i));
  87. }
  88. for (i=0; i<count; i++) {
  89. global_char_array2 = OTHERLAND_MSG ~ toString(i);
  90. if (global_char_array2 != OTHERLAND_MSG ~ toString(i))
  91. throw new Exception("Test variables 3 failed, iteration " ~ toString(i));
  92. }
  93. for (i=0; i<count; i++) {
  94. if (global_const_char != CPLUSPLUS_MSG)
  95. throw new Exception("Test variables 4 failed, iteration " ~ toString(i));
  96. }
  97. for (i=0; i<count; i++) {
  98. if (global_const_char_array1 != CPLUSPLUS_MSG)
  99. throw new Exception("Test variables 5 failed, iteration " ~ toString(i));
  100. }
  101. for (i=0; i<count; i++) {
  102. if (global_const_char_array2 != CPLUSPLUS_MSG)
  103. throw new Exception("Test variables 6 failed, iteration " ~ toString(i));
  104. }
  105. // char *& tests
  106. for (i=0; i<count; i++) {
  107. char[] str = GetCharPointerRef();
  108. if (str != CPLUSPLUS_MSG)
  109. throw new Exception("Test char pointer ref get failed, iteration " ~ toString(i));
  110. }
  111. for (i=0; i<count; i++) {
  112. if (!SetCharPointerRef(OTHERLAND_MSG ~ toString(i), i))
  113. throw new Exception("Test char pointer ref set failed, iteration " ~ toString(i));
  114. }
  115. for (i=0; i<count; i++) {
  116. char[] str = GetConstCharPointerRef();
  117. if (str != CPLUSPLUS_MSG)
  118. throw new Exception("Test const char pointer ref get failed, iteration " ~ toString(i));
  119. }
  120. for (i=0; i<count; i++) {
  121. if (!SetConstCharPointerRef(OTHERLAND_MSG ~ toString(i), i))
  122. throw new Exception("Test const char pointer ref set failed, iteration " ~ toString(i));
  123. }
  124. }