/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
1module char_strings_runme; 2 3import std.conv; 4import std.exception; 5import std.range; 6import char_strings.char_strings; 7 8enum CPLUSPLUS_MSG = "A message from the deep dark world of C++, where anything is possible."; 9enum OTHERLAND_MSG = "Little message from the safe world."; 10enum TEST_RANGE = iota(0, 10000); 11 12void main() { 13 // get functions 14 foreach (i; TEST_RANGE) { 15 enforce(GetCharHeapString() == CPLUSPLUS_MSG, "Test char get 1 failed, iteration " ~ to!string(i)); 16 DeleteCharHeapString(); 17 } 18 19 foreach (i; TEST_RANGE) { 20 enforce(GetConstCharProgramCodeString() == CPLUSPLUS_MSG, "Test char get 2 failed, iteration " ~ to!string(i)); 21 DeleteCharHeapString(); 22 } 23 24 foreach (i; TEST_RANGE) { 25 enforce(GetCharStaticString() == CPLUSPLUS_MSG, "Test char get 3 failed, iteration " ~ to!string(i)); 26 } 27 28 foreach (i; TEST_RANGE) { 29 enforce(GetCharStaticStringFixed() == CPLUSPLUS_MSG, "Test char get 4 failed, iteration " ~ to!string(i)); 30 } 31 32 foreach (i; TEST_RANGE) { 33 enforce(GetConstCharStaticStringFixed() == CPLUSPLUS_MSG, "Test char get 5 failed, iteration " ~ to!string(i)); 34 } 35 36 // set functions 37 foreach (i; TEST_RANGE) { 38 enforce(SetCharHeapString(OTHERLAND_MSG ~ to!string(i), i), "Test char set 1 failed, iteration " ~ to!string(i)); 39 } 40 41 foreach (i; TEST_RANGE) { 42 enforce(SetCharStaticString(OTHERLAND_MSG ~ to!string(i), i), "Test char set 2 failed, iteration " ~ to!string(i)); 43 } 44 45 foreach (i; TEST_RANGE) { 46 enforce(SetCharArrayStaticString(OTHERLAND_MSG ~ to!string(i), i), "Test char set 3 failed, iteration " ~ to!string(i)); 47 } 48 49 foreach (i; TEST_RANGE) { 50 enforce(SetConstCharHeapString(OTHERLAND_MSG ~ to!string(i), i), "Test char set 4 failed, iteration " ~ to!string(i)); 51 } 52 53 foreach (i; TEST_RANGE) { 54 enforce(SetConstCharStaticString(OTHERLAND_MSG ~ to!string(i), i), "Test char set 5 failed, iteration " ~ to!string(i)); 55 } 56 57 foreach (i; TEST_RANGE) { 58 enforce(SetConstCharArrayStaticString(OTHERLAND_MSG ~ to!string(i), i), "Test char set 6 failed, iteration " ~ to!string(i)); 59 } 60 61 foreach (i; TEST_RANGE) { 62 enforce(SetCharConstStaticString(OTHERLAND_MSG ~ to!string(i), i), "Test char set 7 failed, iteration " ~ to!string(i)); 63 } 64 65 foreach (i; TEST_RANGE) { 66 enforce(SetConstCharConstStaticString(OTHERLAND_MSG ~ to!string(i), i), "Test char set 8 failed, iteration " ~ to!string(i)); 67 } 68 69 // get set function 70 foreach (i; TEST_RANGE) { 71 string ping = OTHERLAND_MSG ~ to!string(i); 72 string pong = CharPingPong(ping); 73 enforce(ping == pong, "Test PingPong 1 failed.\nExpected:" ~ ping ~ "\nReceived:" ~ pong); 74 } 75 76 // variables 77 foreach (i; TEST_RANGE) { 78 const msg = OTHERLAND_MSG ~ to!string(i); 79 global_char = msg; 80 enforce(global_char == msg, "Test variables 1 failed, iteration " ~ to!string(i)); 81 } 82 83 foreach (i; TEST_RANGE) { 84 const msg = OTHERLAND_MSG ~ to!string(i); 85 global_char_array1 = msg; 86 enforce(global_char_array1 == msg, "Test variables 2 failed, iteration " ~ to!string(i)); 87 } 88 89 foreach (i; TEST_RANGE) { 90 const msg = OTHERLAND_MSG ~ to!string(i); 91 global_char_array2 = msg; 92 enforce(global_char_array2 == msg, "Test variables 2 failed, iteration " ~ to!string(i)); 93 } 94 95 foreach (i; TEST_RANGE) { 96 enforce(global_const_char == CPLUSPLUS_MSG, "Test variables 4 failed, iteration " ~ to!string(i)); 97 } 98 99 foreach (i; TEST_RANGE) { 100 enforce(global_const_char_array1 == CPLUSPLUS_MSG, "Test variables 5 failed, iteration " ~ to!string(i)); 101 } 102 103 foreach (i; TEST_RANGE) { 104 enforce(global_const_char_array2 == CPLUSPLUS_MSG, "Test variables 6 failed, iteration " ~ to!string(i)); 105 } 106 107 // char *& tests 108 foreach (i; TEST_RANGE) { 109 enforce(GetCharPointerRef() == CPLUSPLUS_MSG, "Test char pointer ref get failed, iteration " ~ to!string(i)); 110 } 111 112 foreach (i; TEST_RANGE) { 113 enforce(SetCharPointerRef(OTHERLAND_MSG ~ to!string(i), i), "Test char pointer ref set failed, iteration " ~ to!string(i)); 114 } 115 116 foreach (i; TEST_RANGE) { 117 enforce(GetConstCharPointerRef() == CPLUSPLUS_MSG, "Test const char pointer ref get failed, iteration " ~ to!string(i)); 118 } 119 120 foreach (i; TEST_RANGE) { 121 enforce(SetConstCharPointerRef(OTHERLAND_MSG ~ to!string(i), i), "Test const char pointer ref set failed, iteration " ~ to!string(i)); 122 } 123}