2
0

unit1663.c 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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_data,
  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(input_data, &dev, &iface, &host);
  55. fail_unless(rc == exp_rc, "Curl_parse_interface() failed");
  56. fail_unless(!!exp_dev == !!dev, "dev expectation failed.");
  57. fail_unless(!!exp_iface == !!iface, "iface expectation failed");
  58. fail_unless(!!exp_host == !!host, "host expectation failed");
  59. if(!unitfail) {
  60. fail_unless(!exp_dev || strcmp(dev, exp_dev) == 0,
  61. "dev should be equal to exp_dev");
  62. fail_unless(!exp_iface || strcmp(iface, exp_iface) == 0,
  63. "iface should be equal to exp_iface");
  64. fail_unless(!exp_host || strcmp(host, exp_host) == 0,
  65. "host should be equal to exp_host");
  66. }
  67. free(dev);
  68. free(iface);
  69. free(host);
  70. }
  71. UNITTEST_START
  72. {
  73. test_parse("dev", "dev", NULL, NULL, CURLE_OK);
  74. test_parse("if!eth0", NULL, "eth0", NULL, CURLE_OK);
  75. test_parse("host!myname", NULL, NULL, "myname", CURLE_OK);
  76. test_parse("ifhost!eth0!myname", NULL, "eth0", "myname", CURLE_OK);
  77. test_parse("", NULL, NULL, NULL, CURLE_BAD_FUNCTION_ARGUMENT);
  78. test_parse("!", "!", NULL, NULL, CURLE_OK);
  79. test_parse("if!", NULL, NULL, NULL, CURLE_BAD_FUNCTION_ARGUMENT);
  80. test_parse("if!eth0!blubb", NULL, "eth0!blubb", NULL, CURLE_OK);
  81. test_parse("host!", NULL, NULL, NULL, CURLE_BAD_FUNCTION_ARGUMENT);
  82. test_parse("ifhost!", NULL, NULL, NULL, CURLE_BAD_FUNCTION_ARGUMENT);
  83. test_parse("ifhost!eth0", NULL, NULL, NULL, CURLE_BAD_FUNCTION_ARGUMENT);
  84. test_parse("ifhost!eth0!", NULL, NULL, NULL, CURLE_BAD_FUNCTION_ARGUMENT);
  85. }
  86. UNITTEST_STOP