Return to lib1553.c CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / curl / tests / libtest |
1.1 ! misho 1: /*************************************************************************** ! 2: * _ _ ____ _ ! 3: * Project ___| | | | _ \| | ! 4: * / __| | | | |_) | | ! 5: * | (__| |_| | _ <| |___ ! 6: * \___|\___/|_| \_\_____| ! 7: * ! 8: * Copyright (C) 1998 - 2017, 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 https://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: #include "test.h" ! 23: ! 24: #include "testutil.h" ! 25: #include "warnless.h" ! 26: #include "memdebug.h" ! 27: ! 28: #define TEST_HANG_TIMEOUT 60 * 1000 ! 29: ! 30: static int xferinfo(void *p, ! 31: curl_off_t dltotal, curl_off_t dlnow, ! 32: curl_off_t ultotal, curl_off_t ulnow) ! 33: { ! 34: (void)p; ! 35: (void)dlnow; ! 36: (void)dltotal; ! 37: (void)ulnow; ! 38: (void)ultotal; ! 39: fprintf(stderr, "xferinfo fail!\n"); ! 40: return 1; /* fail as fast as we can */ ! 41: } ! 42: ! 43: int test(char *URL) ! 44: { ! 45: CURL *curls = NULL; ! 46: CURLM *multi = NULL; ! 47: int still_running; ! 48: int i = 0; ! 49: int res = 0; ! 50: curl_mimepart *field = NULL; ! 51: curl_mime *mime = NULL; ! 52: int counter = 1; ! 53: ! 54: start_test_timing(); ! 55: ! 56: global_init(CURL_GLOBAL_ALL); ! 57: ! 58: multi_init(multi); ! 59: ! 60: easy_init(curls); ! 61: ! 62: mime = curl_mime_init(curls); ! 63: field = curl_mime_addpart(mime); ! 64: curl_mime_name(field, "name"); ! 65: curl_mime_data(field, "value", CURL_ZERO_TERMINATED); ! 66: ! 67: easy_setopt(curls, CURLOPT_URL, URL); ! 68: easy_setopt(curls, CURLOPT_HEADER, 1L); ! 69: easy_setopt(curls, CURLOPT_VERBOSE, 1L); ! 70: easy_setopt(curls, CURLOPT_MIMEPOST, mime); ! 71: easy_setopt(curls, CURLOPT_USERPWD, "u:s"); ! 72: easy_setopt(curls, CURLOPT_XFERINFOFUNCTION, xferinfo); ! 73: easy_setopt(curls, CURLOPT_NOPROGRESS, 1L); ! 74: ! 75: multi_add_handle(multi, curls); ! 76: ! 77: multi_perform(multi, &still_running); ! 78: ! 79: abort_on_test_timeout(); ! 80: ! 81: while(still_running && counter--) { ! 82: int num; ! 83: res = curl_multi_wait(multi, NULL, 0, TEST_HANG_TIMEOUT, &num); ! 84: if(res != CURLM_OK) { ! 85: printf("curl_multi_wait() returned %d\n", res); ! 86: res = TEST_ERR_MAJOR_BAD; ! 87: goto test_cleanup; ! 88: } ! 89: ! 90: abort_on_test_timeout(); ! 91: ! 92: multi_perform(multi, &still_running); ! 93: ! 94: abort_on_test_timeout(); ! 95: } ! 96: ! 97: test_cleanup: ! 98: ! 99: curl_mime_free(mime); ! 100: curl_multi_remove_handle(multi, curls); ! 101: curl_multi_cleanup(multi); ! 102: curl_easy_cleanup(curls); ! 103: curl_global_cleanup(); ! 104: ! 105: if(res) ! 106: i = res; ! 107: ! 108: return i; /* return the final return code */ ! 109: }