1 /***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) 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
unit_setup(void)31 static CURLcode unit_setup(void)
32 {
33 CURLcode res = CURLE_OK;
34 global_init(CURL_GLOBAL_ALL);
35 return res;
36 }
37
unit_stop(void)38 static void unit_stop(void)
39 {
40 curl_global_cleanup();
41 }
42
43 UNITTEST_START
44 {
45 CURLcode rc;
46 struct Curl_easy *empty;
47 const char *hostname = "hostname";
48 enum dupstring i;
49 char *userstr = NULL;
50 char *passwdstr = NULL;
51
52 bool async = FALSE;
53 bool protocol_connect = FALSE;
54
55 rc = Curl_open(&empty);
56 if(rc)
57 goto unit_test_abort;
58 fail_unless(rc == CURLE_OK, "Curl_open() failed");
59
60 rc = Curl_connect(empty, &async, &protocol_connect);
61 fail_unless(rc == CURLE_URL_MALFORMAT,
62 "Curl_connect() failed to return CURLE_URL_MALFORMAT");
63
64 fail_unless(empty->magic == CURLEASY_MAGIC_NUMBER,
65 "empty->magic should be equal to CURLEASY_MAGIC_NUMBER");
66
67 /* double invoke to ensure no dependency on internal state */
68 rc = Curl_connect(empty, &async, &protocol_connect);
69 fail_unless(rc == CURLE_URL_MALFORMAT,
70 "Curl_connect() failed to return CURLE_URL_MALFORMAT");
71
72 rc = Curl_init_userdefined(empty);
73 fail_unless(rc == CURLE_OK, "Curl_userdefined() failed");
74
75 rc = Curl_init_do(empty, empty->conn);
76 fail_unless(rc == CURLE_OK, "Curl_init_do() failed");
77
78 rc = Curl_parse_login_details(hostname, strlen(hostname),
79 &userstr, &passwdstr, NULL);
80 fail_unless(rc == CURLE_OK,
81 "Curl_parse_login_details() failed");
82 free(userstr);
83 free(passwdstr);
84
85 Curl_freeset(empty);
86 for(i = (enum dupstring)0; i < STRING_LAST; i++) {
87 fail_unless(empty->set.str[i] == NULL,
88 "Curl_free() did not set to NULL");
89 }
90
91 rc = Curl_close(&empty);
92 fail_unless(rc == CURLE_OK, "Curl_close() failed");
93
94 }
95 UNITTEST_STOP
96