Author: ygrego Date: 2015-03-23 16:40:51 +0000 (Mon, 23 Mar 2015) New Revision: 963 Url: http://forge.nuiton.org/projects/sandbox/repository/revisions/963 Log: Global refactoring of class about transition verification in each method of test execpted for ("beforeTest" and "testVideoBroadcastInit" ). By using of new methods "onChange (which verify each transition), "addTransition" and "addTransitionWithError". Modified: oipf/js/test/VideoBroadcastTest.js Modified: oipf/js/test/VideoBroadcastTest.js =================================================================== --- oipf/js/test/VideoBroadcastTest.js 2015-03-20 14:53:32 UTC (rev 962) +++ oipf/js/test/VideoBroadcastTest.js 2015-03-23 16:40:51 UTC (rev 963) @@ -4,240 +4,229 @@ * */ var VideoBroadcastTest = TestCase.extend({ - error: { + + UNREALIZED: 0, + + CONNECTING: 1, + + PRESENTING: 2, + + STOPPED: 3, + + vidBroadObj: null, + + 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." + 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 () { + init: function() { + }, + beforeTest: function(resolve, reject) { + this.vidBroadObj = oipfObjectFactory.createVideoBroadcastObject(); + this.vidBroadObj.addEventListener("PlayStateChange", this.onChangeState.bind(this, resolve, reject)); + this.transitions = []; + this.previousState = this.vidBroadObj.playState; + this.currentIndex = 0; + logTest("State: Pending"); + }, + + onChangeState: function(resolve, reject, newState, errorCode) { + var currentTransition = this.transitions[this.currentIndex]; + var begin = currentTransition.begin; + var end = currentTransition.end; + 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++; + + } else { + reject("Invalid state"); + } + }, + + addTransition: function(begin, end, callback) { + this.addTransitionWithError(begin, end, null, callback); + }, + + addTransitionWithError: function(begin, end, error, callback) { + this.transitions.push({ + begin: begin, + end: end, + error: error, + callback: callback + }); + }, + /* * Descrtiption: * This method test the initialization of video broadcast object. */ - testInstanceCreation: function (resolve, reject) { - console.log("***************************************************************************************************************************"); - console.log("[TEST-RUNNING][Info] Id: vbTestInstanceCreation, Label: Object creation, State: Pending"); - - try { - - var videoBroadcastObject = oipfObjectFactory.createVideoBroadcastObject(); - - if (this.assertNotNull(videoBroadcastObject) && this.assertNotUndefined(videoBroadcastObject)) { - console.log("[TEST-RUNNING][Info] Id: vbTestInstanceCreation, Label: Object creation, State: Successfull"); - resolve("Successfull"); - } else { - console.log("[TEST-RUNNING][Info] Id: vbTestInstanceCreation, Label: Object creation, State: Failure"); - reject("Failure"); - } - console.log("***************************************************************************************************************************"); - } catch (error) { - console.log(error.message, "Here"); - throw error; + 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){ + var self = this; + + this.addTransition(this.UNREALIZED, this.CONNECTING, function() { + self.vidBroadObj.bindToCurrentChannel(); + }); + + this.addTransition(this.CONNECTING, this.PRESENTING, resolve); + + 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) { - - console.log("***************************************************************************************************************************"); - console.log("[TEST-RUNNING][Info] Id: vbTestBindToCurrentChannel, Label: Bind the current channel stream with a video broadcast objectBind the current channel stream with a video broadcast object, State: Pending"); - - try { - - var videoBroadcastObject = oipfObjectFactory.createVideoBroadcastObject(); - var currentChann = videoBroadcastObject.bindToCurrentChannel(); - - } catch (error) { - console.log(error.message); - throw error; - } - + testBindToCurrentChannel: function(resolve, reject) { var self = this; - videoBroadcastObject.onPlayStateChange = function(state, error) { - var wantedPlayState; - var VerifWantedPlayStateRes; - switch (videoBroadcastObject.playstate) { - - case 0: - wantedPlayState = 2; - VerifWantedPlayStateRes = self.verifWantedPlayState(self, state, wantedPlayState); - //TODO Verification of binding to the necesssary ressources have achieved with success. - break; - - case 1: - - break; - - case 2: - - break; - - case 3: - wantedPlayState = 1; - VerifWantedPlayStateRes = self.verifWantedPlayState(self, state, wantedPlayState); - //TODO Verify that video and audio presentation is enabled - break; - - } - - var success; - success = VerifWantedPlayStateRes[0]; - var errorPlayState = " "; - if (!success) { - errorPlayState = VerifWantedPlayStateRes[1]; - } - - var errorBind = " "; - if (self.assertEquals(videoBroadcastObject.currentChannel, currentChann)) { - console.log("[TEST-RUNNING][Info] Id: vbTestBindToCurrentChannel, Label: Bind the current channel stream with a video broadcast objectBind the current channel stream with a video broadcast object, State: Successfull"); - success = true; - } else { - console.log("[TEST-RUNNING][Info] Id: vbTestBindToCurrentChannel, Label: Bind the current channel stream with a video broadcast objectBind the current channel stream with a video broadcast object, State: Failure"); - success = false; - errorBind = " In binding to current channel."; - } - - if (error || (!success)) { - var errorText = self.error[error]; - reject("Failure:" + errorBind + " " + errorText + " " + errorPlayState); - } else { - resolve("Successfull"); - } - console.log("***************************************************************************************************************************"); - - }; - + this.addTransition(this.UNREALIZED, this.CONNECTING, function() { + self.vidBroadObj.bindToCurrentChannel(); + }); + + this.addTransition(this.CONNECTING, this.PRESENTING, resolve); + + this.vidBroadObj.bindToCurrentChannel(); }, - testPrevChannel: function(resolve, reject) { - console.log("***************************************************************************************************************************"); - console.log("[TEST-RUNNING][Info] Id: vbTestPrevChannel, Label: Switch to precedent channel in channel list, State: Pending"); + testBindToCurrentChannelInConnecting : function(resolve, reject) { + var self = this; + + this.addTransition(this.UNREALIZED, this.CONNECTING, function() { + self.vidBroadObj.bindToCurrentChannel(); + }); - try { - - var videoBroadcastObject = oipfObjectFactory.createVideoBroadcastObject(); - videoBroadcastObject.playstate = 2; - videoBroadcastObject.currentChannel = videoBroadcastObject.getChannelConfig().currentChannel; - videoBroadcastObject.prevChannel(); - - } catch (error) { - console.log(error.message); - throw error; - } + this.addTransition(this.CONNECTING, this.PRESENTING, resolve); + this.vidBroadObj.bindToCurrentChannel(); + }, + + /* + * Description: + * Nominal Case + */ + testPrevChannel: function(resolve, reject) { var self = this; - videoBroadcastObject.onPlayStateChange = function(state, error) { - if (error) { - var errorText = self.error[error]; - console.log("[TEST-RUNNING][Info] Id: vbTestPrevChannel, Label: Switch to precedent channel in channel list, State: Failure"); + this.addTransition(this.UNREALIZED, this.CONNECTING); - reject("Failure:" + errorText); - } - - }; + this.addTransition(this.CONNECTING, this.PRESENTING, function() { + self.vidBroadObj.prevChannel(); + }); - videoBroadcastObject.onChannelChangeError = function(channel, error) { - var errorText = self.error[error]; - console.log("[TEST-RUNNING][Info] Id: vbTestPrevChannel, Label: Switch to precedent channel in channel list, State: Failure"); + this.addTransition(this.PRESENTING, this.CONNECTING); - reject("Failure:" + errorText); - }; + this.addTransition(this.CONNECTING, this.PRESENTING); - videoBroadcastObject.onChannelChangeSucceeded = function(channel) { - if (self.assertNotNull(channel)) { - console.log("[TEST-RUNNING][Info] Id: vbTestPrevChannel, Label: Switch to precedent channel in channel list, State: Successful"); - console.log(channel); + this.vidBroadObj.onChannelChangeSucceeded = function(channel) { + + if (self.assertNotNull(channel) && self.assertEquals(this.vidBroadObj, this.PRESENTING)) { + logTest("State: Successful"); resolve("Successfull"); } else { - console.log("[TEST-RUNNING][Info] Id: vbTestPrevChannel, Label: Switch to precedent channel in channel list, State: Failure"); - reject("Failure : The channel is null because a unknown reason."); + logTest("State: Failure"); + reject("Failure : The channel is null for a unknown reason or wrong play state."); } - }; - console.log("***************************************************************************************************************************"); - + this.vidBroadObj.bindToCurrentChannel(); + }, + /* + * Description: + * Nominal Case + */ testNextChannel: function(resolve, reject) { - console.log("***************************************************************************************************************************"); - console.log("[TEST-RUNNING][Info] Id: vbTestNextChannel, Label: Switch to next channel in channel list, State: Pending"); - - try { - - var videoBroadcastObject = oipfObjectFactory.createVideoBroadcastObject(); - videoBroadcastObject.playstate = 2; - videoBroadcastObject.currentChannel = videoBroadcastObject.getChannelConfig().currentChannel; - videoBroadcastObject.nextChannel(); - - } catch (error) { - console.log(error.message); - throw error; - } - var self = this; - videoBroadcastObject.onPlayStateChange = function(state, error) { - if (error) { - var errorText = self.error[error]; - console.log("[TEST-RUNNING][Info] Id: vbTestNextChannel, Label: Switch to next channel in channel list, State: Failure"); - reject("Failure:" + errorText); - } + this.addTransition(this.UNREALIZED, this.CONNECTING); - }; + this.addTransition(this.CONNECTING, this.PRESENTING, function() { + self.vidBroadObj.nextChannel(); + }); - videoBroadcastObject.onChannelChangeError = function(channel, error) { - var errorText = self.error[error]; - console.log("[TEST-RUNNING][Info] Id: vbTestNextChannel, Label: Switch to next channel in channel list, State: Failure"); + this.addTransition(this.PRESENTING, this.CONNECTING); - reject("Failure:" + errorText); - }; + this.addTransition(this.CONNECTING, this.PRESENTING); - videoBroadcastObject.onChannelChangeSucceeded = function(channel) { - if (self.assertNotNull(channel)) { - console.log("[TEST-RUNNING][Info] Id: vbTestNextChannel, Label: Switch to next channel in channel list, State: Successful"); - console.log(channel.name); + this.vidBroadObj.onChannelChangeSucceeded = function(channel) { + + if (self.assertNotNull(channel) && self.assertEquals(this.vidBroadObj, this.PRESENTING)) { + logTest("State: Successful"); resolve("Successfull"); } else { - console.log("[TEST-RUNNING][Info] Id: vbTestNextChannel, Label: Switch to next channel in channel list, State: Failure"); - reject("Failure : The channel is null for a unknown reason."); + logTest("State: Failure"); + reject("Failure : The channel is null for a unknown reason or wrong play state."); } - }; - console.log("***************************************************************************************************************************"); + this.vidBroadObj.bindToCurrentChannel(); }, - verifWantedPlayState: function (currentObject, receivedPlayState, wantedPlayState) { - if (currentObject.assertEquals(receivedPlayState, wantedPlayState)) { - return true; - - } else { - console.log("[TEST-RUNNING][Info] Id: vbTestBindToCurrentChannel, Label: Bind the current channel stream with a video broadcast objectBind the current channel stream with a video broadcast object, State: Failure"); - return [false, "Wrong play state changement."]; - - } - } -}); + /* + * Description: + * Nominal Case + */ + testRelease: function(resolve, reject) { + var self = this; + this.addTransition(this.UNREALIZED, this.CONNECTING); + + this.addTransition(this.CONNECTING, this.PRESENTING, function() { + self.vidBroadObj.release(); + }); + + this.addTransition(this.PRESENTING, this.UNREALIZED, resolve); + + this.vidBroadObj.bindToCurrentChannel(); + }, + + /* + * Description: + * Nominal Case + */ + testStop: 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, resolve); + + this.vidBroadObj.bindToCurrentChannel(); + } +}); \ No newline at end of file
participants (1)
-
ygrego@users.nuiton.org