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

Side by Side Diff: tests/SHA1Test.cpp

Issue 14265010: Make SkSHA1 and SkM5 use common SkDigestHash result type (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: add_SkHashDigest_wrapper_for_cityhash 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
« tests/BitmapHasherTest.cpp ('K') | « tests/MD5Test.cpp ('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 /* 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 "SkSHA1.h" 8 #include "SkSHA1.h"
9 9
10 static bool digests_equal(const SkSHA1::Digest& expectedDigest, const SkSHA1::Di gest& computedDigest) { 10 struct SHA1Digest {
11 for (size_t i = 0; i < SK_ARRAY_COUNT(expectedDigest.data); ++i) { 11 uint8_t data[20];
12 if (expectedDigest.data[i] != computedDigest.data[i]) { 12 };
13 return false;
14 }
15 }
16 return true;
17 }
18 13
19 static struct SHA1Test { 14 static struct SHA1Test {
20 const char* message; 15 const char* message;
21 const unsigned long int repeatCount; 16 const unsigned long int repeatCount;
22 const SkSHA1::Digest digest; 17 const SHA1Digest digestBytes;
23 } sha1_tests[] = { 18 } sha1_tests[] = {
24 // Reference tests from RFC3174 Section 7.3 ( http://www.ietf.org/rfc/rfc317 4.txt ) 19 // Reference tests from RFC3174 Section 7.3 ( http://www.ietf.org/rfc/rfc317 4.txt )
25 { "abc", 1, {{ 0xA9, 0x99, 0x3E, 0x36, 0x47, 0x06, 0x81, 0x6A, 0xBA, 0x3E, 0 x25, 0x71, 0x78, 0x50, 0xC2, 0x6C, 0x9C, 0xD0, 0xD8, 0x9D }} }, 20 { "abc", 1, {{ 0xA9, 0x99, 0x3E, 0x36, 0x47, 0x06, 0x81, 0x6A, 0xBA, 0x3E, 0 x25, 0x71, 0x78, 0x50, 0xC2, 0x6C, 0x9C, 0xD0, 0xD8, 0x9D }} },
26 { "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 1, {{ 0x84, 0x 98, 0x3E, 0x44, 0x1C, 0x3B, 0xD2, 0x6E, 0xBA, 0xAE, 0x4A, 0xA1, 0xF9, 0x51, 0x29 , 0xE5, 0xE5, 0x46, 0x70, 0xF1 }} }, 21 { "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 1, {{ 0x84, 0x 98, 0x3E, 0x44, 0x1C, 0x3B, 0xD2, 0x6E, 0xBA, 0xAE, 0x4A, 0xA1, 0xF9, 0x51, 0x29 , 0xE5, 0xE5, 0x46, 0x70, 0xF1 }} },
27 { "a", 1000000, {{ 0x34, 0xAA, 0x97, 0x3C, 0xD4, 0xC4, 0xDA, 0xA4, 0xF6, 0x1 E, 0xEB, 0x2B, 0xDB, 0xAD, 0x27, 0x31, 0x65, 0x34, 0x01, 0x6F }} }, 22 { "a", 1000000, {{ 0x34, 0xAA, 0x97, 0x3C, 0xD4, 0xC4, 0xDA, 0xA4, 0xF6, 0x1 E, 0xEB, 0x2B, 0xDB, 0xAD, 0x27, 0x31, 0x65, 0x34, 0x01, 0x6F }} },
28 { "0123456701234567012345670123456701234567012345670123456701234567", 10, {{ 0xDE, 0xA3, 0x56, 0xA2, 0xCD, 0xDD, 0x90, 0xC7, 0xA7, 0xEC, 0xED, 0xC5, 0xEB, 0 xB5, 0x63, 0x93, 0x4F, 0x46, 0x04, 0x52 }} }, 23 { "0123456701234567012345670123456701234567012345670123456701234567", 10, {{ 0xDE, 0xA3, 0x56, 0xA2, 0xCD, 0xDD, 0x90, 0xC7, 0xA7, 0xEC, 0xED, 0xC5, 0xEB, 0 xB5, 0x63, 0x93, 0x4F, 0x46, 0x04, 0x52 }} },
29 24
30 // Reference tests from running GNU sha1sum on test input 25 // Reference tests from running GNU sha1sum on test input
31 { "The quick brown fox jumps over the lazy dog", 1, {{ 0x2f, 0xd4, 0xe1, 0xc 6, 0x7a, 0x2d, 0x28, 0xfc, 0xed, 0x84, 0x9e, 0xe1, 0xbb, 0x76, 0xe7, 0x39, 0x1b, 0x93, 0xeb, 0x12 }} }, 26 { "The quick brown fox jumps over the lazy dog", 1, {{ 0x2f, 0xd4, 0xe1, 0xc 6, 0x7a, 0x2d, 0x28, 0xfc, 0xed, 0x84, 0x9e, 0xe1, 0xbb, 0x76, 0xe7, 0x39, 0x1b, 0x93, 0xeb, 0x12 }} },
32 { "", 1, {{ 0xda, 0x39, 0xa3, 0xee, 0x5e, 0x6b, 0x4b, 0x0d, 0x32, 0x55, 0xbf , 0xef, 0x95, 0x60, 0x18, 0x90, 0xaf, 0xd8, 0x07, 0x09 }} }, 27 { "", 1, {{ 0xda, 0x39, 0xa3, 0xee, 0x5e, 0x6b, 0x4b, 0x0d, 0x32, 0x55, 0xbf , 0xef, 0x95, 0x60, 0x18, 0x90, 0xaf, 0xd8, 0x07, 0x09 }} },
33 }; 28 };
34 29
35 static void sha1_test(const SHA1Test& test, skiatest::Reporter* reporter) { 30 static void sha1_test(const SHA1Test& test, skiatest::Reporter* reporter) {
36 size_t len = strlen(test.message); 31 size_t len = strlen(test.message);
37 32
38 SkSHA1 context; 33 SkSHA1 context;
39 for (unsigned long int i = 0; i < test.repeatCount; ++i) { 34 for (unsigned long int i = 0; i < test.repeatCount; ++i) {
40 context.update(reinterpret_cast<const uint8_t*>(test.message), len); 35 context.update(reinterpret_cast<const uint8_t*>(test.message), len);
41 } 36 }
42 SkSHA1::Digest digest; 37 SkHashDigest actualDigest;
43 context.finish(digest); 38 context.finish(actualDigest);
44 39
45 REPORTER_ASSERT(reporter, digests_equal(test.digest, digest)); 40 SkHashDigest expectedDigest(test.digestBytes.data, sizeof(test.digestBytes.d ata));
41 REPORTER_ASSERT(reporter, expectedDigest.equals(actualDigest));
46 } 42 }
47 43
48 static void TestSHA1(skiatest::Reporter* reporter) { 44 static void TestSHA1(skiatest::Reporter* reporter) {
49 for (size_t i = 0; i < SK_ARRAY_COUNT(sha1_tests); ++i) { 45 for (size_t i = 0; i < SK_ARRAY_COUNT(sha1_tests); ++i) {
50 sha1_test(sha1_tests[i], reporter); 46 sha1_test(sha1_tests[i], reporter);
51 } 47 }
52 } 48 }
53 49
54 #include "TestClassDef.h" 50 #include "TestClassDef.h"
55 DEFINE_TESTCLASS("SHA1", SHA1TestClass, TestSHA1) 51 DEFINE_TESTCLASS("SHA1", SHA1TestClass, TestSHA1)
OLDNEW
« tests/BitmapHasherTest.cpp ('K') | « tests/MD5Test.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698