1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "char_strings/char_strings_wrap.h"
int main() {
char *CPLUSPLUS_MSG = "A message from the deep dark world of C++, where anything is possible.";
char *OTHERLAND_MSG = "Little message from the safe world.";
int count = 10000;
int i = 0;
// get functions
for (i=0; i<count; i++) {
char *str = char_strings_GetCharHeapString();
if (strcmp(str, CPLUSPLUS_MSG) != 0) {
fprintf(stderr, "Test char get 1 failed, iteration %d\n", i);
exit(1);
}
char_strings_DeleteCharHeapString();
}
for (i=0; i<count; i++) {
const char *str = char_strings_GetConstCharProgramCodeString();
if (strcmp(str, CPLUSPLUS_MSG) != 0) {
fprintf(stderr, "Test char get 2 failed, iteration %d\n", i);
exit(1);
}
char_strings_DeleteCharHeapString();
}
for (i=0; i<count; i++) {
char *str = char_strings_GetCharStaticString();
if (strcmp(str, CPLUSPLUS_MSG) != 0) {
fprintf(stderr, "Test char get 3 failed, iteration %d\n", i);
exit(1);
}
}
for (i=0; i<count; i++) {
char *str = char_strings_GetCharStaticStringFixed();
if (strcmp(str, CPLUSPLUS_MSG) != 0) {
fprintf(stderr, "Test char get 4 failed, iteration %d\n", i);
exit(1);
}
}
for (i=0; i<count; i++) {
const char *str = char_strings_GetConstCharStaticStringFixed();
if (strcmp(str, CPLUSPLUS_MSG) != 0) {
fprintf(stderr, "Test char get 5 failed, iteration %d\n", i);
exit(1);
}
}
// set functions
for (i=0; i<count; i++) {
char str[256];
sprintf(str, "%s%d", OTHERLAND_MSG, i);
if (!char_strings_SetCharHeapString(str, i)) {
fprintf(stderr, "Test char set 1 failed, iteration %d\n", i);
exit(1);
}
}
for (i=0; i<count; i++) {
char str[256];
sprintf(str, "%s%d", OTHERLAND_MSG, i);
if (!char_strings_SetCharStaticString(str, i)) {
fprintf(stderr, "Test char set 2 failed, iteration %d\n", i);
exit(1);
}
}
for (i=0; i<count; i++) {
char str[256];
sprintf(str, "%s%d", OTHERLAND_MSG, i);
if (!char_strings_SetCharArrayStaticString(str, i)) {
fprintf(stderr, "Test char set 3 failed, iteration %d\n", i);
exit(1);
}
}
for (i=0; i<count; i++) {
char str[256];
sprintf(str, "%s%d", OTHERLAND_MSG, i);
if (!char_strings_SetConstCharHeapString(str, i)) {
fprintf(stderr, "Test char set 4 failed, iteration %d\n", i);
exit(1);
}
}
for (i=0; i<count; i++) {
char str[256];
sprintf(str, "%s%d", OTHERLAND_MSG, i);
if (!char_strings_SetConstCharStaticString(str, i)) {
fprintf(stderr, "Test char set 5 failed, iteration %d\n", i);
exit(1);
}
}
for (i=0; i<count; i++) {
char str[256];
sprintf(str, "%s%d", OTHERLAND_MSG, i);
if (!char_strings_SetConstCharArrayStaticString(str, i)) {
fprintf(stderr, "Test char set 6 failed, iteration %d\n", i);
exit(1);
}
}
// get set function
for (i=0; i<count; i++) {
char ping[256];
sprintf(ping, "%s%d", OTHERLAND_MSG, i);
char *pong = char_strings_CharPingPong(ping);
if (strcmp(ping, pong) != 0) {
fprintf(stderr, "Test PingPong 1 failed.\nExpected:%s\nReceived:%s\n", ping, pong);
exit(1);
}
}
// variables
for (i=0; i<count; i++) {
char str[256];
sprintf(str, "%s%d", OTHERLAND_MSG, i);
char_strings_global_char_set(str);
if (strcmp(char_strings_global_char_get(), str) != 0) {
fprintf(stderr, "Test variables 1 failed, iteration %d\n", i);
exit(1);
}
}
for (i=0; i<count; i++) {
char str[256];
sprintf(str, "%s%d", OTHERLAND_MSG, i);
sprintf(char_strings_global_char_array1_get(), "%s%d", OTHERLAND_MSG, i);
if (strcmp(char_strings_global_char_array1_get(), str) != 0) {
fprintf(stderr, "Test variables 2 failed, iteration %d\n", i);
exit(1);
}
}
for (i=0; i<count; i++) {
char str[256];
sprintf(str, "%s%d", OTHERLAND_MSG, i);
sprintf(char_strings_global_char_array2_get(), "%s%d", OTHERLAND_MSG, i);
if (strcmp(char_strings_global_char_array2_get(), str) != 0) {
fprintf(stderr, "Test variables 3 failed, iteration %d\n", i);
exit(1);
}
}
for (i=0; i<count; i++) {
if (strcmp(char_strings_global_const_char_get(), CPLUSPLUS_MSG) != 0) {
fprintf(stderr, "Test variables 3 failed, iteration %d\n", i);
exit(1);
}
}
/*
for (i=0; i<count; i++) {
if (strcmp(global_const_char_array1, CPLUSPLUS_MSG) != 0) {
fprintf(stderr, "Test variables 5 failed, iteration %d\n", i);
exit(1);
}
}
for (i=0; i<count; i++) {
if (strcmp(global_const_char_array2, CPLUSPLUS_MSG) != 0) {
fprintf(stderr, "Test variables 6 failed, iteration %d\n", i);
exit(1);
}
}
*/
// char *& tests
for (i=0; i<count; i++) {
const char **str = char_strings_GetConstCharPointerRef();
if (strcmp(*str, CPLUSPLUS_MSG) != 0) {
fprintf(stderr, "Test char pointer ref get failed, iteration %d\n",i);
exit(1);
}
}
for (i=0; i<count; i++) {
char *str = (char*) malloc(sizeof(char) * 256);
sprintf(str, "%s%d", OTHERLAND_MSG, i);
if (!char_strings_SetConstCharPointerRef((const char **)&str, i)) {
fprintf(stderr, "Test char pointer ref set failed, iteration %d\n", i);
exit(1);
}
}
exit(0);
}
|