From b95302ff1aba99ece571a79d9ff21113ae163aae Mon Sep 17 00:00:00 2001 From: Santiago Gimeno Date: Tue, 11 Mar 2014 15:59:58 +0100 Subject: [PATCH] Add basic RANDR integration test - Some improvements in test-runner. --- test-runner.js | 166 ++++++++++++++++++++++++++++--------------------- test/randr.js | 42 +++++++++++++ 2 files changed, 136 insertions(+), 72 deletions(-) create mode 100644 test/randr.js diff --git a/test-runner.js b/test-runner.js index 309d27e..f30e9d7 100644 --- a/test-runner.js +++ b/test-runner.js @@ -6,86 +6,108 @@ var util = require('util'); var async = require('async'); var mocha = new Mocha({ - timeout : 80000 + timeout : 80000, + reporter : 'spec' }); // To be able to perform the tests we need the server: // 1 - to support the dpms extension. // 2 - dpms version is 1.1. // 3 - to be dpms capable. -var run_dpms_test = function(cb) { - var client = x11.createClient(function(err, dpy) { - if (err) return cb(false); - var display = dpy; - var X = display.client; - X.require('dpms', function(ext) { - if (!util.isError(ext)) { - dpms = ext; - dpms.GetVersion(undefined, undefined, function(err, version) { - if (!err && version[0] === 1 && version[1] === 1) { - dpms.Capable(function(err, capable) { - if (!err && capable[0] == 1) cb(true); - else cb(false); - }); - } else { - cb(false); - } - }); - } else { - cb(false); - } - }); - }); - - client.on('error', function() { - cb(false); - }); -}; - -var run_xtest_test = function(cb) { - var client = x11.createClient(function(err, dpy) { - if (err) return cb(false); - var display = dpy; - var X = display.client; - X.require('dpms', function(ext) { - if (!util.isError(ext)) cb(true); - else cb(false); - }); - }); - - client.on('error', function() { - cb(false); - }); -}; - -// Add all files from test root directory -async.forEach( - fs.readdirSync('./test'), - function(file, cb) { - if (file === 'dpms.js') { - run_dpms_test(function(run) { - if (run) { - mocha.addFile(path.join('./test', file)); +var run_dpms_test = function(X, cb) { + X.require('dpms', function(ext) { + if (!util.isError(ext)) { + dpms = ext; + dpms.GetVersion(undefined, undefined, function(err, version) { + if (!err && version[0] === 1 && version[1] === 1) { + dpms.Capable(function(err, capable) { + if (!err && capable[0] == 1) cb(true); + else cb(false); + }); + } else { + cb(false); } - - cb(); - }); - } else if (file === 'xtest.js') { - run_xtest_test(function(run) { - if (run) { - mocha.addFile(path.join('./test', file)); - } - - cb(); }); } else { - mocha.addFile(path.join('./test', file)); - cb(); + cb(false); } - }, - function(err) { - mocha.run(function() { - process.exit(); - }); + }); +}; + +var run_xtest_test = function(X, cb) { + X.require('xtest', function(ext) { + if (!util.isError(ext)) cb(true); + else cb(false); + }); +}; + +var run_randr_test = function(X, cb) { + X.require('randr', function(ext) { + if (!util.isError(ext)) { + randr = ext; + randr.QueryVersion(1, 2, function(err, version) { + if (err) { + cb(false); + } else { + console.log(version); + cb((version[0] === 1) && (version[1] >= 2)); + } + }); + } else { + cb(false); + } + }); +}; + +x11.createClient(function(err, display) { + if (err) { + console.log('Could not create X client'); + process.exit(-1); } -); + + var X = display.client; + // Add all files from test root directory + async.forEach( + fs.readdirSync('./test'), + function(file, cb) { + if (file === 'dpms.js') { + run_dpms_test(X, function(run) { + if (run) { + mocha.addFile(path.join('./test', file)); + } + + cb(); + }); + } else if (file === 'xtest.js') { + run_xtest_test(X, function(run) { + if (run) { + mocha.addFile(path.join('./test', file)); + } + + cb(); + }); + } else if (file === 'randr.js') { + run_randr_test(X, function(run) { + console.log('RUN: ' + run); + if (run) { + mocha.addFile(path.join('./test', file)); + } + + cb(); + }); + } else { + mocha.addFile(path.join('./test', file)); + cb(); + } + }, + function() { + X.terminate(); + X.on('end', function() { + mocha.run(function() { + process.exit(); + }); + }); + + } + ); +}); diff --git a/test/randr.js b/test/randr.js new file mode 100644 index 0000000..97d101d --- /dev/null +++ b/test/randr.js @@ -0,0 +1,42 @@ +var x11 = require('../lib'); +var should = require('should'); +var assert = require('assert'); +var util = require('util'); + +describe('RANDR extension', function() { + before(function(done) { + var self = this; + var client = x11.createClient(function(err, dpy) { + should.not.exist(err); + self.X = dpy.client; + self.screen = dpy.screen[0]; + self.root = self.screen.root; + self.X.require('randr', function(ext) { + util.isError(ext).should.equal(false); + self.randr = ext; + /* We HAVE to QueryVersion before using it. Otherwise it does not work as expected */ + self.randr.QueryVersion(1, 2, done); + }); + }); + + client.on('error', done); + }); + + it('GetScreenInfo should get same px and mm width and height as in display.screen[0]', function(done) { + var self = this; + this.randr.GetScreenInfo(this.root, function(err, info) { + should.not.exist(err); + var active_screen = info.screens[info.sizeID]; + active_screen.px_width.should.equal(self.screen.pixel_width); + active_screen.px_height.should.equal(self.screen.pixel_height); + active_screen.mm_width.should.equal(self.screen.mm_width); + active_screen.mm_height.should.equal(self.screen.mm_height); + done(); + }); + }); + + after(function(done) { + this.X.terminate(); + this.X.on('end', done); + }); +});