Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: components/base32/base32_unittest.cc

Issue 2017123002: Adds a base32 component. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addresses gab's comments Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/base32/base32.cc ('k') | components/components.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <string>
6
7 #include "components/base32/base32.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9
10 namespace base32 {
11 namespace {
12
13 TEST(Base32Test, EncodesRfcTestVectorsCorrectlyWithoutPadding) {
14 // Tests from http://tools.ietf.org/html/rfc4648#section-10.
15 const std::string test_str = "foobar";
gab 2016/06/07 01:24:10 s/const std::string/constexpr char[]/ here and in
Rob Percival 2016/06/07 23:11:15 Done.
16
17 const std::string expected[] = {"", "MY", "MZXQ", "MZXW6",
18 "MZXW6YQ", "MZXW6YTB", "MZXW6YTBOI"};
19
20 // Run the tests, with one more letter in the input every pass.
21 for (size_t i = 0; i < arraysize(expected); ++i) {
22 std::string output = Base32Encode(base::StringPiece(test_str.data(), i),
23 Base32EncodePolicy::OMIT_PADDING);
24 EXPECT_EQ(expected[i], output);
25 }
26 }
27
28 TEST(Base32Test, EncodesRfcTestVectorsCorrectlyWithPadding) {
29 // Tests from http://tools.ietf.org/html/rfc4648#section-10.
30 const std::string test_str = "foobar";
31
32 const std::string expected[] = {
33 "", "MY======", "MZXQ====", "MZXW6===",
34 "MZXW6YQ=", "MZXW6YTB", "MZXW6YTBOI======"};
35
36 // Run the tests, with one more letter in the input every pass.
37 for (size_t i = 0; i < arraysize(expected); ++i) {
38 std::string output = Base32Encode(base::StringPiece(test_str.data(), i));
39 EXPECT_EQ(expected[i], output);
40 }
41 }
42
43 TEST(Base32Test, EncodesSha256HashCorrectly) {
44 // Useful to test with longer input than the RFC test vectors, and encoding
45 // SHA-256 hashes is one of the use cases for this component.
46 const std::string hash =
47 "\x1f\x25\xe1\xca\xba\x4f\xf9\xb8\x27\x24\x83\x0f\xca\x60\xe4\xc2\xbe\xa8"
48 "\xc3\xa9\x44\x1c\x27\xb0\xb4\x3e\x6a\x96\x94\xc7\xb8\x04";
49 std::string output = Base32Encode(hash, Base32EncodePolicy::OMIT_PADDING);
50 EXPECT_EQ("D4S6DSV2J743QJZEQMH4UYHEYK7KRQ5JIQOCPMFUHZVJNFGHXACA", output);
51 }
52
53 } // namespace
54 } // namespace base32
OLDNEW
« no previous file with comments | « components/base32/base32.cc ('k') | components/components.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698