113498266Sopenharmony_ci/***************************************************************************
213498266Sopenharmony_ci *                                  _   _ ____  _
313498266Sopenharmony_ci *  Project                     ___| | | |  _ \| |
413498266Sopenharmony_ci *                             / __| | | | |_) | |
513498266Sopenharmony_ci *                            | (__| |_| |  _ <| |___
613498266Sopenharmony_ci *                             \___|\___/|_| \_\_____|
713498266Sopenharmony_ci *
813498266Sopenharmony_ci * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
913498266Sopenharmony_ci *
1013498266Sopenharmony_ci * This software is licensed as described in the file COPYING, which
1113498266Sopenharmony_ci * you should have received as part of this distribution. The terms
1213498266Sopenharmony_ci * are also available at https://curl.se/docs/copyright.html.
1313498266Sopenharmony_ci *
1413498266Sopenharmony_ci * You may opt to use, copy, modify, merge, publish, distribute and/or sell
1513498266Sopenharmony_ci * copies of the Software, and permit persons to whom the Software is
1613498266Sopenharmony_ci * furnished to do so, under the terms of the COPYING file.
1713498266Sopenharmony_ci *
1813498266Sopenharmony_ci * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
1913498266Sopenharmony_ci * KIND, either express or implied.
2013498266Sopenharmony_ci *
2113498266Sopenharmony_ci * SPDX-License-Identifier: curl
2213498266Sopenharmony_ci *
2313498266Sopenharmony_ci ***************************************************************************/
2413498266Sopenharmony_ci#include "curlcheck.h"
2513498266Sopenharmony_ci
2613498266Sopenharmony_ci#include "urldata.h"
2713498266Sopenharmony_ci#include "url.h"
2813498266Sopenharmony_ci
2913498266Sopenharmony_ci#include "memdebug.h" /* LAST include file */
3013498266Sopenharmony_ci
3113498266Sopenharmony_cistatic CURLcode unit_setup(void)
3213498266Sopenharmony_ci{
3313498266Sopenharmony_ci  CURLcode res = CURLE_OK;
3413498266Sopenharmony_ci  global_init(CURL_GLOBAL_ALL);
3513498266Sopenharmony_ci  return res;
3613498266Sopenharmony_ci}
3713498266Sopenharmony_ci
3813498266Sopenharmony_cistatic void unit_stop(void)
3913498266Sopenharmony_ci{
4013498266Sopenharmony_ci  curl_global_cleanup();
4113498266Sopenharmony_ci}
4213498266Sopenharmony_ci
4313498266Sopenharmony_ciUNITTEST_START
4413498266Sopenharmony_ci{
4513498266Sopenharmony_ci  int rc;
4613498266Sopenharmony_ci  struct Curl_easy *empty;
4713498266Sopenharmony_ci  const char *hostname = "hostname";
4813498266Sopenharmony_ci  enum dupstring i;
4913498266Sopenharmony_ci
5013498266Sopenharmony_ci  bool async = FALSE;
5113498266Sopenharmony_ci  bool protocol_connect = FALSE;
5213498266Sopenharmony_ci
5313498266Sopenharmony_ci  rc = Curl_open(&empty);
5413498266Sopenharmony_ci  if(rc)
5513498266Sopenharmony_ci    goto unit_test_abort;
5613498266Sopenharmony_ci  fail_unless(rc == CURLE_OK, "Curl_open() failed");
5713498266Sopenharmony_ci
5813498266Sopenharmony_ci  rc = Curl_connect(empty, &async, &protocol_connect);
5913498266Sopenharmony_ci  fail_unless(rc == CURLE_URL_MALFORMAT,
6013498266Sopenharmony_ci              "Curl_connect() failed to return CURLE_URL_MALFORMAT");
6113498266Sopenharmony_ci
6213498266Sopenharmony_ci  fail_unless(empty->magic == CURLEASY_MAGIC_NUMBER,
6313498266Sopenharmony_ci              "empty->magic should be equal to CURLEASY_MAGIC_NUMBER");
6413498266Sopenharmony_ci
6513498266Sopenharmony_ci  /* double invoke to ensure no dependency on internal state */
6613498266Sopenharmony_ci  rc = Curl_connect(empty, &async, &protocol_connect);
6713498266Sopenharmony_ci  fail_unless(rc == CURLE_URL_MALFORMAT,
6813498266Sopenharmony_ci              "Curl_connect() failed to return CURLE_URL_MALFORMAT");
6913498266Sopenharmony_ci
7013498266Sopenharmony_ci  rc = Curl_init_userdefined(empty);
7113498266Sopenharmony_ci  fail_unless(rc == CURLE_OK, "Curl_userdefined() failed");
7213498266Sopenharmony_ci
7313498266Sopenharmony_ci  rc = Curl_init_do(empty, empty->conn);
7413498266Sopenharmony_ci  fail_unless(rc == CURLE_OK, "Curl_init_do() failed");
7513498266Sopenharmony_ci
7613498266Sopenharmony_ci  rc = Curl_parse_login_details(
7713498266Sopenharmony_ci                          hostname, strlen(hostname), NULL, NULL, NULL);
7813498266Sopenharmony_ci  fail_unless(rc == CURLE_OK,
7913498266Sopenharmony_ci              "Curl_parse_login_details() failed");
8013498266Sopenharmony_ci
8113498266Sopenharmony_ci  Curl_freeset(empty);
8213498266Sopenharmony_ci  for(i = (enum dupstring)0; i < STRING_LAST; i++) {
8313498266Sopenharmony_ci    fail_unless(empty->set.str[i] == NULL,
8413498266Sopenharmony_ci                "Curl_free() did not set to NULL");
8513498266Sopenharmony_ci  }
8613498266Sopenharmony_ci
8713498266Sopenharmony_ci  Curl_free_request_state(empty);
8813498266Sopenharmony_ci
8913498266Sopenharmony_ci  rc = Curl_close(&empty);
9013498266Sopenharmony_ci  fail_unless(rc == CURLE_OK, "Curl_close() failed");
9113498266Sopenharmony_ci
9213498266Sopenharmony_ci}
9313498266Sopenharmony_ciUNITTEST_STOP
94