unit1396.c
Go to the documentation of this file.
1 /***************************************************************************
2  * _ _ ____ _
3  * Project ___| | | | _ \| |
4  * / __| | | | |_) | |
5  * | (__| |_| | _ <| |___
6  * \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 1998 - 2017, 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 
24 static CURL *hnd;
25 
26 static CURLcode unit_setup(void)
27 {
28  int res = CURLE_OK;
29 
31  return res;
32 }
33 
34 static void unit_stop(void)
35 {
36  if(hnd)
39 }
40 
41 struct test {
42  const char *in;
43  int inlen;
44  const char *out;
45  int outlen;
46 };
47 
49 {
50  /* unescape, this => that */
51  const struct test list1[]={
52  {"%61", 3, "a", 1},
53  {"%61a", 4, "aa", 2},
54  {"%61b", 4, "ab", 2},
55  {"%6 1", 4, "%6 1", 4},
56  {"%61", 1, "%", 1},
57  {"%61", 2, "%6", 2},
58  {"%6%a", 4, "%6%a", 4},
59  {"%6a", 0, "j", 1},
60  {"%FF", 0, "\xff", 1},
61  {"%FF%00%ff", 9, "\xff\x00\xff", 3},
62  {"%-2", 0, "%-2", 3},
63  {"%FG", 0, "%FG", 3},
64  {NULL, 0, NULL, 0} /* end of list marker */
65  };
66  /* escape, this => that */
67  const struct test list2[]={
68  {"a", 1, "a", 1},
69  {"/", 1, "%2F", 3},
70  {"a=b", 3, "a%3Db", 5},
71  {"a=b", 0, "a%3Db", 5},
72  {"a=b", 1, "a", 1},
73  {"a=b", 2, "a%3D", 4},
74  {"1/./0", 5, "1%2F.%2F0", 9},
75  {"-._~!#%&", 0, "-._~%21%23%25%26", 16},
76  {"a", 2, "a%00", 4},
77  {"a\xff\x01g", 4, "a%FF%01g", 8},
78  {NULL, 0, NULL, 0} /* end of list marker */
79  };
80  int i;
81 
82  hnd = curl_easy_init();
83  abort_unless(hnd != NULL, "returned NULL!");
84  for(i = 0; list1[i].in; i++) {
85  int outlen;
86  char *out = curl_easy_unescape(hnd,
87  list1[i].in, list1[i].inlen,
88  &outlen);
89 
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");
94 
95  printf("curl_easy_unescape test %d DONE\n", i);
96 
97  curl_free(out);
98  }
99 
100  for(i = 0; list2[i].in; i++) {
101  int outlen;
102  char *out = curl_easy_escape(hnd, list2[i].in, list2[i].inlen);
103  abort_unless(out != NULL, "returned NULL!");
104 
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");
109 
110  printf("curl_easy_escape test %d DONE (%s)\n", i, out);
111 
112  curl_free(out);
113  }
114 }
CURL_EXTERN void curl_free(void *p)
Definition: escape.c:239
abort_unless(hnd!=NULL,"returned NULL!")
static void unit_stop(void)
Definition: unit1396.c:34
CURL_EXTERN char * curl_easy_escape(CURL *handle, const char *string, int length)
#define global_init(A)
Definition: test.h:431
int i
Definition: unit1396.c:80
const char * out
Definition: unit1396.c:44
CURLcode
Definition: curl.h:454
const char * in
Definition: unit1396.c:42
static int res
UNITTEST_START
Definition: unit1396.c:49
static CURLcode unit_setup(void)
Definition: unit1396.c:26
#define printf
Definition: curl_printf.h:40
int outlen
Definition: unit1396.c:45
#define fail_unless(expr, msg)
Definition: curlcheck.h:32
CURL_EXTERN CURL * curl_easy_init(void)
Definition: easy.c:343
int inlen
Definition: unit1396.c:43
CURL_EXTERN void curl_easy_cleanup(CURL *curl)
Definition: curl.h:455
#define UNITTEST_STOP
Definition: curlcheck.h:95
const struct test list2[]
Definition: unit1396.c:67
static CURL * hnd
Definition: unit1396.c:24
void CURL
Definition: curl.h:102
CURL_EXTERN void curl_global_cleanup(void)
curl_global_cleanup() globally cleanups curl, uses the value of "init_flags" to determine what needs ...
Definition: easy.c:312
#define CURL_GLOBAL_ALL
Definition: curl.h:2519
CURL_EXTERN char * curl_easy_unescape(CURL *handle, const char *string, int length, int *outlength)


rc_tagdetect_client
Author(s): Monika Florek-Jasinska , Raphael Schaller
autogenerated on Sat Feb 13 2021 03:42:16