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

Side by Side Diff: chrome/browser/safe_browsing/prefix_set_unittest.cc

Issue 7466003: MD5Update function uses StringPiece instead of raw buffer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove line from license. 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 "chrome/browser/safe_browsing/prefix_set.h" 5 #include "chrome/browser/safe_browsing/prefix_set.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 long file_size = ftell(fp); 106 long file_size = ftell(fp);
107 107
108 using base::MD5Digest; 108 using base::MD5Digest;
109 size_t payload_size = static_cast<size_t>(file_size) - sizeof(MD5Digest); 109 size_t payload_size = static_cast<size_t>(file_size) - sizeof(MD5Digest);
110 size_t digested_size = 0; 110 size_t digested_size = 0;
111 ASSERT_NE(-1, fseek(fp, 0, SEEK_SET)); 111 ASSERT_NE(-1, fseek(fp, 0, SEEK_SET));
112 while (digested_size < payload_size) { 112 while (digested_size < payload_size) {
113 char buf[1024]; 113 char buf[1024];
114 size_t nitems = std::min(payload_size - digested_size, sizeof(buf)); 114 size_t nitems = std::min(payload_size - digested_size, sizeof(buf));
115 ASSERT_EQ(nitems, fread(buf, 1, nitems, fp)); 115 ASSERT_EQ(nitems, fread(buf, 1, nitems, fp));
116 base::MD5Update(&context, &buf, nitems); 116 base::MD5Update(&context, base::StringPiece(buf, nitems));
117 digested_size += nitems; 117 digested_size += nitems;
118 } 118 }
119 ASSERT_EQ(digested_size, payload_size); 119 ASSERT_EQ(digested_size, payload_size);
120 ASSERT_EQ(static_cast<long>(digested_size), ftell(fp)); 120 ASSERT_EQ(static_cast<long>(digested_size), ftell(fp));
121 121
122 base::MD5Digest new_digest; 122 base::MD5Digest new_digest;
123 base::MD5Final(&new_digest, &context); 123 base::MD5Final(&new_digest, &context);
124 ASSERT_NE(-1, fseek(fp, digested_size, SEEK_SET)); 124 ASSERT_NE(-1, fseek(fp, digested_size, SEEK_SET));
125 ASSERT_EQ(1U, fwrite(&new_digest, sizeof(new_digest), 1, fp)); 125 ASSERT_EQ(1U, fwrite(&new_digest, sizeof(new_digest), 1, fp));
126 ASSERT_EQ(file_size, ftell(fp)); 126 ASSERT_EQ(file_size, ftell(fp));
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 if (delta > 0xFFFF) { 448 if (delta > 0xFFFF) {
449 EXPECT_FALSE(prefix_set.IsDeltaAt(i)); 449 EXPECT_FALSE(prefix_set.IsDeltaAt(i));
450 } else { 450 } else {
451 ASSERT_TRUE(prefix_set.IsDeltaAt(i)); 451 ASSERT_TRUE(prefix_set.IsDeltaAt(i));
452 EXPECT_EQ(delta, prefix_set.DeltaAt(i)); 452 EXPECT_EQ(delta, prefix_set.DeltaAt(i));
453 } 453 }
454 } 454 }
455 } 455 }
456 456
457 } // namespace 457 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/prefix_set.cc ('k') | chrome/browser/safe_browsing/safe_browsing_store_file.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698