Changeset 738:d666051658bd in freeDiameter for tests/testostr.c
- Timestamp:
- Mar 2, 2011, 6:21:59 PM (13 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/testostr.c
r717 r738 99 99 CHECK( 0, strcasecmp(res, TEST_IDN_UTF8) ); 100 100 CHECK( 0, fd_os_cmp(res, len, TEST_IDN_UTF8, CONSTSTRLEN(TEST_IDN_UTF8)) ); 101 CHECK( 0, fd_os_almostcase cmp(res, len, TEST_IDN_UTF8, CONSTSTRLEN(TEST_IDN_UTF8)) );101 CHECK( 0, fd_os_almostcasesrch(res, len, TEST_IDN_UTF8, CONSTSTRLEN(TEST_IDN_UTF8), NULL) ); 102 102 CHECK( 0, fd_os_validate_DiameterIdentity(&res, &len, 0) ); 103 103 CHECK( 0, strcasecmp(res, TEST_IDN_UTF8) ); … … 128 128 } 129 129 130 { 131 /* test fd_os_cmp and fd_os_almostcasesrch and that they are compatible */ 132 char *t1 = "a"; 133 char *t2 = "b"; 134 char *t3 = "C"; 135 char *t4 = "d"; 136 char *t5 = "aa"; 137 char *t6 = "aB"; 138 char *t7 = "Ac"; 139 char *t8 = "aD"; 140 char *t9 = "AAA"; 141 142 char *t5b = "Aa"; 143 char *t6b = "ab"; 144 145 /* First, create a list with all the elements in order given by fd_os_cmp */ 146 char *t[] = { t1, t2, t3, t4, t5, t6,t7, t8, t9 }; 147 int i; 148 struct fd_list *li, l = FD_LIST_INITIALIZER(l); 149 for (i = 0; i < sizeof(t) / sizeof(t[0]); i++) { 150 /* insert t[i] */ 151 struct fd_list *n = malloc(sizeof(struct fd_list)); 152 CHECK( 1, n ? 1 : 0 ); 153 fd_list_init(n, t[i]); 154 for (li = l.next; li != &l; li = li->next) { 155 if ( fd_os_cmp(t[i], strlen(t[i]), li->o, strlen(li->o)) < 0 ) 156 break; 157 } 158 fd_list_insert_before(li, n); 159 } 160 /* in principle the result is: [ "C", "a", "b", "d", "Ac", "aB", "aD", "aa", "AAA" ] */ 161 162 /* Since there is no equal value in the list (even case-insensitive), check that the order is valid also for the caseinsensitive variant */ 163 for (li = l.next; li != l.prev; li = li->next) { 164 CHECK( 1, fd_os_almostcasesrch(li->o, strlen(li->o), li->next->o, strlen(li->next->o), NULL) < 0 ? 1 : 0 ); 165 } 166 167 /* Now check that we can case-insentively find t5b and t6b to be equal to t5 and t6 resp. (this is how we use it in the daemon) */ 168 for (li = l.next; li != &l; li = li->next) { 169 int cont, cmp; 170 cmp = fd_os_almostcasesrch(t5b, strlen(t5b), li->o, strlen(li->o), &cont); 171 TRACE_DEBUG(FULL, "Comp '%s' : %d, %d", (char *)li->o, cmp, cont); 172 if (cmp == 0) 173 break; 174 if (!cont) 175 break; 176 } 177 CHECK( li->o, t5 ); 178 179 for (li = l.next; li != &l; li = li->next) { 180 int cont, cmp; 181 cmp = fd_os_almostcasesrch(t6b, strlen(t6b), li->o, strlen(li->o), &cont); 182 TRACE_DEBUG(FULL, "Comp '%s' : %d, %d", (char *)li->o, cmp, cont); 183 if (cmp == 0) 184 break; 185 if (!cont) 186 break; 187 } 188 CHECK( li->o, t6 ); 189 190 191 /* done */ 192 while (!FD_IS_LIST_EMPTY(&l)) { 193 li = l.next; 194 fd_list_unlink(li); 195 free(li); 196 } 197 } 198 130 199 /* That's all for the tests yet */ 131 200 PASSTEST();
Note: See TracChangeset
for help on using the changeset viewer.