unit1302.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 #include "urldata.h"
00025 #include "url.h" /* for Curl_safefree */
00026 #include "curl_base64.h"
00027 #include "memdebug.h" /* LAST include file */
00028 
00029 static struct Curl_easy *data;
00030 
00031 static CURLcode unit_setup(void)
00032 {
00033   data = curl_easy_init();
00034   if(!data)
00035     return CURLE_OUT_OF_MEMORY;
00036   return CURLE_OK;
00037 }
00038 
00039 static void unit_stop(void)
00040 {
00041   curl_easy_cleanup(data);
00042 }
00043 
00044 UNITTEST_START
00045 
00046 char *output;
00047 unsigned char *decoded;
00048 size_t size = 0;
00049 unsigned char anychar = 'x';
00050 CURLcode rc;
00051 
00052 rc = Curl_base64_encode(data, "i", 1, &output, &size);
00053 fail_unless(rc == CURLE_OK, "return code should be CURLE_OK");
00054 fail_unless(size == 4, "size should be 4");
00055 verify_memory(output, "aQ==", 4);
00056 Curl_safefree(output);
00057 
00058 rc = Curl_base64_encode(data, "ii", 2, &output, &size);
00059 fail_unless(rc == CURLE_OK, "return code should be CURLE_OK");
00060 fail_unless(size == 4, "size should be 4");
00061 verify_memory(output, "aWk=", 4);
00062 Curl_safefree(output);
00063 
00064 rc = Curl_base64_encode(data, "iii", 3, &output, &size);
00065 fail_unless(rc == CURLE_OK, "return code should be CURLE_OK");
00066 fail_unless(size == 4, "size should be 4");
00067 verify_memory(output, "aWlp", 4);
00068 Curl_safefree(output);
00069 
00070 rc = Curl_base64_encode(data, "iiii", 4, &output, &size);
00071 fail_unless(rc == CURLE_OK, "return code should be CURLE_OK");
00072 fail_unless(size == 8, "size should be 8");
00073 verify_memory(output, "aWlpaQ==", 8);
00074 Curl_safefree(output);
00075 
00076 rc = Curl_base64_encode(data, "\xff\x01\xfe\x02", 4, &output, &size);
00077 fail_unless(rc == CURLE_OK, "return code should be CURLE_OK");
00078 fail_unless(size == 8, "size should be 8");
00079 verify_memory(output, "/wH+Ag==", 8);
00080 Curl_safefree(output);
00081 
00082 rc = Curl_base64url_encode(data, "\xff\x01\xfe\x02", 4, &output, &size);
00083 fail_unless(rc == CURLE_OK, "return code should be CURLE_OK");
00084 fail_unless(size == 8, "size should be 8");
00085 verify_memory(output, "_wH-Ag==", 8);
00086 Curl_safefree(output);
00087 
00088 rc = Curl_base64url_encode(data, "iiii", 4, &output, &size);
00089 fail_unless(rc == CURLE_OK, "return code should be CURLE_OK");
00090 fail_unless(size == 8, "size should be 8");
00091 verify_memory(output, "aWlpaQ==", 8);
00092 Curl_safefree(output);
00093 
00094 /* 0 length makes it do strlen() */
00095 rc = Curl_base64_encode(data, "iiii", 0, &output, &size);
00096 fail_unless(rc == CURLE_OK, "return code should be CURLE_OK");
00097 fail_unless(size == 8, "size should be 8");
00098 verify_memory(output, "aWlpaQ==", 8);
00099 Curl_safefree(output);
00100 
00101 rc = Curl_base64_decode("aWlpaQ==", &decoded, &size);
00102 fail_unless(rc == CURLE_OK, "return code should be CURLE_OK");
00103 fail_unless(size == 4, "size should be 4");
00104 verify_memory(decoded, "iiii", 4);
00105 Curl_safefree(decoded);
00106 
00107 rc = Curl_base64_decode("aWlp", &decoded, &size);
00108 fail_unless(rc == CURLE_OK, "return code should be CURLE_OK");
00109 fail_unless(size == 3, "size should be 3");
00110 verify_memory(decoded, "iii", 3);
00111 Curl_safefree(decoded);
00112 
00113 rc = Curl_base64_decode("aWk=", &decoded, &size);
00114 fail_unless(rc == CURLE_OK, "return code should be CURLE_OK");
00115 fail_unless(size == 2, "size should be 2");
00116 verify_memory(decoded, "ii", 2);
00117 Curl_safefree(decoded);
00118 
00119 rc = Curl_base64_decode("aQ==", &decoded, &size);
00120 fail_unless(rc == CURLE_OK, "return code should be CURLE_OK");
00121 fail_unless(size == 1, "size should be 1");
00122 verify_memory(decoded, "i", 2);
00123 Curl_safefree(decoded);
00124 
00125 /* This is illegal input as the data is too short */
00126 size = 1; /* not zero */
00127 decoded = &anychar; /* not NULL */
00128 rc = Curl_base64_decode("aQ", &decoded, &size);
00129 fail_unless(rc == CURLE_BAD_CONTENT_ENCODING,
00130             "return code should be CURLE_BAD_CONTENT_ENCODING");
00131 fail_unless(size == 0, "size should be 0");
00132 fail_if(decoded, "returned pointer should be NULL");
00133 
00134 /* This is illegal input as it contains three padding characters */
00135 size = 1; /* not zero */
00136 decoded = &anychar; /* not NULL */
00137 rc = Curl_base64_decode("a===", &decoded, &size);
00138 fail_unless(rc == CURLE_BAD_CONTENT_ENCODING,
00139             "return code should be CURLE_BAD_CONTENT_ENCODING");
00140 fail_unless(size == 0, "size should be 0");
00141 fail_if(decoded, "returned pointer should be NULL");
00142 
00143 /* This is illegal input as it contains a padding character mid input */
00144 size = 1; /* not zero */
00145 decoded = &anychar; /* not NULL */
00146 rc = Curl_base64_decode("a=Q=", &decoded, &size);
00147 fail_unless(rc == CURLE_BAD_CONTENT_ENCODING,
00148             "return code should be CURLE_BAD_CONTENT_ENCODING");
00149 fail_unless(size == 0, "size should be 0");
00150 fail_if(decoded, "returned pointer should be NULL");
00151 
00152 /* This is garbage input as it contains an illegal base64 character */
00153 size = 1; /* not zero */
00154 decoded = &anychar; /* not NULL */
00155 rc = Curl_base64_decode("a\x1f==", &decoded, &size);
00156 fail_unless(rc == CURLE_BAD_CONTENT_ENCODING,
00157             "return code should be CURLE_BAD_CONTENT_ENCODING");
00158 fail_unless(size == 0, "size should be 0");
00159 fail_if(decoded, "returned pointer should be NULL");
00160 
00161 UNITTEST_STOP


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