Skip to content

Commit

Permalink
Test units for URI and NameAddrHeader classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
ibc committed Feb 13, 2013
1 parent 826ce12 commit 360c946
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 19 deletions.
39 changes: 39 additions & 0 deletions qunitjs/javascript/test-NameAddrHeader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
test('JsSIP.NameAddrHeader', function() {
var name, uri;

uri = new JsSIP.URI('sip', 'alice', 'jssip.net');
name = new JsSIP.NameAddrHeader(uri, 'Alice æßð');

strictEqual(name.display_name, 'Alice æßð');
strictEqual(name.toString(), '"Alice æßð" <sip:[email protected]>');

name.display_name = null;
strictEqual(name.toString(), '<sip:[email protected]>');

name.display_name = 0;
strictEqual(name.toString(), '"0" <sip:[email protected]>');

name.display_name = "";
strictEqual(name.toString(), '<sip:[email protected]>');

deepEqual(name.parameters, {});

name.setParam('Foo', null);
strictEqual(name.hasParam('FOO'), true);

name.setParam('Baz', 123);
strictEqual(name.getParam('baz'), '123');
strictEqual(name.toString(), '<sip:[email protected]>;foo;baz=123');

strictEqual(name.deleteParam('bAz'), '123');

name.clearParams();
strictEqual(name.toString(), '<sip:[email protected]>');

var name2 = name.clone();
strictEqual(name2.toString(), name.toString());
name2.display_name = '@ł€';
strictEqual(name2.display_name, '@ł€');
strictEqual(name.user, undefined);
});

