mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
88 lines
1.9 KiB
88 lines
1.9 KiB
15 years ago
|
require('../common');
|
||
15 years ago
|
|
||
15 years ago
|
// TODO Improved this test. test_ca.pem is too small. A proper test would
|
||
|
// great a large utf8 (with multibyte chars) file and stream it in,
|
||
|
// performing sanity checks throughout.
|
||
|
|
||
|
Buffer = require('buffer').Buffer;
|
||
|
path = require('path');
|
||
|
fs = require('fs');
|
||
15 years ago
|
fn = path.join(fixturesDir, 'elipses.txt');
|
||
15 years ago
|
|
||
15 years ago
|
callbacks = { open: 0, end: 0, close: 0, destroy: 0 };
|
||
15 years ago
|
|
||
|
paused = false;
|
||
|
|
||
15 years ago
|
file = fs.createReadStream(fn);
|
||
15 years ago
|
|
||
|
file.addListener('open', function(fd) {
|
||
15 years ago
|
file.length = 0;
|
||
15 years ago
|
callbacks.open++;
|
||
|
assert.equal('number', typeof fd);
|
||
|
assert.ok(file.readable);
|
||
|
});
|
||
|
|
||
|
|
||
|
file.addListener('data', function(data) {
|
||
|
assert.ok(data instanceof Buffer);
|
||
|
assert.ok(!paused);
|
||
15 years ago
|
file.length += data.length;
|
||
|
|
||
15 years ago
|
paused = true;
|
||
|
file.pause();
|
||
|
assert.ok(file.paused);
|
||
|
|
||
|
setTimeout(function() {
|
||
|
paused = false;
|
||
|
file.resume();
|
||
|
assert.ok(!file.paused);
|
||
|
}, 10);
|
||
|
});
|
||
|
|
||
15 years ago
|
|
||
15 years ago
|
file.addListener('end', function(chunk) {
|
||
|
callbacks.end++;
|
||
|
});
|
||
|
|
||
15 years ago
|
|
||
15 years ago
|
file.addListener('close', function() {
|
||
|
callbacks.close++;
|
||
|
assert.ok(!file.readable);
|
||
|
|
||
15 years ago
|
//assert.equal(fs.readFileSync(fn), fileContent);
|
||
15 years ago
|
});
|
||
15 years ago
|
|
||
15 years ago
|
var file2 = fs.createReadStream(fn);
|
||
15 years ago
|
file2.destroy(function(err) {
|
||
15 years ago
|
assert.ok(!err);
|
||
15 years ago
|
callbacks.destroy++;
|
||
15 years ago
|
});
|
||
|
|
||
15 years ago
|
var file3 = fs.createReadStream(fn);
|
||
|
file3.length = 0;
|
||
|
file3.setEncoding('utf8');
|
||
|
file3.addListener('data', function(data) {
|
||
|
assert.equal("string", typeof(data));
|
||
|
file3.length += data.length;
|
||
|
|
||
|
for (var i = 0; i < data.length; i++) {
|
||
|
// http://www.fileformat.info/info/unicode/char/2026/index.htm
|
||
|
assert.equal("\u2026", data[i]);
|
||
15 years ago
|
}
|
||
15 years ago
|
});
|
||
15 years ago
|
|
||
|
file3.addListener('close', function () {
|
||
|
callbacks.close++;
|
||
|
});
|
||
|
|
||
|
process.addListener('exit', function() {
|
||
|
assert.equal(1, callbacks.open);
|
||
|
assert.equal(1, callbacks.end);
|
||
|
assert.equal(1, callbacks.destroy);
|
||
|
|
||
|
assert.equal(2, callbacks.close);
|
||
|
|
||
|
assert.equal(30000, file.length);
|
||
|
assert.equal(10000, file3.length);
|
||
|
});
|