mirror of https://github.com/lukechilds/node.git
Ryan Dahl
15 years ago
4 changed files with 388 additions and 0 deletions
@ -0,0 +1,54 @@ |
|||
process.mixin(require('../common')); |
|||
|
|||
var |
|||
fn = path.join(fixturesDir, 'multipart.js'), |
|||
file = fs.createReadStream(fn), |
|||
|
|||
callbacks = { |
|||
open: -1, |
|||
end: -1, |
|||
close: -1 |
|||
}, |
|||
|
|||
paused = false, |
|||
|
|||
fileContent = ''; |
|||
|
|||
file |
|||
.addListener('open', function(fd) { |
|||
callbacks.open++; |
|||
assert.equal('number', typeof fd); |
|||
assert.ok(file.readable); |
|||
}) |
|||
.addListener('error', function(err) { |
|||
throw err; |
|||
}) |
|||
.addListener('data', function(data) { |
|||
assert.ok(!paused); |
|||
fileContent += data; |
|||
|
|||
paused = true; |
|||
file.pause(); |
|||
assert.ok(file.paused); |
|||
|
|||
setTimeout(function() { |
|||
paused = false; |
|||
file.resume(); |
|||
assert.ok(!file.paused); |
|||
}, 10); |
|||
}) |
|||
.addListener('end', function(chunk) { |
|||
callbacks.end++; |
|||
}) |
|||
.addListener('close', function() { |
|||
callbacks.close++; |
|||
assert.ok(!file.readable); |
|||
|
|||
assert.equal(fs.readFileSync(fn), fileContent); |
|||
}); |
|||
|
|||
process.addListener('exit', function() { |
|||
for (var k in callbacks) { |
|||
assert.equal(0, callbacks[k], k+' count off by '+callbacks[k]); |
|||
} |
|||
}); |
@ -0,0 +1,50 @@ |
|||
process.mixin(require('../common')); |
|||
|
|||
var |
|||
fn = path.join(fixturesDir, "write.txt"), |
|||
file = fs.createWriteStream(fn), |
|||
|
|||
EXPECTED = '0123456789', |
|||
|
|||
callbacks = { |
|||
open: -1, |
|||
drain: -2, |
|||
close: -1 |
|||
}; |
|||
|
|||
file |
|||
.addListener('open', function(fd) { |
|||
callbacks.open++; |
|||
assert.equal('number', typeof fd); |
|||
}) |
|||
.addListener('error', function(err) { |
|||
throw err; |
|||
}) |
|||
.addListener('drain', function() { |
|||
callbacks.drain++; |
|||
if (callbacks.drain == -1) { |
|||
assert.equal(EXPECTED, fs.readFileSync(fn)); |
|||
file.write(EXPECTED); |
|||
} else if (callbacks.drain == 0) { |
|||
assert.equal(EXPECTED+EXPECTED, fs.readFileSync(fn)); |
|||
file.close(); |
|||
} |
|||
}) |
|||
.addListener('close', function() { |
|||
callbacks.close++; |
|||
assert.throws(function() { |
|||
file.write('should not work anymore'); |
|||
}); |
|||
|
|||
fs.unlinkSync(fn); |
|||
}); |
|||
|
|||
for (var i = 0; i < 10; i++) { |
|||
assert.strictEqual(false, file.write(i)); |
|||
} |
|||
|
|||
process.addListener('exit', function() { |
|||
for (var k in callbacks) { |
|||
assert.equal(0, callbacks[k], k+' count off by '+callbacks[k]); |
|||
} |
|||
}); |
Loading…
Reference in new issue