unit1396.c
Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                  _   _ ____  _
00003  *  Project                     ___| | | |  _ \| |
00004  *                             / __| | | | |_) | |
00005  *                            | (__| |_| |  _ <| |___
00006  *                             \___|\___/|_| \_\_____|
00007  *
00008  * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
00009  *
00010  * This software is licensed as described in the file COPYING, which
00011  * you should have received as part of this distribution. The terms
00012  * are also available at https://curl.haxx.se/docs/copyright.html.
00013  *
00014  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
00015  * copies of the Software, and permit persons to whom the Software is
00016  * furnished to do so, under the terms of the COPYING file.
00017  *
00018  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
00019  * KIND, either express or implied.
00020  *
00021  ***************************************************************************/
00022 #include "curlcheck.h"
00023 
00024 CURL *hnd;
00025 
00026 static CURLcode unit_setup(void)
00027 {
00028   return CURLE_OK;
00029 }
00030 
00031 static void unit_stop(void)
00032 {
00033   if(hnd)
00034     curl_easy_cleanup(hnd);
00035 }
00036 
00037 struct test {
00038   const char *in;
00039   int inlen;
00040   const char *out;
00041   int outlen;
00042 };
00043 
00044 UNITTEST_START
00045 {
00046   /* unescape, this => that */
00047   const struct test list1[]={
00048     {"%61", 3, "a", 1},
00049     {"%61a", 4, "aa", 2},
00050     {"%61b", 4, "ab", 2},
00051     {"%6 1", 4, "%6 1", 4},
00052     {"%61", 1, "%", 1},
00053     {"%61", 2, "%6", 2},
00054     {"%6%a", 4, "%6%a", 4},
00055     {"%6a", 0, "j", 1},
00056     {"%FF", 0, "\xff", 1},
00057     {"%FF%00%ff", 9, "\xff\x00\xff", 3},
00058     {"%-2", 0, "%-2", 3},
00059     {"%FG", 0, "%FG", 3},
00060     {NULL, 0, NULL, 0} /* end of list marker */
00061   };
00062   /* escape, this => that */
00063   const struct test list2[]={
00064     {"a", 1, "a", 1},
00065     {"/", 1, "%2F", 3},
00066     {"a=b", 3, "a%3Db", 5},
00067     {"a=b", 0, "a%3Db", 5},
00068     {"a=b", 1, "a", 1},
00069     {"a=b", 2, "a%3D", 4},
00070     {"1/./0", 5, "1%2F.%2F0", 9},
00071     {"-._~!#%&", 0, "-._~%21%23%25%26", 16},
00072     {"a", 2, "a%00", 4},
00073     {"a\xff\x01g", 4, "a%FF%01g", 8},
00074     {NULL, 0, NULL, 0} /* end of list marker */
00075   };
00076   int i;
00077 
00078   hnd = curl_easy_init();
00079   abort_unless(hnd != NULL, "returned NULL!");
00080   for(i=0; list1[i].in; i++) {
00081     int outlen;
00082     char *out = curl_easy_unescape(hnd,
00083                                    list1[i].in, list1[i].inlen,
00084                                    &outlen);
00085 
00086     abort_unless(out != NULL, "returned NULL!");
00087     fail_unless(outlen == list1[i].outlen, "wrong output length returned");
00088     fail_unless(!memcmp(out, list1[i].out, list1[i].outlen),
00089                 "bad output data returned");
00090 
00091     printf("curl_easy_unescape test %d DONE\n", i);
00092 
00093     curl_free(out);
00094   }
00095 
00096   for(i=0; list2[i].in; i++) {
00097     int outlen;
00098     char *out = curl_easy_escape(hnd, list2[i].in, list2[i].inlen);
00099     abort_unless(out != NULL, "returned NULL!");
00100 
00101     outlen = (int)strlen(out);
00102     fail_unless(outlen == list2[i].outlen, "wrong output length returned");
00103     fail_unless(!memcmp(out, list2[i].out, list2[i].outlen),
00104                 "bad output data returned");
00105 
00106     printf("curl_easy_escape test %d DONE (%s)\n", i, out);
00107 
00108     curl_free(out);
00109   }
00110 }
00111 UNITTEST_STOP


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:07