Git init
[external/curl.git] / tests / libtest / lib513.c
1 /*****************************************************************************
2  *                                  _   _ ____  _
3  *  Project                     ___| | | |  _ \| |
4  *                             / __| | | | |_) | |
5  *                            | (__| |_| |  _ <| |___
6  *                             \___|\___/|_| \_\_____|
7  *
8  */
9
10 #include "test.h"
11
12 #include "memdebug.h"
13
14 static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *userp)
15 {
16   (void)ptr;
17   (void)size;
18   (void)nmemb;
19   (void)userp;
20   return CURL_READFUNC_ABORT;
21 }
22
23 int test(char *URL)
24 {
25   CURL *curl;
26   CURLcode res=CURLE_OK;
27
28   if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
29     fprintf(stderr, "curl_global_init() failed\n");
30     return TEST_ERR_MAJOR_BAD;
31   }
32
33   if ((curl = curl_easy_init()) == NULL) {
34     fprintf(stderr, "curl_easy_init() failed\n");
35     curl_global_cleanup();
36     return TEST_ERR_MAJOR_BAD;
37   }
38
39   /* First set the URL that is about to receive our POST. */
40   test_setopt(curl, CURLOPT_URL, URL);
41
42   /* Now specify we want to POST data */
43   test_setopt(curl, CURLOPT_POST, 1L);
44
45   /* Set the expected POST size */
46   test_setopt(curl, CURLOPT_POSTFIELDSIZE, 1L);
47
48   /* we want to use our own read function */
49   test_setopt(curl, CURLOPT_READFUNCTION, read_callback);
50
51   /* pointer to pass to our read function */
52   test_setopt(curl, CURLOPT_INFILE, NULL);
53
54   /* get verbose debug output please */
55   test_setopt(curl, CURLOPT_VERBOSE, 1L);
56
57   /* include headers in the output */
58   test_setopt(curl, CURLOPT_HEADER, 1L);
59
60   /* Perform the request, res will get the return code */
61   res = curl_easy_perform(curl);
62
63 test_cleanup:
64
65   /* always cleanup */
66   curl_easy_cleanup(curl);
67   curl_global_cleanup();
68
69   return (int)res;
70 }