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

Unified Diff: tests/standalone/io/zlib_test.dart

Issue 130513003: [ZLIB] Add support for windowBits, memLevel, raw (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: integrate 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/io/data_transformer.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/standalone/io/zlib_test.dart
diff --git a/tests/standalone/io/zlib_test.dart b/tests/standalone/io/zlib_test.dart
index 5b0fc492e0b1777d5fbd896a2b3b300ee8d410a5..ac9f797305358547be4def235df40870cd16b49b 100644
--- a/tests/standalone/io/zlib_test.dart
+++ b/tests/standalone/io/zlib_test.dart
@@ -8,28 +8,6 @@ import 'dart:io';
import "package:async_helper/async_helper.dart";
import "package:expect/expect.dart";
-void testZLibDeflate() {
- test(int level, List<int> expected) {
- asyncStart();
- var data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
- var controller = new StreamController(sync: true);
- controller.stream.transform(new ZLibEncoder(gzip: false, level: level))
- .fold([], (buffer, data) {
- buffer.addAll(data);
- return buffer;
- })
- .then((data) {
- Expect.listEquals(expected, data);
- asyncEnd();
- });
- controller.add(data);
- controller.close();
- }
- test(6, [120, 156, 99, 96, 100, 98, 102, 97, 101, 99, 231, 224, 4, 0, 0, 175,
- 0, 46]);
-}
-
-
void testZLibDeflateEmpty() {
asyncStart();
var controller = new StreamController(sync: true);
@@ -45,6 +23,41 @@ void testZLibDeflateEmpty() {
controller.close();
}
+void testZLibDeflateEmptyGzip() {
+ asyncStart();
+ var controller = new StreamController(sync: true);
+ controller.stream.transform(new ZLibEncoder(gzip: true, level: 6))
+ .fold([], (buffer, data) {
+ buffer.addAll(data);
+ return buffer;
+ })
+ .then((data) {
+ Expect.listEquals([31, 139, 8, 0, 0, 0, 0, 0, 0, 3, 3, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0], data);
+ asyncEnd();
+ });
+ controller.close();
+}
+
+void testZLibDeflate() {
+ asyncStart();
+ var data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
+ var controller = new StreamController(sync: true);
+ controller.stream.transform(new ZLibEncoder(gzip: false, level: 6))
+ .fold([], (buffer, data) {
+ buffer.addAll(data);
+ return buffer;
+ })
+ .then((data) {
+ Expect.listEquals(
+ [120, 156, 99, 96, 100, 98, 102, 97, 101, 99, 231, 224, 4, 0, 0,
+ 175, 0, 46],
+ data);
+ asyncEnd();
+ });
+ controller.add(data);
+ controller.close();
+}
void testZLibDeflateGZip() {
asyncStart();
@@ -67,35 +80,77 @@ void testZLibDeflateGZip() {
controller.close();
}
+void testZLibDeflateRaw() {
+ asyncStart();
+ var data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
+ var controller = new StreamController(sync: true);
+ controller.stream.transform(new ZLibEncoder(raw: true, level: 6))
+ .fold([], (buffer, data) {
+ buffer.addAll(data);
+ return buffer;
+ })
+ .then((data) {
+ print(data);
+ Expect.listEquals([99, 96, 100, 98, 102, 97, 101, 99, 231, 224, 4, 0],
+ data);
+ asyncEnd();
+ });
+ controller.add(data);
+ controller.close();
+}
+
void testZLibDeflateInvalidLevel() {
test2(gzip, level) {
- try {
- new ZLibEncoder(gzip: gzip, level: level).startChunkedConversion(null);
- Expect.fail("No exception thrown");
- } catch (e) {
- }
- }
- test(level) {
- test2(false, level);
- test2(true, level);
- test2(9, level);
- }
- test(-2);
- test(-20);
- test(10);
- test(42);
- test(null);
- test("9");
+ [true, false].forEach((gzip) {
+ [-2, -20, 10, 42, null, "9"].forEach((level) {
+ Expect.throws(
+ () => new ZLibEncoder(gzip: gzip, level: level),
+ (e) => e is ArgumentError,
+ "'level' must be in range -1..9"
+ );
+ });
+ });
+ };
}
void testZLibInflate() {
- test2(bool gzip, int level) {
+ var data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
+
+ [true, false].forEach((gzip) {
+ [ZLibOption.STRATEGY_FILTERED, ZLibOption.STRATEGY_HUFFMAN_ONLY,
+ ZLibOption.STRATEGY_RLE, ZLibOption.STRATEGY_FIXED,
+ ZLibOption.STRATEGY_DEFAULT].forEach((strategy) {
+ [3, 6, 9].forEach((level) {
+ asyncStart();
+ var controller = new StreamController(sync: true);
+ controller.stream
+ .transform(new ZLibEncoder(gzip: gzip, level: level,
+ strategy: strategy))
+ .transform(new ZLibDecoder())
+ .fold([], (buffer, data) {
+ buffer.addAll(data);
+ return buffer;
+ })
+ .then((inflated) {
+ Expect.listEquals(data, inflated);
+ asyncEnd();
+ });
+ controller.add(data);
+ controller.close();
+ });
+ });
+ });
+}
+
+void testZLibInflateRaw() {
+ var data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
+
+ [3, 6, 9].forEach((level) {
asyncStart();
- var data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
var controller = new StreamController(sync: true);
controller.stream
- .transform(new ZLibEncoder(gzip: gzip, level: level))
- .transform(new ZLibDecoder())
+ .transform(new ZLibEncoder(raw: true, level: level))
+ .transform(new ZLibDecoder(raw: true))
.fold([], (buffer, data) {
buffer.addAll(data);
return buffer;
@@ -106,39 +161,78 @@ void testZLibInflate() {
});
controller.add(data);
controller.close();
- }
- void test(int level) {
- test2(false, level);
- test2(true, level);
- }
- for (int i = -1; i < 10; i++) {
- test(i);
- }
+ });
}
void testZLibInflateSync() {
- test2(bool gzip, int level) {
- var data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
- var encoded = new ZLibEncoder(gzip: gzip, level: level).convert(data);
- var decoded = new ZLibDecoder().convert(encoded);
+ var data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
+
+ [true, false].forEach((gzip) {
+ [3, 6, 9].forEach((level) {
+ var encoded = new ZLibEncoder(gzip: gzip, level: level).convert(data);
+ var decoded = new ZLibDecoder().convert(encoded);
+ Expect.listEquals(data, decoded);
+ });
+ });
+}
+
+void testZlibInflateThrowsWithSmallerWindow() {
+ var data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
+ var encoder = new ZLibEncoder(windowBits: 10);
+ var encodedData = encoder.convert(data);
+ var decoder = new ZLibDecoder(windowBits: 8);
+ Expect.throws(() => decoder.convert(encodedData));
+}
+
+void testZlibInflateWithLargerWindow() {
+ var data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
+
+ [true, false].forEach((gzip) {
+ [3, 6, 9].forEach((level) {
+ asyncStart();
+ var controller = new StreamController(sync: true);
+ controller.stream
+ .transform(new ZLibEncoder(gzip: gzip, level: level, windowBits: 8))
+ .transform(new ZLibDecoder(windowBits: 10))
+ .fold([], (buffer, data) {
+ buffer.addAll(data);
+ return buffer;
+ })
+ .then((inflated) {
+ Expect.listEquals(data, inflated);
+ asyncEnd();
+ });
+ controller.add(data);
+ controller.close();
+ });
+ });
+}
+
+void testZlibWithDictionary() {
+ var dict = [102, 111, 111, 98, 97, 114];
+ var data = [98, 97, 114, 102, 111, 111];
+
+ [3, 6, 9].forEach((level) {
+ var encoded = new ZLibEncoder(level: level, dictionary: dict)
+ .convert(data);
+ var decoded = new ZLibDecoder(dictionary: dict).convert(encoded);
Expect.listEquals(data, decoded);
- }
- void test(int level) {
- test2(false, level);
- test2(true, level);
- }
- for (int i = -1; i < 10; i++) {
- test(i);
- }
+ });
}
void main() {
asyncStart();
testZLibDeflate();
testZLibDeflateEmpty();
+ testZLibDeflateEmptyGzip();
testZLibDeflateGZip();
testZLibDeflateInvalidLevel();
testZLibInflate();
testZLibInflateSync();
+ testZlibInflateThrowsWithSmallerWindow();
+ testZlibInflateWithLargerWindow();
+ testZLibDeflateRaw();
+ testZLibInflateRaw();
+ testZlibWithDictionary();
asyncEnd();
}
« no previous file with comments | « sdk/lib/io/data_transformer.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698