PageRenderTime 42ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
D | 123 lines | 92 code | 26 blank | 5 comment | 14 complexity | 6b5d52145d66d4ff18d0a143025bfcbb MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. module char_strings_runme;
  2. import std.conv;
  3. import std.exception;
  4. import std.range;
  5. import char_strings.char_strings;
  6. enum CPLUSPLUS_MSG = "A message from the deep dark world of C++, where anything is possible.";
  7. enum OTHERLAND_MSG = "Little message from the safe world.";
  8. enum TEST_RANGE = iota(0, 10000);
  9. void main() {
  10. // get functions
  11. foreach (i; TEST_RANGE) {
  12. enforce(GetCharHeapString() == CPLUSPLUS_MSG, "Test char get 1 failed, iteration " ~ to!string(i));
  13. DeleteCharHeapString();
  14. }
  15. foreach (i; TEST_RANGE) {
  16. enforce(GetConstCharProgramCodeString() == CPLUSPLUS_MSG, "Test char get 2 failed, iteration " ~ to!string(i));
  17. DeleteCharHeapString();
  18. }
  19. foreach (i; TEST_RANGE) {
  20. enforce(GetCharStaticString() == CPLUSPLUS_MSG, "Test char get 3 failed, iteration " ~ to!string(i));
  21. }
  22. foreach (i; TEST_RANGE) {
  23. enforce(GetCharStaticStringFixed() == CPLUSPLUS_MSG, "Test char get 4 failed, iteration " ~ to!string(i));
  24. }
  25. foreach (i; TEST_RANGE) {
  26. enforce(GetConstCharStaticStringFixed() == CPLUSPLUS_MSG, "Test char get 5 failed, iteration " ~ to!string(i));
  27. }
  28. // set functions
  29. foreach (i; TEST_RANGE) {
  30. enforce(SetCharHeapString(OTHERLAND_MSG ~ to!string(i), i), "Test char set 1 failed, iteration " ~ to!string(i));
  31. }
  32. foreach (i; TEST_RANGE) {
  33. enforce(SetCharStaticString(OTHERLAND_MSG ~ to!string(i), i), "Test char set 2 failed, iteration " ~ to!string(i));
  34. }
  35. foreach (i; TEST_RANGE) {
  36. enforce(SetCharArrayStaticString(OTHERLAND_MSG ~ to!string(i), i), "Test char set 3 failed, iteration " ~ to!string(i));
  37. }
  38. foreach (i; TEST_RANGE) {
  39. enforce(SetConstCharHeapString(OTHERLAND_MSG ~ to!string(i), i), "Test char set 4 failed, iteration " ~ to!string(i));
  40. }
  41. foreach (i; TEST_RANGE) {
  42. enforce(SetConstCharStaticString(OTHERLAND_MSG ~ to!string(i), i), "Test char set 5 failed, iteration " ~ to!string(i));
  43. }
  44. foreach (i; TEST_RANGE) {
  45. enforce(SetConstCharArrayStaticString(OTHERLAND_MSG ~ to!string(i), i), "Test char set 6 failed, iteration " ~ to!string(i));
  46. }
  47. foreach (i; TEST_RANGE) {
  48. enforce(SetCharConstStaticString(OTHERLAND_MSG ~ to!string(i), i), "Test char set 7 failed, iteration " ~ to!string(i));
  49. }
  50. foreach (i; TEST_RANGE) {
  51. enforce(SetConstCharConstStaticString(OTHERLAND_MSG ~ to!string(i), i), "Test char set 8 failed, iteration " ~ to!string(i));
  52. }
  53. // get set function
  54. foreach (i; TEST_RANGE) {
  55. string ping = OTHERLAND_MSG ~ to!string(i);
  56. string pong = CharPingPong(ping);
  57. enforce(ping == pong, "Test PingPong 1 failed.\nExpected:" ~ ping ~ "\nReceived:" ~ pong);
  58. }
  59. // variables
  60. foreach (i; TEST_RANGE) {
  61. const msg = OTHERLAND_MSG ~ to!string(i);
  62. global_char = msg;
  63. enforce(global_char == msg, "Test variables 1 failed, iteration " ~ to!string(i));
  64. }
  65. foreach (i; TEST_RANGE) {
  66. const msg = OTHERLAND_MSG ~ to!string(i);
  67. global_char_array1 = msg;
  68. enforce(global_char_array1 == msg, "Test variables 2 failed, iteration " ~ to!string(i));
  69. }
  70. foreach (i; TEST_RANGE) {
  71. const msg = OTHERLAND_MSG ~ to!string(i);
  72. global_char_array2 = msg;
  73. enforce(global_char_array2 == msg, "Test variables 2 failed, iteration " ~ to!string(i));
  74. }
  75. foreach (i; TEST_RANGE) {
  76. enforce(global_const_char == CPLUSPLUS_MSG, "Test variables 4 failed, iteration " ~ to!string(i));
  77. }
  78. foreach (i; TEST_RANGE) {
  79. enforce(global_const_char_array1 == CPLUSPLUS_MSG, "Test variables 5 failed, iteration " ~ to!string(i));
  80. }
  81. foreach (i; TEST_RANGE) {
  82. enforce(global_const_char_array2 == CPLUSPLUS_MSG, "Test variables 6 failed, iteration " ~ to!string(i));
  83. }
  84. // char *& tests
  85. foreach (i; TEST_RANGE) {
  86. enforce(GetCharPointerRef() == CPLUSPLUS_MSG, "Test char pointer ref get failed, iteration " ~ to!string(i));
  87. }
  88. foreach (i; TEST_RANGE) {
  89. enforce(SetCharPointerRef(OTHERLAND_MSG ~ to!string(i), i), "Test char pointer ref set failed, iteration " ~ to!string(i));
  90. }
  91. foreach (i; TEST_RANGE) {
  92. enforce(GetConstCharPointerRef() == CPLUSPLUS_MSG, "Test const char pointer ref get failed, iteration " ~ to!string(i));
  93. }
  94. foreach (i; TEST_RANGE) {
  95. enforce(SetConstCharPointerRef(OTHERLAND_MSG ~ to!string(i), i), "Test const char pointer ref set failed, iteration " ~ to!string(i));
  96. }
  97. }