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

Unified Diff: tests/lib/crypto/base64_test.dart

Issue 12534011: Add base64 decoder and change existing base64 encoder. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: minor fix Created 7 years, 9 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
« sdk/lib/crypto/crypto_utils.dart ('K') | « sdk/lib/crypto/crypto_utils.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.
+}
« sdk/lib/crypto/crypto_utils.dart ('K') | « sdk/lib/crypto/crypto_utils.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698