unit1664.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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. #ifdef HAVE_NETINET_IN_H
  26. #include <netinet/in.h>
  27. #endif
  28. #ifdef HAVE_NETINET_IN6_H
  29. #include <netinet/in6.h>
  30. #endif
  31. #include <curl/curl.h>
  32. #include "strparse.h"
  33. #include "memdebug.h" /* LAST include file */
  34. static CURLcode unit_setup(void)
  35. {
  36. CURLcode res = CURLE_OK;
  37. global_init(CURL_GLOBAL_ALL);
  38. return res;
  39. }
  40. static void unit_stop(void)
  41. {
  42. curl_global_cleanup();
  43. }
  44. UNITTEST_START
  45. {
  46. static const char *wordparse[] = {
  47. "word",
  48. "word ",
  49. " word ",
  50. "wo rd",
  51. "word(",
  52. "wor(d",
  53. "perfect",
  54. "",
  55. "longerth",
  56. NULL
  57. };
  58. int i;
  59. printf("Curl_str_word\n");
  60. for(i = 0; wordparse[i]; i++) {
  61. struct Curl_str out;
  62. char *line = (char *)wordparse[i];
  63. char *orgline = line;
  64. int rc = Curl_str_word(&line, &out, 7);
  65. printf("%u: (\"%s\") %d, \"%.*s\" [%d], line %d\n",
  66. i, orgline, rc, (int)out.len, out.str, (int)out.len,
  67. (int)(line - orgline));
  68. }
  69. printf("Curl_str_until\n");
  70. for(i = 0; wordparse[i]; i++) {
  71. struct Curl_str out;
  72. char *line = (char *)wordparse[i];
  73. char *orgline = line;
  74. int rc = Curl_str_until(&line, &out, 7, 'd');
  75. printf("%u: (\"%s\") %d, \"%.*s\" [%d], line %d\n",
  76. i, orgline, rc, (int)out.len, out.str, (int)out.len,
  77. (int)(line - orgline));
  78. }
  79. {
  80. static const char *qwords[] = {
  81. "\"word\"",
  82. "\"word",
  83. "word\"",
  84. "\"word\"\"",
  85. "\"word\" ",
  86. " \"word\"",
  87. "\"perfect\"",
  88. "\"p r e t\"",
  89. "\"perfec\\\"",
  90. "\"\"",
  91. "",
  92. "\"longerth\"",
  93. NULL
  94. };
  95. printf("Curl_str_quotedword\n");
  96. for(i = 0; qwords[i]; i++) {
  97. struct Curl_str out;
  98. char *line = (char *)qwords[i];
  99. char *orgline = line;
  100. int rc = Curl_str_quotedword(&line, &out, 7);
  101. printf("%u: (\"%s\") %d, \"%.*s\" [%d], line %d\n",
  102. i, orgline, rc, (int)out.len, out.str, (int)out.len,
  103. (int)(line - orgline));
  104. }
  105. }
  106. {
  107. static const char *single[] = {
  108. "a",
  109. "aa",
  110. "A",
  111. "b",
  112. "\\",
  113. " ",
  114. "",
  115. NULL
  116. };
  117. printf("Curl_str_single\n");
  118. for(i = 0; single[i]; i++) {
  119. char *line = (char *)single[i];
  120. char *orgline = line;
  121. int rc = Curl_str_single(&line, 'a');
  122. printf("%u: (\"%s\") %d, line %d\n",
  123. i, orgline, rc, (int)(line - orgline));
  124. }
  125. }
  126. {
  127. static const char *single[] = {
  128. "a",
  129. "aa",
  130. "A",
  131. "b",
  132. "\\",
  133. " ",
  134. "\t",
  135. "\n",
  136. "",
  137. NULL
  138. };
  139. printf("Curl_str_singlespace\n");
  140. for(i = 0; single[i]; i++) {
  141. char *line = (char *)single[i];
  142. char *orgline = line;
  143. int rc = Curl_str_singlespace(&line);
  144. printf("%u: (\"%s\") %d, line %d\n",
  145. i, orgline, rc, (int)(line - orgline));
  146. }
  147. }
  148. {
  149. static const char *single[] = {
  150. "a",
  151. "aa",
  152. "A",
  153. "b",
  154. "\\",
  155. " ",
  156. "",
  157. NULL
  158. };
  159. printf("Curl_str_single\n");
  160. for(i = 0; single[i]; i++) {
  161. char *line = (char *)single[i];
  162. char *orgline = line;
  163. int rc = Curl_str_single(&line, 'a');
  164. printf("%u: (\"%s\") %d, line %d\n",
  165. i, orgline, rc, (int)(line - orgline));
  166. }
  167. }
  168. {
  169. static const char *nums[] = {
  170. "1",
  171. "10000",
  172. "1234",
  173. "1235",
  174. "1236",
  175. "01234",
  176. "00000000000000000000000000001234",
  177. "0123 345",
  178. "0123O345",
  179. "-12",
  180. " 123",
  181. "",
  182. NULL
  183. };
  184. printf("Curl_str_number\n");
  185. for(i = 0; nums[i]; i++) {
  186. size_t num;
  187. char *line = (char *)nums[i];
  188. char *orgline = line;
  189. int rc = Curl_str_number(&line, &num, 1235);
  190. printf("%u: (\"%s\") %d, [%u] line %d\n",
  191. i, orgline, rc, (int)num, (int)(line - orgline));
  192. }
  193. }
  194. {
  195. /* SIZE_T_MAX is typically 18446744073709551615 */
  196. static const char *nums[] = {
  197. "9223372036854775808", /* 2^63 */
  198. "9223372036854775809", /* 2^63 + 1 */
  199. "18446744073709551615", /* 2^64 - 1 */
  200. "18446744073709551616", /* 2^64 */
  201. "18446744073709551617", /* 2^64 + 1 */
  202. NULL
  203. };
  204. printf("Curl_str_number / max\n");
  205. for(i = 0; nums[i]; i++) {
  206. size_t num;
  207. char *line = (char *)nums[i];
  208. char *orgline = line;
  209. int rc = Curl_str_number(&line, &num, SIZE_T_MAX);
  210. printf("%u: (\"%s\") %d, [%zu] line %d\n",
  211. i, orgline, rc, num, (int)(line - orgline));
  212. }
  213. }
  214. {
  215. static const char *newl[] = {
  216. "a",
  217. "aa",
  218. "A",
  219. "b",
  220. "\\",
  221. " ",
  222. "\n",
  223. "\r",
  224. "\r\n",
  225. "",
  226. NULL
  227. };
  228. printf("Curl_str_newline\n");
  229. for(i = 0; newl[i]; i++) {
  230. char *line = (char *)newl[i];
  231. char *orgline = line;
  232. int rc = Curl_str_newline(&line);
  233. printf("%u: (\"%s\") %d, line %d\n",
  234. i, orgline, rc, (int)(line - orgline));
  235. }
  236. }
  237. }
  238. UNITTEST_STOP