Skip to content

Commit

Permalink
Migrating from expresso to mocha and adding travis config.
Browse files Browse the repository at this point in the history
  • Loading branch information
farhadi committed Mar 14, 2013
1 parent 4c47ace commit 21c3778
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 59 deletions.
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
language: node_js
node_js:
- 0.6
- 0.8
- 0.10
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ node-smpp
=========
SMPP client and server implementation in node.js.

[![Build Status](https://travis-ci.org/farhadi/node-smpp.png)](https://travis-ci.org/farhadi/node-smpp)

Introduction
------------
This is a complete implementation of SMPP v5.0 in node.js, with support for
Expand All @@ -17,8 +19,6 @@ Installation

npm install smpp

Note that it only works on node 0.5.5 and higher.

Usage
-----
### Creating a SMPP session
Expand Down Expand Up @@ -73,14 +73,14 @@ server.listen(2775);
API
-------

### smpp.createSession([host], [port])
### smpp.connect([host], [port])
Creates a new smpp session to the given `host` and `port`. If `port` is omited,
the default smpp port (2775) will be used. If `host` is also omitted, `localhost`
will be assumed.

### smpp.Session
This is the base object for a SMPP session. sessions can be created by calling
`smpp.createSession()` or can be created by a smpp server when a client
`smpp.connect()` or can be created by a smpp server when a client
establishes a connection to the server. In this case the server passes the
session object to the `'session'` event listener.

Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "SMPP client and server implementation in node.js",
"author": "Ali Farhadi <a.farhadi@gmail.com>",
"engines": {
"node": ">= 0.5.5"
"node": ">=0.5.5"
},
"main": "./lib/smpp",
"repository": {
Expand All @@ -17,7 +17,10 @@
"url": "https://raw.github.com/farhadi/node-smpp/master/LICENSE"
}
],
"scripts": {
"test": "mocha -u tdd"
},
"devDependencies": {
"expresso": "~0.8.1"
"mocha": "*"
}
}
148 changes: 95 additions & 53 deletions test/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,88 @@ var assert = require('assert'),
defs = require('../lib/defs'),
types = defs.types;

exports['Test int8 type'] = function() {
suite('int8', function() {
var b = new Buffer([0, 0x65]), expected = 0x65;
var result = types.int8.read(b, 1);
assert.equal(result, expected);
assert.equal(types.int8.size(expected), 1);
types.int8.write(expected, b, 0);
assert.eql(new Buffer([0x65]), b.slice(0, 1));
};
test('read()', function() {
var result = types.int8.read(b, 1);
assert.equal(result, expected);
});
test('size()', function() {
assert.equal(types.int8.size(expected), 1);
});
test('write()', function() {
types.int8.write(expected, b, 0);
assert.deepEqual(new Buffer([0x65]), b.slice(0, 1));
});
});

exports['Test int16 type'] = function() {
suite('int16', function() {
var b = new Buffer([0, 0x05, 0x65]), expected = 0x0565;
var result = types.int16.read(b, 1);
assert.equal(result, expected);
assert.equal(types.int16.size(expected), 2);
types.int16.write(expected, b, 0);
assert.eql(new Buffer([0x05, 0x65]), b.slice(0, 2));
};
test('read()', function() {
var result = types.int16.read(b, 1);
assert.equal(result, expected);
});
test('size()', function() {
assert.equal(types.int16.size(expected), 2);
});
test('write()', function() {
types.int16.write(expected, b, 0);
assert.deepEqual(new Buffer([0x05, 0x65]), b.slice(0, 2));
});
});

exports['Test int32 type'] = function() {
suite('int32', function() {
var b = new Buffer([0, 0x10, 0x02, 0x40, 0x45]), expected = 0x10024045;
var result = types.int32.read(b, 1);
assert.equal(result, expected);
assert.equal(types.int32.size(expected), 4);
types.int32.write(expected, b, 0);
assert.eql(new Buffer([0x10, 0x02, 0x40, 0x45]), b.slice(0, 4));
};
test('read()', function() {
var result = types.int32.read(b, 1);
assert.equal(result, expected);
});
test('size()', function() {
assert.equal(types.int32.size(expected), 4);
});
test('write()', function() {
types.int32.write(expected, b, 0);
assert.deepEqual(new Buffer([0x10, 0x02, 0x40, 0x45]), b.slice(0, 4));
});
});

