Permalink
Browse files

Add output serialization tests and improve README.md

  • Loading branch information...
1 parent 3c9bb03 commit 70642d9f22e0ee7007abaf43b02700ab1986ebd1 @wanderview committed Mar 3, 2013
Showing with 107 additions and 23 deletions.
  1. +20 −20 README.md
  2. +84 −0 test/test-expand.js
  3. +3 −3 test/{test-stream.js → test-reduce.js}
View
@@ -51,30 +51,30 @@ var ipstream5 = new IpStream({fragmentTimeout: 5000});
### Writing
```javascript
- var IpStream = require('ip-stream');
- var EtherStream = require('ether-stream');
- var IpHeader = require('ip-header');
- var EtherFrame = require('ether-frame');
+var IpStream = require('ip-stream');
+var EtherStream = require('ether-stream');
+var IpHeader = require('ip-header');
+var EtherFrame = require('ether-frame');
- var estream = new EtherStream();
- var ipstream = new IpStream();
+var estream = new EtherStream();
+var ipstream = new IpStream();
- estream.pipe(ipstream);
+estream.pipe(ipstream);
- // define the content to write out to the buffer
- var in = {
- ether: new EtherFrame({ dst: '01:23:45:54:32:10' }),
- ip: new IpHeader({ dst: '1.1.1.1', dataLength: 500 }),
- data: new Buffer(8*1024) // adequate storage for header
- };
+// define the content to write out to the buffer
+var input = {
+ ether: new EtherFrame({ dst: '01:23:45:54:32:10' }),
+ ip: new IpHeader({ dst: '1.1.1.1', dataLength: 500 }),
+ data: new Buffer(8*1024) // adequate storage for header
+};
- // NOTE: packet payload is not in.data, that must be appended later
+// NOTE: packet payload is not input.data, that must be appended later
- estream.write(in);
- var out = ipstream.read();
+estream.write(input);
+var output = ipstream.read();
- // header values have been written to the buffer
- out.offset === (in.ether.length * in.ip.length);
- test.deepEqual(in.ether, new EtherFrame(out.data, 0));
- test.deepEqual(in.ip, new IpHeader(out.data, in.ether.length));
+// header values have been written to the buffer
+out.offset === (input.ether.length * input.ip.length);
+test.deepEqual(input.ether, new EtherFrame(out.data, 0));
+test.deepEqual(input.ip, new IpHeader(out.data, input.ether.length));
```
View
@@ -0,0 +1,84 @@
+// Copyright (c) 2013, Benjamin J. Kelly ("Author")
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this
+// list of conditions and the following disclaimer.
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+// this list of conditions and the following disclaimer in the documentation
+// and/or other materials provided with the distribution.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+'use strict';
+
+var IpStream = require('../stream');
+
+var IpHeader = require('ip-header');
+
+module.exports.defaults = function(test) {
+ test.expect(2);
+
+ var ipDefault = new IpHeader({
+ src: '52.13.128.211',
+ dst: '1.2.3.4',
+ protocol: 'tcp',
+ datalength: 672
+ });
+
+ var ipstream = new IpStream({ip: ipDefault});
+
+ var input = {
+ data: new Buffer(8*1024),
+ };
+
+ ipstream.write(input);
+ var output = ipstream.read();
+
+ test.deepEqual(ipDefault, output.ip);
+ test.deepEqual(ipDefault, new IpHeader(output.data));
+
+ test.done();
+};
+
+module.exports.message = function(test) {
+ test.expect(2);
+
+ var ipDefault = new IpHeader({
+ src: '52.13.128.211',
+ dst: '1.2.3.4',
+ protocol: 'tcp',
+ datalength: 672
+ });
+
+ var ipstream = new IpStream({ip: ipDefault});
+
+ var input = {
+ data: new Buffer(8*1024),
+ ip: new IpHeader({
+ src: '1.2.3.4',
+ dst: '52.13.128.211',
+ protocol: 'udp',
+ dataLength: 100
+ })
+ };
+
+ ipstream.write(input);
+ var output = ipstream.read();
+
+ test.deepEqual(input.ip, output.ip);
+ test.deepEqual(input.ip, new IpHeader(output.data));
+
+ test.done();
+};
@@ -27,7 +27,7 @@ var IpStream = require('../stream');
var IpHeader = require('ip-header');
-module.exports.writeBuffer = function(test) {
+module.exports.buffer = function(test) {
test.expect(2);
var iph = new IpHeader({
@@ -52,7 +52,7 @@ module.exports.writeBuffer = function(test) {
ipstream.end();
};
-module.exports.writeObject = function(test) {
+module.exports.object = function(test) {
test.expect(2);
var iph = new IpHeader({
@@ -77,7 +77,7 @@ module.exports.writeObject = function(test) {
ipstream.end();
};
-module.exports.writeIgnore = function(test) {
+module.exports.ignore = function(test) {
test.expect(1);
var value = {

0 comments on commit 70642d9

Please sign in to comment.