unit1608.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 "hostip.h"
  26. #ifndef CURL_DISABLE_SHUFFLE_DNS
  27. CURLcode Curl_shuffle_addr(struct Curl_easy *data,
  28. struct Curl_addrinfo **addr);
  29. #define NUM_ADDRS 8
  30. static struct Curl_addrinfo addrs[NUM_ADDRS];
  31. static CURLcode unit_setup(void)
  32. {
  33. int i;
  34. for(i = 0; i < NUM_ADDRS - 1; i++) {
  35. addrs[i].ai_next = &addrs[i + 1];
  36. }
  37. return CURLE_OK;
  38. }
  39. static void unit_stop(void)
  40. {
  41. curl_global_cleanup();
  42. }
  43. UNITTEST_START
  44. int i;
  45. CURLcode code;
  46. struct Curl_addrinfo *addrhead = addrs;
  47. struct Curl_easy *easy = curl_easy_init();
  48. abort_unless(easy, "out of memory");
  49. code = curl_easy_setopt(easy, CURLOPT_DNS_SHUFFLE_ADDRESSES, 1L);
  50. abort_unless(code == CURLE_OK, "curl_easy_setopt failed");
  51. /* Shuffle repeatedly and make sure that the list changes */
  52. for(i = 0; i < 10; i++) {
  53. if(CURLE_OK != Curl_shuffle_addr(easy, &addrhead))
  54. break;
  55. if(addrhead != addrs)
  56. break;
  57. }
  58. curl_easy_cleanup(easy);
  59. curl_global_cleanup();
  60. abort_unless(addrhead != addrs, "addresses are not being reordered");
  61. UNITTEST_STOP
  62. #else
  63. static CURLcode unit_setup(void)
  64. {
  65. return CURLE_OK;
  66. }
  67. static void unit_stop(void)
  68. {
  69. }
  70. UNITTEST_START
  71. UNITTEST_STOP
  72. #endif