Author: ygrego Date: 2015-03-31 08:15:29 +0000 (Tue, 31 Mar 2015) New Revision: 989 Url: http://forge.nuiton.org/projects/sandbox/repository/revisions/989 Log: -New method added "afterTest". -New tests added about "volume" and "bind to current channel". -The method "onChangeState" has been modified to manage a possible error. -A reference on "onChangeState" is saved in order to remove it in method "afterTest". Modified: oipf/js/test/VideoBroadcastTest.js Modified: oipf/js/test/VideoBroadcastTest.js =================================================================== --- oipf/js/test/VideoBroadcastTest.js 2015-03-31 08:03:16 UTC (rev 988) +++ oipf/js/test/VideoBroadcastTest.js 2015-03-31 08:15:29 UTC (rev 989) @@ -22,7 +22,7 @@ 2: "Tuner locked by other object.", 3: "Parental lock on channel.", 4: "Encrypted channel, key/module missing.", - 5: "Unknown channel (e.g. can’t resolve DVB or ISDB triplet).", + 5: "Unknown channel (e.g. can’t resolve DVB or ISDB triplet).", 6: "Channel switch interrupted (e.g. because another channel switch was activated before the previous one completed).", 7: "Channel cannot be changed, because it is currently being recorded.", 8: "Cannot resolve URI of referenced IP channel.", @@ -34,18 +34,43 @@ }, + errorMap: { + + 0: "Channel not supported by tuner.", + 1: "Cannot tune to given transport stream (e.g. no signal).", + 2: "Tuner locked by other object.", + 3: "Parental lock on channel.", + 4: "Encrypted channel, key/module missing.", + 5: "Unknown channel (e.g. can’t resolve DVB or ISDB triplet).", + 6: "Channel switch interrupted (e.g. because another channel switch was activated before the previous one completed).", + 7: "Channel cannot be changed, because it is currently being recorded.", + 8: "Cannot resolve URI of referenced IP channel.", + 9: "Insufficient bandwidth.", + 10: "Channel cannot be changed by nextChannel()/prevChannel() methods either because the OITF does not maintain a favourites or channel list or because the video/broadcast object is in the Unrealized state.", + 11: "Insufficient resources are available to present the given channel (e.g. a lack of available codec resources).", + 12: "Specified channel not found in transport stream.", + 100: "Unidentified error." + + }, + init: function() { }, beforeTest: function(resolve, reject) { this.vidBroadObj = oipfObjectFactory.createVideoBroadcastObject(); - this.vidBroadObj.addEventListener("PlayStateChange", this.onChangeState.bind(this, resolve, reject)); + this.onPlayStateChange = this.onChangeState.bind(this, resolve, reject); + this.vidBroadObj.addEventListener("PlayStateChange", this.onPlayStateChange, false); this.transitions = []; this.previousState = this.vidBroadObj.playState; this.currentIndex = 0; logTest("State: Pending"); }, + + afterTest: function() { +// this.vidBroadObj.release(); //Useful for test on tv plateform + this.vidBroadObj.removeEventListener("PlayStateChange", this.onPlayStateChange); + }, onChangeState: function(resolve, reject, newState, errorCode) { var currentTransition = this.transitions[this.currentIndex]; @@ -54,11 +79,15 @@ var error = currentTransition.error; console.log(this.vidBroadObj.playState); if (begin == this.previousState && end == newState && error == errorCode) { - currentTransition.callback && currentTransition.callback(); - - this.previousState = newState; - this.currentIndex++; - + if (this.errorMap[errorCode]) { + console.log(this.errorMap[errorCode]); + reject(this.errorMap[errorCode]); + } else { + currentTransition.callback && currentTransition.callback(); + this.previousState = newState; + this.currentIndex++; + } + } else { reject("Invalid state"); } @@ -76,25 +105,15 @@ callback: callback }); }, - + /* * Descrtiption: - * This method test the initialization of video broadcast object. + * This method test the binding between the video broadcast object and the current program stream. + * ToDO: Extraction of method onPlayStateChange out. */ - testVideoBroadcastInit: function (resolve, reject) { - - if (this.assertNotNull(this.vidBroadObj) && this.assertNotUndefined(this.vidBroadObj)) { - logTest("State: Successfull"); - resolve("Successfull"); - } else { - logTest("State: Failure"); - reject("Failure"); - } - }, - - testBind2Stop : function (resolve, reject){ + testBindToCurrentChannel: function(resolve, reject) { var self = this; - + this.addTransition(this.UNREALIZED, this.CONNECTING, function() { self.vidBroadObj.bindToCurrentChannel(); }); @@ -102,15 +121,50 @@ this.addTransition(this.CONNECTING, this.PRESENTING, resolve); this.vidBroadObj.bindToCurrentChannel(); - }, + }, + /* + * This method must throw a error by using the method reject. + * + * @param {type} resolve + * @param {type} reject + * @returns {undefined} + */ + testBindToCurrentChannelWhenNoChannelPresentation: function(resolve, reject) { + //Subject to modification not rigth way failed on the tv plateform. + this.vidBroadObj._channelService.currentChannel = null; + + this.addTransitionWithError(this.UNREALIZED, this.UNREALIZED, 100); + this.vidBroadObj.bindToCurrentChannel(); + }, + + /* * Descrtiption: * This method test the binding between the video broadcast object and the current program stream. * ToDO: Extraction of method onPlayStateChange out. */ - testBindToCurrentChannel: function(resolve, reject) { +// testBindToCurrentChannel: function(resolve, reject) { +// var self = this; +// +// this.addTransition(this.previousState, this.PRESENTING); +// +// this.vidBroadObj.bindToCurrentChannel(); +// }, + + testDoubleBindToCurrentChannel: function(resolve, reject) { var self = this; + this.addTransition(this.UNREALIZED, this.CONNECTING); + + this.addTransition(this.CONNECTING, this.PRESENTING, resolve); + + this.vidBroadObj.bindToCurrentChannel(); + this.vidBroadObj.bindToCurrentChannel(); + }, + + testBindToCurrentChannelInConnecting: function(resolve, reject) { + var self = this; + this.addTransition(this.UNREALIZED, this.CONNECTING, function() { self.vidBroadObj.bindToCurrentChannel(); }); @@ -120,19 +174,69 @@ this.vidBroadObj.bindToCurrentChannel(); }, - testBindToCurrentChannelInConnecting : function(resolve, reject) { + testBindToCurrentChannelInPresenting: function(resolve, reject) { var self = this; - this.addTransition(this.UNREALIZED, this.CONNECTING, function() { + this.addTransition(this.UNREALIZED, this.CONNECTING); + + this.addTransition(this.CONNECTING, this.PRESENTING, function() { self.vidBroadObj.bindToCurrentChannel(); + resolve(); }); + this.vidBroadObj.bindToCurrentChannel(); + }, + + testBindToCurrentChannelInStopped: function(resolve, reject) { + var self = this; + + this.addTransition(this.UNREALIZED, this.CONNECTING); + + this.addTransition(this.CONNECTING, this.PRESENTING, function() { + self.vidBroadObj.stop(); + }); + + this.addTransition(this.PRESENTING, this.STOPPED, function() { + self.vidBroadObj.bindToCurrentChannel(); + }); + + this.addTransition(this.STOPPED, this.CONNECTING, resolve); this.addTransition(this.CONNECTING, this.PRESENTING, resolve); this.vidBroadObj.bindToCurrentChannel(); + }, /* + * This method must throw a error by using the method reject. + * @param {type} resolve + * @param {type} reject + * @returns {undefined} + */ + testBindToCurrentChannelInStoppedWhenNoTuner: function(resolve, reject) { + var self = this; + + var self = this; + + this.addTransition(this.UNREALIZED, this.CONNECTING); + + this.addTransition(this.CONNECTING, this.PRESENTING, function() { + self.vidBroadObj.stop(); + }); + + this.addTransition(this.PRESENTING, this.STOPPED, function() { + //We want test the case where the current channel has a idType whose + //any tuner supporting this kind of channel exist. + //So we create channel of idType "ATSCT". + self.vidBroadObj._channelService.currentChannel = new Channel(ID_ATSC_T, null, null); + self.vidBroadObj.bindToCurrentChannel(); + }); + + this.addTransitionWithError(this.STOPPED, this.STOPPED, 0); + + this.vidBroadObj.bindToCurrentChannel(); + }, + /* * Description: * Nominal Case */ @@ -163,6 +267,28 @@ }, +// testPrevChannel: function(resolve, reject) { +// var self = this; +// +// this.addTransition(this.PRESENTING, this.CONNECTING); +// +// this.addTransition(this.CONNECTING, this.PRESENTING); +// +// this.vidBroadObj.onChannelChangeSucceeded = function(channel) { +// +// if (self.assertNotNull(channel) && self.assertEquals(this.vidBroadObj, this.PRESENTING)) { +// logTest("State: Successful"); +// resolve("Successfull"); +// } else { +// logTest("State: Failure"); +// reject("Failure : The channel is null for a unknown reason or wrong play state."); +// } +// }; +// +// this.vidBroadObj.prevChannel(); +// +// }, + /* * Description: * Nominal Case @@ -190,10 +316,46 @@ reject("Failure : The channel is null for a unknown reason or wrong play state."); } }; + this.addTransition(this.PRESENTING, this.CONNECTING); + + this.addTransition(this.CONNECTING, this.PRESENTING); + this.vidBroadObj.onChannelChangeSucceeded = function(channel) { + + if (self.assertNotNull(channel) && self.assertEquals(this.vidBroadObj, this.PRESENTING)) { + logTest("State: Successful"); + resolve("Successfull"); + } else { + logTest("State: Failure"); + reject("Failure : The channel is null for a unknown reason or wrong play state."); + } + }; + + this.vidBroadObj.prevChannel(); this.vidBroadObj.bindToCurrentChannel(); }, +// testNextChannel: function(resolve, reject) { +// var self = this; +// +// this.addTransition(this.PRESENTING, this.CONNECTING); +// +// this.addTransition(this.CONNECTING, this.PRESENTING); +// +// this.vidBroadObj.onChannelChangeSucceeded = function(channel) { +// +// if (self.assertNotNull(channel) && self.assertEquals(this.vidBroadObj, this.PRESENTING)) { +// logTest("State: Successful"); +// resolve("Successfull"); +// } else { +// logTest("State: Failure"); +// reject("Failure : The channel is null for a unknown reason or wrong play state."); +// } +// }; +// +// this.vidBroadObj.nextChannel(); +// }, + /* * Description: * Nominal Case @@ -212,6 +374,14 @@ this.vidBroadObj.bindToCurrentChannel(); }, +// testRelease: function(resolve, reject) { +// var self = this; +// +// this.addTransition(this.PRESENTING, this.UNREALIZED, resolve); +// +// this.vidBroadObj.release(); +// }, + /* * Description: * Nominal Case @@ -228,5 +398,231 @@ this.addTransition(this.PRESENTING, this.STOPPED, resolve); this.vidBroadObj.bindToCurrentChannel(); + }, + +// testStop: function(resolve, reject) { +// var self = this; +// +// this.addTransition(this.PRESENTING, this.STOPPED, resolve); +// +// this.vidBroadObj.stop(); +// }, + + /* + * Description: + * Nominal Case + */ + testSetVolume: function(resolve, reject) { + var volume = 15; + var self = this; + this.addTransition(this.UNREALIZED, this.CONNECTING); + + this.addTransition(this.CONNECTING, this.PRESENTING, function() { + var done = self.vidBroadObj.setVolume(volume); + if (done && self.assertEquals(volume, self.vidBroadObj._volume)) { + resolve(); + } else { + reject(); + } + }); + + this.vidBroadObj.bindToCurrentChannel(); + }, + + testSetVolumeWithoutArgument: function(resolve, reject) { + var self = this; + this.addTransition(this.UNREALIZED, this.CONNECTING); + + this.addTransition(this.CONNECTING, this.PRESENTING, function() { + var done = self.vidBroadObj.setVolume(); + if (done) { + reject(); + } else { + reject(); + } + }); + + this.vidBroadObj.bindToCurrentChannel(); + }, + + testSetVolumeWithFloatArgument: function(resolve, reject) { + var volume = 15.8; + var self = this; + this.addTransition(this.UNREALIZED, this.CONNECTING); + + this.addTransition(this.CONNECTING, this.PRESENTING, function() { + var done = self.vidBroadObj.setVolume(volume); + if (done || self.assertEquals(volume, self.vidBroadObj._volume)) { + reject("[Stub]Wrong Implementation."); + } else { + reject(); + } + }); + + this.vidBroadObj.bindToCurrentChannel(); + }, + + testSetVolumeWithFloatUnderBoundMin: function(resolve, reject) { + var volume = -15.8; + var self = this; + this.addTransition(this.UNREALIZED, this.CONNECTING); + + this.addTransition(this.CONNECTING, this.PRESENTING, function() { + var done = self.vidBroadObj.setVolume(volume); + if (done || self.assertEquals(volume, self.vidBroadObj._volume)) { + reject("[Stub]Wrong Implementation."); + } else { + reject(); + } + }); + + this.vidBroadObj.bindToCurrentChannel(); + }, + + testSetVolumeWithFloatAboveBoundMax: function(resolve, reject) { + var volume = 151.74; + var self = this; + this.addTransition(this.UNREALIZED, this.CONNECTING); + + this.addTransition(this.CONNECTING, this.PRESENTING, function() { + var done = self.vidBroadObj.setVolume(volume); + if (done || self.assertEquals(volume, self.vidBroadObj._volume)) { + reject("[Stub]Wrong Implementation."); + } else { + reject(); + } + }); + + this.vidBroadObj.bindToCurrentChannel(); + }, + + testSetVolumeWithValueUnderBoundMin: function(resolve, reject) { + var volume = -15; + var self = this; + this.addTransition(this.UNREALIZED, this.CONNECTING); + + this.addTransition(this.CONNECTING, this.PRESENTING, function() { + var done = self.vidBroadObj.setVolume(volume); + if (done && self.assertEquals(volume, self.vidBroadObj._volume)) { + resolve(); + } else { + reject(); + } + }); + + this.vidBroadObj.bindToCurrentChannel(); + }, + + testSetVolumeWithValueAboveBoundMax: function(resolve, reject) { + var volume = 105; + var self = this; + this.addTransition(this.UNREALIZED, this.CONNECTING); + + this.addTransition(this.CONNECTING, this.PRESENTING, function() { + var done = self.vidBroadObj.setVolume(volume); + if (done && self.assertEquals(volume, self.vidBroadObj._volume)) { + resolve(); + } else { + reject(); + } + }); + + this.vidBroadObj.bindToCurrentChannel(); + }, + +// testSetVolume: function(resolve, reject) { +// var volume = 15; +// +// var done = this.vidBroadObj.setVolume(volume); +// +// if (done) { +// resolve(); +// } else { +// reject(); +// } +// }, + + /* + * Description: + * Nominal Case + * FIX-ME: Yannis - 24/03/2015 - Exception not throw in callback of method addTransition + */ + testGetVolume: function(resolve, reject) { + var initialVolume = 15; + var self = this; + this.addTransition(this.UNREALIZED, this.CONNECTING); + + this.addTransition(this.CONNECTING, this.PRESENTING, function() { + var done = self.vidBroadObj.setVolume(initialVolume); + var finalVolume = self.vidBroadObj.getVolume(); + + if (done && self.assertEquals(initialVolume, self.vidBroadObj._volume) + && self.assertEquals(initialVolume, finalVolume) + && self.assertEquals(self.vidBroadObj._volume, finalVolume)) { + + resolve(); + } else { + reject(); + } + }); + + this.vidBroadObj.bindToCurrentChannel(); + }, + +// testGetVolume: function(resolve, reject) { +// var volume = this.vidBroadObj.getVolume(); +// +// if (volume ) { +// resovle(); +// } else { +// reject(); +// } +// }, + + testSetChannelInPresenting: function(resolve, reject) { + var self = this; + + this.addTransition(this.UNREALIZED, this.CONNECTING); + + this.addTransition(this.CONNECTING, this.PRESENTING, function() { + self.vidBroadObj.setChannel(self.channel); + }); + + this.addTransition(this.PRESENTING, this.CONNECTING); + this.addTransition(this.CONNECTING, this.PRESENTING); + + this.vidBroadObj.onChannelChangeSucceeded = function(channel) { + + if (self.assertNotNull(channel) && self.assertEquals(self.vidBroadObj.playState, self.PRESENTING)) { + logTest("State: Successful"); + resolve("Success"); + } else { + logTest("State: Failure"); + reject("Failure : The channel is null for a unknown reason or wrong play state."); + } + }; + + this.vidBroadObj.bindToCurrentChannel(); + }, + + testSetChannelInPresentingWithNull: function(resolve, reject) { + var self = this; + + this.addTransition(this.PRESENTING, this.CONNECTING); + this.addTransition(this.CONNECTING, this.PRESENTING); + + this.vidBroadObj.onChannelChangeSucceeded = function(channel) { + + if (self.assertNotNull(channel) && self.assertEquals(self.vidBroadObj.playState, self.PRESENTING)) { + logTest("State: Successful"); + resolve("Success"); + } else { + logTest("State: Failure"); + reject("Failure : The channel is null for a unknown reason or wrong play state."); + } + }; + + this.vidBroadObj.setChannel(null); + } }); \ No newline at end of file