Changeset 118 for pjproject/trunk/pjlib/src/pjlib-test/string.c
- Timestamp:
- Jan 9, 2006 5:20:59 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib/src/pjlib-test/string.c
r77 r118 48 48 * - pj_strtoul() 49 49 * - pj_create_random_string() 50 * 50 * - ... and mode.. 51 51 * 52 52 * This file is <b>pjlib-test/string.c</b> … … 67 67 static int stricmp_test(void) 68 68 { 69 /* This specificly tests and benchmark pj_stricmp(), pj_stricmp_alnum(). 70 * In addition, it also tests pj_stricmp2(), pj_strnicmp(), and 71 * pj_strnicmp2(). 72 */ 69 73 #define STRTEST(res,S1,S2,code) \ 70 74 do { \ 71 s1.ptr=S1; s1.slen=len; \72 s2.ptr=S2; s2.slen=len; \75 s1.ptr=S1; s1.slen=S1?len:0; \ 76 s2.ptr=S2; s2.slen=S2?len:0; \ 73 77 pj_get_timestamp(&t1); \ 74 78 if (pj_stricmp(&s1,&s2)!=res) return code; \ … … 81 85 pj_sub_timestamp(&t2, &t1); \ 82 86 pj_add_timestamp(&e2, &t2); \ 87 if (pj_stricmp2(&s1,S2)!=res) return code*10; \ 88 if (pj_strnicmp(&s1,&s2,len)!=res) return code*100; \ 89 if (pj_strnicmp2(&s1,S2,len)!=res) return code*1000; \ 83 90 } while (0) 84 91 … … 96 103 len=0; 97 104 STRTEST( 0, "","",-500); 105 STRTEST( 0, NULL,"",-502); 106 STRTEST( 0, "",NULL,-504); 107 STRTEST( 0, NULL,NULL,-506); 108 STRTEST( 0, "hello","world",-508); 98 109 99 110 /* equal, length=1 … … 105 116 STRTEST( 0, "a",buf+1,-512); 106 117 STRTEST( -1, "0", "P", -514); 118 STRTEST(-1, NULL, "a", -516); 119 STRTEST(1, "a", NULL, -518); 107 120 108 121 /* equal, length=2 … … 208 221 } 209 222 223 /* This tests pj_strcmp(), pj_strcmp2(), pj_strncmp(), pj_strncmp2() */ 224 static int strcmp_test(void) 225 { 226 #define STR_TEST(res,S1,S2,code) \ 227 do { \ 228 s1.ptr=S1; s1.slen=S1?len:0; \ 229 s2.ptr=S2; s2.slen=S2?len:0; \ 230 if (pj_strcmp(&s1,&s2)!=res) return code; \ 231 if (pj_strcmp2(&s1,S2)!=res) return code-1; \ 232 if (pj_strncmp(&s1,&s2,len)!=res) return code-2; \ 233 if (pj_strncmp2(&s1,S2,len)!=res) return code-3; \ 234 } while (0) 235 236 pj_str_t s1, s2; 237 int len; 238 239 /* Test with length == 0 */ 240 len=0; 241 STR_TEST(0, "", "", -400); 242 STR_TEST(0, NULL, "", -405); 243 STR_TEST(0, "", NULL, -410); 244 STR_TEST(0, NULL, NULL, -415); 245 STR_TEST(0, "hello", "", -420); 246 STR_TEST(0, "hello", NULL, -425); 247 248 /* Test with length != 0 */ 249 len = 2; 250 STR_TEST(0, "12", "12", -430); 251 STR_TEST(1, "12", "1", -435); 252 STR_TEST(-1, "1", "12", -440); 253 STR_TEST(-1, NULL, "12", -445); 254 STR_TEST(1, "12", NULL, -450); 255 256 return 0; 257 258 #undef STR_TEST 259 } 260 210 261 int string_test(void) 211 262 { … … 308 359 pj_pool_release(pool); 309 360 310 return stricmp_test(); 361 /* Case sensitive comparison test. */ 362 i = strcmp_test(); 363 if (i != 0) 364 return i; 365 366 /* Caseless comparison test. */ 367 i = stricmp_test(); 368 if (i != 0) 369 return i; 370 371 return 0; 311 372 } 312 373
Note: See TracChangeset
for help on using the changeset viewer.