OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #include "SkBase64.h" | 10 #include "SkBase64.h" |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 | 155 |
156 SkBase64::Error SkBase64::decode(const char* src, size_t len) { | 156 SkBase64::Error SkBase64::decode(const char* src, size_t len) { |
157 Error err = decode(src, len, false); | 157 Error err = decode(src, len, false); |
158 SkASSERT(err == kNoError); | 158 SkASSERT(err == kNoError); |
159 if (err != kNoError) | 159 if (err != kNoError) |
160 return err; | 160 return err; |
161 fData = new char[fLength]; // should use sk_malloc/sk_free | 161 fData = new char[fLength]; // should use sk_malloc/sk_free |
162 decode(src, len, true); | 162 decode(src, len, true); |
163 return kNoError; | 163 return kNoError; |
164 } | 164 } |
165 | |
166 #ifdef SK_SUPPORT_UNITTEST | |
167 void SkBase64::UnitTest() { | |
168 signed char all[256]; | |
169 for (int index = 0; index < 256; index++) | |
170 all[index] = (signed char) (index + 1); | |
171 for (int offset = 0; offset < 6; offset++) { | |
172 size_t length = 256 - offset; | |
173 size_t encodeLength = Encode(all + offset, length, NULL); | |
174 char* src = (char*)sk_malloc_throw(encodeLength + 1); | |
175 Encode(all + offset, length, src); | |
176 src[encodeLength] = '\0'; | |
177 SkBase64 tryMe; | |
178 tryMe.decode(src, encodeLength); | |
179 SkASSERT(length == tryMe.fLength); | |
180 SkASSERT(strcmp((const char*) (all + offset), tryMe.fData) == 0); | |
181 sk_free(src); | |
182 delete[] tryMe.fData; | |
183 } | |
184 } | |
185 #endif | |
OLD | NEW |