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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "include/private/SkTo.h" |
| 9 | #include "include/utils/SkBase64.h" |
tfarina@chromium.org | ceddfeb | 2014-01-30 22:51:42 +0000 | [diff] [blame] | 10 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "tests/Test.h" |
tfarina@chromium.org | ceddfeb | 2014-01-30 22:51:42 +0000 | [diff] [blame] | 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]; |
Brian Osman | 50ea3c0 | 2019-02-04 10:01:53 -0500 | [diff] [blame] | 15 | for (int index = 0; index < 255; ++index) { |
tfarina@chromium.org | ceddfeb | 2014-01-30 22:51:42 +0000 | [diff] [blame] | 16 | all[index] = (signed char) (index + 1); |
| 17 | } |
Brian Osman | 50ea3c0 | 2019-02-04 10:01:53 -0500 | [diff] [blame] | 18 | all[255] = 0; |
tfarina@chromium.org | ceddfeb | 2014-01-30 22:51:42 +0000 | [diff] [blame] | 19 | |
robertphillips@google.com | 7017288 | 2014-02-01 15:45:23 +0000 | [diff] [blame] | 20 | for (int offset = 0; offset < 6; ++offset) { |
tfarina@chromium.org | ceddfeb | 2014-01-30 22:51:42 +0000 | [diff] [blame] | 21 | size_t length = 256 - offset; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 22 | size_t encodeLength = SkBase64::Encode(all + offset, length, nullptr); |
tfarina@chromium.org | ceddfeb | 2014-01-30 22:51:42 +0000 | [diff] [blame] | 23 | SkAutoTMalloc<char> src(encodeLength + 1); |
| 24 | SkBase64::Encode(all + offset, length, src.get()); |
bsalomon | fbaace0 | 2014-12-12 16:41:46 -0800 | [diff] [blame] | 25 | src[SkToInt(encodeLength)] = '\0'; |
tfarina@chromium.org | ceddfeb | 2014-01-30 22:51:42 +0000 | [diff] [blame] | 26 | SkBase64 tryMe; |
| 27 | tryMe.decode(src.get(), encodeLength); |
| 28 | REPORTER_ASSERT(reporter, (strcmp((const char*) (all + offset), tryMe.getData()) == 0)); |
| 29 | delete[] tryMe.getData(); |
| 30 | } |
| 31 | } |