sources: update source headers
[platform/upstream/curl.git] / tests / libtest / lib578.c
1 /***************************************************************************
2  *                                  _   _ ____  _
3  *  Project                     ___| | | |  _ \| |
4  *                             / __| | | | |_) | |
5  *                            | (__| |_| |  _ <| |___
6  *                             \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 1998 - 2011, 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 http://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
23 #include "test.h"
24
25 #include "memdebug.h"
26
27 /* The size of data should be kept below MAX_INITIAL_POST_SIZE! */
28 static char data[]="this is a short string.\n";
29
30 static size_t data_size = sizeof(data) / sizeof(char);
31
32 static int progress_callback(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow)
33 {
34   FILE *moo = fopen(libtest_arg2, "wb");
35
36   (void)clientp; /* UNUSED */
37   (void)dltotal; /* UNUSED */
38   (void)dlnow; /* UNUSED */
39
40   if(moo) {
41     if ((size_t)ultotal == data_size && (size_t)ulnow == data_size)
42       fprintf(moo, "PASSED, UL data matched data size\n");
43     else
44       fprintf(moo, "Progress callback called with UL %f out of %f\n", ulnow, ultotal);
45     fclose(moo);
46   }
47   return 0;
48 }
49
50 int test(char *URL)
51 {
52   CURL *curl;
53   CURLcode res=CURLE_OK;
54
55   if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
56     fprintf(stderr, "curl_global_init() failed\n");
57     return TEST_ERR_MAJOR_BAD;
58   }
59
60   if ((curl = curl_easy_init()) == NULL) {
61     fprintf(stderr, "curl_easy_init() failed\n");
62     curl_global_cleanup();
63     return TEST_ERR_MAJOR_BAD;
64   }
65
66   /* First set the URL that is about to receive our POST. */
67   test_setopt(curl, CURLOPT_URL, URL);
68
69   /* Now specify we want to POST data */
70   test_setopt(curl, CURLOPT_POST, 1L);
71
72 #ifdef CURL_DOES_CONVERSIONS
73   /* Convert the POST data to ASCII */
74   test_setopt(curl, CURLOPT_TRANSFERTEXT, 1L);
75 #endif
76
77   /* Set the expected POST size */
78   test_setopt(curl, CURLOPT_POSTFIELDSIZE, data_size);
79   test_setopt(curl, CURLOPT_POSTFIELDS, data);
80
81   /* we want to use our own progress function */
82   test_setopt(curl, CURLOPT_NOPROGRESS, 0L);
83   test_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_callback);
84
85   /* pointer to pass to our read function */
86
87   /* get verbose debug output please */
88   test_setopt(curl, CURLOPT_VERBOSE, 1L);
89
90   /* include headers in the output */
91   test_setopt(curl, CURLOPT_HEADER, 1L);
92
93   /* Perform the request, res will get the return code */
94   res = curl_easy_perform(curl);
95
96 test_cleanup:
97
98   /* always cleanup */
99   curl_easy_cleanup(curl);
100   curl_global_cleanup();
101
102   return res;
103 }