xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame^] | 1 | /*************************************************************************** |
| 2 | * _ _ ____ _ |
| 3 | * Project ___| | | | _ \| | |
| 4 | * / __| | | | |_) | | |
| 5 | * | (__| |_| | _ <| |___ |
| 6 | * \___|\___/|_| \_\_____| |
| 7 | * |
| 8 | * Copyright (C) 1998 - 2022, 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 https://curl.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 | * SPDX-License-Identifier: curl |
| 22 | * |
| 23 | ***************************************************************************/ |
| 24 | #include "curlcheck.h" |
| 25 | |
| 26 | #include "urldata.h" |
| 27 | #include "url.h" |
| 28 | |
| 29 | #include "memdebug.h" /* LAST include file */ |
| 30 | |
| 31 | static CURLcode unit_setup(void) |
| 32 | { |
| 33 | CURLcode res = CURLE_OK; |
| 34 | global_init(CURL_GLOBAL_ALL); |
| 35 | return res; |
| 36 | } |
| 37 | |
| 38 | static void unit_stop(void) |
| 39 | { |
| 40 | curl_global_cleanup(); |
| 41 | } |
| 42 | |
| 43 | UNITTEST_START |
| 44 | { |
| 45 | int rc; |
| 46 | struct Curl_easy *empty; |
| 47 | const char *hostname = "hostname"; |
| 48 | enum dupstring i; |
| 49 | |
| 50 | bool async = FALSE; |
| 51 | bool protocol_connect = FALSE; |
| 52 | |
| 53 | rc = Curl_open(&empty); |
| 54 | if(rc) |
| 55 | goto unit_test_abort; |
| 56 | fail_unless(rc == CURLE_OK, "Curl_open() failed"); |
| 57 | |
| 58 | rc = Curl_connect(empty, &async, &protocol_connect); |
| 59 | fail_unless(rc == CURLE_URL_MALFORMAT, |
| 60 | "Curl_connect() failed to return CURLE_URL_MALFORMAT"); |
| 61 | |
| 62 | fail_unless(empty->magic == CURLEASY_MAGIC_NUMBER, |
| 63 | "empty->magic should be equal to CURLEASY_MAGIC_NUMBER"); |
| 64 | |
| 65 | /* double invoke to ensure no dependency on internal state */ |
| 66 | rc = Curl_connect(empty, &async, &protocol_connect); |
| 67 | fail_unless(rc == CURLE_URL_MALFORMAT, |
| 68 | "Curl_connect() failed to return CURLE_URL_MALFORMAT"); |
| 69 | |
| 70 | rc = Curl_init_userdefined(empty); |
| 71 | fail_unless(rc == CURLE_OK, "Curl_userdefined() failed"); |
| 72 | |
| 73 | rc = Curl_init_do(empty, empty->conn); |
| 74 | fail_unless(rc == CURLE_OK, "Curl_init_do() failed"); |
| 75 | |
| 76 | rc = Curl_parse_login_details( |
| 77 | hostname, strlen(hostname), NULL, NULL, NULL); |
| 78 | fail_unless(rc == CURLE_OK, |
| 79 | "Curl_parse_login_details() failed"); |
| 80 | |
| 81 | Curl_freeset(empty); |
| 82 | for(i = (enum dupstring)0; i < STRING_LAST; i++) { |
| 83 | fail_unless(empty->set.str[i] == NULL, |
| 84 | "Curl_free() did not set to NULL"); |
| 85 | } |
| 86 | |
| 87 | Curl_free_request_state(empty); |
| 88 | |
| 89 | rc = Curl_close(&empty); |
| 90 | fail_unless(rc == CURLE_OK, "Curl_close() failed"); |
| 91 | |
| 92 | } |
| 93 | UNITTEST_STOP |