2010-03-09 00:06:29 +01:00
|
|
|
require('../common');
|
2010-03-03 12:39:41 +01:00
|
|
|
|
2010-05-25 00:47:40 +02:00
|
|
|
// 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');
|
2010-05-27 03:32:56 +02:00
|
|
|
fn = path.join(fixturesDir, 'elipses.txt');
|
2010-05-25 00:47:40 +02:00
|
|
|
|
2010-05-27 03:32:56 +02:00
|
|
|
callbacks = { open: 0, end: 0, close: 0, destroy: 0 };
|
2010-05-25 00:47:40 +02:00
|
|
|
|
|
|
|
paused = false;
|
|
|
|
|
2010-05-27 03:32:56 +02:00
|
|
|
file = fs.createReadStream(fn);
|
2010-05-25 00:47:40 +02:00
|
|
|
|
|
|
|
file.addListener('open', function(fd) {
|
2010-05-27 03:32:56 +02:00
|
|
|
file.length = 0;
|
2010-05-25 00:47:40 +02:00
|
|
|
callbacks.open++;
|
|
|
|
assert.equal('number', typeof fd);
|
|
|
|
assert.ok(file.readable);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
file.addListener('data', function(data) {
|
|
|
|
assert.ok(data instanceof Buffer);
|
|
|
|
assert.ok(!paused);
|
2010-05-27 03:32:56 +02:00
|
|
|
file.length += data.length;
|
|
|
|
|
2010-05-25 00:47:40 +02:00
|
|
|
paused = true;
|
|
|
|
file.pause();
|
|
|
|
assert.ok(file.paused);
|
|
|
|
|
|
|
|
setTimeout(function() {
|
|
|
|
paused = false;
|
|
|
|
file.resume();
|
|
|
|
assert.ok(!file.paused);
|
|
|
|
}, 10);
|
|
|
|
});
|
|
|
|
|
2010-05-27 03:32:56 +02:00
|
|
|
|
2010-05-25 00:47:40 +02:00
|
|
|
file.addListener('end', function(chunk) {
|
|
|
|
callbacks.end++;
|
|
|
|
});
|
|
|
|
|
2010-05-27 03:32:56 +02:00
|
|
|
|
2010-05-25 00:47:40 +02:00
|
|
|
file.addListener('close', function() {
|
|
|
|
callbacks.close++;
|
|
|
|
assert.ok(!file.readable);
|
|
|
|
|
2010-05-27 03:32:56 +02:00
|
|
|
//assert.equal(fs.readFileSync(fn), fileContent);
|
2010-05-25 00:47:40 +02:00
|
|
|
});
|
2010-03-03 12:39:41 +01:00
|
|
|
|
2010-03-07 16:33:21 +01:00
|
|
|
var file2 = fs.createReadStream(fn);
|
2010-04-08 19:44:22 +02:00
|
|
|
file2.destroy(function(err) {
|
2010-03-07 16:33:21 +01:00
|
|
|
assert.ok(!err);
|
2010-04-08 19:44:22 +02:00
|
|
|
callbacks.destroy++;
|
2010-03-07 16:33:21 +01:00
|
|
|
});
|
|
|
|
|
2010-05-27 03:32:56 +02:00
|
|
|
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]);
|
2010-03-03 12:39:41 +01:00
|
|
|
}
|
2010-03-20 03:22:04 +01:00
|
|
|
});
|
2010-05-27 03:32:56 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
});
|