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

Side by Side Diff: pkg/crypto/test/sha256_test.dart

Issue 169363008: pkg/crypto: move tests to unittest package (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: feedback Created 6 years, 10 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
« no previous file with comments | « pkg/crypto/test/sha1_test.dart ('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 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 // Library tag to allow Dartium to run the tests. 5 // Library tag to allow Dartium to run the tests.
6 library sha256_test; 6 library sha256_test;
7 7
8 import "package:expect/expect.dart"; 8 import "package:unittest/unittest.dart";
9 import "package:crypto/crypto.dart"; 9 import "package:crypto/crypto.dart";
10 10
11 part 'sha256_long_test_vectors.dart'; 11 part 'sha256_long_test_vectors.dart';
12 part 'sha256_short_test_vectors.dart'; 12 part 'sha256_short_test_vectors.dart';
13 13
14 List<int> createTestArr(int len) { 14
15 var arr = new List<int>(len); 15 void main() {
16 for (var i = 0; i < len; i++) { 16 test('expected values', _testExpectedValues);
17 arr[i] = i; 17 test('invalid use', _testInvalidUse);
18 } 18 test('repeated digest', _testRepeatedDigest);
19 return arr; 19 test('long inputs',
20 () => _testStandardVectors(sha256_long_inputs, sha256_long_mds));
21 test('short inputs',
22 () => _testStandardVectors(sha256_short_inputs, sha256_short_mds));
20 } 23 }
21 24
22 void test() { 25 void _testExpectedValues() {
23 final expected_values = const [ 26 var expectedValues = const [
24 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', 27 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855',
25 '6e340b9cffb37a989ca544e6bb780a2c78901d3fb33738768511a30617afa01d', 28 '6e340b9cffb37a989ca544e6bb780a2c78901d3fb33738768511a30617afa01d',
26 'b413f47d13ee2fe6c845b2ee141af81de858df4ec549a58b7970bb96645bc8d2', 29 'b413f47d13ee2fe6c845b2ee141af81de858df4ec549a58b7970bb96645bc8d2',
27 'ae4b3280e56e2faf83f414a6e3dabe9d5fbe18976544c05fed121accb85b53fc', 30 'ae4b3280e56e2faf83f414a6e3dabe9d5fbe18976544c05fed121accb85b53fc',
28 '054edec1d0211f624fed0cbca9d4f9400b0e491c43742af2c5b0abebf0c990d8', 31 '054edec1d0211f624fed0cbca9d4f9400b0e491c43742af2c5b0abebf0c990d8',
29 '08bb5e5d6eaac1049ede0893d30ed022b1a4d9b5b48db414871f51c9cb35283d', 32 '08bb5e5d6eaac1049ede0893d30ed022b1a4d9b5b48db414871f51c9cb35283d',
30 '17e88db187afd62c16e5debf3e6527cd006bc012bc90b51a810cd80c2d511f43', 33 '17e88db187afd62c16e5debf3e6527cd006bc012bc90b51a810cd80c2d511f43',
31 '57355ac3303c148f11aef7cb179456b9232cde33a818dfda2c2fcb9325749a6b', 34 '57355ac3303c148f11aef7cb179456b9232cde33a818dfda2c2fcb9325749a6b',
32 '8a851ff82ee7048ad09ec3847f1ddf44944104d2cbd17ef4e3db22c6785a0d45', 35 '8a851ff82ee7048ad09ec3847f1ddf44944104d2cbd17ef4e3db22c6785a0d45',
33 'f8348e0b1df00833cbbbd08f07abdecc10c0efb78829d7828c62a7f36d0cc549', 36 'f8348e0b1df00833cbbbd08f07abdecc10c0efb78829d7828c62a7f36d0cc549',
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 '4b96ec3b91e9f764ac0227ca7df451bd8294cd46298047b43b960ae1c0b0afc5', 274 '4b96ec3b91e9f764ac0227ca7df451bd8294cd46298047b43b960ae1c0b0afc5',
272 'c6fefe1bfbe6f5364bf0e40447ffca27fde55f1cd815e1fa3bafb46a41c91749', 275 'c6fefe1bfbe6f5364bf0e40447ffca27fde55f1cd815e1fa3bafb46a41c91749',
273 '552a69d052ae2980aa92ef44b4a8752fc585d70127d9df1ac53137e266786e4d', 276 '552a69d052ae2980aa92ef44b4a8752fc585d70127d9df1ac53137e266786e4d',
274 '369d7da16156c5e2c0d519cdbab3996a7249e20d3e48c36a3a873e987190bd89', 277 '369d7da16156c5e2c0d519cdbab3996a7249e20d3e48c36a3a873e987190bd89',
275 'ef67e0723230f6c535ff556e45ca2174e1e97deed306e9e87f1b65579076ec06', 278 'ef67e0723230f6c535ff556e45ca2174e1e97deed306e9e87f1b65579076ec06',
276 '2cb1e75cd7505a2783769276f30b122cb136fbbd03300510b71a7196ca670b37', 279 '2cb1e75cd7505a2783769276f30b122cb136fbbd03300510b71a7196ca670b37',
277 '1211b6885890be48f89934ec5246f1ce3cfff46c626cfcd686d5fdce9b1fb830', 280 '1211b6885890be48f89934ec5246f1ce3cfff46c626cfcd686d5fdce9b1fb830',
278 'd6a8bdb01e763fb64f3a02512e7be905679a5add6bb408f8750d679d17cad92f', 281 'd6a8bdb01e763fb64f3a02512e7be905679a5add6bb408f8750d679d17cad92f',
279 '3f8591112c6bbe5c963965954e293108b7208ed2af893e500d859368c654eabe' ]; 282 '3f8591112c6bbe5c963965954e293108b7208ed2af893e500d859368c654eabe' ];
280 283
281 for (var i = 0; i < expected_values.length; i++) { 284 for (var i = 0; i < expectedValues.length; i++) {
282 var hash = new SHA256(); 285 var hash = new SHA256();
283 hash.add(createTestArr(i)); 286 hash.add(new List<int>.generate(i, (j) => j, growable: false));
284 var d = hash.close(); 287 var d = hash.close();
285 Expect.equals(expected_values[i], CryptoUtils.bytesToHex(d), '$i'); 288 expect(expectedValues[i], CryptoUtils.bytesToHex(d), reason: '$i');
286 } 289 }
287 } 290 }
288 291
289 void testInvalidUse() { 292 void _testInvalidUse() {
290 var sha = new SHA256(); 293 var sha = new SHA256();
291 sha.close(); 294 sha.close();
292 Expect.throws(() => sha.add([0]), (e) => e is StateError); 295 expect(() => sha.add([0]), throwsStateError);
293 } 296 }
294 297
295 void testRepeatedDigest() { 298 void _testRepeatedDigest() {
296 var sha = new SHA256(); 299 var sha = new SHA256();
297 var digest = sha.close(); 300 var digest = sha.close();
298 Expect.listEquals(digest, sha.close()); 301 expect(digest, sha.close());
299 } 302 }
300 303
301 void testStandardVectors(inputs, mds) { 304 void _testStandardVectors(inputs, mds) {
302 for (var i = 0; i < inputs.length; i++) { 305 for (var i = 0; i < inputs.length; i++) {
303 var hash = new SHA256(); 306 var hash = new SHA256();
304 hash.add(inputs[i]); 307 hash.add(inputs[i]);
305 var d = hash.close(); 308 var d = hash.close();
306 Expect.equals(mds[i], CryptoUtils.bytesToHex(d), '$i'); 309 expect(mds[i], CryptoUtils.bytesToHex(d), reason: '$i');
307 } 310 }
308 } 311 }
309
310 void main() {
311 test();
312 testInvalidUse();
313 testRepeatedDigest();
314 testStandardVectors(sha256_long_inputs, sha256_long_mds);
315 testStandardVectors(sha256_short_inputs, sha256_short_mds);
316 }
317
OLDNEW
« no previous file with comments | « pkg/crypto/test/sha1_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698