1cb93a386Sopenharmony_ci/* 2cb93a386Sopenharmony_ci * Copyright 2014 Google Inc. 3cb93a386Sopenharmony_ci * 4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be 5cb93a386Sopenharmony_ci * found in the LICENSE file. 6cb93a386Sopenharmony_ci */ 7cb93a386Sopenharmony_ci 8cb93a386Sopenharmony_ci#include "include/private/SkTo.h" 9cb93a386Sopenharmony_ci#include "include/utils/SkBase64.h" 10cb93a386Sopenharmony_ci 11cb93a386Sopenharmony_ci#include "tests/Test.h" 12cb93a386Sopenharmony_ci 13cb93a386Sopenharmony_ciDEF_TEST(SkBase64, reporter) { 14cb93a386Sopenharmony_ci char all[256]; 15cb93a386Sopenharmony_ci for (int index = 0; index < 255; ++index) { 16cb93a386Sopenharmony_ci all[index] = (signed char) (index + 1); 17cb93a386Sopenharmony_ci } 18cb93a386Sopenharmony_ci all[255] = 0; 19cb93a386Sopenharmony_ci 20cb93a386Sopenharmony_ci for (int offset = 0; offset < 6; ++offset) { 21cb93a386Sopenharmony_ci size_t length = 256 - offset; 22cb93a386Sopenharmony_ci 23cb93a386Sopenharmony_ci // Encode 24cb93a386Sopenharmony_ci size_t encodeLength = SkBase64::Encode(all + offset, length, nullptr); 25cb93a386Sopenharmony_ci SkAutoTMalloc<char> src(encodeLength + 1); 26cb93a386Sopenharmony_ci SkBase64::Encode(all + offset, length, src.get()); 27cb93a386Sopenharmony_ci 28cb93a386Sopenharmony_ci src[SkToInt(encodeLength)] = '\0'; 29cb93a386Sopenharmony_ci 30cb93a386Sopenharmony_ci // Decode 31cb93a386Sopenharmony_ci SkBase64::Error err; 32cb93a386Sopenharmony_ci 33cb93a386Sopenharmony_ci size_t decodeLength; 34cb93a386Sopenharmony_ci err = SkBase64::Decode(src.get(), encodeLength, nullptr, &decodeLength); 35cb93a386Sopenharmony_ci if (err != SkBase64::kNoError) { 36cb93a386Sopenharmony_ci REPORT_FAILURE(reporter, "err", SkString("SkBase64::Decode failed!")); 37cb93a386Sopenharmony_ci continue; 38cb93a386Sopenharmony_ci } 39cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, decodeLength == length); 40cb93a386Sopenharmony_ci 41cb93a386Sopenharmony_ci SkAutoTMalloc<char> dst(decodeLength); 42cb93a386Sopenharmony_ci err = SkBase64::Decode(src.get(), encodeLength, dst, &decodeLength); 43cb93a386Sopenharmony_ci if (err != SkBase64::kNoError) { 44cb93a386Sopenharmony_ci REPORT_FAILURE(reporter, "err", SkString("SkBase64::Decode failed!")); 45cb93a386Sopenharmony_ci continue; 46cb93a386Sopenharmony_ci } 47cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, decodeLength == length); 48cb93a386Sopenharmony_ci 49cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, (strcmp((const char*) (all + offset), dst.get()) == 0)); 50cb93a386Sopenharmony_ci } 51cb93a386Sopenharmony_ci} 52