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

Side by Side Diff: base/md5_unittest.cc

Issue 7466003: MD5Update function uses StringPiece instead of raw buffer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: tfarina review Created 9 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
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <string.h> 5 #include <string.h>
6 #include <string> 6 #include <string>
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/md5.h" 10 #include "base/md5.h"
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 113
114 for (int i = 0; i < length; ++i) 114 for (int i = 0; i < length; ++i)
115 data[i] = i & 0xFF; 115 data[i] = i & 0xFF;
116 116
117 int total = 0; 117 int total = 0;
118 while (total < length) { 118 while (total < length) {
119 int len = 4097; // intentionally not 2^k. 119 int len = 4097; // intentionally not 2^k.
120 if (len > length - total) 120 if (len > length - total)
121 len = length - total; 121 len = length - total;
122 122
123 MD5Update(&ctx, data.get() + total, len); 123 MD5Update(&ctx,
124 StringPiece(reinterpret_cast<char*>(data.get() + total), len));
124 total += len; 125 total += len;
125 } 126 }
126 127
127 EXPECT_EQ(length, total); 128 EXPECT_EQ(length, total);
128 129
129 MD5Digest digest; 130 MD5Digest digest;
130 MD5Final(&digest, &ctx); 131 MD5Final(&digest, &ctx);
131 132
132 int expected[] = { 133 int expected[] = {
133 0x90, 0xbd, 0x6a, 0xd9, 134 0x90, 0xbd, 0x6a, 0xd9,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 182
182 TEST(MD5, MD5StringTestSuite7) { 183 TEST(MD5, MD5StringTestSuite7) {
183 std::string actual = MD5String("12345678901234567890" 184 std::string actual = MD5String("12345678901234567890"
184 "12345678901234567890" 185 "12345678901234567890"
185 "12345678901234567890" 186 "12345678901234567890"
186 "12345678901234567890"); 187 "12345678901234567890");
187 std::string expected = "57edf4a22be3c955ac49da2e2107b67a"; 188 std::string expected = "57edf4a22be3c955ac49da2e2107b67a";
188 EXPECT_EQ(expected, actual); 189 EXPECT_EQ(expected, actual);
189 } 190 }
190 191
192 TEST(MD5, ContextWithStringData) {
193 MD5Context ctx;
194 MD5Init(&ctx);
195
196 MD5Update(&ctx, "abc");
197
198 MD5Digest digest;
199 MD5Final(&digest, &ctx);
200
201 std::string actual = MD5DigestToBase16(digest);
202 std::string expected = "900150983cd24fb0d6963f7d28e17f72";
203
204 EXPECT_EQ(expected, actual);
205 }
206
191 } // namespace base 207 } // namespace base
OLDNEW
« base/md5.cc ('K') | « base/md5.cc ('k') | chrome/browser/bookmarks/bookmark_codec.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698