unit1608.c (2271B)
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 #include "hostip.h" 27 28 #ifndef CURL_DISABLE_SHUFFLE_DNS 29 30 CURLcode Curl_shuffle_addr(struct Curl_easy *data, 31 struct Curl_addrinfo **addr); 32 33 static struct Curl_addrinfo addrs[8]; 34 35 static CURLcode t1608_setup(void) 36 { 37 size_t i; 38 for(i = 0; i < CURL_ARRAYSIZE(addrs) - 1; i++) { 39 addrs[i].ai_next = &addrs[i + 1]; 40 } 41 42 return CURLE_OK; 43 } 44 45 static CURLcode test_unit1608(char *arg) 46 { 47 UNITTEST_BEGIN(t1608_setup()) 48 49 int i; 50 CURLcode code; 51 struct Curl_addrinfo *addrhead = addrs; 52 53 struct Curl_easy *easy = curl_easy_init(); 54 abort_unless(easy, "out of memory"); 55 56 code = curl_easy_setopt(easy, CURLOPT_DNS_SHUFFLE_ADDRESSES, 1L); 57 abort_unless(code == CURLE_OK, "curl_easy_setopt failed"); 58 59 /* Shuffle repeatedly and make sure that the list changes */ 60 for(i = 0; i < 10; i++) { 61 if(CURLE_OK != Curl_shuffle_addr(easy, &addrhead)) 62 break; 63 if(addrhead != addrs) 64 break; 65 } 66 67 curl_easy_cleanup(easy); 68 curl_global_cleanup(); 69 70 abort_unless(addrhead != addrs, "addresses are not being reordered"); 71 72 UNITTEST_END(curl_global_cleanup()) 73 } 74 75 #else 76 77 static CURLcode test_unit1608(char *arg) 78 { 79 UNITTEST_BEGIN_SIMPLE 80 UNITTEST_END_SIMPLE 81 } 82 83 #endif