Skip to content
Permalink
Browse files

Test units for URI and NameAddrHeader classes.

  • Loading branch information
ibc committed Feb 13, 2013
1 parent 826ce12 commit 360c946d603a718625729c0f64f90e8c0100e638
@@ -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:alice@jssip.net>');

name.display_name = null;
strictEqual(name.toString(), '<sip:alice@jssip.net>');

name.display_name = 0;
strictEqual(name.toString(), '"0" <sip:alice@jssip.net>');

name.display_name = "";
strictEqual(name.toString(), '<sip:alice@jssip.net>');

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:alice@jssip.net>;foo;baz=123');

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

name.clearParams();
strictEqual(name.toString(), '<sip:alice@jssip.net>');

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

@@ -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;
@@ -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;
@@ -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:alice@jssip.net:6060');
strictEqual(uri.toAor(), 'sip:alice@jssip.net');

uri.scheme = 'SIPS';
strictEqual(uri.scheme, 'sips');
strictEqual(uri.toAor(), 'sips:alice@jssip.net');
uri.scheme = 'sip';

uri.user = 'Iñaki ðđ';
strictEqual(uri.user, 'Iñaki ðđ');
strictEqual(uri.toString(), 'sip:I%C3%B1aki%20%C3%B0%C4%91@jssip.net:6060');
strictEqual(uri.toAor(), 'sip:I%C3%B1aki%20%C3%B0%C4%91@jssip.net');

uri.user = '%61lice';
strictEqual(uri.toAor(), 'sip:alice@jssip.net');

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:alice@jssip.net');

uri.port = '123ABCD'; // Should become 123.
strictEqual(uri.toString(), 'sip:alice@jssip.net:123');

uri.port = 0;
strictEqual(uri.port, 0);
strictEqual(uri.toString(), 'sip:alice@jssip.net: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:alice@jssip.net;foo;baz=123');

uri.setParam('zero', 0);
strictEqual(uri.hasParam('ZERO'), true);
strictEqual(uri.getParam('ZERO'), '0');
strictEqual(uri.toString(), 'sip:alice@jssip.net;foo;baz=123;zero=0');
strictEqual(uri.deleteParam('ZERO'), '0');

strictEqual(uri.deleteParam('baZ'), '123');
strictEqual(uri.deleteParam('NOO'), undefined);
strictEqual(uri.toString(), 'sip:alice@jssip.net;foo');

uri.clearParams();
strictEqual(uri.toString(), 'sip:alice@jssip.net');

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

uri.setHeader('Foo', 'LALALA');
strictEqual(uri.hasHeader('FOO'), true);
deepEqual(uri.getHeader('FOO'), ['LALALA']);
strictEqual(uri.toString(), 'sip:alice@jssip.net?Foo=LALALA');

uri.setHeader('bAz', ['ABC-1', 'ABC-2']);
deepEqual(uri.getHeader('baz'), ['ABC-1', 'ABC-2']);
strictEqual(uri.toString(), 'sip:alice@jssip.net?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:alice@jssip.net');

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

@@ -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>

0 comments on commit 360c946

Please sign in to comment.
You can’t perform that action at this time.