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

Side by Side Diff: third_party/libaddressinput/chromium/cpp/test/util/md5_unittest.cc

Issue 389863002: Remove Chrome's own version of libaddressinput in favor of the upstream. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2013 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 // The original source code is from:
6 // http://src.chromium.org/viewvc/chrome/trunk/src/base/md5_unittest.cc?revision =94203
7
8 #include "util/md5.h"
9
10 #include <libaddressinput/util/scoped_ptr.h>
11
12 #include <cstring>
13 #include <string>
14
15 #include <gtest/gtest.h>
16
17 namespace {
18
19 using i18n::addressinput::MD5Context;
20 using i18n::addressinput::MD5Digest;
21 using i18n::addressinput::MD5Init;
22 using i18n::addressinput::MD5String;
23 using i18n::addressinput::MD5Update;
24
25 TEST(MD5, DigestToBase16) {
26 MD5Digest digest;
27
28 int data[] = {
29 0xd4, 0x1d, 0x8c, 0xd9,
30 0x8f, 0x00, 0xb2, 0x04,
31 0xe9, 0x80, 0x09, 0x98,
32 0xec, 0xf8, 0x42, 0x7e
33 };
34
35 for (int i = 0; i < 16; ++i)
36 digest.a[i] = data[i] & 0xff;
37
38 std::string actual = MD5DigestToBase16(digest);
39 std::string expected = "d41d8cd98f00b204e9800998ecf8427e";
40
41 EXPECT_EQ(expected, actual);
42 }
43
44 TEST(MD5, MD5SumEmtpyData) {
45 MD5Digest digest;
46 const char* data = "";
47
48 MD5Sum(data, strlen(data), &digest);
49
50 int expected[] = {
51 0xd4, 0x1d, 0x8c, 0xd9,
52 0x8f, 0x00, 0xb2, 0x04,
53 0xe9, 0x80, 0x09, 0x98,
54 0xec, 0xf8, 0x42, 0x7e
55 };
56
57 for (int i = 0; i < 16; ++i)
58 EXPECT_EQ(expected[i], digest.a[i] & 0xFF);
59 }
60
61 TEST(MD5, MD5SumOneByteData) {
62 MD5Digest digest;
63 const char* data = "a";
64
65 MD5Sum(data, strlen(data), &digest);
66
67 int expected[] = {
68 0x0c, 0xc1, 0x75, 0xb9,
69 0xc0, 0xf1, 0xb6, 0xa8,
70 0x31, 0xc3, 0x99, 0xe2,
71 0x69, 0x77, 0x26, 0x61
72 };
73
74 for (int i = 0; i < 16; ++i)
75 EXPECT_EQ(expected[i], digest.a[i] & 0xFF);
76 }
77
78 TEST(MD5, MD5SumLongData) {
79 const int length = 10 * 1024 * 1024 + 1;
80 scoped_ptr<char[]> data(new char[length]);
81
82 for (int i = 0; i < length; ++i)
83 data[i] = i & 0xFF;
84
85 MD5Digest digest;
86 MD5Sum(data.get(), length, &digest);
87
88 int expected[] = {
89 0x90, 0xbd, 0x6a, 0xd9,
90 0x0a, 0xce, 0xf5, 0xad,
91 0xaa, 0x92, 0x20, 0x3e,
92 0x21, 0xc7, 0xa1, 0x3e
93 };
94
95 for (int i = 0; i < 16; ++i)
96 EXPECT_EQ(expected[i], digest.a[i] & 0xFF);
97 }
98
99 TEST(MD5, ContextWithEmptyData) {
100 MD5Context ctx;
101 MD5Init(&ctx);
102
103 MD5Digest digest;
104 MD5Final(&digest, &ctx);
105
106 int expected[] = {
107 0xd4, 0x1d, 0x8c, 0xd9,
108 0x8f, 0x00, 0xb2, 0x04,
109 0xe9, 0x80, 0x09, 0x98,
110 0xec, 0xf8, 0x42, 0x7e
111 };
112
113 for (int i = 0; i < 16; ++i)
114 EXPECT_EQ(expected[i], digest.a[i] & 0xFF);
115 }
116
117 TEST(MD5, ContextWithLongData) {
118 MD5Context ctx;
119 MD5Init(&ctx);
120
121 const int length = 10 * 1024 * 1024 + 1;
122 scoped_ptr<char[]> data(new char[length]);
123
124 for (int i = 0; i < length; ++i)
125 data[i] = i & 0xFF;
126
127 int total = 0;
128 while (total < length) {
129 int len = 4097; // intentionally not 2^k.
130 if (len > length - total)
131 len = length - total;
132
133 MD5Update(&ctx,
134 std::string(reinterpret_cast<char*>(data.get() + total), len));
135 total += len;
136 }
137
138 EXPECT_EQ(length, total);
139
140 MD5Digest digest;
141 MD5Final(&digest, &ctx);
142
143 int expected[] = {
144 0x90, 0xbd, 0x6a, 0xd9,
145 0x0a, 0xce, 0xf5, 0xad,
146 0xaa, 0x92, 0x20, 0x3e,
147 0x21, 0xc7, 0xa1, 0x3e
148 };
149
150 for (int i = 0; i < 16; ++i)
151 EXPECT_EQ(expected[i], digest.a[i] & 0xFF);
152 }
153
154 // Example data from http://www.ietf.org/rfc/rfc1321.txt A.5 Test Suite
155 TEST(MD5, MD5StringTestSuite1) {
156 std::string actual = MD5String("");
157 std::string expected = "d41d8cd98f00b204e9800998ecf8427e";
158 EXPECT_EQ(expected, actual);
159 }
160
161 TEST(MD5, MD5StringTestSuite2) {
162 std::string actual = MD5String("a");
163 std::string expected = "0cc175b9c0f1b6a831c399e269772661";
164 EXPECT_EQ(expected, actual);
165 }
166
167 TEST(MD5, MD5StringTestSuite3) {
168 std::string actual = MD5String("abc");
169 std::string expected = "900150983cd24fb0d6963f7d28e17f72";
170 EXPECT_EQ(expected, actual);
171 }
172
173 TEST(MD5, MD5StringTestSuite4) {
174 std::string actual = MD5String("message digest");
175 std::string expected = "f96b697d7cb7938d525a2f31aaf161d0";
176 EXPECT_EQ(expected, actual);
177 }
178
179 TEST(MD5, MD5StringTestSuite5) {
180 std::string actual = MD5String("abcdefghijklmnopqrstuvwxyz");
181 std::string expected = "c3fcd3d76192e4007dfb496cca67e13b";
182 EXPECT_EQ(expected, actual);
183 }
184
185 TEST(MD5, MD5StringTestSuite6) {
186 std::string actual = MD5String("ABCDEFGHIJKLMNOPQRSTUVWXYZ"
187 "abcdefghijklmnopqrstuvwxyz"
188 "0123456789");
189 std::string expected = "d174ab98d277d9f5a5611c2c9f419d9f";
190 EXPECT_EQ(expected, actual);
191 }
192
193 TEST(MD5, MD5StringTestSuite7) {
194 std::string actual = MD5String("12345678901234567890"
195 "12345678901234567890"
196 "12345678901234567890"
197 "12345678901234567890");
198 std::string expected = "57edf4a22be3c955ac49da2e2107b67a";
199 EXPECT_EQ(expected, actual);
200 }
201
202 TEST(MD5, ContextWithStringData) {
203 MD5Context ctx;
204 MD5Init(&ctx);
205
206 MD5Update(&ctx, "abc");
207
208 MD5Digest digest;
209 MD5Final(&digest, &ctx);
210
211 std::string actual = MD5DigestToBase16(digest);
212 std::string expected = "900150983cd24fb0d6963f7d28e17f72";
213
214 EXPECT_EQ(expected, actual);
215 }
216
217 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698