test_str_compare.c (34085B)
1 /* 2 This file is part of libmicrohttpd 3 Copyright (C) 2016 Karlson2k (Evgeny Grin) 4 5 This test tool is free software; you can redistribute it and/or 6 modify it under the terms of the GNU General Public License as 7 published by the Free Software Foundation; either version 2, or 8 (at your option) any later version. 9 10 This test tool is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 Lesser General Public License for more details. 14 15 You should have received a copy of the GNU Lesser General Public 16 License along with this library; if not, write to the Free Software 17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 */ 19 20 /** 21 * @file microhttpd/unit_str_test.h 22 * @brief Unit tests for mhd_str functions 23 * @author Karlson2k (Evgeny Grin) 24 */ 25 26 #include "mhd_sys_options.h" 27 #include "../mhd2/mhd_str.h" 28 #include "../mhd2/mhd_str.c" 29 #include "../mhdt_checks.h" 30 31 #include <stdio.h> 32 #include <locale.h> 33 #include <string.h> 34 #ifdef HAVE_INTTYPES_H 35 #include <inttypes.h> 36 #else /* ! HAVE_INTTYPES_H */ 37 #define PRIu64 "llu" 38 #define PRIuPTR "u" 39 #define PRIX64 "llX" 40 #endif /* ! HAVE_INTTYPES_H */ 41 #include <stdint.h> 42 #ifdef HAVE_STDLIB_H 43 #include <stdlib.h> 44 #endif /* HAVE_STDLIB_H */ 45 #include "mhd_limits.h" 46 #include "mhd_str.h" 47 #include "test_helpers.h" 48 49 50 static int verbose = 0; /* verbose level (0-3)*/ 51 52 /* Locale names to test. 53 * Functions must not depend of current current locale, 54 * so result must be the same in any locale. 55 */ 56 static const char *const locale_names[] = { 57 "C", 58 "", /* System default locale */ 59 #if defined(_WIN32) && ! defined(__CYGWIN__) 60 ".OCP", /* W32 system default OEM code page */ 61 ".ACP", /* W32 system default ANSI code page */ 62 ".65001", /* UTF-8 */ 63 ".437", 64 ".850", 65 ".857", 66 ".866", 67 ".1250", 68 ".1251", 69 ".1252", 70 "en", 71 "english", 72 "French_France", 73 "Turkish_Turkey.1254", 74 "de", 75 "zh-Hans", 76 "ru-RU.1251" 77 #if 0 /* Disabled extra checks */ 78 , 79 ".1254", 80 ".20866", /* number for KOI8-R */ 81 ".28591", /* number for ISO-8859-1 */ 82 ".28595", /* number for ISO-8859-5 */ 83 ".28599", /* number for ISO-8859-9 */ 84 ".28605", /* number for ISO-8859-15 */ 85 "en-US", 86 "English-US", 87 "en-US.437", 88 "English_United States.437", 89 "en-US.1252", 90 "English_United States.1252", 91 "English_United States.28591", 92 "English_United States.65001", 93 "fra", 94 "french", 95 "fr-FR", 96 "fr-FR.850", 97 "french_france.850", 98 "fr-FR.1252", 99 "French_france.1252", 100 "French_france.28605", 101 "French_France.65001", 102 "de-DE", 103 "de-DE.850", 104 "German_Germany.850", 105 "German_Germany.1250", 106 "de-DE.1252", 107 "German_Germany.1252", 108 "German_Germany.28605", 109 "German_Germany.65001", 110 "tr", 111 "trk", 112 "turkish", 113 "tr-TR", 114 "tr-TR.1254", 115 "tr-TR.857", 116 "Turkish_Turkey.857", 117 "Turkish_Turkey.28599", 118 "Turkish_Turkey.65001", 119 "ru", 120 "ru-RU", 121 "Russian", 122 "ru-RU.866", 123 "Russian_Russia.866", 124 "Russian_Russia.1251", 125 "Russian_Russia.20866", 126 "Russian_Russia.28595", 127 "Russian_Russia.65001", 128 "zh-Hans.936", 129 "chinese-simplified" 130 #endif /* Disabled extra checks */ 131 #else /* ! _WIN32 || __CYGWIN__ */ 132 "C.UTF-8", 133 "POSIX", 134 "en", 135 "en_US", 136 "en_US.ISO-8859-1", 137 "en_US.ISO_8859-1", 138 "en_US.ISO8859-1", 139 "en_US.iso88591", 140 "en_US.ISO-8859-15", 141 "en_US.DIS_8859-15", 142 "en_US.ISO8859-15", 143 "en_US.iso885915", 144 "en_US.1252", 145 "en_US.CP1252", 146 "en_US.UTF-8", 147 "en_US.utf8", 148 "fr", 149 "fr_FR", 150 "fr_FR.850", 151 "fr_FR.IBM850", 152 "fr_FR.1252", 153 "fr_FR.CP1252", 154 "fr_FR.ISO-8859-1", 155 "fr_FR.ISO_8859-1", 156 "fr_FR.ISO8859-1", 157 "fr_FR.iso88591", 158 "fr_FR.ISO-8859-15", 159 "fr_FR.DIS_8859-15", 160 "fr_FR.ISO8859-15", 161 "fr_FR.iso8859-15", 162 "fr_FR.UTF-8", 163 "fr_FR.utf8", 164 "de", 165 "de_DE", 166 "de_DE.850", 167 "de_DE.IBM850", 168 "de_DE.1250", 169 "de_DE.CP1250", 170 "de_DE.1252", 171 "de_DE.CP1252", 172 "de_DE.ISO-8859-1", 173 "de_DE.ISO_8859-1", 174 "de_DE.ISO8859-1", 175 "de_DE.iso88591", 176 "de_DE.ISO-8859-15", 177 "de_DE.DIS_8859-15", 178 "de_DE.ISO8859-15", 179 "de_DE.iso885915", 180 "de_DE.UTF-8", 181 "de_DE.utf8", 182 "tr", 183 "tr_TR", 184 "tr_TR.1254", 185 "tr_TR.CP1254", 186 "tr_TR.857", 187 "tr_TR.IBM857", 188 "tr_TR.ISO-8859-9", 189 "tr_TR.ISO8859-9", 190 "tr_TR.iso88599", 191 "tr_TR.UTF-8", 192 "tr_TR.utf8", 193 "ru", 194 "ru_RU", 195 "ru_RU.1251", 196 "ru_RU.CP1251", 197 "ru_RU.866", 198 "ru_RU.IBM866", 199 "ru_RU.KOI8-R", 200 "ru_RU.koi8-r", 201 "ru_RU.KOI8-RU", 202 "ru_RU.ISO-8859-5", 203 "ru_RU.ISO_8859-5", 204 "ru_RU.ISO8859-5", 205 "ru_RU.iso88595", 206 "ru_RU.UTF-8", 207 "zh_CN", 208 "zh_CN.GB2312", 209 "zh_CN.UTF-8", 210 #endif /* ! _WIN32 || __CYGWIN__ */ 211 }; 212 213 static const unsigned int locale_name_count = sizeof(locale_names) 214 / sizeof(locale_names[0]); 215 216 217 /* 218 * Helper functions 219 */ 220 221 static int 222 set_test_locale (size_t num) 223 { 224 if (num >= locale_name_count) 225 { 226 fprintf (stderr, "Unexpected number of locale.\n"); 227 exit (99); 228 } 229 if (verbose > 2) 230 printf ("Setting locale \"%s\":", locale_names[num]); 231 if (setlocale (LC_ALL, locale_names[num])) 232 { 233 if (verbose > 2) 234 printf (" succeed.\n"); 235 return 1; 236 } 237 if (verbose > 2) 238 printf (" failed.\n"); 239 return 0; 240 } 241 242 243 static const char * 244 get_current_locale_str (void) 245 { 246 char const *loc_str = setlocale (LC_ALL, NULL); 247 return loc_str ? loc_str : "unknown"; 248 } 249 250 251 static char tmp_bufs[4][4 * 1024]; /* should be enough for testing */ 252 static size_t buf_idx = 0; 253 254 /* print non-printable chars as char codes */ 255 static char * 256 n_prnt (const char *str) 257 { 258 static char *buf; /* should be enough for testing */ 259 static const size_t buf_size = sizeof(tmp_bufs[0]); 260 const unsigned char *p = (const unsigned char *) str; 261 size_t w_pos = 0; 262 if (++buf_idx > 3) 263 buf_idx = 0; 264 buf = tmp_bufs[buf_idx]; 265 266 while (*p && w_pos + 1 < buf_size) 267 { 268 const unsigned char c = *p; 269 if ((c == '\\') || (c == '"') ) 270 { 271 if (w_pos + 2 >= buf_size) 272 break; 273 buf[w_pos++] = '\\'; 274 buf[w_pos++] = (char) c; 275 } 276 else if ((c >= 0x20) && (c <= 0x7E) ) 277 buf[w_pos++] = (char) c; 278 else 279 { 280 if (w_pos + 4 >= buf_size) 281 break; 282 if (snprintf (buf + w_pos, buf_size - w_pos, "\\x%02hX", (short unsigned 283 int) c) != 4) 284 break; 285 w_pos += 4; 286 } 287 p++; 288 } 289 if (*p) 290 { /* not full string is printed */ 291 /* enough space for "..." ? */ 292 if (w_pos + 3 > buf_size) 293 w_pos = buf_size - 4; 294 buf[w_pos++] = '.'; 295 buf[w_pos++] = '.'; 296 buf[w_pos++] = '.'; 297 } 298 buf[w_pos] = 0; 299 return buf; 300 } 301 302 303 struct str_with_len 304 { 305 const char *const str; 306 const size_t len; 307 }; 308 309 #define D_STR_W_LEN(s) {(s), (sizeof((s)) / sizeof(char)) - 1} 310 311 /* 312 * String caseless equality functions tests 313 */ 314 315 struct two_eq_strs 316 { 317 const struct str_with_len s1; 318 const struct str_with_len s2; 319 }; 320 321 static const struct two_eq_strs eq_strings[] = { 322 {D_STR_W_LEN ("1234567890!@~%&$@#{}[]\\/!?`."), 323 D_STR_W_LEN ("1234567890!@~%&$@#{}[]\\/!?`.")}, 324 {D_STR_W_LEN ("Simple string."), D_STR_W_LEN ("Simple string.")}, 325 {D_STR_W_LEN ("SIMPLE STRING."), D_STR_W_LEN ("SIMPLE STRING.")}, 326 {D_STR_W_LEN ("simple string."), D_STR_W_LEN ("simple string.")}, 327 {D_STR_W_LEN ("simple string."), D_STR_W_LEN ("Simple String.")}, 328 {D_STR_W_LEN ("sImPlE StRiNg."), D_STR_W_LEN ("SiMpLe sTrInG.")}, 329 {D_STR_W_LEN ("SIMPLE STRING."), D_STR_W_LEN ("simple string.")}, 330 {D_STR_W_LEN ("abcdefghijklmnopqrstuvwxyz"), 331 D_STR_W_LEN ("abcdefghijklmnopqrstuvwxyz")}, 332 {D_STR_W_LEN ("ABCDEFGHIJKLMNOPQRSTUVWXYZ"), 333 D_STR_W_LEN ("ABCDEFGHIJKLMNOPQRSTUVWXYZ")}, 334 {D_STR_W_LEN ("abcdefghijklmnopqrstuvwxyz"), 335 D_STR_W_LEN ("ABCDEFGHIJKLMNOPQRSTUVWXYZ")}, 336 {D_STR_W_LEN ("zyxwvutsrqponMLKJIHGFEDCBA"), 337 D_STR_W_LEN ("ZYXWVUTSRQPONmlkjihgfedcba")}, 338 339 {D_STR_W_LEN ("Cha\x8cne pour le test."), 340 D_STR_W_LEN ("Cha\x8cne pour le test.")}, /* "Chaîne pour le test." in CP850 */ 341 {D_STR_W_LEN ("cha\x8cne pOur Le TEst."), 342 D_STR_W_LEN ("Cha\x8cne poUr Le teST.")}, 343 {D_STR_W_LEN ("Cha\xeene pour le test."), 344 D_STR_W_LEN ("Cha\xeene pour le test.")}, /* "Chaîne pour le test." in CP1252/ISO-8859-1/ISO-8859-15 */ 345 {D_STR_W_LEN ("CHa\xeene POUR le test."), 346 D_STR_W_LEN ("Cha\xeeNe pour lE TEST.")}, 347 {D_STR_W_LEN ("Cha\xc3\xaene pour le Test."), 348 D_STR_W_LEN ("Cha\xc3\xaene pour le Test.")}, /* "Chaîne pour le test." in UTF-8 */ 349 {D_STR_W_LEN ("ChA\xc3\xaene pouR lE TesT."), 350 D_STR_W_LEN ("Cha\xc3\xaeNe Pour le teSt.")}, 351 352 {D_STR_W_LEN (".Beispiel Zeichenfolge"), 353 D_STR_W_LEN (".Beispiel Zeichenfolge")}, 354 {D_STR_W_LEN (".bEisPiel ZEIchenfoLgE"), 355 D_STR_W_LEN (".BEiSpiEl zeIcheNfolge")}, 356 357 {D_STR_W_LEN ("Do\xa7rulama \x87izgi!"), 358 D_STR_W_LEN ("Do\xa7rulama \x87izgi!")}, /* "Doğrulama çizgi!" in CP857 */ 359 {D_STR_W_LEN ("Do\xa7rulama \x87IzgI!"), /* Spelling intentionally incorrect here */ 360 D_STR_W_LEN ("Do\xa7rulama \x87izgi!")}, /* Note: 'i' is not caseless equal to 'I' in Turkish */ 361 {D_STR_W_LEN ("Do\xf0rulama \xe7izgi!"), 362 D_STR_W_LEN ("Do\xf0rulama \xe7izgi!")}, /* "Doğrulama çizgi!" in CP1254/ISO-8859-9 */ 363 {D_STR_W_LEN ("Do\xf0rulamA \xe7Izgi!"), 364 D_STR_W_LEN ("do\xf0rulama \xe7izgi!")}, 365 {D_STR_W_LEN ("Do\xc4\x9frulama \xc3\xa7izgi!"), 366 D_STR_W_LEN ("Do\xc4\x9frulama \xc3\xa7izgi!")}, /* "Doğrulama çizgi!" in UTF-8 */ 367 {D_STR_W_LEN ("do\xc4\x9fruLAMA \xc3\xa7Izgi!"), /* Spelling intentionally incorrect here */ 368 D_STR_W_LEN ("DO\xc4\x9frulama \xc3\xa7izgI!")}, /* Spelling intentionally incorrect here */ 369 370 {D_STR_W_LEN ("\x92\xa5\xe1\xe2\xae\xa2\xa0\xef \x91\xe2\xe0\xae\xaa\xa0."), 371 D_STR_W_LEN ("\x92\xa5\xe1\xe2\xae\xa2\xa0\xef \x91\xe2\xe0\xae\xaa\xa0.")}, /* "Тестовая Строка." in CP866 */ 372 {D_STR_W_LEN ("\xd2\xe5\xf1\xf2\xee\xe2\xe0\xff \xd1\xf2\xf0\xee\xea\xe0."), 373 D_STR_W_LEN ("\xd2\xe5\xf1\xf2\xee\xe2\xe0\xff \xd1\xf2\xf0\xee\xea\xe0.")}, /* "Тестовая Строка." in CP1251 */ 374 {D_STR_W_LEN ("\xf4\xc5\xd3\xd4\xcf\xd7\xc1\xd1 \xf3\xd4\xd2\xcf\xcb\xc1."), 375 D_STR_W_LEN ("\xf4\xc5\xd3\xd4\xcf\xd7\xc1\xd1 \xf3\xd4\xd2\xcf\xcb\xc1.")}, /* "Тестовая Строка." in KOI8-R */ 376 {D_STR_W_LEN ("\xc2\xd5\xe1\xe2\xde\xd2\xd0\xef \xc1\xe2\xe0\xde\xda\xd0."), 377 D_STR_W_LEN ("\xc2\xd5\xe1\xe2\xde\xd2\xd0\xef \xc1\xe2\xe0\xde\xda\xd0.")}, /* "Тестовая Строка." in ISO-8859-5 */ 378 {D_STR_W_LEN ("\xd0\xa2\xd0\xb5\xd1\x81\xd1\x82\xd0\xbe\xd0\xb2\xd0\xb0\xd1" 379 "\x8f \xd0\xa1\xd1\x82\xd1\x80\xd0\xbe\xd0\xba\xd0\xb0."), 380 D_STR_W_LEN ("\xd0\xa2\xd0\xb5\xd1\x81\xd1\x82\xd0\xbe\xd0\xb2\xd0\xb0\xd1" 381 "\x8f \xd0\xa1\xd1\x82\xd1\x80\xd0\xbe\xd0\xba\xd0\xb0.")}, /* "Тестовая Строка." in UTF-8 */ 382 383 {D_STR_W_LEN ( 384 "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14" 385 "\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !\"#$%&'()*+,-./0123456789:;<=>?@[\\]" 386 "^_`{|}~\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90" 387 "\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4" 388 "\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8" 389 "\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc" 390 "\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0" 391 "\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4" 392 "\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff"), 393 D_STR_W_LEN ( 394 "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14" 395 "\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !\"#$%&'()*+,-./0123456789:;<=>?@[\\]" 396 "^_`{|}~\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90" 397 "\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4" 398 "\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8" 399 "\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc" 400 "\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0" 401 "\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4" 402 "\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff")}, /* Full sequence without a-z */ 403 {D_STR_W_LEN ( 404 "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14" 405 "\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !\"#$%&'()*+,-./0123456789:;<=>?@AB" 406 "CDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x7f\x80\x81\x82\x83" 407 "\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97" 408 "\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab" 409 "\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf" 410 "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3" 411 "\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7" 412 "\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb" 413 "\xfc\xfd\xfe\xff"), 414 D_STR_W_LEN ( 415 "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14" 416 "\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !\"#$%&'()*+,-./0123456789:;<=>?@AB" 417 "CDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x7f\x80\x81\x82\x83" 418 "\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97" 419 "\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab" 420 "\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf" 421 "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3" 422 "\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7" 423 "\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb" 424 "\xfc\xfd\xfe\xff")}, /* Full sequence */ 425 {D_STR_W_LEN ( 426 "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14" 427 "\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !\"#$%&'()*+,-./0123456789:;<=>?@AB" 428 "CDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`{|}~\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89" 429 "\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d" 430 "\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1" 431 "\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5" 432 "\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9" 433 "\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed" 434 "\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff") 435 , 436 D_STR_W_LEN ( 437 "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14" 438 "\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !\"#$%&'()*+,-./0123456789:;<=>?@ab" 439 "cdefghijklmnopqrstuvwxyz[\\]^_`{|}~\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89" 440 "\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d" 441 "\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1" 442 "\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5" 443 "\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9" 444 "\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed" 445 "\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff") 446 } /* Full with A/a match */ 447 }; 448 449 struct two_neq_strs 450 { 451 const struct str_with_len s1; 452 const struct str_with_len s2; 453 const size_t dif_pos; 454 }; 455 456 static const struct two_neq_strs neq_strings[] = { 457 {D_STR_W_LEN ("1234567890!@~%&$@#{}[]\\/!?`."), 458 D_STR_W_LEN ("1234567890!@~%&$@#{}[]\\/!?`"), 27}, 459 {D_STR_W_LEN (".1234567890!@~%&$@#{}[]\\/!?`."), 460 D_STR_W_LEN ("1234567890!@~%&$@#{}[]\\/!?`"), 0}, 461 {D_STR_W_LEN ("Simple string."), D_STR_W_LEN ("Simple ctring."), 7}, 462 {D_STR_W_LEN ("simple string."), D_STR_W_LEN ("simple string"), 13}, 463 {D_STR_W_LEN ("simple strings"), D_STR_W_LEN ("Simple String."), 13}, 464 {D_STR_W_LEN ("sImPlE StRiNg."), D_STR_W_LEN ("SYMpLe sTrInG."), 1}, 465 {D_STR_W_LEN ("SIMPLE STRING."), D_STR_W_LEN ("simple string.2"), 14}, 466 {D_STR_W_LEN ("abcdefghijklmnopqrstuvwxyz,"), 467 D_STR_W_LEN ("abcdefghijklmnopqrstuvwxyz."), 26}, 468 {D_STR_W_LEN ("abcdefghijklmnopqrstuvwxyz!"), 469 D_STR_W_LEN ("ABCDEFGHIJKLMNOPQRSTUVWXYZ?"), 26}, 470 {D_STR_W_LEN ("zyxwvutsrqponwMLKJIHGFEDCBA"), 471 D_STR_W_LEN ("ZYXWVUTSRQPON%mlkjihgfedcba"), 13}, 472 473 {D_STR_W_LEN ("S\xbdur veulent plus d'\xbdufs."), /* "Sœur veulent plus d'œufs." in ISO-8859-15 */ 474 D_STR_W_LEN ("S\xbcUR VEULENT PLUS D'\xbcUFS."), 1}, /* "SŒUR VEULENT PLUS D'ŒUFS." in ISO-8859-15 */ 475 {D_STR_W_LEN ("S\x9cur veulent plus d'\x9cufs."), /* "Sœur veulent plus d'œufs." in CP1252 */ 476 D_STR_W_LEN ("S\x8cUR VEULENT PLUS D'\x8cUFS."), 1}, /* "SŒUR VEULENT PLUS D'ŒUFS." in CP1252 */ 477 {D_STR_W_LEN ("S\xc5\x93ur veulent plus d'\xc5\x93ufs."), /* "Sœur veulent plus d'œufs." in UTF-8 */ 478 D_STR_W_LEN ("S\xc5\x92UR VEULENT PLUS D'\xc5\x92UFS."), 2}, /* "SŒUR VEULENT PLUS D'ŒUFS." in UTF-8 */ 479 480 {D_STR_W_LEN ("Um ein sch\x94nes M\x84" "dchen zu k\x81ssen."), /* "Um ein schönes Mädchen zu küssen." in CP850 */ 481 D_STR_W_LEN ("UM EIN SCH\x99NES M\x8e" "DCHEN ZU K\x9aSSEN."), 10}, /* "UM EIN SCHÖNES MÄDCHEN ZU KÜSSEN." in CP850 */ 482 {D_STR_W_LEN ("Um ein sch\xf6nes M\xe4" "dchen zu k\xfcssen."), /* "Um ein schönes Mädchen zu küssen." in ISO-8859-1/ISO-8859-15/CP1250/CP1252 */ 483 D_STR_W_LEN ("UM EIN SCH\xd6NES M\xc4" "DCHEN ZU K\xdcSSEN."), 10}, /* "UM EIN SCHÖNES MÄDCHEN ZU KÜSSEN." in ISO-8859-1/ISO-8859-15/CP1250/CP1252 */ 484 {D_STR_W_LEN ("Um ein sch\xc3\xb6nes M\xc3\xa4" "dchen zu k\xc3\xbcssen."), /* "Um ein schönes Mädchen zu küssen." in UTF-8 */ 485 D_STR_W_LEN ("UM EIN SCH\xc3\x96NES M\xc3\x84" "DCHEN ZU K\xc3\x9cSSEN."), 486 11}, /* "UM EIN SCHÖNES MÄDCHEN ZU KÜSSEN." in UTF-8 */ 487 488 {D_STR_W_LEN ("\x98stanbul"), /* "İstanbul" in CP857 */ 489 D_STR_W_LEN ("istanbul"), 0}, /* "istanbul" in CP857 */ 490 {D_STR_W_LEN ("\xddstanbul"), /* "İstanbul" in ISO-8859-9/CP1254 */ 491 D_STR_W_LEN ("istanbul"), 0}, /* "istanbul" in ISO-8859-9/CP1254 */ 492 {D_STR_W_LEN ("\xc4\xb0stanbul"), /* "İstanbul" in UTF-8 */ 493 D_STR_W_LEN ("istanbul"), 0}, /* "istanbul" in UTF-8 */ 494 {D_STR_W_LEN ("Diyarbak\x8dr"), /* "Diyarbakır" in CP857 */ 495 D_STR_W_LEN ("DiyarbakIR"), 8}, /* "DiyarbakIR" in CP857 */ 496 {D_STR_W_LEN ("Diyarbak\xfdr"), /* "Diyarbakır" in ISO-8859-9/CP1254 */ 497 D_STR_W_LEN ("DiyarbakIR"), 8}, /* "DiyarbakIR" in ISO-8859-9/CP1254 */ 498 {D_STR_W_LEN ("Diyarbak\xc4\xb1r"), /* "Diyarbakır" in UTF-8 */ 499 D_STR_W_LEN ("DiyarbakIR"), 8}, /* "DiyarbakIR" in UTF-8 */ 500 501 {D_STR_W_LEN ("\x92\xa5\xe1\xe2\xae\xa2\xa0\xef \x91\xe2\xe0\xae\xaa\xa0."), /* "Тестовая Строка." in CP866 */ 502 D_STR_W_LEN ("\x92\x85\x91\x92\x8e\x82\x80\x9f \x91\x92\x90\x8e\x8a\x80."), 503 1}, /* "ТЕСТОВАЯ СТРОКА." in CP866 */ 504 {D_STR_W_LEN ("\xd2\xe5\xf1\xf2\xee\xe2\xe0\xff \xd1\xf2\xf0\xee\xea\xe0."), /* "Тестовая Строка." in CP1251 */ 505 D_STR_W_LEN ("\xd2\xc5\xd1\xd2\xce\xc2\xc0\xdf \xd1\xd2\xd0\xce\xca\xc0."), 506 1}, /* "ТЕСТОВАЯ СТРОКА." in CP1251 */ 507 {D_STR_W_LEN ("\xf4\xc5\xd3\xd4\xcf\xd7\xc1\xd1 \xf3\xd4\xd2\xcf\xcb\xc1."), /* "Тестовая Строка." in KOI8-R */ 508 D_STR_W_LEN ("\xf4\xe5\xf3\xf4\xef\xf7\xe1\xf1 \xf3\xf4\xf2\xef\xeb\xe1."), 509 1}, /* "ТЕСТОВАЯ СТРОКА." in KOI8-R */ 510 {D_STR_W_LEN ("\xc2\xd5\xe1\xe2\xde\xd2\xd0\xef \xc1\xe2\xe0\xde\xda\xd0."), /* "Тестовая Строка." in ISO-8859-5 */ 511 D_STR_W_LEN ("\xc2\xb5\xc1\xc2\xbe\xb2\xb0\xcf \xc1\xc2\xc0\xbe\xba\xb0."), 512 1}, /* "ТЕСТОВАЯ СТРОКА." in ISO-8859-5 */ 513 {D_STR_W_LEN ("\xd0\xa2\xd0\xb5\xd1\x81\xd1\x82\xd0\xbe\xd0\xb2\xd0\xb0\xd1" 514 "\x8f \xd0\xa1\xd1\x82\xd1\x80\xd0\xbe\xd0\xba\xd0\xb0."), /* "Тестовая Строка." in UTF-8 */ 515 D_STR_W_LEN ("\xd0\xa2\xd0\x95\xd0\xa1\xd0\xa2\xd0\x9e\xd0\x92\xd0\x90\xd0" 516 "\xaf \xd0\xa1\xd0\xa2\xd0\xa0\xd0\x9e\xd0\x9a\xd0\x90."), 3} /* "ТЕСТОВАЯ СТРОКА." in UTF-8 */ 517 }; 518 519 520 static size_t 521 check_eq_strings (void) 522 { 523 size_t t_failed = 0; 524 size_t i, j; 525 int c_failed[sizeof(eq_strings) / sizeof(eq_strings[0])]; 526 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 527 528 memset (c_failed, 0, sizeof(c_failed)); 529 530 for (j = 0; j < locale_name_count; j++) 531 { 532 set_test_locale (j); /* setlocale() can be slow! */ 533 for (i = 0; i < n_checks; i++) 534 { 535 const struct two_eq_strs *const t = eq_strings + i; 536 if (c_failed[i]) 537 continue; /* skip already failed checks */ 538 if (! mhd_str_equal_caseless (t->s1.str, t->s2.str)) 539 { 540 t_failed++; 541 c_failed[i] = ! 0; 542 fprintf (stderr, 543 "FAILED: mhd_str_equal_caseless(\"%s\", \"%s\") returned zero, while expected non-zero." 544 " Locale: %s\n", n_prnt (t->s1.str), n_prnt (t->s2.str), 545 get_current_locale_str ()); 546 } 547 else if (! mhd_str_equal_caseless (t->s2.str, t->s1.str)) 548 { 549 t_failed++; 550 c_failed[i] = ! 0; 551 fprintf (stderr, 552 "FAILED: mhd_str_equal_caseless(\"%s\", \"%s\") returned zero, while expected non-zero." 553 " Locale: %s\n", n_prnt (t->s2.str), n_prnt (t->s1.str), 554 get_current_locale_str ()); 555 } 556 if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[i]) 557 printf ("PASSED: mhd_str_equal_caseless(\"%s\", \"%s\") != 0 && \\\n" 558 " mhd_str_equal_caseless(\"%s\", \"%s\") != 0\n", 559 n_prnt (t->s1.str), n_prnt (t->s2.str), 560 n_prnt (t->s2.str), n_prnt (t->s1.str)); 561 } 562 } 563 return t_failed; 564 } 565 566 567 static size_t 568 check_neq_strings (void) 569 { 570 size_t t_failed = 0; 571 size_t i, j; 572 int c_failed[sizeof(neq_strings) / sizeof(neq_strings[0])]; 573 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 574 575 memset (c_failed, 0, sizeof(c_failed)); 576 577 for (j = 0; j < locale_name_count; j++) 578 { 579 set_test_locale (j); /* setlocale() can be slow! */ 580 for (i = 0; i < n_checks; i++) 581 { 582 const struct two_neq_strs *const t = neq_strings + i; 583 if (c_failed[i]) 584 continue; /* skip already failed checks */ 585 if (mhd_str_equal_caseless (t->s1.str, t->s2.str)) 586 { 587 t_failed++; 588 c_failed[i] = ! 0; 589 fprintf (stderr, 590 "FAILED: mhd_str_equal_caseless(\"%s\", \"%s\") returned non-zero, while expected zero." 591 " Locale: %s\n", n_prnt (t->s1.str), n_prnt (t->s2.str), 592 get_current_locale_str ()); 593 } 594 else if (mhd_str_equal_caseless (t->s2.str, t->s1.str)) 595 { 596 t_failed++; 597 c_failed[i] = ! 0; 598 fprintf (stderr, 599 "FAILED: mhd_str_equal_caseless(\"%s\", \"%s\") returned non-zero, while expected zero." 600 " Locale: %s\n", n_prnt (t->s2.str), n_prnt (t->s1.str), 601 get_current_locale_str ()); 602 } 603 if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[i]) 604 printf ("PASSED: mhd_str_equal_caseless(\"%s\", \"%s\") == 0 && \\\n" 605 " mhd_str_equal_caseless(\"%s\", \"%s\") == 0\n", 606 n_prnt (t->s1.str), n_prnt (t->s2.str), 607 n_prnt (t->s2.str), n_prnt (t->s1.str)); 608 } 609 } 610 return t_failed; 611 } 612 613 614 static size_t 615 check_eq_strings_n (void) 616 { 617 size_t t_failed = 0; 618 size_t i, j, k; 619 int c_failed[sizeof(eq_strings) / sizeof(eq_strings[0])]; 620 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 621 622 memset (c_failed, 0, sizeof(c_failed)); 623 624 for (j = 0; j < locale_name_count; j++) 625 { 626 set_test_locale (j); /* setlocale() can be slow! */ 627 for (i = 0; i < n_checks; i++) 628 { 629 size_t m_len; 630 const struct two_eq_strs *const t = eq_strings + i; 631 m_len = (t->s1.len > t->s2.len) ? t->s1.len : t->s2.len; 632 for (k = 0; k <= m_len + 1 && ! c_failed[i]; k++) 633 { 634 if (! mhd_str_equal_caseless_n (t->s1.str, t->s2.str, k)) 635 { 636 t_failed++; 637 c_failed[i] = ! 0; 638 fprintf (stderr, 639 "FAILED: mhd_str_equal_caseless_n(\"%s\", \"%s\", %u) returned zero," 640 " while expected non-zero. Locale: %s\n", 641 n_prnt (t->s1.str), n_prnt (t->s2.str), (unsigned int) k, 642 get_current_locale_str ()); 643 } 644 else if (! mhd_str_equal_caseless_n (t->s2.str, t->s1.str, k)) 645 { 646 t_failed++; 647 c_failed[i] = ! 0; 648 fprintf (stderr, 649 "FAILED: mhd_str_equal_caseless_n(\"%s\", \"%s\", %u) returned zero," 650 " while expected non-zero. Locale: %s\n", 651 n_prnt (t->s2.str), n_prnt (t->s1.str), (unsigned int) k, 652 get_current_locale_str ()); 653 } 654 } 655 if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[i]) 656 printf ("PASSED: mhd_str_equal_caseless_n(\"%s\", \"%s\", N) " \ 657 "!= 0 && \\\n" \ 658 " mhd_str_equal_caseless_n(\"%s\", \"%s\", N) " \ 659 "!= 0, where N is 0..%u\n", 660 n_prnt (t->s1.str), n_prnt (t->s2.str), n_prnt (t->s2.str), 661 n_prnt (t->s1.str), (unsigned int) m_len + 1); 662 } 663 } 664 return t_failed; 665 } 666 667 668 static size_t 669 check_neq_strings_n (void) 670 { 671 size_t t_failed = 0; 672 size_t i, j, k; 673 int c_failed[sizeof(neq_strings) / sizeof(neq_strings[0])]; 674 static const size_t n_checks = sizeof(c_failed) / sizeof(c_failed[0]); 675 676 memset (c_failed, 0, sizeof(c_failed)); 677 678 for (j = 0; j < locale_name_count; j++) 679 { 680 set_test_locale (j); /* setlocale() can be slow! */ 681 for (i = 0; i < n_checks; i++) 682 { 683 size_t m_len; 684 const struct two_neq_strs *const t = neq_strings + i; 685 m_len = t->s1.len > t->s2.len ? t->s1.len : t->s2.len; 686 if (t->dif_pos >= m_len) 687 { 688 fprintf (stderr, 689 "ERROR: neq_strings[%u] has wrong dif_pos (%u): dif_pos is expected to be less than " 690 "s1.len (%u) or s2.len (%u).\n", (unsigned int) i, (unsigned 691 int) t-> 692 dif_pos, 693 (unsigned int) t->s1.len, (unsigned int) t->s2.len); 694 exit (99); 695 } 696 if (t->dif_pos > t->s1.len) 697 { 698 fprintf (stderr, 699 "ERROR: neq_strings[%u] has wrong dif_pos (%u): dif_pos is expected to be less or " 700 "equal to s1.len (%u).\n", (unsigned int) i, (unsigned 701 int) t->dif_pos, 702 (unsigned int) t->s1.len); 703 exit (99); 704 } 705 if (t->dif_pos > t->s2.len) 706 { 707 fprintf (stderr, 708 "ERROR: neq_strings[%u] has wrong dif_pos (%u): dif_pos is expected to be less or " 709 "equal to s2.len (%u).\n", (unsigned int) i, (unsigned 710 int) t->dif_pos, 711 (unsigned int) t->s2.len); 712 exit (99); 713 } 714 for (k = 0; k <= m_len + 1 && ! c_failed[i]; k++) 715 { 716 if (k <= t->dif_pos) 717 { 718 if (! mhd_str_equal_caseless_n (t->s1.str, t->s2.str, k)) 719 { 720 t_failed++; 721 c_failed[i] = ! 0; 722 fprintf (stderr, 723 "FAILED: mhd_str_equal_caseless_n(\"%s\", \"%s\", %u) returned zero," 724 " while expected non-zero. Locale: %s\n", 725 n_prnt (t->s1.str), n_prnt (t->s2.str), (unsigned int) k, 726 get_current_locale_str ()); 727 } 728 else if (! mhd_str_equal_caseless_n (t->s2.str, t->s1.str, k)) 729 { 730 t_failed++; 731 c_failed[i] = ! 0; 732 fprintf (stderr, 733 "FAILED: mhd_str_equal_caseless_n(\"%s\", \"%s\", %u) returned zero," 734 " while expected non-zero. Locale: %s\n", 735 n_prnt (t->s2.str), n_prnt (t->s1.str), (unsigned int) k, 736 get_current_locale_str ()); 737 } 738 } 739 else 740 { 741 if (mhd_str_equal_caseless_n (t->s1.str, t->s2.str, k)) 742 { 743 t_failed++; 744 c_failed[i] = ! 0; 745 fprintf (stderr, 746 "FAILED: mhd_str_equal_caseless_n(\"%s\", \"%s\", %u) returned non-zero," 747 " while expected zero. Locale: %s\n", 748 n_prnt (t->s1.str), n_prnt (t->s2.str), (unsigned int) k, 749 get_current_locale_str ()); 750 } 751 else if (mhd_str_equal_caseless_n (t->s2.str, t->s1.str, k)) 752 { 753 t_failed++; 754 c_failed[i] = ! 0; 755 fprintf (stderr, 756 "FAILED: mhd_str_equal_caseless_n(\"%s\", \"%s\", %u) returned non-zero," 757 " while expected zero. Locale: %s\n", 758 n_prnt (t->s2.str), n_prnt (t->s1.str), (unsigned int) k, 759 get_current_locale_str ()); 760 } 761 } 762 } 763 if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[i]) 764 { 765 printf ( 766 "PASSED: mhd_str_equal_caseless_n(\"%s\", \"%s\", N) != 0 && \\\n" 767 " mhd_str_equal_caseless_n(\"%s\", \"%s\", N) != 0, where N is 0..%u\n", 768 n_prnt (t->s1.str), n_prnt (t->s2.str), n_prnt (t->s2.str), 769 n_prnt (t->s1.str), 770 (unsigned int) t->dif_pos); 771 772 printf ( 773 "PASSED: mhd_str_equal_caseless_n(\"%s\", \"%s\", N) == 0 && \\\n" 774 " mhd_str_equal_caseless_n(\"%s\", \"%s\", N) == 0, where N is %u..%u\n", 775 n_prnt (t->s1.str), n_prnt (t->s2.str), n_prnt (t->s2.str), 776 n_prnt (t->s1.str), 777 (unsigned int) t->dif_pos + 1, (unsigned int) m_len + 1); 778 } 779 } 780 } 781 return t_failed; 782 } 783 784 785 /* 786 * Run eq/neq strings tests 787 */ 788 static int 789 run_eq_neq_str_tests (void) 790 { 791 size_t str_equal_caseless_fails = 0; 792 size_t str_equal_caseless_n_fails = 0; 793 size_t res; 794 795 res = check_eq_strings (); 796 if (res != 0) 797 { 798 str_equal_caseless_fails += res; 799 fprintf (stderr, "FAILED: testcase check_eq_strings() failed.\n\n"); 800 } 801 else if (verbose > 1) 802 printf ("PASSED: testcase check_eq_strings() successfully passed.\n\n"); 803 804 res = check_neq_strings (); 805 if (res != 0) 806 { 807 str_equal_caseless_fails += res; 808 fprintf (stderr, "FAILED: testcase check_neq_strings() failed.\n\n"); 809 } 810 else if (verbose > 1) 811 printf ("PASSED: testcase check_neq_strings() successfully passed.\n\n"); 812 813 if (str_equal_caseless_fails) 814 fprintf (stderr, 815 "FAILED: function mhd_str_equal_caseless() failed %lu time%s.\n\n", 816 (unsigned long) str_equal_caseless_fails, 817 str_equal_caseless_fails == 1 ? "" : 818 "s"); 819 else if (verbose > 0) 820 printf ( 821 "PASSED: function mhd_str_equal_caseless() successfully passed all checks.\n\n"); 822 823 res = check_eq_strings_n (); 824 if (res != 0) 825 { 826 str_equal_caseless_n_fails += res; 827 fprintf (stderr, "FAILED: testcase check_eq_strings_n() failed.\n\n"); 828 } 829 else if (verbose > 1) 830 printf ("PASSED: testcase check_eq_strings_n() successfully passed.\n\n"); 831 832 res = check_neq_strings_n (); 833 if (res != 0) 834 { 835 str_equal_caseless_n_fails += res; 836 fprintf (stderr, "FAILED: testcase check_neq_strings_n() failed.\n\n"); 837 } 838 else if (verbose > 1) 839 printf ("PASSED: testcase check_neq_strings_n() successfully passed.\n\n"); 840 841 if (str_equal_caseless_n_fails) 842 fprintf (stderr, 843 "FAILED: function mhd_str_equal_caseless_n() failed %lu time%s.\n\n", 844 (unsigned long) str_equal_caseless_n_fails, 845 str_equal_caseless_n_fails == 1 ? "" : 846 "s"); 847 else if (verbose > 0) 848 printf ( 849 "PASSED: function mhd_str_equal_caseless_n() successfully passed all checks.\n\n"); 850 851 if (str_equal_caseless_fails || str_equal_caseless_n_fails) 852 { 853 if (verbose > 0) 854 printf ("At least one test failed.\n"); 855 856 return 1; 857 } 858 859 if (verbose > 0) 860 printf ("All tests passed successfully.\n"); 861 862 return 0; 863 } 864 865 866 int 867 main (int argc, 868 char *argv[]) 869 { 870 if (has_param (argc, argv, "-v") || 871 has_param (argc, argv, "--verbose") || 872 has_param (argc, argv, "--verbose1")) 873 MHDT_set_verbosity (MHDT_VERB_LVL_BASIC); 874 if (has_param (argc, argv, "-vv") || 875 has_param (argc, argv, "--verbose2")) 876 MHDT_set_verbosity (MHDT_VERB_LVL_VERBOSE); 877 878 return run_eq_neq_str_tests (); 879 }