Chromium Code Reviews| Index: tests/lib/crypto/base64_test.dart |
| diff --git a/tests/lib/crypto/base64_test.dart b/tests/lib/crypto/base64_test.dart |
| index 0070a50666be48e41f373caf5fc4622308670fad..699c8d8541c1addb4cecdd2dd33b2950a59d3397 100644 |
| --- a/tests/lib/crypto/base64_test.dart |
| +++ b/tests/lib/crypto/base64_test.dart |
| @@ -43,13 +43,61 @@ var longLineResultNoBreak = |
| "ZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm" |
| "5hbCBwbGVhc3VyZS4="; |
| -void main() { |
| +void testEncoder() { |
| for (var i = 0; i < inputs.length; i++) { |
| var enc = CryptoUtils.bytesToBase64(inputs[i].codeUnits); |
| Expect.equals(results[i], enc); |
| } |
| - Expect.equals(CryptoUtils.bytesToBase64(longLine.codeUnits, 76), |
| + Expect.equals(CryptoUtils.bytesToBase64(longLine.codeUnits, addLineSeparator : true), |
| longLineResult); |
| Expect.equals(CryptoUtils.bytesToBase64(longLine.codeUnits), |
| longLineResultNoBreak); |
| } |
| + |
| +void testDecoder() { |
| + for (var i = 0; i < results.length; i++) { |
| + List<int> dec = CryptoUtils.base64StringToBytes(results[i]); |
| + Expect.equals(inputs[i], new String.fromCharCodes(dec)); |
| + } |
| + var longLineDecoded = CryptoUtils.base64StringToBytes(longLineResult); |
| + Expect.equals(new String.fromCharCodes(longLineDecoded), longLine); |
| + var longLineResultNoBreak = CryptoUtils.base64StringToBytes(longLineResult); |
| + Expect.equals(new String.fromCharCodes(longLineResultNoBreak), longLine); |
| +} |
| + |
| +void testDecoderForMalformedInput() { |
| + try { |
| + CryptoUtils.base64StringToBytes("AB~", ignoreErrors : false); |
| + Expect.fail("Should have failed on Malformed input."); |
| + } on FormatException catch(e) { |
| + // pass |
| + } |
| + try { |
| + // Missing padding. |
| + CryptoUtils.base64StringToBytes("Zg=", ignoreErrors : false); |
| + Expect.fail("Should have failed on Malformed input."); |
| + } on FormatException catch(e) { |
| + // pass |
| + } |
| +} |
| + |
| +void testEncodeDecode() { |
| + for (int i = 0; i < 10; i++) { |
| + for (int j = 0; j < 256 - i; j++) { |
| + List<int> x = new List<int>(i); |
| + for (int k = 0; k < i; k++) { |
| + x[k] = j; |
| + } |
| + var enc = CryptoUtils.bytesToBase64(x); |
| + var dec = CryptoUtils.base64StringToBytes(enc); |
| + Expect.listEquals(x, dec); |
| + } |
| + } |
| +} |
| + |
| +void main() { |
| + testEncoder(); |
| + testDecoder(); |
| + testDecoderForMalformedInput(); |
| + testEncodeDecode(); |
|
Lasse Reichstein Nielsen
2013/03/22 09:16:56
Add tests for url-safe and ignoreErrors too.
mdakin1
2013/03/25 17:05:02
Done.
|
| +} |