Add basic RANDR integration test

- Some improvements in test-runner.
This commit is contained in:
Santiago Gimeno 2014-03-11 15:59:58 +01:00
parent 88ac8179c6
commit b95302ff1a
2 changed files with 136 additions and 72 deletions

View file

@ -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();
});
});
}
);
});

42
test/randr.js Normal file
View file

@ -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);
});
});