lib1535.c
Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                  _   _ ____  _
00003  *  Project                     ___| | | |  _ \| |
00004  *                             / __| | | | |_) | |
00005  *                            | (__| |_| |  _ <| |___
00006  *                             \___|\___/|_| \_\_____|
00007  *
00008  * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
00009  *
00010  * This software is licensed as described in the file COPYING, which
00011  * you should have received as part of this distribution. The terms
00012  * are also available at https://curl.haxx.se/docs/copyright.html.
00013  *
00014  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
00015  * copies of the Software, and permit persons to whom the Software is
00016  * furnished to do so, under the terms of the COPYING file.
00017  *
00018  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
00019  * KIND, either express or implied.
00020  *
00021  ***************************************************************************/
00022 #include "test.h"
00023 
00024 #include "memdebug.h"
00025 
00026 /* Test CURLINFO_PROTOCOL */
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   /* Test that protocol is properly initialized on curl_easy_init.
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   /* Test that a protocol is properly set after receiving an HTTP resource.
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   /* Test that a protocol is properly initialized on curl_easy_duphandle.
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   /* Test that a protocol is properly initialized on curl_easy_reset.
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 }


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:05