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

Side by Side Diff: tests/MD5Test.cpp

Issue 14265010: Make SkSHA1 and SkM5 use common SkDigestHash result type (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: switch_to_MD5 Created 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 #include "Test.h" 7 #include "Test.h"
8 #include "SkMD5.h" 8 #include "SkMD5.h"
9 9
10 static bool digests_equal(const SkMD5::Digest& expectedDigest, const SkMD5::Dige st& computedDigest) { 10 struct MD5Digest {
11 for (size_t i = 0; i < SK_ARRAY_COUNT(expectedDigest.data); ++i) { 11 uint8_t data[16];
12 if (expectedDigest.data[i] != computedDigest.data[i]) { 12 };
13 return false;
14 }
15 }
16 return true;
17 }
18 13
19 static void md5_test(const char* string, const SkMD5::Digest& expectedDigest, sk iatest::Reporter* reporter) { 14 static void md5_test(const char* string, const SkHashDigest& expectedDigest,
15 skiatest::Reporter* reporter) {
20 size_t len = strlen(string); 16 size_t len = strlen(string);
21 17
22 // All at once 18 // All at once
23 { 19 {
24 SkMD5 context; 20 SkMD5 context;
25 context.update(reinterpret_cast<const uint8_t*>(string), len); 21 context.update(reinterpret_cast<const uint8_t*>(string), len);
26 SkMD5::Digest digest; 22 SkHashDigest actualDigest;
27 context.finish(digest); 23 context.finish(actualDigest);
28 24
29 REPORTER_ASSERT(reporter, digests_equal(expectedDigest, digest)); 25 REPORTER_ASSERT(reporter, expectedDigest.equals(actualDigest));
30 } 26 }
31 27
32 // One byte at a time. 28 // One byte at a time.
33 { 29 {
34 SkMD5 context; 30 SkMD5 context;
35 const uint8_t* data = reinterpret_cast<const uint8_t*>(string); 31 const uint8_t* data = reinterpret_cast<const uint8_t*>(string);
36 const uint8_t* end = reinterpret_cast<const uint8_t*>(string + len); 32 const uint8_t* end = reinterpret_cast<const uint8_t*>(string + len);
37 for (; data < end; ++data) { 33 for (; data < end; ++data) {
38 context.update(data, 1); 34 context.update(data, 1);
39 } 35 }
40 SkMD5::Digest digest; 36 SkHashDigest actualDigest;
41 context.finish(digest); 37 context.finish(actualDigest);
42 38
43 REPORTER_ASSERT(reporter, digests_equal(expectedDigest, digest)); 39 REPORTER_ASSERT(reporter, expectedDigest.equals(actualDigest));
44 } 40 }
45 } 41 }
46 42
47 static struct MD5Test { 43 static struct MD5Test {
48 const char* message; 44 const char* message;
49 SkMD5::Digest digest; 45 const MD5Digest digestBytes;
50 } md5_tests[] = { 46 } md5_tests[] = {
51 // Reference tests from RFC1321 Section A.5 ( http://www.ietf.org/rfc/rfc132 1.txt ) 47 // Reference tests from RFC1321 Section A.5 ( http://www.ietf.org/rfc/rfc132 1.txt )
52 { "", {{ 0xd4, 0x1d, 0x8c, 0xd9, 0x8f, 0x00, 0xb2, 0x04, 0xe9, 0x80, 0x09, 0 x98, 0xec, 0xf8, 0x42, 0x7e }} }, 48 { "", {{ 0xd4, 0x1d, 0x8c, 0xd9, 0x8f, 0x00, 0xb2, 0x04, 0xe9, 0x80, 0x09, 0 x98, 0xec, 0xf8, 0x42, 0x7e }} },
53 { "a", {{ 0x0c, 0xc1, 0x75, 0xb9, 0xc0, 0xf1, 0xb6, 0xa8, 0x31, 0xc3, 0x99, 0xe2, 0x69, 0x77, 0x26, 0x61 }} }, 49 { "a", {{ 0x0c, 0xc1, 0x75, 0xb9, 0xc0, 0xf1, 0xb6, 0xa8, 0x31, 0xc3, 0x99, 0xe2, 0x69, 0x77, 0x26, 0x61 }} },
54 { "abc", {{ 0x90, 0x01, 0x50, 0x98, 0x3c, 0xd2, 0x4f, 0xb0, 0xd6, 0x96, 0x3f , 0x7d, 0x28, 0xe1, 0x7f, 0x72 }} }, 50 { "abc", {{ 0x90, 0x01, 0x50, 0x98, 0x3c, 0xd2, 0x4f, 0xb0, 0xd6, 0x96, 0x3f , 0x7d, 0x28, 0xe1, 0x7f, 0x72 }} },
55 { "message digest", {{ 0xf9, 0x6b, 0x69, 0x7d, 0x7c, 0xb7, 0x93, 0x8d, 0x52, 0x5a, 0x2f, 0x31, 0xaa, 0xf1, 0x61, 0xd0 }} }, 51 { "message digest", {{ 0xf9, 0x6b, 0x69, 0x7d, 0x7c, 0xb7, 0x93, 0x8d, 0x52, 0x5a, 0x2f, 0x31, 0xaa, 0xf1, 0x61, 0xd0 }} },
56 { "abcdefghijklmnopqrstuvwxyz", {{ 0xc3, 0xfc, 0xd3, 0xd7, 0x61, 0x92, 0xe4, 0x00, 0x7d, 0xfb, 0x49, 0x6c, 0xca, 0x67, 0xe1, 0x3b }} }, 52 { "abcdefghijklmnopqrstuvwxyz", {{ 0xc3, 0xfc, 0xd3, 0xd7, 0x61, 0x92, 0xe4, 0x00, 0x7d, 0xfb, 0x49, 0x6c, 0xca, 0x67, 0xe1, 0x3b }} },
57 { "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", {{ 0xd1, 0x74, 0xab, 0x98, 0xd2, 0x77, 0xd9, 0xf5, 0xa5, 0x61, 0x1c, 0x2c, 0x9f, 0x41, 0 x9d, 0x9f }} }, 53 { "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", {{ 0xd1, 0x74, 0xab, 0x98, 0xd2, 0x77, 0xd9, 0xf5, 0xa5, 0x61, 0x1c, 0x2c, 0x9f, 0x41, 0 x9d, 0x9f }} },
58 { "1234567890123456789012345678901234567890123456789012345678901234567890123 4567890", {{ 0x57, 0xed, 0xf4, 0xa2, 0x2b, 0xe3, 0xc9, 0x55, 0xac, 0x49, 0xda, 0 x2e, 0x21, 0x07, 0xb6, 0x7a }} }, 54 { "1234567890123456789012345678901234567890123456789012345678901234567890123 4567890", {{ 0x57, 0xed, 0xf4, 0xa2, 0x2b, 0xe3, 0xc9, 0x55, 0xac, 0x49, 0xda, 0 x2e, 0x21, 0x07, 0xb6, 0x7a }} },
59 }; 55 };
60 56
61 static void TestMD5(skiatest::Reporter* reporter) { 57 static void TestMD5(skiatest::Reporter* reporter) {
62 for (size_t i = 0; i < SK_ARRAY_COUNT(md5_tests); ++i) { 58 for (size_t i = 0; i < SK_ARRAY_COUNT(md5_tests); ++i) {
63 md5_test(md5_tests[i].message, md5_tests[i].digest, reporter); 59 SkHashDigest expectedDigest(md5_tests[i].digestBytes.data,
60 sizeof(md5_tests[i].digestBytes.data));
61 md5_test(md5_tests[i].message, expectedDigest, reporter);
64 } 62 }
65 } 63 }
66 64
67 #include "TestClassDef.h" 65 #include "TestClassDef.h"
68 DEFINE_TESTCLASS("MD5", MD5TestClass, TestMD5) 66 DEFINE_TESTCLASS("MD5", MD5TestClass, TestMD5)
OLDNEW
« tests/BitmapHasherTest.cpp ('K') | « tests/BitmapHasherTest.cpp ('k') | tests/SHA1Test.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698