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

Unified Diff: base/md5_unittest.cc

Issue 6896006: added md5_unittest (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 9 years, 8 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 side-by-side diff with in-line comments
Download patch
« base/base.gyp ('K') | « base/base.gyp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/md5_unittest.cc
diff --git a/base/md5_unittest.cc b/base/md5_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..81d44b5f347fb4dcb54eb9d5fd61852f0045bac5
--- /dev/null
+++ b/base/md5_unittest.cc
@@ -0,0 +1,115 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
Mark Mentovai 2011/04/22 03:13:29 In addition to the test data that you have, I’d li
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <string>
+
+#include "base/logging.h"
+#include "base/md5.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using namespace std;
Mark Mentovai 2011/04/22 03:13:29 This is forbidden. http://google-styleguide.googl
+
+TEST(MD5, EmtpyString) {
+ MD5Digest digest;
+ const char* data = "";
+
+ MD5Sum(data, strlen(data), &digest);
Mark Mentovai 2011/04/22 03:13:29 #include <string.h>. Alternatively, #include "bas
+
+ string expected = "d41d8cd98f00b204e9800998ecf8427e";
+ string actual = MD5DigestToBase16(digest);
Mark Mentovai 2011/04/22 03:13:29 All of your tests run “actual” through MD5DigestTo
+
+ EXPECT_EQ(expected, actual);
+}
+
+TEST(MD5, OneByteStrnig) {
Mark Mentovai 2011/04/22 03:13:29 Typo: OneByteString.
+ MD5Digest digest;
+ const char* data = "a";
+
+ MD5Sum(data, strlen(data), &digest);
+
+ string expected = "0cc175b9c0f1b6a831c399e269772661";
+ string actual = MD5DigestToBase16(digest);
+
+ EXPECT_EQ(expected, actual);
+}
+
+TEST(MD5, ShortString) {
+ MD5Digest digest;
+ const char* data = "The quick brown fox jumps over the lazy dog";
+
+ MD5Sum(data, strlen(data), &digest);
+
+ string expected = "9e107d9d372bb6826bd81d3542a419d6";
+ string actual = MD5DigestToBase16(digest);
+
+ EXPECT_EQ(expected, actual);
+}
+
+TEST(MD5, LongString) {
+ MD5Digest digest;
+
+ const int N = 10 * 1024 * 1024 + 1;
Mark Mentovai 2011/04/22 03:13:29 N is a bad name for a variable. Also below on line
+ char* data = new char[N];
+
+ for (int i = 0; i < N; ++i) {
+ data[i] = i & 0xFF;
+ }
+
+ MD5Sum(data, N, &digest);
+
+ string expected = "90bd6ad90acef5adaa92203e21c7a13e";
+ string actual = MD5DigestToBase16(digest);
+
+ EXPECT_EQ(expected, actual);
+
+ delete[] data;
+}
+
+TEST(MD5, ContextWithEmptyData) {
+ MD5Context ctx;
+ MD5Init(&ctx);
+
+ MD5Digest digest;
+ MD5Final(&digest, &ctx);
+
+ string expected = "d41d8cd98f00b204e9800998ecf8427e";
+ string actual = MD5DigestToBase16(digest);
+
+ EXPECT_EQ(expected, actual);
+}
+
+TEST(MD5, ContextWithLongData) {
+ MD5Context ctx;
+ MD5Init(&ctx);
+
+ const int N = 10 * 1024 * 1024 + 1;
+ char* data = new char[N];
+
+ for (int i = 0; i < N; ++i) {
+ data[i] = i & 0xFF;
+ }
+
+ int totalLen = 0;
Mark Mentovai 2011/04/22 03:13:29 Variables are named like_this and not likeThis. h
+ while (totalLen < N) {
+ int len = 4097; // intentionally not 2^k.
Mark Mentovai 2011/04/22 03:13:29 http://google-styleguide.googlecode.com/svn/trunk/
+ if (len > N - totalLen) {
+ len = N - totalLen;
+ }
+
+ MD5Update(&ctx, data + totalLen, len);
+ totalLen += len;
+ }
+
+ DCHECK_EQ(totalLen, N);
Mark Mentovai 2011/04/22 03:13:29 EXPECT_EQ(N, total_length)?
+
+ MD5Digest digest;
+ MD5Final(&digest, &ctx);
+
+ string expected = "90bd6ad90acef5adaa92203e21c7a13e";
+ string actual = MD5DigestToBase16(digest);
+
+ EXPECT_EQ(expected, actual);
+
+ delete[] data;
+}
Mark Mentovai 2011/04/22 03:13:29 No test of MD5String?
« base/base.gyp ('K') | « base/base.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698