21 changes: 2 additions & 19 deletions qunitjs/javascript/test-UA-no-WebRTC.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,7 @@ test('UA no WS connection', function() {
deepEqual(ua.configuration[parameter], TestJsSIP.Helpers.DEFAULT_JSSIP_CONFIGURATION_AFTER_START[parameter], 'testing parameter ' + parameter);
}

var views = {
selfView: document.getElementById('selfView'),
remoteView: document.getElementById('remoteView')
};

// TODO: This requires running on a WebRTC capable browser by retrieving
// this web via HTTP protocol.
//
// ua.call('test', views, {
// mediaTypes: { audio: false, video: false },
// eventHandlers: {
// failed: function(e) {
// strictEqual(e.data.cause, JsSIP.C.causes.CONNECTION_ERROR);
// }
// }
// });

ua.sendMessage('test', 'FAIL PLEASE', {
ua.sendMessage('test', 'FAIL WITH CONNECTION_ERROR PLEASE', {
eventHandlers: {
sending: function(e) {
var ruri = e.data.request.ruri;
Expand All @@ -48,7 +31,7 @@ test('UA no WS connection', function() {
}
});

ua.sendMessage('sip:ibc@iñaki.ðđß', 'FAIL PLEASE', {
ua.sendMessage('sip:ibc@iñaki.ðđß', 'FAIL WITH INVALID_TARGET PLEASE', {
eventHandlers: {
sending: function(e) {
var ruri = e.data.request.ruri;
Expand Down
113 changes: 113 additions & 0 deletions qunitjs/javascript/test-URI.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
test('JsSIP.URI', function() {
var uri;

uri = new JsSIP.URI(null, 'alice', 'jssip.net', 6060);

strictEqual(uri.scheme, 'sip');
strictEqual(uri.user, 'alice');
strictEqual(uri.host, 'jssip.net');
strictEqual(uri.port, 6060);
deepEqual(uri.parameters, {});
deepEqual(uri.headers, {});
strictEqual(uri.toString(), 'sip:[email protected]:6060');
strictEqual(uri.toAor(), 'sip:[email protected]');

uri.scheme = 'SIPS';
strictEqual(uri.scheme, 'sips');
strictEqual(uri.toAor(), 'sips:[email protected]');
uri.scheme = 'sip';

uri.user = 'Iñaki ðđ';
strictEqual(uri.user, 'Iñaki ðđ');
strictEqual(uri.toString(), 'sip:I%C3%B1aki%20%C3%B0%C4%[email protected]:6060');
strictEqual(uri.toAor(), 'sip:I%C3%B1aki%20%C3%B0%C4%[email protected]');

uri.user = '%61lice';
strictEqual(uri.toAor(), 'sip:[email protected]');

uri.user = null;
strictEqual(uri.user, null);
strictEqual(uri.toAor(), 'sip:jssip.net');
uri.user = 'alice';

throws(
function() {
uri.host = null;
},
TypeError
);
throws(
function() {
uri.host = {bar: 'foo'};
},
TypeError
);
strictEqual(uri.host, 'jssip.net');

uri.host = 'VERSATICA.com';
strictEqual(uri.host, 'versatica.com');
uri.host = 'jssip.net';

uri.port = null;
strictEqual(uri.port, null);

uri.port = undefined;
strictEqual(uri.port, null);

uri.port = 'ABCD'; // Should become null.
strictEqual(uri.toString(), 'sip:[email protected]');

uri.port = '123ABCD'; // Should become 123.
strictEqual(uri.toString(), 'sip:[email protected]:123');

uri.port = 0;
strictEqual(uri.port, 0);
strictEqual(uri.toString(), 'sip:[email protected]:0');
uri.port = null;

strictEqual(uri.hasParam('foo'), false);

uri.setParam('Foo', null);
strictEqual(uri.hasParam('FOO'), true);

uri.setParam('Baz', 123);
strictEqual(uri.getParam('baz'), '123');
strictEqual(uri.toString(), 'sip:[email protected];foo;baz=123');

uri.setParam('zero', 0);
strictEqual(uri.hasParam('ZERO'), true);
strictEqual(uri.getParam('ZERO'), '0');
strictEqual(uri.toString(), 'sip:[email protected];foo;baz=123;zero=0');
strictEqual(uri.deleteParam('ZERO'), '0');

strictEqual(uri.deleteParam('baZ'), '123');
strictEqual(uri.deleteParam('NOO'), undefined);
strictEqual(uri.toString(), 'sip:[email protected];foo');

uri.clearParams();
strictEqual(uri.toString(), 'sip:[email protected]');

strictEqual(uri.hasHeader('foo'), false);

uri.setHeader('Foo', 'LALALA');
strictEqual(uri.hasHeader('FOO'), true);
deepEqual(uri.getHeader('FOO'), ['LALALA']);
strictEqual(uri.toString(), 'sip:[email protected]?Foo=LALALA');

uri.setHeader('bAz', ['ABC-1', 'ABC-2']);
deepEqual(uri.getHeader('baz'), ['ABC-1', 'ABC-2']);
strictEqual(uri.toString(), 'sip:[email protected]?Foo=LALALA&Baz=ABC-1&Baz=ABC-2');

deepEqual(uri.deleteHeader('baZ'), ['ABC-1', 'ABC-2']);
deepEqual(uri.deleteHeader('NOO'), undefined);

uri.clearHeaders();
strictEqual(uri.toString(), 'sip:[email protected]');

var uri2 = uri.clone();
strictEqual(uri2.toString(), uri.toString());
uri2.user = 'popo';
strictEqual(uri2.user, 'popo');
strictEqual(uri.user, 'alice');
});

2 changes: 2 additions & 0 deletions qunitjs/testNoWebRTC.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
<script src="javascript/qunit-1.11.0.js"></script>
<script src="javascript/helpers.js"></script>
<script src="javascript/test-parser.js"></script>
<script src="javascript/test-URI.js"></script>
<script src="javascript/test-NameAddrHeader.js"></script>
<script src="javascript/test-normalizeURI.js"></script>
<script src="javascript/test-UA-no-WebRTC.js"></script>
</head>
Expand Down

0 comments on commit 360c946

Please sign in to comment.