tfarina@chromium.org | ceddfeb | 2014-01-30 22:51:42 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "SkBase64.h" |
Hal Canary | c640d0d | 2018-06-13 09:59:02 -0400 | [diff] [blame] | 9 | #include "SkTo.h" |
tfarina@chromium.org | ceddfeb | 2014-01-30 22:51:42 +0000 | [diff] [blame] | 10 | |
| 11 | #include "Test.h" |
| 12 | |
tfarina | 9ea53f9 | 2014-06-24 06:50:39 -0700 | [diff] [blame] | 13 | DEF_TEST(SkBase64, reporter) { |
tfarina@chromium.org | ceddfeb | 2014-01-30 22:51:42 +0000 | [diff] [blame] | 14 | char all[256]; |
robertphillips@google.com | 7017288 | 2014-02-01 15:45:23 +0000 | [diff] [blame] | 15 | for (int index = 0; index < 256; ++index) { |
tfarina@chromium.org | ceddfeb | 2014-01-30 22:51:42 +0000 | [diff] [blame] | 16 | all[index] = (signed char) (index + 1); |
| 17 | } |
| 18 | |
robertphillips@google.com | 7017288 | 2014-02-01 15:45:23 +0000 | [diff] [blame] | 19 | for (int offset = 0; offset < 6; ++offset) { |
tfarina@chromium.org | ceddfeb | 2014-01-30 22:51:42 +0000 | [diff] [blame] | 20 | size_t length = 256 - offset; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 21 | size_t encodeLength = SkBase64::Encode(all + offset, length, nullptr); |
tfarina@chromium.org | ceddfeb | 2014-01-30 22:51:42 +0000 | [diff] [blame] | 22 | SkAutoTMalloc<char> src(encodeLength + 1); |
| 23 | SkBase64::Encode(all + offset, length, src.get()); |
bsalomon | fbaace0 | 2014-12-12 16:41:46 -0800 | [diff] [blame] | 24 | src[SkToInt(encodeLength)] = '\0'; |
tfarina@chromium.org | ceddfeb | 2014-01-30 22:51:42 +0000 | [diff] [blame] | 25 | SkBase64 tryMe; |
| 26 | tryMe.decode(src.get(), encodeLength); |
| 27 | REPORTER_ASSERT(reporter, (strcmp((const char*) (all + offset), tryMe.getData()) == 0)); |
| 28 | delete[] tryMe.getData(); |
| 29 | } |
| 30 | } |