unit1620.c 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. #include "urldata.h"
  26. #include "url.h"
  27. #include "memdebug.h" /* LAST include file */
  28. static CURLcode unit_setup(void)
  29. {
  30. CURLcode res = CURLE_OK;
  31. global_init(CURL_GLOBAL_ALL);
  32. return res;
  33. }
  34. static void unit_stop(void)
  35. {
  36. curl_global_cleanup();
  37. }
  38. UNITTEST_START
  39. {
  40. CURLcode rc;
  41. struct Curl_easy *empty;
  42. const char *hostname = "hostname";
  43. enum dupstring i;
  44. char *userstr = NULL;
  45. char *passwdstr = NULL;
  46. bool async = FALSE;
  47. bool protocol_connect = FALSE;
  48. rc = Curl_open(&empty);
  49. if(rc)
  50. goto unit_test_abort;
  51. fail_unless(rc == CURLE_OK, "Curl_open() failed");
  52. rc = Curl_connect(empty, &async, &protocol_connect);
  53. fail_unless(rc == CURLE_URL_MALFORMAT,
  54. "Curl_connect() failed to return CURLE_URL_MALFORMAT");
  55. fail_unless(empty->magic == CURLEASY_MAGIC_NUMBER,
  56. "empty->magic should be equal to CURLEASY_MAGIC_NUMBER");
  57. /* double invoke to ensure no dependency on internal state */
  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. rc = Curl_init_userdefined(empty);
  62. fail_unless(rc == CURLE_OK, "Curl_userdefined() failed");
  63. rc = Curl_init_do(empty, empty->conn);
  64. fail_unless(rc == CURLE_OK, "Curl_init_do() failed");
  65. rc = Curl_parse_login_details(hostname, strlen(hostname),
  66. &userstr, &passwdstr, NULL);
  67. fail_unless(rc == CURLE_OK,
  68. "Curl_parse_login_details() failed");
  69. free(userstr);
  70. free(passwdstr);
  71. Curl_freeset(empty);
  72. for(i = (enum dupstring)0; i < STRING_LAST; i++) {
  73. fail_unless(empty->set.str[i] == NULL,
  74. "Curl_free() did not set to NULL");
  75. }
  76. rc = Curl_close(&empty);
  77. fail_unless(rc == CURLE_OK, "Curl_close() failed");
  78. }
  79. UNITTEST_STOP