Git init
[external/curl.git] / tests / libtest / lib566.c
1 /*****************************************************************************
2  *                                  _   _ ____  _
3  *  Project                     ___| | | |  _ \| |
4  *                             / __| | | | |_) | |
5  *                            | (__| |_| |  _ <| |___
6  *                             \___|\___/|_| \_\_____|
7  *
8  */
9
10 #include "test.h"
11
12 #include "memdebug.h"
13
14 int test(char *URL)
15 {
16   CURLcode res;
17   CURL *curl;
18
19   double content_length = 3;
20
21   if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
22     fprintf(stderr, "curl_global_init() failed\n");
23     return TEST_ERR_MAJOR_BAD;
24   }
25
26   if ((curl = curl_easy_init()) == NULL) {
27     fprintf(stderr, "curl_easy_init() failed\n");
28     curl_global_cleanup();
29     return TEST_ERR_MAJOR_BAD;
30   }
31
32   test_setopt(curl, CURLOPT_URL, URL);
33   test_setopt(curl, CURLOPT_HEADER, 1L);
34
35   res = curl_easy_perform(curl);
36
37   if(!res) {
38     FILE *moo;
39     res = curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD,
40                             &content_length);
41     moo = fopen(libtest_arg2, "wb");
42     if(moo) {
43       fprintf(moo, "CL: %.0f\n", content_length);
44       fclose(moo);
45     }
46   }
47
48 test_cleanup:
49
50   curl_easy_cleanup(curl);
51   curl_global_cleanup();
52
53   return (int)res;
54 }
55