unit1663.c (3235B)
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 "unitcheck.h" 25 26 #ifdef HAVE_NETINET_IN_H 27 #include <netinet/in.h> 28 #endif 29 #ifdef HAVE_NETINET_IN6_H 30 #include <netinet/in6.h> 31 #endif 32 33 #include "cf-socket.h" 34 35 #include "memdebug.h" /* LAST include file */ 36 37 static CURLcode t1663_setup(void) 38 { 39 CURLcode res = CURLE_OK; 40 global_init(CURL_GLOBAL_ALL); 41 return res; 42 } 43 44 static void t1663_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 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 61 if(!unitfail) { 62 fail_unless(!dev || !exp_dev || strcmp(dev, exp_dev) == 0, 63 "dev should be equal to exp_dev"); 64 fail_unless(!iface || !exp_iface || strcmp(iface, exp_iface) == 0, 65 "iface should be equal to exp_iface"); 66 fail_unless(!host || !exp_host || strcmp(host, exp_host) == 0, 67 "host should be equal to exp_host"); 68 } 69 70 free(dev); 71 free(iface); 72 free(host); 73 } 74 75 static CURLcode test_unit1663(char *arg) 76 { 77 UNITTEST_BEGIN(t1663_setup()) 78 79 t1663_parse("dev", "dev", NULL, NULL, CURLE_OK); 80 t1663_parse("if!eth0", NULL, "eth0", NULL, CURLE_OK); 81 t1663_parse("host!myname", NULL, NULL, "myname", CURLE_OK); 82 t1663_parse("ifhost!eth0!myname", NULL, "eth0", "myname", CURLE_OK); 83 t1663_parse("", NULL, NULL, NULL, CURLE_BAD_FUNCTION_ARGUMENT); 84 t1663_parse("!", "!", NULL, NULL, CURLE_OK); 85 t1663_parse("if!", NULL, NULL, NULL, CURLE_BAD_FUNCTION_ARGUMENT); 86 t1663_parse("if!eth0!blubb", NULL, "eth0!blubb", NULL, CURLE_OK); 87 t1663_parse("host!", NULL, NULL, NULL, CURLE_BAD_FUNCTION_ARGUMENT); 88 t1663_parse("ifhost!", NULL, NULL, NULL, CURLE_BAD_FUNCTION_ARGUMENT); 89 t1663_parse("ifhost!eth0", NULL, NULL, NULL, CURLE_BAD_FUNCTION_ARGUMENT); 90 t1663_parse("ifhost!eth0!", NULL, NULL, NULL, CURLE_BAD_FUNCTION_ARGUMENT); 91 92 UNITTEST_END(curl_global_cleanup()) 93 }