PageRenderTime 16ms CodeModel.GetById 1ms app.highlight 13ms 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
  1module char_strings_runme;
  2
  3import tango.text.convert.Integer;
  4import char_strings.char_strings;
  5
  6const char[] CPLUSPLUS_MSG = "A message from the deep dark world of C++, where anything is possible.";
  7const char[] OTHERLAND_MSG = "Little message from the safe world.";
  8
  9void main() {
 10  const uint count = 10000;
 11  uint i = 0;
 12
 13  // get functions
 14  for (i=0; i<count; i++) {
 15    char[] str = GetCharHeapString();
 16    if (str != CPLUSPLUS_MSG)
 17      throw new Exception("Test char get 1 failed, iteration " ~ toString(i));
 18    DeleteCharHeapString();
 19  }
 20
 21  for (i=0; i<count; i++) {
 22    char[] str = GetConstCharProgramCodeString();
 23    if (str != CPLUSPLUS_MSG)
 24      throw new Exception("Test char get 2 failed, iteration " ~ toString(i));
 25    DeleteCharHeapString();
 26  }
 27
 28  for (i=0; i<count; i++) {
 29    char[] str = GetCharStaticString();
 30    if (str != CPLUSPLUS_MSG)
 31      throw new Exception("Test char get 3 failed, iteration " ~ toString(i));
 32  }
 33
 34  for (i=0; i<count; i++) {
 35    char[] str = GetCharStaticStringFixed();
 36    if (str != CPLUSPLUS_MSG)
 37      throw new Exception("Test char get 4 failed, iteration " ~ toString(i));
 38  }
 39
 40  for (i=0; i<count; i++) {
 41    char[] str = GetConstCharStaticStringFixed();
 42    if (str != CPLUSPLUS_MSG)
 43      throw new Exception("Test char get 5 failed, iteration " ~ toString(i));
 44  }
 45
 46  // set functions
 47  for (i=0; i<count; i++) {
 48    if (!SetCharHeapString(OTHERLAND_MSG ~ toString(i), i))
 49      throw new Exception("Test char set 1 failed, iteration " ~ toString(i));
 50  }
 51
 52  for (i=0; i<count; i++) {
 53    if (!SetCharStaticString(OTHERLAND_MSG ~ toString(i), i))
 54      throw new Exception("Test char set 2 failed, iteration " ~ toString(i));
 55  }
 56
 57  for (i=0; i<count; i++) {
 58    if (!SetCharArrayStaticString(OTHERLAND_MSG ~ toString(i), i))
 59      throw new Exception("Test char set 3 failed, iteration " ~ toString(i));
 60  }
 61
 62  for (i=0; i<count; i++) {
 63    if (!SetConstCharHeapString(OTHERLAND_MSG ~ toString(i), i))
 64      throw new Exception("Test char set 4 failed, iteration " ~ toString(i));
 65  }
 66
 67  for (i=0; i<count; i++) {
 68    if (!SetConstCharStaticString(OTHERLAND_MSG ~ toString(i), i))
 69      throw new Exception("Test char set 5 failed, iteration " ~ toString(i));
 70  }
 71
 72  for (i=0; i<count; i++) {
 73    if (!SetConstCharArrayStaticString(OTHERLAND_MSG ~ toString(i), i))
 74      throw new Exception("Test char set 6 failed, iteration " ~ toString(i));
 75  }
 76
 77  for (i=0; i<count; i++) {
 78    if (!SetCharConstStaticString(OTHERLAND_MSG ~ toString(i), i))
 79      throw new Exception("Test char set 7 failed, iteration " ~ toString(i));
 80  }
 81
 82  for (i=0; i<count; i++) {
 83    if (!SetConstCharConstStaticString(OTHERLAND_MSG ~ toString(i), i))
 84      throw new Exception("Test char set 8 failed, iteration " ~ toString(i));
 85  }
 86
 87  // get set function
 88  for (i=0; i<count*10; i++) {
 89    char[] ping = OTHERLAND_MSG ~ toString(i);
 90    char[] pong = CharPingPong(ping);
 91    if (ping != pong)
 92      throw new Exception("Test PingPong 1 failed.\nExpected:" ~ ping ~ "\nReceived:" ~ pong);
 93  }
 94
 95  // variables
 96  for (i=0; i<count; i++) {
 97    global_char = OTHERLAND_MSG ~ toString(i);
 98    if (global_char != OTHERLAND_MSG ~ toString(i))
 99      throw new Exception("Test variables 1 failed, iteration " ~ toString(i));
100  }
101
102  for (i=0; i<count; i++) {
103    global_char_array1 = OTHERLAND_MSG ~ toString(i);
104    if (global_char_array1 != OTHERLAND_MSG ~ toString(i))
105      throw new Exception("Test variables 2 failed, iteration " ~ toString(i));
106  }
107
108  for (i=0; i<count; i++) {
109    global_char_array2 = OTHERLAND_MSG ~ toString(i);
110    if (global_char_array2 != OTHERLAND_MSG ~ toString(i))
111      throw new Exception("Test variables 3 failed, iteration " ~ toString(i));
112  }
113
114  for (i=0; i<count; i++) {
115    if (global_const_char != CPLUSPLUS_MSG)
116      throw new Exception("Test variables 4 failed, iteration " ~ toString(i));
117  }
118
119  for (i=0; i<count; i++) {
120    if (global_const_char_array1 != CPLUSPLUS_MSG)
121      throw new Exception("Test variables 5 failed, iteration " ~ toString(i));
122  }
123
124  for (i=0; i<count; i++) {
125    if (global_const_char_array2 != CPLUSPLUS_MSG)
126      throw new Exception("Test variables 6 failed, iteration " ~ toString(i));
127  }
128
129  // char *& tests
130  for (i=0; i<count; i++) {
131    char[] str = GetCharPointerRef();
132    if (str != CPLUSPLUS_MSG)
133      throw new Exception("Test char pointer ref get failed, iteration " ~ toString(i));
134  }
135
136  for (i=0; i<count; i++) {
137    if (!SetCharPointerRef(OTHERLAND_MSG ~ toString(i), i))
138      throw new Exception("Test char pointer ref set failed, iteration " ~ toString(i));
139  }
140
141  for (i=0; i<count; i++) {
142    char[] str = GetConstCharPointerRef();
143    if (str != CPLUSPLUS_MSG)
144      throw new Exception("Test const char pointer ref get failed, iteration " ~ toString(i));
145  }
146
147  for (i=0; i<count; i++) {
148    if (!SetConstCharPointerRef(OTHERLAND_MSG ~ toString(i), i))
149      throw new Exception("Test const char pointer ref set failed, iteration " ~ toString(i));
150  }
151}