2010-09-29 12:18:46 +08:00
|
|
|
sys = require('sys');
|
|
|
|
assert = require('assert');
|
2010-10-11 11:42:13 +08:00
|
|
|
Client = require(__dirname+'/../../lib/client');
|
2010-10-06 12:42:41 +08:00
|
|
|
EventEmitter = require('events').EventEmitter;
|
2010-10-09 12:02:01 +08:00
|
|
|
BufferList = require(__dirname+'/buffer-list');
|
2010-10-11 11:42:13 +08:00
|
|
|
buffers = require(__dirname+'/test-buffers');
|
|
|
|
|
2010-09-29 12:18:46 +08:00
|
|
|
|
2010-09-30 13:32:44 +08:00
|
|
|
assert.same = function(actual, expected) {
|
|
|
|
for(var key in expected) {
|
|
|
|
assert.equal(actual[key], expected[key]);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-10-09 12:15:47 +08:00
|
|
|
assert.equalBuffers = function(actual, expected) {
|
|
|
|
if(actual.length != expected.length) {
|
|
|
|
console.log(actual);
|
|
|
|
console.log(expected);
|
|
|
|
assert.equal(actual.length, expected.length);
|
|
|
|
}
|
|
|
|
for(var i = 0; i < actual.length; i++) {
|
|
|
|
if(actual[i] != expected[i]) {
|
|
|
|
console.log(actual);
|
|
|
|
console.log(expected);
|
|
|
|
}
|
|
|
|
assert.equal(actual[i],expected[i]);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-10-07 10:34:51 +08:00
|
|
|
assert.empty = function(actual) {
|
2010-10-08 08:35:21 +08:00
|
|
|
assert.length(actual, 0);
|
2010-10-07 10:34:51 +08:00
|
|
|
};
|
|
|
|
|
2010-10-08 08:35:21 +08:00
|
|
|
assert.length = function(actual, expectedLength) {
|
|
|
|
assert.equal(actual.length, expectedLength);
|
|
|
|
};
|
2010-09-30 13:32:44 +08:00
|
|
|
|
2010-09-29 12:18:46 +08:00
|
|
|
test = function(name, action) {
|
|
|
|
for(var i = 0; i < test.tabout; i++) {
|
|
|
|
name = ' ' + name;
|
|
|
|
}
|
|
|
|
test.tabout += 2;
|
2010-10-09 15:48:41 +08:00
|
|
|
process.stdout.write('.');
|
|
|
|
try{
|
|
|
|
action();
|
|
|
|
}catch(e) {
|
|
|
|
console.log(name);
|
2010-10-11 11:38:16 +08:00
|
|
|
throw e;
|
2010-10-09 15:48:41 +08:00
|
|
|
}
|
2010-09-29 12:18:46 +08:00
|
|
|
test.tabout -= 2;
|
|
|
|
};
|
|
|
|
test.tabout = 0;
|
2010-09-29 12:30:06 +08:00
|
|
|
|
|
|
|
stringToHex = function(string) {
|
2010-09-29 14:01:52 +08:00
|
|
|
var b = Buffer(string,'utf8');
|
|
|
|
var result = [];
|
|
|
|
for(var i = 0; i < b.length; i++) {
|
|
|
|
result.push(b[i]);
|
|
|
|
}
|
|
|
|
return result;
|
2010-09-29 12:30:06 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
hexToString = function(hexArray) {
|
|
|
|
return new Buffer(hexArray).toString('utf8');
|
|
|
|
}
|
2010-09-29 15:39:43 +08:00
|
|
|
|
2010-10-07 08:59:20 +08:00
|
|
|
MemoryStream = function() {
|
|
|
|
EventEmitter.call(this);
|
2010-10-07 10:34:51 +08:00
|
|
|
this.packets = [];
|
2010-10-07 08:59:20 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
sys.inherits(MemoryStream, EventEmitter);
|
|
|
|
|
|
|
|
var p = MemoryStream.prototype;
|
2010-10-08 09:00:49 +08:00
|
|
|
|
|
|
|
p.write = function(packet) {
|
|
|
|
this.packets.push(packet);
|
|
|
|
};
|