unit1608.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2018, 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.haxx.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. ***************************************************************************/
  22. #include "curlcheck.h"
  23. #include "hostip.h"
  24. #define NUM_ADDRS 8
  25. static struct Curl_addrinfo addrs[NUM_ADDRS];
  26. static CURLcode unit_setup(void)
  27. {
  28. int i;
  29. for(i = 0; i < NUM_ADDRS - 1; i++) {
  30. addrs[i].ai_next = &addrs[i + 1];
  31. }
  32. return CURLE_OK;
  33. }
  34. static void unit_stop(void)
  35. {
  36. }
  37. UNITTEST_START
  38. {
  39. int i;
  40. CURLcode code;
  41. struct Curl_addrinfo* addrhead = addrs;
  42. struct Curl_easy *easy = curl_easy_init();
  43. abort_unless(easy, "out of memory");
  44. code = curl_easy_setopt(easy, CURLOPT_DNS_SHUFFLE_ADDRESSES, 1L);
  45. abort_unless(code == CURLE_OK, "curl_easy_setopt failed");
  46. /* Shuffle repeatedly and make sure that the list changes */
  47. for(i = 0; i < 10; i++) {
  48. if(CURLE_OK != Curl_shuffle_addr(easy, &addrhead))
  49. break;
  50. if(addrhead != addrs)
  51. break;
  52. }
  53. curl_easy_cleanup(easy);
  54. abort_unless(addrhead != addrs, "addresses are not being reordered");
  55. return 0;
  56. }
  57. UNITTEST_STOP