Skip to content

Commit

Permalink
a almost full coverage submit test is updated.
Browse files Browse the repository at this point in the history
  • Loading branch information
kaven276 committed Jun 4, 2012
1 parent e2ce90c commit 3e7032a
Showing 1 changed file with 94 additions and 15 deletions.
109 changes: 94 additions & 15 deletions lib/nodes/nodeSP.js
Expand Up @@ -107,11 +107,11 @@ SP.prototype.send = function(msg, callback){

SP.prototype.listen = function(port, host){
var me = this;
var server = net.createServer(function(svrSock){
var halfBuf = [], halfLen = 0;
var server = net.createServer(function(c){
console.log('server connected');
// todo: wait for bind request and check user/pass
// todo: if passed, accept request and emit events for report, userRpt
var spliter = new StreamSpliter(c, 'readUInt32BE')
, bound = false
;
c.on('end', function(){
console.log('SP server end');
});
Expand Down Expand Up @@ -160,16 +160,95 @@ exports.Class = SP;

if (bUnitText) {
var sp = new SP('202.99.87.201', 8801, 'dialbook', 'dialbooktest', 8801, '', 'dialbook', 'dialbooktest');
var msg;
var msg, encoding = 8, content = '', option = {};
var lowDebug = 0
, sendMethod = 1
, amount10 = 20
;
sp.connect();
msg = new Submit(['15620001781'], 0, 'liyong3');
sp.send(msg);
console.log(msg);
// sp.send(new Submit(['15620007256'], 8, 'sms is ok now, thank you!'), callback);
// sp.send(new Submit(['15620001781'], 15, '李勇'), callback);
sp.on('resp', function(msgResp, msgSend){
console.log('send message success for :');
console.log(msgSend);
console.log(msgResp);

switch (lowDebug || encoding) {
case 0:
encoding = 0;
content = '1234567890123456789012345678901234567890123456789012345678901234567890';
content += content;
content = 'password:4644 @http://unidialbook.com/tjuc/register_b.a?rc=4644';
break;
case 1:
encoding = 1;
content = 'liyong4';
break;
case 8:
encoding = 8;
content = '';
// 67 one page, 134 for two page max
for (var i = 0; i < amount10; i++) {
content += '一二三四五六七八九' + ((i + 1) % 10);
}
content += '完'; // 201 chars will cause error
break;
case 15:
encoding = 15;
content = new Buffer([192, 238, 211, 194, 49, 50, 51]); //'李勇';
break;
case -1:
encoding = 8;
content = new Buffer([0x05, 0x00, 0x03, 19, 3, 3, 0x67, 0x4e, 0x52, 0xc7, 0x4e, 0x00, 0x67, 0x4e, 0x52, 0xc7, 0x4e, 0x00, 0x67, 0x4e, 0x52, 0xc7, 0x4e, 0x00, 0x67, 0x4e, 0x52, 0xc7, 0x4e, 0x00, 0x67, 0x4e, 0x52, 0xc7, 0x4e, 0x00, 0x67, 0x4e, 0x52, 0xc7, 0x4e, 0x00, 0x67, 0x4e, 0x52, 0xc7, 0x4e, 0x00, 0x67, 0x4e, 0x52, 0xc7, 0x4e, 0x00]);
//'李勇'; 共计 3*6*10*2=360 字节 15*6*4=360字节
break;
}

if (true) {
// for single target number test
option.ReportFlag = 1;
msg = new Submit('8615620001781', encoding, content, option); // 8618602247757 8615620001781
} else {
// todo: for multiple numbers, SMG result is 5 (bad format)
msg = new Submit(['8615620007256', '8615620001781' , '8618602247741'], encoding, content);
}
// console.log(msg);

sp.on('request', function(req){
console.log('\nReport:');
console.log(req);
});
}

switch (lowDebug || sendMethod) {
case 1 :
sp.send(msg, function(res, req){
// console.log('pair are', req, res, 'end');
});
break;
case 2:
// for send and catch for "resp" event mode
sp.send(msg);
sp.on('resp', function(msgResp, msgSend){
console.log('send message success for :');
//console.log(msgSend);
//console.log(msgSend.PDU.slice(0, 20));
//console.log(msgSend.PDU.slice(20 + 21 + 21));
console.log(msgResp);
console.log(sp.ackQueue.length);
});
break;
case -1:
option = { 'TP_udhi' : 1, 'ScheduleTime' : utl.afterNow(1)};
// for send with response callback mode
var parts = 10;
content.writeUInt8(21, 3);
content.writeUInt8(parts, 4);
for (var j = 0; j < parts; j++) {
(function(){
var c = new Buffer(content);
c.writeUInt8(j + 1, 5);
msg = new Submit('8615620001781', encoding, c, option);
sp.send(msg, function(res, req){
console.log('pair are', req, res, 'end');
});
})();
}
break;
// 81 + (15*4+3)=63*3=189 chars 2.89 page
// 24*24=
}
}

0 comments on commit 3e7032a

Please sign in to comment.