1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
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.
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.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ***************************************************************************/
22 #include "curlcheck.h"
26 static CURLcode unit_setup(void)
30 global_init(CURL_GLOBAL_ALL);
34 static void unit_stop(void)
37 curl_easy_cleanup(hnd);
38 curl_global_cleanup();
50 /* unescape, this => that */
51 const struct test list1[]={
55 {"%6 1", 4, "%6 1", 4},
58 {"%6%a", 4, "%6%a", 4},
60 {"%FF", 0, "\xff", 1},
61 {"%FF%00%ff", 9, "\xff\x00\xff", 3},
64 {NULL, 0, NULL, 0} /* end of list marker */
66 /* escape, this => that */
67 const struct test list2[]={
70 {"a=b", 3, "a%3Db", 5},
71 {"a=b", 0, "a%3Db", 5},
73 {"a=b", 2, "a%3D", 4},
74 {"1/./0", 5, "1%2F.%2F0", 9},
75 {"-._~!#%&", 0, "-._~%21%23%25%26", 16},
77 {"a\xff\x01g", 4, "a%FF%01g", 8},
78 {NULL, 0, NULL, 0} /* end of list marker */
82 hnd = curl_easy_init();
83 abort_unless(hnd != NULL, "returned NULL!");
84 for(i = 0; list1[i].in; i++) {
86 char *out = curl_easy_unescape(hnd,
87 list1[i].in, list1[i].inlen,
90 abort_unless(out != NULL, "returned NULL!");
91 fail_unless(outlen == list1[i].outlen, "wrong output length returned");
92 fail_unless(!memcmp(out, list1[i].out, list1[i].outlen),
93 "bad output data returned");
95 printf("curl_easy_unescape test %d DONE\n", i);
100 for(i = 0; list2[i].in; i++) {
102 char *out = curl_easy_escape(hnd, list2[i].in, list2[i].inlen);
103 abort_unless(out != NULL, "returned NULL!");
105 outlen = (int)strlen(out);
106 fail_unless(outlen == list2[i].outlen, "wrong output length returned");
107 fail_unless(!memcmp(out, list2[i].out, list2[i].outlen),
108 "bad output data returned");
110 printf("curl_easy_escape test %d DONE (%s)\n", i, out);