Skip to content

Commit

Permalink
Added simple app tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafostar committed Jul 24, 2019
1 parent ff06e76 commit 0db5191
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 0 deletions.
26 changes: 26 additions & 0 deletions test/hdmi-switch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
Toggles between 3 available HDMI ports.
Port number can be set with 'hdmiPorts' option when creating new cec-controller object.
Desired port number can also be passed to 'changeSource()' function
(e.g. cec.dev0.changeSource(2) should switch to input 2).
*/

const cecInit = require('./shared/init');
const writeLine = require('./shared/writeLine');
cecInit().then(test);

function test()
{
writeLine();
console.log('--- TV HDMI Switch Test ---');
changeSource();
}

async function changeSource()
{
writeLine(`Switching HDMI input...`);
await cec.dev0.changeSource();

writeLine(`Switching to next port in 5 sec...`);
setTimeout(changeSource, 5000);
}
22 changes: 22 additions & 0 deletions test/power.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
Turns ON and OFF TV.
*/

const cecInit = require('./shared/init');
const writeLine = require('./shared/writeLine');
cecInit().then(test);

function test()
{
writeLine();
console.log('--- TV Power Test ---');
writeLine(`Turning OFF in 10 sec...`);
setTimeout(powerOff, 10000);
}

async function powerOff()
{
writeLine('Turning OFF TV...');
await cec.dev0.turnOff();
writeLine('TV should be in standby');
}
17 changes: 17 additions & 0 deletions test/remote.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
Prints pressed button name to stdout.
For use to determine which buttons can be used with CEC on a particular TV set.
*/

const cecInit = require('./shared/init');
const writeLine = require('./shared/writeLine');
cecInit().then(test);

function test()
{
writeLine();
console.log('--- TV Remote Test ---');
writeLine('Press any button on TV remote');

cec.on('keypress', (keyName) => writeLine(`User pressed: ${keyName}`));
}
28 changes: 28 additions & 0 deletions test/shared/init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const cecController = require('../../index');
const writeLine = require('./writeLine');
process.stdin.resume();

module.exports = () =>
{
return new Promise((resolve, reject) =>
{
writeLine('CEC Controller initializing...');
var cec = new cecController();

cec.on('ready', async() =>
{
if(cec.dev0.powerStatus !== 'on')
{
writeLine('Turning ON TV...');
await cec.dev0.turnOn();
}

writeLine('Setting this device as active source...');
await cec.setActive();

resolve();
});

cec.on('error', (err) => writeLine(err.message));
});
}
6 changes: 6 additions & 0 deletions test/shared/writeLine.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = (text) =>
{
process.stdout.cursorTo(0);
process.stdout.clearLine(0);
process.stdout.write(text);
}

0 comments on commit 0db5191

Please sign in to comment.