00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #define CURL_NO_OLDIES
00031
00032 #include "curl_setup.h"
00033
00034 #include <curl/curl.h>
00035
00036 #ifdef HAVE_SYS_SELECT_H
00037
00038 #include <sys/select.h>
00039 #endif
00040
00041 #ifdef TPF
00042 # include "select.h"
00043 #endif
00044
00045 #include "curl_printf.h"
00046
00047 #define test_setopt(A,B,C) \
00048 if((res = curl_easy_setopt((A), (B), (C))) != CURLE_OK) goto test_cleanup
00049
00050 #define test_multi_setopt(A,B,C) \
00051 if((res = curl_multi_setopt((A), (B), (C))) != CURLE_OK) goto test_cleanup
00052
00053 extern char *libtest_arg2;
00054 extern char *libtest_arg3;
00055
00056
00057 extern int test_argc;
00058 extern char **test_argv;
00059
00060 extern struct timeval tv_test_start;
00061
00062 extern int select_wrapper(int nfds, fd_set *rd, fd_set *wr, fd_set *exc,
00063 struct timeval *tv);
00064
00065 extern void wait_ms(int ms);
00066
00067 extern int test(char *URL);
00068
00069
00070 extern char *hexdump(unsigned char *buffer, size_t len);
00071
00072 #ifdef UNITTESTS
00073 extern int unitfail;
00074 #endif
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085 #define TEST_ERR_MAJOR_BAD 126
00086 #define TEST_ERR_RUNS_FOREVER 125
00087 #define TEST_ERR_EASY_INIT 124
00088 #define TEST_ERR_MULTI_INIT 123
00089 #define TEST_ERR_NUM_HANDLES 122
00090 #define TEST_ERR_SELECT 121
00091 #define TEST_ERR_SUCCESS 120
00092 #define TEST_ERR_FAILURE 119
00093 #define TEST_ERR_USAGE 118
00094 #define TEST_ERR_FOPEN 117
00095 #define TEST_ERR_FSTAT 116
00096 #define TEST_ERR_BAD_TIMEOUT 115
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129 #define exe_easy_init(A,Y,Z) do { \
00130 if(((A) = curl_easy_init()) == NULL) { \
00131 fprintf(stderr, "%s:%d curl_easy_init() failed\n", (Y), (Z)); \
00132 res = TEST_ERR_EASY_INIT; \
00133 } \
00134 } WHILE_FALSE
00135
00136 #define res_easy_init(A) \
00137 exe_easy_init((A), (__FILE__), (__LINE__))
00138
00139 #define chk_easy_init(A,Y,Z) do { \
00140 exe_easy_init((A), (Y), (Z)); \
00141 if(res) \
00142 goto test_cleanup; \
00143 } WHILE_FALSE
00144
00145 #define easy_init(A) \
00146 chk_easy_init((A), (__FILE__), (__LINE__))
00147
00148
00149
00150 #define exe_multi_init(A,Y,Z) do { \
00151 if(((A) = curl_multi_init()) == NULL) { \
00152 fprintf(stderr, "%s:%d curl_multi_init() failed\n", (Y), (Z)); \
00153 res = TEST_ERR_MULTI_INIT; \
00154 } \
00155 } WHILE_FALSE
00156
00157 #define res_multi_init(A) \
00158 exe_multi_init((A), (__FILE__), (__LINE__))
00159
00160 #define chk_multi_init(A,Y,Z) do { \
00161 exe_multi_init((A), (Y), (Z)); \
00162 if(res) \
00163 goto test_cleanup; \
00164 } WHILE_FALSE
00165
00166 #define multi_init(A) \
00167 chk_multi_init((A), (__FILE__), (__LINE__))
00168
00169
00170
00171 #define exe_easy_setopt(A,B,C,Y,Z) do { \
00172 CURLcode ec; \
00173 if((ec = curl_easy_setopt((A), (B), (C))) != CURLE_OK) { \
00174 fprintf(stderr, "%s:%d curl_easy_setopt() failed, " \
00175 "with code %d (%s)\n", \
00176 (Y), (Z), (int)ec, curl_easy_strerror(ec)); \
00177 res = (int)ec; \
00178 } \
00179 } WHILE_FALSE
00180
00181 #define res_easy_setopt(A, B, C) \
00182 exe_easy_setopt((A), (B), (C), (__FILE__), (__LINE__))
00183
00184 #define chk_easy_setopt(A, B, C, Y, Z) do { \
00185 exe_easy_setopt((A), (B), (C), (Y), (Z)); \
00186 if(res) \
00187 goto test_cleanup; \
00188 } WHILE_FALSE
00189
00190 #define easy_setopt(A, B, C) \
00191 chk_easy_setopt((A), (B), (C), (__FILE__), (__LINE__))
00192
00193
00194
00195 #define exe_multi_setopt(A, B, C, Y, Z) do { \
00196 CURLMcode ec; \
00197 if((ec = curl_multi_setopt((A), (B), (C))) != CURLM_OK) { \
00198 fprintf(stderr, "%s:%d curl_multi_setopt() failed, " \
00199 "with code %d (%s)\n", \
00200 (Y), (Z), (int)ec, curl_multi_strerror(ec)); \
00201 res = (int)ec; \
00202 } \
00203 } WHILE_FALSE
00204
00205 #define res_multi_setopt(A,B,C) \
00206 exe_multi_setopt((A), (B), (C), (__FILE__), (__LINE__))
00207
00208 #define chk_multi_setopt(A,B,C,Y,Z) do { \
00209 exe_multi_setopt((A), (B), (C), (Y), (Z)); \
00210 if(res) \
00211 goto test_cleanup; \
00212 } WHILE_FALSE
00213
00214 #define multi_setopt(A,B,C) \
00215 chk_multi_setopt((A), (B), (C), (__FILE__), (__LINE__))
00216
00217
00218
00219 #define exe_multi_add_handle(A,B,Y,Z) do { \
00220 CURLMcode ec; \
00221 if((ec = curl_multi_add_handle((A), (B))) != CURLM_OK) { \
00222 fprintf(stderr, "%s:%d curl_multi_add_handle() failed, " \
00223 "with code %d (%s)\n", \
00224 (Y), (Z), (int)ec, curl_multi_strerror(ec)); \
00225 res = (int)ec; \
00226 } \
00227 } WHILE_FALSE
00228
00229 #define res_multi_add_handle(A, B) \
00230 exe_multi_add_handle((A), (B), (__FILE__), (__LINE__))
00231
00232 #define chk_multi_add_handle(A, B, Y, Z) do { \
00233 exe_multi_add_handle((A), (B), (Y), (Z)); \
00234 if(res) \
00235 goto test_cleanup; \
00236 } WHILE_FALSE
00237
00238 #define multi_add_handle(A, B) \
00239 chk_multi_add_handle((A), (B), (__FILE__), (__LINE__))
00240
00241
00242
00243 #define exe_multi_remove_handle(A,B,Y,Z) do { \
00244 CURLMcode ec; \
00245 if((ec = curl_multi_remove_handle((A), (B))) != CURLM_OK) { \
00246 fprintf(stderr, "%s:%d curl_multi_remove_handle() failed, " \
00247 "with code %d (%s)\n", \
00248 (Y), (Z), (int)ec, curl_multi_strerror(ec)); \
00249 res = (int)ec; \
00250 } \
00251 } WHILE_FALSE
00252
00253 #define res_multi_remove_handle(A, B) \
00254 exe_multi_remove_handle((A), (B), (__FILE__), (__LINE__))
00255
00256 #define chk_multi_remove_handle(A, B, Y, Z) do { \
00257 exe_multi_remove_handle((A), (B), (Y), (Z)); \
00258 if(res) \
00259 goto test_cleanup; \
00260 } WHILE_FALSE
00261
00262
00263 #define multi_remove_handle(A, B) \
00264 chk_multi_remove_handle((A), (B), (__FILE__), (__LINE__))
00265
00266
00267
00268 #define exe_multi_perform(A,B,Y,Z) do { \
00269 CURLMcode ec; \
00270 if((ec = curl_multi_perform((A), (B))) != CURLM_OK) { \
00271 fprintf(stderr, "%s:%d curl_multi_perform() failed, " \
00272 "with code %d (%s)\n", \
00273 (Y), (Z), (int)ec, curl_multi_strerror(ec)); \
00274 res = (int)ec; \
00275 } \
00276 else if(*((B)) < 0) { \
00277 fprintf(stderr, "%s:%d curl_multi_perform() succeeded, " \
00278 "but returned invalid running_handles value (%d)\n", \
00279 (Y), (Z), (int)*((B))); \
00280 res = TEST_ERR_NUM_HANDLES; \
00281 } \
00282 } WHILE_FALSE
00283
00284 #define res_multi_perform(A, B) \
00285 exe_multi_perform((A), (B), (__FILE__), (__LINE__))
00286
00287 #define chk_multi_perform(A, B, Y, Z) do { \
00288 exe_multi_perform((A), (B), (Y), (Z)); \
00289 if(res) \
00290 goto test_cleanup; \
00291 } WHILE_FALSE
00292
00293 #define multi_perform(A,B) \
00294 chk_multi_perform((A), (B), (__FILE__), (__LINE__))
00295
00296
00297
00298 #define exe_multi_fdset(A, B, C, D, E, Y, Z) do { \
00299 CURLMcode ec; \
00300 if((ec = curl_multi_fdset((A), (B), (C), (D), (E))) != CURLM_OK) { \
00301 fprintf(stderr, "%s:%d curl_multi_fdset() failed, " \
00302 "with code %d (%s)\n", \
00303 (Y), (Z), (int)ec, curl_multi_strerror(ec)); \
00304 res = (int)ec; \
00305 } \
00306 else if(*((E)) < -1) { \
00307 fprintf(stderr, "%s:%d curl_multi_fdset() succeeded, " \
00308 "but returned invalid max_fd value (%d)\n", \
00309 (Y), (Z), (int)*((E))); \
00310 res = TEST_ERR_NUM_HANDLES; \
00311 } \
00312 } WHILE_FALSE
00313
00314 #define res_multi_fdset(A, B, C, D, E) \
00315 exe_multi_fdset((A), (B), (C), (D), (E), (__FILE__), (__LINE__))
00316
00317 #define chk_multi_fdset(A, B, C, D, E, Y, Z) do { \
00318 exe_multi_fdset((A), (B), (C), (D), (E), (Y), (Z)); \
00319 if(res) \
00320 goto test_cleanup; \
00321 } WHILE_FALSE
00322
00323 #define multi_fdset(A, B, C, D, E) \
00324 chk_multi_fdset((A), (B), (C), (D), (E), (__FILE__), (__LINE__))
00325
00326
00327
00328 #define exe_multi_timeout(A,B,Y,Z) do { \
00329 CURLMcode ec; \
00330 if((ec = curl_multi_timeout((A), (B))) != CURLM_OK) { \
00331 fprintf(stderr, "%s:%d curl_multi_timeout() failed, " \
00332 "with code %d (%s)\n", \
00333 (Y), (Z), (int)ec, curl_multi_strerror(ec)); \
00334 res = (int)ec; \
00335 } \
00336 else if(*((B)) < -1L) { \
00337 fprintf(stderr, "%s:%d curl_multi_timeout() succeeded, " \
00338 "but returned invalid timeout value (%ld)\n", \
00339 (Y), (Z), (long)*((B))); \
00340 res = TEST_ERR_BAD_TIMEOUT; \
00341 } \
00342 } WHILE_FALSE
00343
00344 #define res_multi_timeout(A, B) \
00345 exe_multi_timeout((A), (B), (__FILE__), (__LINE__))
00346
00347 #define chk_multi_timeout(A, B, Y, Z) do { \
00348 exe_multi_timeout((A), (B), (Y), (Z)); \
00349 if(res) \
00350 goto test_cleanup; \
00351 } WHILE_FALSE
00352
00353 #define multi_timeout(A, B) \
00354 chk_multi_timeout((A), (B), (__FILE__), (__LINE__))
00355
00356
00357
00358 #define exe_select_test(A, B, C, D, E, Y, Z) do { \
00359 int ec; \
00360 if(select_wrapper((A), (B), (C), (D), (E)) == -1) { \
00361 ec = SOCKERRNO; \
00362 fprintf(stderr, "%s:%d select() failed, with " \
00363 "errno %d (%s)\n", \
00364 (Y), (Z), ec, strerror(ec)); \
00365 res = TEST_ERR_SELECT; \
00366 } \
00367 } WHILE_FALSE
00368
00369 #define res_select_test(A, B, C, D, E) \
00370 exe_select_test((A), (B), (C), (D), (E), (__FILE__), (__LINE__))
00371
00372 #define chk_select_test(A, B, C, D, E, Y, Z) do { \
00373 exe_select_test((A), (B), (C), (D), (E), (Y), (Z)); \
00374 if(res) \
00375 goto test_cleanup; \
00376 } WHILE_FALSE
00377
00378 #define select_test(A, B, C, D, E) \
00379 chk_select_test((A), (B), (C), (D), (E), (__FILE__), (__LINE__))
00380
00381
00382
00383 #define start_test_timing() do { \
00384 tv_test_start = tutil_tvnow(); \
00385 } WHILE_FALSE
00386
00387 #define exe_test_timedout(Y,Z) do { \
00388 if(tutil_tvdiff(tutil_tvnow(), tv_test_start) > TEST_HANG_TIMEOUT) { \
00389 fprintf(stderr, "%s:%d ABORTING TEST, since it seems " \
00390 "that it would have run forever.\n", (Y), (Z)); \
00391 res = TEST_ERR_RUNS_FOREVER; \
00392 } \
00393 } WHILE_FALSE
00394
00395 #define res_test_timedout() \
00396 exe_test_timedout((__FILE__), (__LINE__))
00397
00398 #define chk_test_timedout(Y, Z) do { \
00399 exe_test_timedout(Y, Z); \
00400 if(res) \
00401 goto test_cleanup; \
00402 } WHILE_FALSE
00403
00404 #define abort_on_test_timeout() \
00405 chk_test_timedout((__FILE__), (__LINE__))
00406
00407
00408
00409 #define exe_global_init(A,Y,Z) do { \
00410 CURLcode ec; \
00411 if((ec = curl_global_init((A))) != CURLE_OK) { \
00412 fprintf(stderr, "%s:%d curl_global_init() failed, " \
00413 "with code %d (%s)\n", \
00414 (Y), (Z), (int)ec, curl_easy_strerror(ec)); \
00415 res = (int)ec; \
00416 } \
00417 } WHILE_FALSE
00418
00419 #define res_global_init(A) \
00420 exe_global_init((A), (__FILE__), (__LINE__))
00421
00422 #define chk_global_init(A, Y, Z) do { \
00423 exe_global_init((A), (Y), (Z)); \
00424 if(res) \
00425 return res; \
00426 } WHILE_FALSE
00427
00428
00429
00430
00431 #define global_init(A) \
00432 chk_global_init((A), (__FILE__), (__LINE__))
00433
00434