Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorFedor Indutny <fedor.indutny@gmail.com>2012-01-12 01:12:13 +0400
committerFedor Indutny <fedor.indutny@gmail.com>2012-01-12 01:19:19 +0400
commit71ae1753196f41d569d20a940ed036a50c292069 (patch)
treee4cce58089afd76b0bdd5c45be0122fa99c44137 /test
parent89556f5a2f64abcc6cecd3d412488e2ff6d6cd01 (diff)
zlib: reset() method for deflate/inflate streams
* ammended test-zlib-dictionary to cover reusing streams
Diffstat (limited to 'test')
-rw-r--r--test/simple/test-zlib-dictionary.js58
1 files changed, 40 insertions, 18 deletions
diff --git a/test/simple/test-zlib-dictionary.js b/test/simple/test-zlib-dictionary.js
index d16e415d101..f3b1446071b 100644
--- a/test/simple/test-zlib-dictionary.js
+++ b/test/simple/test-zlib-dictionary.js
@@ -43,7 +43,6 @@ var spdyDict = new Buffer([
].join(''));
var deflate = zlib.createDeflate({ dictionary: spdyDict });
-var inflate = zlib.createInflate({ dictionary: spdyDict });
var input = [
'HTTP/1.1 200 Ok',
@@ -52,22 +51,45 @@ var input = [
''
].join('\r\n');
-// Put data into deflate stream
-deflate.on('data', function(chunk) {
- inflate.write(chunk);
-});
-deflate.on('end', function() {
- inflate.end();
-});
+var called = 0;
-// Get data from inflate stream
-var output = [];
-inflate.on('data', function(chunk) {
- output.push(chunk);
-});
-inflate.on('end', function() {
- assert.equal(output.join(''), input);
-});
+//
+// We'll use clean-new inflate stream each time
+// and .reset() old dirty deflate one
+//
+function run(num) {
+ var inflate = zlib.createInflate({ dictionary: spdyDict });
+
+ if (num === 2) {
+ deflate.reset();
+ deflate.removeAllListeners('data');
+ }
-deflate.write(input);
-deflate.end();
+ // Put data into deflate stream
+ deflate.on('data', function(chunk) {
+ inflate.write(chunk);
+ });
+
+ // Get data from inflate stream
+ var output = [];
+ inflate.on('data', function(chunk) {
+ output.push(chunk);
+ });
+ inflate.on('end', function() {
+ called++;
+
+ assert.equal(output.join(''), input);
+
+ if (num < 2) run(num + 1);
+ });
+
+ deflate.write(input);
+ deflate.flush(function() {
+ inflate.end();
+ });
+}
+run(1);
+
+process.on('exit', function() {
+ assert.equal(called, 2);
+});