诸暨麻将添加redis
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

427 lines
16 KiB

  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
  9. *
  10. * This software is licensed as described in the file COPYING, which
  11. * you should have received as part of this distribution. The terms
  12. * are also available at http://curl.haxx.se/docs/copyright.html.
  13. *
  14. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. * copies of the Software, and permit persons to whom the Software is
  16. * furnished to do so, under the terms of the COPYING file.
  17. *
  18. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. * KIND, either express or implied.
  20. *
  21. ***************************************************************************/
  22. /* Now include the curl_setup.h file from libcurl's private libdir (the source
  23. version, but that might include "curl_config.h" from the build dir so we
  24. need both of them in the include path), so that we get good in-depth
  25. knowledge about the system we're building this on */
  26. #define CURL_NO_OLDIES
  27. #include "curl_setup.h"
  28. #include <curl/curl.h>
  29. #ifdef HAVE_SYS_SELECT_H
  30. /* since so many tests use select(), we can just as well include it here */
  31. #include <sys/select.h>
  32. #endif
  33. #ifdef TPF
  34. # include "select.h"
  35. #endif
  36. #define test_setopt(A,B,C) \
  37. if((res = curl_easy_setopt((A),(B),(C))) != CURLE_OK) goto test_cleanup
  38. #define test_multi_setopt(A,B,C) \
  39. if((res = curl_multi_setopt((A),(B),(C))) != CURLE_OK) goto test_cleanup
  40. extern char *libtest_arg2; /* set by first.c to the argv[2] or NULL */
  41. extern char *libtest_arg3; /* set by first.c to the argv[3] or NULL */
  42. /* argc and argv as passed in to the main() function */
  43. extern int test_argc;
  44. extern char **test_argv;
  45. extern struct timeval tv_test_start; /* for test timing */
  46. extern int select_wrapper(int nfds, fd_set *rd, fd_set *wr, fd_set *exc,
  47. struct timeval *tv);
  48. extern int test(char *URL); /* the actual test function provided by each
  49. individual libXXX.c file */
  50. #ifdef UNITTESTS
  51. extern int unitfail;
  52. #endif
  53. /*
  54. ** TEST_ERR_* values must be greater than CURL_LAST CURLcode in order
  55. ** to avoid confusion with any CURLcode or CURLMcode. These TEST_ERR_*
  56. ** codes are returned to signal test specific situations and should
  57. ** not get mixed with CURLcode or CURLMcode values.
  58. **
  59. ** For portability reasons TEST_ERR_* values should be less than 127.
  60. */
  61. #define TEST_ERR_MAJOR_BAD 126
  62. #define TEST_ERR_RUNS_FOREVER 125
  63. #define TEST_ERR_EASY_INIT 124
  64. #define TEST_ERR_MULTI_INIT 123
  65. #define TEST_ERR_NUM_HANDLES 122
  66. #define TEST_ERR_SELECT 121
  67. #define TEST_ERR_SUCCESS 120
  68. #define TEST_ERR_FAILURE 119
  69. #define TEST_ERR_USAGE 118
  70. #define TEST_ERR_FOPEN 117
  71. #define TEST_ERR_FSTAT 116
  72. #define TEST_ERR_BAD_TIMEOUT 115
  73. /*
  74. ** Macros for test source code readability/maintainability.
  75. **
  76. ** All of the following macros require that an int data type 'res' variable
  77. ** exists in scope where macro is used, and that it has been initialized to
  78. ** zero before the macro is used.
  79. **
  80. ** exe_* and chk_* macros are helper macros not intended to be used from
  81. ** outside of this header file. Arguments 'Y' and 'Z' of these represent
  82. ** source code file and line number, while Arguments 'A', 'B', etc, are
  83. ** the arguments used to actually call a libcurl function.
  84. **
  85. ** All easy_* and multi_* macros call a libcurl function and evaluate if
  86. ** the function has succeeded or failed. When the function succeeds 'res'
  87. ** variable is not set nor cleared and program continues normal flow. On
  88. ** the other hand if function fails 'res' variable is set and a jump to
  89. ** label 'test_cleanup' is performed.
  90. **
  91. ** Every easy_* and multi_* macros have a res_easy_* and res_multi_* macro
  92. ** counterpart that operates in tha same way with the exception that no
  93. ** jump takes place in case of failure. res_easy_* and res_multi_* macros
  94. ** should be immediately followed by checking if 'res' variable has been
  95. ** set.
  96. **
  97. ** 'res' variable when set will hold a CURLcode, CURLMcode, or any of the
  98. ** TEST_ERR_* values defined above. It is advisable to return this value
  99. ** as test result.
  100. */
  101. /* ---------------------------------------------------------------- */
  102. #define exe_easy_init(A,Y,Z) do { \
  103. if(((A) = curl_easy_init()) == NULL) { \
  104. fprintf(stderr, "%s:%d curl_easy_init() failed\n", (Y), (Z)); \
  105. res = TEST_ERR_EASY_INIT; \
  106. } \
  107. } WHILE_FALSE
  108. #define res_easy_init(A) \
  109. exe_easy_init((A),(__FILE__),(__LINE__))
  110. #define chk_easy_init(A,Y,Z) do { \
  111. exe_easy_init((A),(Y),(Z)); \
  112. if(res) \
  113. goto test_cleanup; \
  114. } WHILE_FALSE
  115. #define easy_init(A) \
  116. chk_easy_init((A),(__FILE__),(__LINE__))
  117. /* ---------------------------------------------------------------- */
  118. #define exe_multi_init(A,Y,Z) do { \
  119. if(((A) = curl_multi_init()) == NULL) { \
  120. fprintf(stderr, "%s:%d curl_multi_init() failed\n", (Y), (Z)); \
  121. res = TEST_ERR_MULTI_INIT; \
  122. } \
  123. } WHILE_FALSE
  124. #define res_multi_init(A) \
  125. exe_multi_init((A),(__FILE__),(__LINE__))
  126. #define chk_multi_init(A,Y,Z) do { \
  127. exe_multi_init((A),(Y),(Z)); \
  128. if(res) \
  129. goto test_cleanup; \
  130. } WHILE_FALSE
  131. #define multi_init(A) \
  132. chk_multi_init((A),(__FILE__),(__LINE__))
  133. /* ---------------------------------------------------------------- */
  134. #define exe_easy_setopt(A,B,C,Y,Z) do { \
  135. CURLcode ec; \
  136. if((ec = curl_easy_setopt((A),(B),(C))) != CURLE_OK) { \
  137. fprintf(stderr, "%s:%d curl_easy_setopt() failed, " \
  138. "with code %d (%s)\n", \
  139. (Y), (Z), (int)ec, curl_easy_strerror(ec)); \
  140. res = (int)ec; \
  141. } \
  142. } WHILE_FALSE
  143. #define res_easy_setopt(A,B,C) \
  144. exe_easy_setopt((A),(B),(C),(__FILE__),(__LINE__))
  145. #define chk_easy_setopt(A,B,C,Y,Z) do { \
  146. exe_easy_setopt((A),(B),(C),(Y),(Z)); \
  147. if(res) \
  148. goto test_cleanup; \
  149. } WHILE_FALSE
  150. #define easy_setopt(A,B,C) \
  151. chk_easy_setopt((A),(B),(C),(__FILE__),(__LINE__))
  152. /* ---------------------------------------------------------------- */
  153. #define exe_multi_setopt(A,B,C,Y,Z) do { \
  154. CURLMcode ec; \
  155. if((ec = curl_multi_setopt((A),(B),(C))) != CURLM_OK) { \
  156. fprintf(stderr, "%s:%d curl_multi_setopt() failed, " \
  157. "with code %d (%s)\n", \
  158. (Y), (Z), (int)ec, curl_multi_strerror(ec)); \
  159. res = (int)ec; \
  160. } \
  161. } WHILE_FALSE
  162. #define res_multi_setopt(A,B,C) \
  163. exe_multi_setopt((A),(B),(C),(__FILE__),(__LINE__))
  164. #define chk_multi_setopt(A,B,C,Y,Z) do { \
  165. exe_multi_setopt((A),(B),(C),(Y),(Z)); \
  166. if(res) \
  167. goto test_cleanup; \
  168. } WHILE_FALSE
  169. #define multi_setopt(A,B,C) \
  170. chk_multi_setopt((A),(B),(C),(__FILE__),(__LINE__))
  171. /* ---------------------------------------------------------------- */
  172. #define exe_multi_add_handle(A,B,Y,Z) do { \
  173. CURLMcode ec; \
  174. if((ec = curl_multi_add_handle((A),(B))) != CURLM_OK) { \
  175. fprintf(stderr, "%s:%d curl_multi_add_handle() failed, " \
  176. "with code %d (%s)\n", \
  177. (Y), (Z), (int)ec, curl_multi_strerror(ec)); \
  178. res = (int)ec; \
  179. } \
  180. } WHILE_FALSE
  181. #define res_multi_add_handle(A,B) \
  182. exe_multi_add_handle((A),(B),(__FILE__),(__LINE__))
  183. #define chk_multi_add_handle(A,B,Y,Z) do { \
  184. exe_multi_add_handle((A),(B),(Y),(Z)); \
  185. if(res) \
  186. goto test_cleanup; \
  187. } WHILE_FALSE
  188. #define multi_add_handle(A,B) \
  189. chk_multi_add_handle((A),(B),(__FILE__),(__LINE__))
  190. /* ---------------------------------------------------------------- */
  191. #define exe_multi_remove_handle(A,B,Y,Z) do { \
  192. CURLMcode ec; \
  193. if((ec = curl_multi_remove_handle((A),(B))) != CURLM_OK) { \
  194. fprintf(stderr, "%s:%d curl_multi_remove_handle() failed, " \
  195. "with code %d (%s)\n", \
  196. (Y), (Z), (int)ec, curl_multi_strerror(ec)); \
  197. res = (int)ec; \
  198. } \
  199. } WHILE_FALSE
  200. #define res_multi_remove_handle(A,B) \
  201. exe_multi_remove_handle((A),(B),(__FILE__),(__LINE__))
  202. #define chk_multi_remove_handle(A,B,Y,Z) do { \
  203. exe_multi_remove_handle((A),(B),(Y),(Z)); \
  204. if(res) \
  205. goto test_cleanup; \
  206. } WHILE_FALSE
  207. #define multi_remove_handle(A,B) \
  208. chk_multi_remove_handle((A),(B),(__FILE__),(__LINE__))
  209. /* ---------------------------------------------------------------- */
  210. #define exe_multi_perform(A,B,Y,Z) do { \
  211. CURLMcode ec; \
  212. if((ec = curl_multi_perform((A),(B))) != CURLM_OK) { \
  213. fprintf(stderr, "%s:%d curl_multi_perform() failed, " \
  214. "with code %d (%s)\n", \
  215. (Y), (Z), (int)ec, curl_multi_strerror(ec)); \
  216. res = (int)ec; \
  217. } \
  218. else if(*((B)) < 0) { \
  219. fprintf(stderr, "%s:%d curl_multi_perform() succeeded, " \
  220. "but returned invalid running_handles value (%d)\n", \
  221. (Y), (Z), (int)*((B))); \
  222. res = TEST_ERR_NUM_HANDLES; \
  223. } \
  224. } WHILE_FALSE
  225. #define res_multi_perform(A,B) \
  226. exe_multi_perform((A),(B),(__FILE__),(__LINE__))
  227. #define chk_multi_perform(A,B,Y,Z) do { \
  228. exe_multi_perform((A),(B),(Y),(Z)); \
  229. if(res) \
  230. goto test_cleanup; \
  231. } WHILE_FALSE
  232. #define multi_perform(A,B) \
  233. chk_multi_perform((A),(B),(__FILE__),(__LINE__))
  234. /* ---------------------------------------------------------------- */
  235. #define exe_multi_fdset(A,B,C,D,E,Y,Z) do { \
  236. CURLMcode ec; \
  237. if((ec = curl_multi_fdset((A),(B),(C),(D),(E))) != CURLM_OK) { \
  238. fprintf(stderr, "%s:%d curl_multi_fdset() failed, " \
  239. "with code %d (%s)\n", \
  240. (Y), (Z), (int)ec, curl_multi_strerror(ec)); \
  241. res = (int)ec; \
  242. } \
  243. else if(*((E)) < -1) { \
  244. fprintf(stderr, "%s:%d curl_multi_fdset() succeeded, " \
  245. "but returned invalid max_fd value (%d)\n", \
  246. (Y), (Z), (int)*((E))); \
  247. res = TEST_ERR_NUM_HANDLES; \
  248. } \
  249. } WHILE_FALSE
  250. #define res_multi_fdset(A,B,C,D,E) \
  251. exe_multi_fdset((A),(B),(C),(D),(E),(__FILE__),(__LINE__))
  252. #define chk_multi_fdset(A,B,C,D,E,Y,Z) do { \
  253. exe_multi_fdset((A),(B),(C),(D),(E),(Y),(Z)); \
  254. if(res) \
  255. goto test_cleanup; \
  256. } WHILE_FALSE
  257. #define multi_fdset(A,B,C,D,E) \
  258. chk_multi_fdset((A),(B),(C),(D),(E),(__FILE__),(__LINE__))
  259. /* ---------------------------------------------------------------- */
  260. #define exe_multi_timeout(A,B,Y,Z) do { \
  261. CURLMcode ec; \
  262. if((ec = curl_multi_timeout((A),(B))) != CURLM_OK) { \
  263. fprintf(stderr, "%s:%d curl_multi_timeout() failed, " \
  264. "with code %d (%s)\n", \
  265. (Y), (Z), (int)ec, curl_multi_strerror(ec)); \
  266. res = (int)ec; \
  267. } \
  268. else if(*((B)) < -1L) { \
  269. fprintf(stderr, "%s:%d curl_multi_timeout() succeeded, " \
  270. "but returned invalid timeout value (%ld)\n", \
  271. (Y), (Z), (long)*((B))); \
  272. res = TEST_ERR_BAD_TIMEOUT; \
  273. } \
  274. } WHILE_FALSE
  275. #define res_multi_timeout(A,B) \
  276. exe_multi_timeout((A),(B),(__FILE__),(__LINE__))
  277. #define chk_multi_timeout(A,B,Y,Z) do { \
  278. exe_multi_timeout((A),(B),(Y),(Z)); \
  279. if(res) \
  280. goto test_cleanup; \
  281. } WHILE_FALSE
  282. #define multi_timeout(A,B) \
  283. chk_multi_timeout((A),(B),(__FILE__),(__LINE__))
  284. /* ---------------------------------------------------------------- */
  285. #define exe_select_test(A,B,C,D,E,Y,Z) do { \
  286. int ec; \
  287. if(select_wrapper((A),(B),(C),(D),(E)) == -1 ) { \
  288. ec = SOCKERRNO; \
  289. fprintf(stderr, "%s:%d select() failed, with " \
  290. "errno %d (%s)\n", \
  291. (Y), (Z), ec, strerror(ec)); \
  292. res = TEST_ERR_SELECT; \
  293. } \
  294. } WHILE_FALSE
  295. #define res_select_test(A,B,C,D,E) \
  296. exe_select_test((A),(B),(C),(D),(E),(__FILE__),(__LINE__))
  297. #define chk_select_test(A,B,C,D,E,Y,Z) do { \
  298. exe_select_test((A),(B),(C),(D),(E),(Y),(Z)); \
  299. if(res) \
  300. goto test_cleanup; \
  301. } WHILE_FALSE
  302. #define select_test(A,B,C,D,E) \
  303. chk_select_test((A),(B),(C),(D),(E),(__FILE__),(__LINE__))
  304. /* ---------------------------------------------------------------- */
  305. #define start_test_timing() do { \
  306. tv_test_start = tutil_tvnow(); \
  307. } WHILE_FALSE
  308. #define exe_test_timedout(Y,Z) do { \
  309. if(tutil_tvdiff(tutil_tvnow(), tv_test_start) > TEST_HANG_TIMEOUT) { \
  310. fprintf(stderr, "%s:%d ABORTING TEST, since it seems " \
  311. "that it would have run forever.\n", (Y), (Z)); \
  312. res = TEST_ERR_RUNS_FOREVER; \
  313. } \
  314. } WHILE_FALSE
  315. #define res_test_timedout() \
  316. exe_test_timedout((__FILE__),(__LINE__))
  317. #define chk_test_timedout(Y,Z) do { \
  318. exe_test_timedout(Y,Z); \
  319. if(res) \
  320. goto test_cleanup; \
  321. } WHILE_FALSE
  322. #define abort_on_test_timeout() \
  323. chk_test_timedout((__FILE__),(__LINE__))
  324. /* ---------------------------------------------------------------- */
  325. #define exe_global_init(A,Y,Z) do { \
  326. CURLcode ec; \
  327. if((ec = curl_global_init((A))) != CURLE_OK) { \
  328. fprintf(stderr, "%s:%d curl_global_init() failed, " \
  329. "with code %d (%s)\n", \
  330. (Y), (Z), (int)ec, curl_easy_strerror(ec)); \
  331. res = (int)ec; \
  332. } \
  333. } WHILE_FALSE
  334. #define res_global_init(A) \
  335. exe_global_init((A),(__FILE__),(__LINE__))
  336. #define chk_global_init(A,Y,Z) do { \
  337. exe_global_init((A),(Y),(Z)); \
  338. if(res) \
  339. return res; \
  340. } WHILE_FALSE
  341. /* global_init() is different than other macros. In case of
  342. failure it 'return's instead of going to 'test_cleanup'. */
  343. #define global_init(A) \
  344. chk_global_init((A),(__FILE__),(__LINE__))
  345. /* ---------------------------------------------------------------- */