exports['Test string type'] = function() {
suite('string', function() {
var b = new Buffer(9), expected = 'abcd1234';
b[0] = 8;
b.write(expected, 1);
var result = types.string.read(b, 0);
assert.equal(result, expected);
assert.equal(9, types.string.size(expected));
var b2 = new Buffer(9);
types.string.write(expected, b2, 0);
assert.eql(b, b2);
};
test('read()', function() {
var result = types.string.read(b, 0);
assert.equal(result, expected);
});
test('size()', function() {
assert.equal(9, types.string.size(expected));
});
test('write()', function() {
var b2 = new Buffer(9);
types.string.write(expected, b2, 0);
assert.deepEqual(b, b2);
});
});

exports['Test cstring type'] = function() {
suite('cstring', function() {
var b = new Buffer(9), expected = 'abcd1234';
b[8] = 0;
b.write(expected, 0);
var result = types.cstring.read(b, 0);
assert.equal(result, expected);
assert.equal(9, types.cstring.size(expected));
var b2 = new Buffer(9);
types.cstring.write(expected, b2, 0);
assert.eql(b, b2);
};
test('read()', function() {
var result = types.cstring.read(b, 0);
assert.equal(result, expected);
});
test('size()', function() {
assert.equal(9, types.cstring.size(expected));
});
test('write()', function() {
var b2 = new Buffer(9);
types.cstring.write(expected, b2, 0);
assert.deepEqual(b, b2);
});
});

exports['Test dest_address_array type'] = function() {
suite('dest_address_array', function() {
var b = new Buffer([
0x02, 0x01, 0x01, 0x02, 0x31, 0x32, 0x33, 0x00,
0x02, 0x61, 0x62, 0x63, 0x00
Expand All @@ -66,15 +96,21 @@ exports['Test dest_address_array type'] = function() {
},
{ dl_name: 'abc' }
];
var result = types.dest_address_array.read(b, 0);
assert.eql(result, expected);
assert.equal(types.dest_address_array.size(expected), 13);
var b2 = new Buffer(13);
types.dest_address_array.write(expected, b2, 0);
assert.eql(b, b2);
};
test('read()', function() {
var result = types.dest_address_array.read(b, 0);
assert.deepEqual(result, expected);
});
test('size()', function() {
assert.equal(types.dest_address_array.size(expected), 13);
});
test('write()', function() {
var b2 = new Buffer(13);
types.dest_address_array.write(expected, b2, 0);
assert.deepEqual(b, b2);
});
});

exports['Test unsuccess_sme_array type'] = function() {
suite('unsuccess_sme_array', function() {
var b = new Buffer([
0x02, 0x03, 0x04, 0x61, 0x62, 0x63, 0x00, 0x00, 0x00, 0x00, 0x07,
0x05, 0x06, 0x31, 0x32, 0x33, 0x00, 0x10, 0x00, 0x00, 0x08
Expand All @@ -93,10 +129,16 @@ exports['Test unsuccess_sme_array type'] = function() {
error_status_code: 0x10000008
}
];
var result = types.unsuccess_sme_array.read(b, 0);
assert.eql(result, expected);
assert.equal(types.unsuccess_sme_array.size(expected), 21);
var b2 = new Buffer(21);
types.unsuccess_sme_array.write(expected, b2, 0);
assert.eql(b, b2);
};
test('read()', function() {
var result = types.unsuccess_sme_array.read(b, 0);
assert.deepEqual(result, expected);
});
test('size()', function() {
assert.equal(types.unsuccess_sme_array.size(expected), 21);
});
test('write()', function() {
var b2 = new Buffer(21);
types.unsuccess_sme_array.write(expected, b2, 0);
assert.deepEqual(b, b2);
});
});

0 comments on commit 21c3778

Please sign in to comment.