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

Side by Side Diff: base/md5_unittest.cc

Issue 211503004: base::MD5Clone() clones MD5Context. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: commentsmithing. Created 6 years, 9 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
« no previous file with comments | « base/md5.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 197
198 MD5Digest digest; 198 MD5Digest digest;
199 MD5Final(&digest, &ctx); 199 MD5Final(&digest, &ctx);
200 200
201 std::string actual = MD5DigestToBase16(digest); 201 std::string actual = MD5DigestToBase16(digest);
202 std::string expected = "900150983cd24fb0d6963f7d28e17f72"; 202 std::string expected = "900150983cd24fb0d6963f7d28e17f72";
203 203
204 EXPECT_EQ(expected, actual); 204 EXPECT_EQ(expected, actual);
205 } 205 }
206 206
207 // Test that a cloned context gives the same digest as an uncloned context, and
208 // also that the cloned-from context gives the same digest as a context which
209 // was never cloned.
210 TEST(MD5, Clone) {
211 // Independent context over the header.
212 MD5Context check_header_context;
213 MD5Init(&check_header_context);
214
215 // Independent context over entire input.
216 MD5Context check_full_context;
217 MD5Init(&check_full_context);
218
219 // Context will be cloned after header.
220 MD5Context context;
221 MD5Init(&context);
222
223 const char kHeader[] = "header data";
224 const char kBody[] = "payload data";
225
226 MD5Update(&context, kHeader);
227 MD5Update(&check_header_context, kHeader);
228 MD5Update(&check_full_context, kHeader);
229
230 MD5Digest check_header_digest;
231 MD5Final(&check_header_digest, &check_header_context);
232
233 MD5Context clone_context;
234 MD5Clone(&clone_context, &context);
235
236 MD5Digest clone_digest;
237 MD5Final(&clone_digest, &clone_context);
238
239 MD5Update(&context, kBody);
240 MD5Update(&check_full_context, kBody);
241
242 MD5Digest check_full_digest;
243 MD5Final(&check_full_digest, &check_full_context);
244
245 MD5Digest digest;
246 MD5Final(&digest, &context);
247
248 // The header and full digest pairs are the same, and they aren't the same as
249 // each other.
250 EXPECT_TRUE(!memcmp(&check_header_digest, &clone_digest,
251 sizeof(check_header_digest)));
252 EXPECT_TRUE(!memcmp(&digest, &check_full_digest, sizeof(digest)));
253 EXPECT_FALSE(!memcmp(&digest, &clone_digest, sizeof(digest)));
254 }
255
207 } // namespace base 256 } // namespace base
OLDNEW
« no previous file with comments | « base/md5.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698