00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "test.h"
00023
00024 #include "memdebug.h"
00025
00026
00027
00028 int test(char *URL)
00029 {
00030 CURL *curl, *dupe = NULL;
00031 long protocol;
00032 int res = CURLE_OK;
00033
00034 global_init(CURL_GLOBAL_ALL);
00035
00036 easy_init(curl);
00037
00038
00039
00040
00041 res = curl_easy_getinfo(curl, CURLINFO_PROTOCOL, &protocol);
00042 if(res) {
00043 fprintf(stderr, "%s:%d curl_easy_getinfo() failed with code %d (%s)\n",
00044 __FILE__, __LINE__, res, curl_easy_strerror(res));
00045 goto test_cleanup;
00046 }
00047 if(protocol != 0) {
00048 fprintf(stderr, "%s:%d protocol init failed; expected 0 but is %ld\n",
00049 __FILE__, __LINE__, protocol);
00050 res = CURLE_FAILED_INIT;
00051 goto test_cleanup;
00052 }
00053
00054 easy_setopt(curl, CURLOPT_URL, URL);
00055
00056 res = curl_easy_perform(curl);
00057 if(res) {
00058 fprintf(stderr, "%s:%d curl_easy_perform() failed with code %d (%s)\n",
00059 __FILE__, __LINE__, res, curl_easy_strerror(res));
00060 goto test_cleanup;
00061 }
00062
00063
00064
00065
00066 res = curl_easy_getinfo(curl, CURLINFO_PROTOCOL, &protocol);
00067 if(res) {
00068 fprintf(stderr, "%s:%d curl_easy_getinfo() failed with code %d (%s)\n",
00069 __FILE__, __LINE__, res, curl_easy_strerror(res));
00070 goto test_cleanup;
00071 }
00072 if(protocol != CURLPROTO_HTTP) {
00073 fprintf(stderr, "%s:%d protocol of http resource is incorrect; "
00074 "expected %ld but is %ld\n",
00075 __FILE__, __LINE__, CURLPROTO_HTTP, protocol);
00076 res = CURLE_HTTP_RETURNED_ERROR;
00077 goto test_cleanup;
00078 }
00079
00080
00081
00082
00083 dupe = curl_easy_duphandle(curl);
00084 if(!dupe) {
00085 fprintf(stderr, "%s:%d curl_easy_duphandle() failed\n",
00086 __FILE__, __LINE__);
00087 res = CURLE_FAILED_INIT;
00088 goto test_cleanup;
00089 }
00090
00091 res = curl_easy_getinfo(dupe, CURLINFO_PROTOCOL, &protocol);
00092 if(res) {
00093 fprintf(stderr, "%s:%d curl_easy_getinfo() failed with code %d (%s)\n",
00094 __FILE__, __LINE__, res, curl_easy_strerror(res));
00095 goto test_cleanup;
00096 }
00097 if(protocol != 0) {
00098 fprintf(stderr, "%s:%d protocol init failed; expected 0 but is %ld\n",
00099 __FILE__, __LINE__, protocol);
00100 res = CURLE_FAILED_INIT;
00101 goto test_cleanup;
00102 }
00103
00104
00105
00106
00107
00108 curl_easy_reset(curl);
00109
00110 res = curl_easy_getinfo(curl, CURLINFO_PROTOCOL, &protocol);
00111 if(res) {
00112 fprintf(stderr, "%s:%d curl_easy_getinfo() failed with code %d (%s)\n",
00113 __FILE__, __LINE__, res, curl_easy_strerror(res));
00114 goto test_cleanup;
00115 }
00116 if(protocol != 0) {
00117 fprintf(stderr, "%s:%d protocol init failed; expected 0 but is %ld\n",
00118 __FILE__, __LINE__, protocol);
00119 res = CURLE_FAILED_INIT;
00120 goto test_cleanup;
00121 }
00122
00123 test_cleanup:
00124 curl_easy_cleanup(curl);
00125 curl_easy_cleanup(dupe);
00126 curl_global_cleanup();
00127 return res;
00128 }