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