2
0

unit1663.c 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. #ifdef HAVE_NETINET_IN_H
  26. #include <netinet/in.h>
  27. #endif
  28. #ifdef HAVE_NETINET_IN6_H
  29. #include <netinet/in6.h>
  30. #endif
  31. #include <curl/curl.h>
  32. #include "cf-socket.h"
  33. #include "memdebug.h" /* LAST include file */
  34. static CURLcode unit_setup(void)
  35. {
  36. CURLcode res = CURLE_OK;
  37. global_init(CURL_GLOBAL_ALL);
  38. return res;
  39. }
  40. static void unit_stop(void)
  41. {
  42. curl_global_cleanup();
  43. }
  44. static void test_parse(
  45. const char *input,
  46. const char *exp_dev,
  47. const char *exp_iface,
  48. const char *exp_host,
  49. CURLcode exp_rc)
  50. {
  51. char *dev = NULL;
  52. char *iface = NULL;
  53. char *host = NULL;
  54. CURLcode rc = Curl_parse_interface(
  55. input, strlen(input), &dev, &iface, &host);
  56. fail_unless(rc == exp_rc, "Curl_parse_interface() failed");
  57. fail_unless(!!exp_dev == !!dev, "dev expectation failed.");
  58. fail_unless(!!exp_iface == !!iface, "iface expectation failed");
  59. fail_unless(!!exp_host == !!host, "host expectation failed");
  60. if(!unitfail) {
  61. fail_unless(!exp_dev || strcmp(dev, exp_dev) == 0,
  62. "dev should be equal to exp_dev");
  63. fail_unless(!exp_iface || strcmp(iface, exp_iface) == 0,
  64. "iface should be equal to exp_iface");
  65. fail_unless(!exp_host || strcmp(host, exp_host) == 0,
  66. "host should be equal to exp_host");
  67. }
  68. free(dev);
  69. free(iface);
  70. free(host);
  71. }
  72. UNITTEST_START
  73. {
  74. test_parse("dev", "dev", NULL, NULL, CURLE_OK);
  75. test_parse("if!eth0", NULL, "eth0", NULL, CURLE_OK);
  76. test_parse("host!myname", NULL, NULL, "myname", CURLE_OK);
  77. test_parse("ifhost!eth0!myname", NULL, "eth0", "myname", CURLE_OK);
  78. test_parse("", NULL, NULL, NULL, CURLE_BAD_FUNCTION_ARGUMENT);
  79. test_parse("!", "!", NULL, NULL, CURLE_OK);
  80. test_parse("if!", NULL, NULL, NULL, CURLE_BAD_FUNCTION_ARGUMENT);
  81. test_parse("if!eth0!blubb", NULL, "eth0!blubb", NULL, CURLE_OK);
  82. test_parse("host!", NULL, NULL, NULL, CURLE_BAD_FUNCTION_ARGUMENT);
  83. test_parse("ifhost!", NULL, NULL, NULL, CURLE_BAD_FUNCTION_ARGUMENT);
  84. test_parse("ifhost!eth0", NULL, NULL, NULL, CURLE_BAD_FUNCTION_ARGUMENT);
  85. test_parse("ifhost!eth0!", NULL, NULL, NULL, CURLE_BAD_FUNCTION_ARGUMENT);
  86. }
  87. UNITTEST_STOP