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 "include/private/SkTo.h"
9 #include "include/utils/SkBase64.h"
10 
11 #include "tests/Test.h"
12 
DEF_TEST(SkBase64,reporter)13 DEF_TEST(SkBase64, reporter) {
14     char all[256];
15     for (int index = 0; index < 255; ++index) {
16         all[index] = (signed char) (index + 1);
17     }
18     all[255] = 0;
19 
20     for (int offset = 0; offset < 6; ++offset) {
21         size_t length = 256 - offset;
22 
23         // Encode
24         size_t encodeLength = SkBase64::Encode(all + offset, length, nullptr);
25         SkAutoTMalloc<char> src(encodeLength + 1);
26         SkBase64::Encode(all + offset, length, src.get());
27 
28         src[SkToInt(encodeLength)] = '\0';
29 
30         // Decode
31         SkBase64::Error err;
32 
33         size_t decodeLength;
34         err = SkBase64::Decode(src.get(), encodeLength, nullptr, &decodeLength);
35         if (err != SkBase64::kNoError) {
36             REPORT_FAILURE(reporter, "err", SkString("SkBase64::Decode failed!"));
37             continue;
38         }
39         REPORTER_ASSERT(reporter, decodeLength == length);
40 
41         SkAutoTMalloc<char> dst(decodeLength);
42         err = SkBase64::Decode(src.get(), encodeLength, dst, &decodeLength);
43         if (err != SkBase64::kNoError) {
44             REPORT_FAILURE(reporter, "err", SkString("SkBase64::Decode failed!"));
45             continue;
46         }
47         REPORTER_ASSERT(reporter, decodeLength == length);
48 
49         REPORTER_ASSERT(reporter, (strcmp((const char*) (all + offset), dst.get()) == 0));
50     }
51 }
52