OLD | NEW |
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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 0x31, 0xc3, 0x99, 0xe2, | 60 0x31, 0xc3, 0x99, 0xe2, |
61 0x69, 0x77, 0x26, 0x61 | 61 0x69, 0x77, 0x26, 0x61 |
62 }; | 62 }; |
63 | 63 |
64 for (int i = 0; i < 16; ++i) | 64 for (int i = 0; i < 16; ++i) |
65 EXPECT_EQ(expected[i], digest.a[i] & 0xFF); | 65 EXPECT_EQ(expected[i], digest.a[i] & 0xFF); |
66 } | 66 } |
67 | 67 |
68 TEST(MD5, MD5SumLongData) { | 68 TEST(MD5, MD5SumLongData) { |
69 const int length = 10 * 1024 * 1024 + 1; | 69 const int length = 10 * 1024 * 1024 + 1; |
70 scoped_array<char> data(new char[length]); | 70 scoped_ptr<char[]> data(new char[length]); |
71 | 71 |
72 for (int i = 0; i < length; ++i) | 72 for (int i = 0; i < length; ++i) |
73 data[i] = i & 0xFF; | 73 data[i] = i & 0xFF; |
74 | 74 |
75 MD5Digest digest; | 75 MD5Digest digest; |
76 MD5Sum(data.get(), length, &digest); | 76 MD5Sum(data.get(), length, &digest); |
77 | 77 |
78 int expected[] = { | 78 int expected[] = { |
79 0x90, 0xbd, 0x6a, 0xd9, | 79 0x90, 0xbd, 0x6a, 0xd9, |
80 0x0a, 0xce, 0xf5, 0xad, | 80 0x0a, 0xce, 0xf5, 0xad, |
(...skipping 21 matching lines...) Expand all Loading... |
102 | 102 |
103 for (int i = 0; i < 16; ++i) | 103 for (int i = 0; i < 16; ++i) |
104 EXPECT_EQ(expected[i], digest.a[i] & 0xFF); | 104 EXPECT_EQ(expected[i], digest.a[i] & 0xFF); |
105 } | 105 } |
106 | 106 |
107 TEST(MD5, ContextWithLongData) { | 107 TEST(MD5, ContextWithLongData) { |
108 MD5Context ctx; | 108 MD5Context ctx; |
109 MD5Init(&ctx); | 109 MD5Init(&ctx); |
110 | 110 |
111 const int length = 10 * 1024 * 1024 + 1; | 111 const int length = 10 * 1024 * 1024 + 1; |
112 scoped_array<char> data(new char[length]); | 112 scoped_ptr<char[]> data(new char[length]); |
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 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 } // namespace base | 207 } // namespace base |
OLD | NEW |