lib1597.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2022, 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. /* Testing CURLOPT_PROTOCOLS_STR */
  25. #include "test.h"
  26. #include "memdebug.h"
  27. struct pair {
  28. const char *in;
  29. CURLcode exp;
  30. };
  31. int test(char *URL)
  32. {
  33. CURL *curl = NULL;
  34. int res = 0;
  35. CURLcode result = CURLE_OK;
  36. int i;
  37. struct pair prots[] = {
  38. {"goobar", CURLE_BAD_FUNCTION_ARGUMENT},
  39. {"http ", CURLE_BAD_FUNCTION_ARGUMENT},
  40. {" http", CURLE_BAD_FUNCTION_ARGUMENT},
  41. {"http", CURLE_OK},
  42. {"http,", CURLE_OK},
  43. {"https,", CURLE_OK},
  44. {"https,http", CURLE_OK},
  45. {"http,http", CURLE_OK},
  46. {"HTTP,HTTP", CURLE_OK},
  47. {",HTTP,HTTP", CURLE_OK},
  48. {"http,http,ft", CURLE_BAD_FUNCTION_ARGUMENT},
  49. {"", CURLE_BAD_FUNCTION_ARGUMENT},
  50. {",,", CURLE_BAD_FUNCTION_ARGUMENT},
  51. {"DICT,FILE,FTP,FTPS,GOPHER,GOPHERS,HTTP,HTTPS,IMAP,IMAPS,LDAP,LDAPS,"
  52. "POP3,POP3S,RTMP,RTMPE,RTMPS,RTMPT,RTMPTE,RTMPTS,RTSP,SCP,SFTP,SMB,"
  53. "SMBS,SMTP,SMTPS,TELNET,TFTP", CURLE_OK},
  54. {"all", CURLE_OK},
  55. {NULL, FALSE},
  56. };
  57. (void)URL;
  58. global_init(CURL_GLOBAL_ALL);
  59. easy_init(curl);
  60. for(i = 0; prots[i].in; i++) {
  61. result = curl_easy_setopt(curl, CURLOPT_PROTOCOLS_STR, prots[i].in);
  62. if(result != prots[i].exp) {
  63. printf("unexpectedly '%s' returned %u\n",
  64. prots[i].in, result);
  65. break;
  66. }
  67. }
  68. printf("Tested %u strings\n", i);
  69. res = (int)result;
  70. test_cleanup:
  71. curl_easy_cleanup(curl);
  72. curl_global_cleanup();
  73. return (int)result;
  74. }