Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Finish up the "test-server-*" test cases.
  • Loading branch information
TooTallNate committed Jan 5, 2011
1 parent 72d1115 commit 1d77f7e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
9 changes: 6 additions & 3 deletions test/test-server-with-catchall.js
Expand Up @@ -5,7 +5,7 @@ var assert = require('assert');

exports['server with "catch-all"'] = function() {
var server = s.createServer(function(req, res) {
console.log(req);
//console.log(req);
assert.equal(req.startAddress, 0);
assert.equal(req.quantity, 10);
var rtn = new Array(req.quantity);
Expand All @@ -17,8 +17,11 @@ exports['server with "catch-all"'] = function() {
server.listen(PORT, function() {
var conn = require('net').createConnection(PORT);
var clientRequest = new ModbusRequestStack(conn);
clientRequest.request(4, 0, 10, function(err, clientResponse) {
console.log(clientResponse);
var quantity = 10;
clientRequest.request(4, 0, quantity, function(err, clientResponse) {
//console.log(clientResponse);
assert.ok(Array.isArray(clientResponse));
assert.equal(clientResponse.length, quantity);
conn.end();
server.close();
});
Expand Down
14 changes: 9 additions & 5 deletions test/test-server-with-handlers.js
Expand Up @@ -5,10 +5,12 @@ var assert = require('assert');

exports['server with a "handlers" Object'] = function() {
var handlers = {};
var startAddress = 0;
var quantity = 10;
handlers[4] = function(req, res) {
console.log(req);
assert.equal(req.startAddress, 0);
assert.equal(req.quantity, 10);
//console.log(req);
assert.equal(req.startAddress, startAddress);
assert.equal(req.quantity, quantity);
var rtn = new Array(req.quantity);
for (var i=0; i<req.quantity; i++) {
rtn[i] = req.startAddress + i;
Expand All @@ -19,8 +21,10 @@ exports['server with a "handlers" Object'] = function() {
server.listen(PORT, function() {
var conn = require('net').createConnection(PORT);
var clientRequest = new ModbusRequestStack(conn);
clientRequest.request(4, 0, 10, function(err, clientResponse) {
console.log(clientResponse);
clientRequest.request(4, startAddress, quantity, function(err, clientResponse) {
//console.log(clientResponse);
assert.ok(Array.isArray(clientResponse));
assert.equal(clientResponse.length, quantity);
conn.end();
server.close();
});
Expand Down

0 comments on commit 1d77f7e

Please sign in to comment.