2
0

unit2604.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 "curl_path.h"
  26. static CURLcode unit_setup(void)
  27. {
  28. return CURLE_OK;
  29. }
  30. static void unit_stop(void)
  31. {
  32. }
  33. struct set {
  34. const char *cp;
  35. const char *expect; /* the returned content */
  36. const char *next; /* what cp points to after the call */
  37. const char *home;
  38. CURLcode result;
  39. };
  40. UNITTEST_START
  41. #ifdef USE_SSH
  42. {
  43. /* 60 a's */
  44. #define SA60 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
  45. /* 540 a's */
  46. #define SA540 SA60 SA60 SA60 SA60 SA60 SA60 SA60 SA60 SA60
  47. int i;
  48. int error = 0;
  49. size_t too_long = 90720;
  50. struct set list[] = {
  51. { "-too-long-", "", "", "", CURLE_TOO_LARGE},
  52. { SA540 " c", SA540, "c", "/", CURLE_OK},
  53. { "\" " SA540 "\" c", " " SA540, "c", "/", CURLE_OK},
  54. { "a a", "a", "a", "/home/", CURLE_OK},
  55. { "b a", "b", "a", "/", CURLE_OK},
  56. { "a", "a", "", "/home/", CURLE_OK},
  57. { "b", "b", "", "/", CURLE_OK},
  58. { "\"foo bar\"\tb", "foo bar", "b", "/", CURLE_OK},
  59. { "/~/hej", "/home/user/hej", "", "/home/user", CURLE_OK},
  60. { "\"foo bar", "", "", "/", CURLE_QUOTE_ERROR},
  61. { "\"foo\\\"bar\" a", "foo\"bar", "a", "/", CURLE_OK},
  62. { "\"foo\\\'bar\" b", "foo\'bar", "b", "/", CURLE_OK},
  63. { "\"foo\\\\bar\" c", "foo\\bar", "c", "/", CURLE_OK},
  64. { "\"foo\\pbar\" c", "foo\\bar", "", "/", CURLE_QUOTE_ERROR},
  65. { "\"\" c", "", "", "", CURLE_QUOTE_ERROR},
  66. { "foo\"", "foo\"", "", "/", CURLE_OK},
  67. { "foo \"", "foo", "\"", "/", CURLE_OK},
  68. { NULL, NULL, NULL, NULL, CURLE_OK }
  69. };
  70. list[0].cp = calloc(1, too_long + 1);
  71. fail_unless(list[0].cp, "could not alloc too long value");
  72. memset((void *)list[0].cp, 'a', too_long);
  73. for(i = 0; list[i].home; i++) {
  74. char *path;
  75. const char *cp = list[i].cp;
  76. CURLcode result = Curl_get_pathname(&cp, &path, list[i].home);
  77. printf("%u - Curl_get_pathname(\"%s\", ... \"%s\") == %u\n", i,
  78. list[i].cp, list[i].home, list[i].result);
  79. if(result != list[i].result) {
  80. printf("... returned %d\n", result);
  81. error++;
  82. }
  83. if(!result) {
  84. if(cp && strcmp(cp, list[i].next)) {
  85. printf("... cp points to '%s', not '%s' as expected \n",
  86. cp, list[i].next);
  87. error++;
  88. }
  89. if(path && strcmp(path, list[i].expect)) {
  90. printf("... gave '%s', not '%s' as expected \n",
  91. path, list[i].expect);
  92. error++;
  93. }
  94. curl_free(path);
  95. }
  96. }
  97. free((void *)list[0].cp);
  98. return error == 0 ? CURLE_OK : TEST_ERR_FAILURE;
  99. }
  100. #endif
  101. UNITTEST_STOP