Skip to content

Commit

Permalink
Video: Add more unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stephendade committed May 14, 2022
1 parent b09f8ba commit d9421a5
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 17 deletions.
46 changes: 29 additions & 17 deletions server/videostream.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,13 @@ class videoStream {
resetVideo () {
this.active = false
this.savedDevice = null
this.settings.setValue('videostream.active', this.active)
this.settings.setValue('videostream.savedDevice', this.savedDevice)
try {
this.settings.setValue('videostream.active', this.active)
this.settings.setValue('videostream.savedDevice', this.savedDevice)
} catch (e) {
console.log(e)
this.winston.info(e)
}
console.log('Reset Video Settings')
this.winston.info('Reset Video Settings')
}
Expand Down Expand Up @@ -134,15 +139,17 @@ class videoStream {
if (active) {
// check it's a valid video device
let found = false
for (let j = 0; j < this.devices.length; j++) {
if (device === this.devices[j].value) {
found = true
if (this.devices !== null) {
for (let j = 0; j < this.devices.length; j++) {
if (device === this.devices[j].value) {
found = true
}
}
if (!found) {
console.log('No video device: ' + device)
this.winston.info('No video device: ' + device)
return callback('No video device: ' + device)
}
}
if (!found) {
console.log('No video device: ' + device)
this.winston.info('No video device: ' + device)
return callback('No video device: ' + device)
}

this.active = true
Expand Down Expand Up @@ -179,14 +186,19 @@ class videoStream {
'--udp=' + ((useUDP === false) ? '0' : useUDPIP + ':' + useUDPPort.toString())
])

if (this.deviceStream === null) {
this.settings.setValue('videostream.active', false)
console.log('Error spawning rtsp-server.py')
this.winston.info('Error spawning rtsp-server.py')
return callback(null, this.active, this.deviceAddresses)
try {
if (this.deviceStream === null) {
this.settings.setValue('videostream.active', false)
console.log('Error spawning rtsp-server.py')
this.winston.info('Error spawning rtsp-server.py')
return callback(null, this.active, this.deviceAddresses)
}
this.settings.setValue('videostream.active', this.active)
this.settings.setValue('videostream.savedDevice', this.savedDevice)
} catch (e) {
console.log(e)
this.winston.info(e)
}
this.settings.setValue('videostream.active', this.active)
this.settings.setValue('videostream.savedDevice', this.savedDevice)

this.deviceStream.stdout.on('data', (data) => {
this.winston.info('startStopStreaming() data ' + data)
Expand Down
22 changes: 22 additions & 0 deletions server/videostream.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,26 @@ describe('Video Functions', function () {
done()
})
}).timeout(5000)

it('#videomanagerisUbuntu()', async function () {
const vManager = new VideoStream(settings, winston)

const res = await vManager.isUbuntu()
assert.equal(res, true)
})

it('#videomanagerstartStopStreaming()', function (done) {
const vManager = new VideoStream(settings, winston)

vManager.startStopStreaming(true, 'testsrc', '1080', '1920', 'video/x-h264', '0', '1000', '5', false, false, false, function (err, status, addresses) {
assert.equal(err, null)
assert.equal(status, true)
assert.notEqual(vManager.deviceStream.pid, null)
vManager.startStopStreaming(false, 'testsrc', '1080', '1920', 'video/x-h264', '0', '1000', '5', false, false, false, function (err, status, addresses) {
assert.equal(err, null)
assert.equal(status, false)
done()
})
})
})
})

0 comments on commit d9421a5

Please sign in to comment.