blob: d855ef57ad2162142f8d22f8224d3a79157c5da6 [file] [log] [blame]
tfarina@chromium.orgceddfeb2014-01-30 22:51:42 +00001/*
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"
9
10#include "Test.h"
11
tfarina9ea53f92014-06-24 06:50:39 -070012DEF_TEST(SkBase64, reporter) {
tfarina@chromium.orgceddfeb2014-01-30 22:51:42 +000013 char all[256];
robertphillips@google.com70172882014-02-01 15:45:23 +000014 for (int index = 0; index < 256; ++index) {
tfarina@chromium.orgceddfeb2014-01-30 22:51:42 +000015 all[index] = (signed char) (index + 1);
16 }
17
robertphillips@google.com70172882014-02-01 15:45:23 +000018 for (int offset = 0; offset < 6; ++offset) {
tfarina@chromium.orgceddfeb2014-01-30 22:51:42 +000019 size_t length = 256 - offset;
halcanary96fcdcc2015-08-27 07:41:13 -070020 size_t encodeLength = SkBase64::Encode(all + offset, length, nullptr);
tfarina@chromium.orgceddfeb2014-01-30 22:51:42 +000021 SkAutoTMalloc<char> src(encodeLength + 1);
22 SkBase64::Encode(all + offset, length, src.get());
bsalomonfbaace02014-12-12 16:41:46 -080023 src[SkToInt(encodeLength)] = '\0';
tfarina@chromium.orgceddfeb2014-01-30 22:51:42 +000024 SkBase64 tryMe;
25 tryMe.decode(src.get(), encodeLength);
26 REPORTER_ASSERT(reporter, (strcmp((const char*) (all + offset), tryMe.getData()) == 0));
27 delete[] tryMe.getData();
28 }
29}