00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "curlcheck.h"
00023
00024 #include "urldata.h"
00025 #include "url.h"
00026 #include "curl_base64.h"
00027 #include "memdebug.h"
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
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
00126 size = 1;
00127 decoded = &anychar;
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
00135 size = 1;
00136 decoded = &anychar;
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
00144 size = 1;
00145 decoded = &anychar;
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
00153 size = 1;
00154 decoded = &anychar;
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