Skip to content

Commit 93faa8a

Browse files
Fix more tests
1 parent 122a341 commit 93faa8a

File tree

5 files changed

+143
-129
lines changed

5 files changed

+143
-129
lines changed

test/test-zlib-dictionary-fail.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
/* eslint-env mocha */
22
'use strict'
33

4+
var assert = require('assert')
45
var common = require('./common')
56
var zlib = require('../')
67

7-
describe('zlib - dictionary fails', function () {
8+
describe.skip('zlib - dictionary fails', function () {
89
it('should fail on missing dictionary', function (done) {
910
// Should raise an error, not trigger an assertion in src/node_zlib.cc
1011
var stream = zlib.createInflate()
1112

1213
stream.on('error', common.mustCall(function (err) {
13-
console.log(err.message)
14-
// assert(/Missing dictionary/.test(err.message))
14+
assert(/Missing dictionary/.test(err.message))
1515
done()
1616
}))
1717

@@ -24,8 +24,7 @@ describe('zlib - dictionary fails', function () {
2424
var stream = zlib.createInflate({ dictionary: Buffer('fail') })
2525

2626
stream.on('error', common.mustCall(function (err) {
27-
console.log(err.message)
28-
// assert(/Bad dictionary/.test(err.message))
27+
assert(/Bad dictionary/.test(err.message))
2928
done()
3029
}))
3130

test/test-zlib-random-byte-pipes.js

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1+
/* eslint-env mocha */
12
'use strict'
2-
var common = require('./common')
3-
var assert = require('assert')
43

5-
if (!common.hasCrypto) {
6-
console.log('1..0 # Skipped: missing crypto')
7-
// return
8-
}
4+
var assert = require('assert')
95
var crypto = require('crypto')
106

117
var stream = require('stream')
@@ -86,7 +82,7 @@ RandomReadStream.prototype._process = function () {
8682

8783
this._remaining -= block
8884

89-
console.error('block=%d\nremain=%d\n', block, this._remaining)
85+
// console.error('block=%d\nremain=%d\n', block, this._remaining)
9086
this._processing = false
9187

9288
this.emit('data', buf)
@@ -126,36 +122,41 @@ HashStream.prototype.end = function (c) {
126122
this.emit('end')
127123
}
128124

129-
var inp = new RandomReadStream({ total: 1024, block: 256, jitter: 16 })
130-
var out = new HashStream()
131-
var gzip = zlib.createGzip()
132-
var gunz = zlib.createGunzip()
133-
134-
inp.pipe(gzip).pipe(gunz).pipe(out)
135-
136-
inp.on('data', function (c) {
137-
console.error('inp data', c.length)
138-
})
139-
140-
gzip.on('data', function (c) {
141-
console.error('gzip data', c.length)
142-
})
143-
144-
gunz.on('data', function (c) {
145-
console.error('gunz data', c.length)
146-
})
147-
148-
out.on('data', function (c) {
149-
console.error('out data', c.length)
150-
})
151-
152-
var didSomething = false
153-
out.on('data', function (c) {
154-
didSomething = true
155-
console.error('hash=%s', c)
156-
assert.equal(c, inp._hash, 'hashes should match')
157-
})
158-
159-
process.on('exit', function () {
160-
assert(didSomething, 'should have done something')
125+
describe('zlib - random byte pipes', function () {
126+
it('works', function (done) {
127+
var inp = new RandomReadStream({ total: 1024, block: 256, jitter: 16 })
128+
var out = new HashStream()
129+
var gzip = zlib.createGzip()
130+
var gunz = zlib.createGunzip()
131+
132+
inp.pipe(gzip).pipe(gunz).pipe(out)
133+
134+
// inp.on('data', function (c) {
135+
// console.error('inp data', c.length)
136+
// })
137+
138+
// gzip.on('data', function (c) {
139+
// console.error('gzip data', c.length)
140+
// })
141+
142+
// gunz.on('data', function (c) {
143+
// console.error('gunz data', c.length)
144+
// })
145+
146+
// out.on('data', function (c) {
147+
// console.error('out data', c.length)
148+
// })
149+
150+
var didSomething = false
151+
out.on('data', function (c) {
152+
didSomething = true
153+
// console.error('hash=%s', c)
154+
assert.equal(c, inp._hash, 'hashes should match')
155+
})
156+
157+
out.on('end', function () {
158+
assert(didSomething, 'should have done something')
159+
done()
160+
})
161+
})
161162
})

test/test-zlib-truncated.js

Lines changed: 43 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,55 @@
1+
/* eslint-env mocha */
12
'use strict'
2-
// tests zlib streams with truncated compressed input
33

4+
// tests zlib streams with truncated compressed input
45
const assert = require('assert')
56
const zlib = require('zlib')
67

78
const inputString = 'ΩΩLorem ipsum dolor sit amet, consectetur adipiscing el' +
8-
'it. Morbi faucibus, purus at gravida dictum, libero arcu convallis la' +
9-
'cus, in commodo libero metus eu nisi. Nullam commodo, neque nec porta' +
10-
' placerat, nisi est fermentum augue, vitae gravida tellus sapien sit ' +
11-
'amet tellus. Aenean non diam orci. Proin quis elit turpis. Suspendiss' +
12-
'e non diam ipsum. Suspendisse nec ullamcorper odio. Vestibulum arcu m' +
13-
'i, sodales non suscipit id, ultrices ut massa. Sed ac sem sit amet ar' +
14-
'cu malesuada fermentum. Nunc sed. '
15-
16-
;[
17-
{ comp: 'gzip', decomp: 'gunzip', decompSync: 'gunzipSync' },
18-
{ comp: 'gzip', decomp: 'unzip', decompSync: 'unzipSync' },
19-
{ comp: 'deflate', decomp: 'inflate', decompSync: 'inflateSync' },
20-
{ comp: 'deflateRaw', decomp: 'inflateRaw', decompSync: 'inflateRawSync' }
21-
].forEach(function (methods) {
22-
zlib[methods.comp](inputString, function (err, compressed) {
23-
assert(!err)
24-
const truncated = compressed.slice(0, compressed.length / 2)
25-
26-
// sync sanity
27-
assert.doesNotThrow(function () {
28-
const decompressed = zlib[methods.decompSync](compressed)
29-
assert.equal(decompressed, inputString)
30-
})
9+
'it. Morbi faucibus, purus at gravida dictum, libero arcu convallis la' +
10+
'cus, in commodo libero metus eu nisi. Nullam commodo, neque nec porta' +
11+
' placerat, nisi est fermentum augue, vitae gravida tellus sapien sit ' +
12+
'amet tellus. Aenean non diam orci. Proin quis elit turpis. Suspendiss' +
13+
'e non diam ipsum. Suspendisse nec ullamcorper odio. Vestibulum arcu m' +
14+
'i, sodales non suscipit id, ultrices ut massa. Sed ac sem sit amet ar' +
15+
'cu malesuada fermentum. Nunc sed. '
3116

32-
// async sanity
33-
zlib[methods.decomp](compressed, function (err, result) {
34-
assert.ifError(err)
35-
assert.equal(result, inputString)
36-
})
17+
describe('zlib - truncated', function () {
18+
[
19+
{ comp: 'gzip', decomp: 'gunzip', decompSync: 'gunzipSync' },
20+
{ comp: 'gzip', decomp: 'unzip', decompSync: 'unzipSync' },
21+
{ comp: 'deflate', decomp: 'inflate', decompSync: 'inflateSync' },
22+
{ comp: 'deflateRaw', decomp: 'inflateRaw', decompSync: 'inflateRawSync' }
23+
].forEach(function (methods) {
24+
it(methods.comp, function (done) {
25+
zlib[methods.comp](inputString, function (err, compressed) {
26+
assert(!err)
27+
const truncated = compressed.slice(0, compressed.length / 2)
28+
29+
// sync sanity
30+
assert.doesNotThrow(function () {
31+
const decompressed = zlib[methods.decompSync](compressed)
32+
assert.equal(decompressed, inputString)
33+
})
34+
35+
// async sanity
36+
zlib[methods.decomp](compressed, function (err, result) {
37+
assert.ifError(err)
38+
assert.equal(result, inputString)
39+
})
40+
41+
// sync truncated input test
42+
assert.throws(function () {
43+
zlib[methods.decompSync](truncated)
44+
}, /unexpected end of file/)
3745

38-
// sync truncated input test
39-
assert.throws(function () {
40-
zlib[methods.decompSync](truncated)
41-
}, /unexpected end of file/)
46+
// async truncated input test
47+
zlib[methods.decomp](truncated, function (err, result) {
48+
assert(/unexpected end of file/.test(err.message))
49+
})
4250

43-
// async truncated input test
44-
zlib[methods.decomp](truncated, function (err, result) {
45-
assert(/unexpected end of file/.test(err.message))
51+
done()
52+
})
4653
})
4754
})
4855
})

test/test-zlib-write-after-flush.js

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,39 @@
1+
/* eslint-env mocha */
12
'use strict'
23

34
var assert = require('assert')
45
var zlib = require('../')
56

6-
var gzip = zlib.createGzip()
7-
var gunz = zlib.createUnzip()
8-
9-
gzip.pipe(gunz)
10-
11-
var output = ''
12-
var input = 'A line of data\n'
13-
gunz.setEncoding('utf8')
14-
gunz.on('data', function (c) {
15-
output += c
7+
describe('zlib - write after flush', function () {
8+
it('works', function (done) {
9+
var gzip = zlib.createGzip()
10+
var gunz = zlib.createUnzip()
11+
12+
gzip.pipe(gunz)
13+
14+
var output = ''
15+
var input = 'A line of data\n'
16+
gunz.setEncoding('utf8')
17+
gunz.on('data', function (c) {
18+
output += c
19+
})
20+
21+
// make sure that flush/write doesn't trigger an assert failure
22+
gzip.flush()
23+
write()
24+
25+
gunz.on('end', function () {
26+
assert.equal(output, input)
27+
28+
// Make sure that the flush flag was set back to normal
29+
assert.equal(gzip._flushFlag, zlib.Z_NO_FLUSH)
30+
done()
31+
})
32+
33+
function write () {
34+
gzip.write(input)
35+
gzip.end()
36+
gunz.read(0)
37+
}
38+
})
1639
})
17-
18-
process.on('exit', function () {
19-
assert.equal(output, input)
20-
21-
// Make sure that the flush flag was set back to normal
22-
assert.equal(gzip._flushFlag, zlib.Z_NO_FLUSH)
23-
24-
console.log('ok')
25-
})
26-
27-
// make sure that flush/write doesn't trigger an assert failure
28-
gzip.flush(); write()
29-
function write () {
30-
gzip.write(input)
31-
gzip.end()
32-
gunz.read(0)
33-
}

test/test-zlib-zero-byte.js

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
1+
/* eslint-env mocha */
12
'use strict'
23

34
var assert = require('assert')
4-
55
var zlib = require('../')
6-
var gz = zlib.Gzip()
7-
var emptyBuffer = new Buffer(0)
8-
var received = 0
9-
gz.on('data', function (c) {
10-
received += c.length
11-
})
12-
var ended = false
13-
gz.on('end', function () {
14-
ended = true
15-
})
16-
var finished = false
17-
gz.on('finish', function () {
18-
finished = true
19-
})
20-
gz.write(emptyBuffer)
21-
gz.end()
226

23-
process.on('exit', function () {
24-
assert.equal(received, 20)
25-
assert(ended)
26-
assert(finished)
27-
console.log('ok')
7+
describe('zlib - zero byte', function () {
8+
it('works', function (done) {
9+
var gz = zlib.Gzip()
10+
var emptyBuffer = new Buffer(0)
11+
var received = 0
12+
gz.on('data', function (c) {
13+
received += c.length
14+
})
15+
16+
var finished = false
17+
gz.on('end', function () {
18+
assert.equal(received, 20)
19+
assert(finished)
20+
done()
21+
})
22+
23+
gz.on('finish', function () {
24+
finished = true
25+
})
26+
gz.write(emptyBuffer)
27+
gz.end()
28+
})
2829
})

0 commit comments

Comments
 (0)