Skip to content

Commit

Permalink
Tests to check several namespaces and null values
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Élie Fauché committed Nov 25, 2013
1 parent 736aa80 commit 02001d8
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 0 deletions.
29 changes: 29 additions & 0 deletions test/fixtures/calendar-item-with-null-body-with-namespace.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"ItemOperations:ItemOperations": {
"Status": "1",
"Response": {
"Fetch": {
"Status": "1",
"AirSync:CollectionId": "1:AHApGqUqePFJmJ2RaEV2H2/TSX3s7gImT4AvBWwiEOhm",
"AirSync:ServerId": "1:qqbwn4vjKUGwtiQNr1VrGA==",
"ItemOperations:Properties": {
"Calendar:AllDayEvent": "0",
"AirSyncBase:Body": {
"AirSyncBase:Type": "1",
"AirSyncBase:Data": null
},
"Calendar:BusyStatus": "2",
"Calendar:Subject": "delete me",
"Calendar:MeetingStatus": "0",
"Calendar:Sensitivity": "0",
"Calendar:Reminder": "15",
"Calendar:UID": "9ff0a6aa-e38b-4129-b0b6-240daf556b18",
"Calendar:TimeZone": "LAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAsAAAABAAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAACAAIAAAAAAAAAxP///w==",
"Calendar:StartTime": "20131127T140000Z",
"Calendar:EndTime": "20131127T150000Z",
"Calendar:DtStamp": "20131125T205642Z"
}
}
}
}
}
Binary file added test/fixtures/calendar-item-with-null-body.hex
Binary file not shown.
29 changes: 29 additions & 0 deletions test/fixtures/calendar-item-with-null-body.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"ItemOperations": {
"Status": "1",
"Response": {
"Fetch": {
"Status": "1",
"CollectionId": "1:AHApGqUqePFJmJ2RaEV2H2/TSX3s7gImT4AvBWwiEOhm",
"ServerId": "1:qqbwn4vjKUGwtiQNr1VrGA==",
"Properties": {
"AllDayEvent": "0",
"Body": {
"Type": "1",
"Data": null
},
"BusyStatus": "2",
"Subject": "delete me",
"MeetingStatus": "0",
"Sensitivity": "0",
"Reminder": "15",
"UID": "9ff0a6aa-e38b-4129-b0b6-240daf556b18",
"TimeZone": "LAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAsAAAABAAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAACAAIAAAAAAAAAxP///w==",
"StartTime": "20131127T140000Z",
"EndTime": "20131127T150000Z",
"DtStamp": "20131125T205642Z"
}
}
}
}
}
84 changes: 84 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,23 @@ describe('decode without callback', function() {

fstream.pipe(decoder);
})

it('itemoperations with null body', function (done) {
var decoder = wbxml.Decoder({codepages: codepages}),
fstream = fs.createReadStream(__dirname + '/fixtures/calendar-item-with-null-body.hex'),
json = JSON.parse(fs.readFileSync(__dirname + '/fixtures/calendar-item-with-null-body.json', {encoding: 'utf8'}));

decoder.on('readable', function () {
var obj = decoder.read();
assert.deepEqual(obj, json);
})

decoder.on('end', function () {
done();
})

fstream.pipe(decoder);
})
})

describe('decode with callback', function() {
Expand Down Expand Up @@ -69,6 +86,20 @@ describe('decode with callback', function() {

fstream.pipe(decoder)
})

it('itemoperations with null body', function (done) {
var decoder = wbxml.Decoder({codepages: codepages}, cb),
fstream = fs.createReadStream(__dirname + '/fixtures/calendar-item-with-null-body.hex'),
json = JSON.parse(fs.readFileSync(__dirname + '/fixtures/calendar-item-with-null-body.json', {encoding: 'utf8'}));

function cb (err, obj) {
if (err) throw err;
assert.deepEqual(obj, json);
done()
}

fstream.pipe(decoder)
})
})

describe('encode without callback', function() {
Expand Down Expand Up @@ -128,6 +159,38 @@ describe('encode without callback', function() {
encoder.write(json);
encoder.end()
})

it('itemoperations with null body', function (done) {

var encoder = wbxml.Encoder({
codepages: codepages,
namespaces: namespaces
});

var correct = fs.readFileSync(__dirname + '/fixtures/calendar-item-with-null-body.hex'),
json = JSON.parse(fs.readFileSync(__dirname + '/fixtures/calendar-item-with-null-body-with-namespace.json', {encoding: 'utf8'}));

encoder.on('readable', function () {
var buffer = encoder.read();
var out = '';
for(var i = 0; i < correct.length; i++){
out += (' ' + buffer[i].toString(16));
if (buffer[i] !== correct[i]) {
console.log(out)
console.log('failed at ', i)
}
assert.equal(buffer[i], correct[i]);
}
console.log(out)
})

encoder.on('end', function () {
done();
})

encoder.write(json);
encoder.end()
})
})

describe('encode with callback', function() {
Expand Down Expand Up @@ -172,4 +235,25 @@ describe('encode with callback', function() {
encoder.write(json);
encoder.end()
})

it('itemoperations with null body', function (done) {
var encoder = wbxml.Encoder({
codepages: codepages,
namespaces: namespaces
}, cb);

var correct = fs.readFileSync(__dirname + '/fixtures/calendar-item-with-null-body.hex'),
json = JSON.parse(fs.readFileSync(__dirname + '/fixtures/calendar-item-with-null-body-with-namespace.json', {encoding: 'utf8'}));

function cb (err, buffer) {
if (err) throw err;
for(var i = 0; i < correct.length; i++){
assert.equal(buffer[i], correct[i]);
}
done()
}

encoder.write(json);
encoder.end()
})
})

0 comments on commit 02001d8

Please sign in to comment.