mirror of
https://github.com/danbulant/node-x11
synced 2026-05-24 12:35:39 +00:00
Add basic RANDR integration test
- Some improvements in test-runner.
This commit is contained in:
parent
88ac8179c6
commit
b95302ff1a
2 changed files with 136 additions and 72 deletions
|
|
@ -6,18 +6,15 @@ var util = require('util');
|
||||||
var async = require('async');
|
var async = require('async');
|
||||||
|
|
||||||
var mocha = new Mocha({
|
var mocha = new Mocha({
|
||||||
timeout : 80000
|
timeout : 80000,
|
||||||
|
reporter : 'spec'
|
||||||
});
|
});
|
||||||
|
|
||||||
// To be able to perform the tests we need the server:
|
// To be able to perform the tests we need the server:
|
||||||
// 1 - to support the dpms extension.
|
// 1 - to support the dpms extension.
|
||||||
// 2 - dpms version is 1.1.
|
// 2 - dpms version is 1.1.
|
||||||
// 3 - to be dpms capable.
|
// 3 - to be dpms capable.
|
||||||
var run_dpms_test = function(cb) {
|
var run_dpms_test = function(X, 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) {
|
X.require('dpms', function(ext) {
|
||||||
if (!util.isError(ext)) {
|
if (!util.isError(ext)) {
|
||||||
dpms = ext;
|
dpms = ext;
|
||||||
|
|
@ -35,35 +32,46 @@ var run_dpms_test = function(cb) {
|
||||||
cb(false);
|
cb(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
client.on('error', function() {
|
|
||||||
cb(false);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var run_xtest_test = function(cb) {
|
var run_xtest_test = function(X, cb) {
|
||||||
var client = x11.createClient(function(err, dpy) {
|
X.require('xtest', function(ext) {
|
||||||
if (err) return cb(false);
|
|
||||||
var display = dpy;
|
|
||||||
var X = display.client;
|
|
||||||
X.require('dpms', function(ext) {
|
|
||||||
if (!util.isError(ext)) cb(true);
|
if (!util.isError(ext)) cb(true);
|
||||||
else cb(false);
|
else cb(false);
|
||||||
});
|
});
|
||||||
});
|
};
|
||||||
|
|
||||||
client.on('error', function() {
|
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);
|
cb(false);
|
||||||
|
} else {
|
||||||
|
console.log(version);
|
||||||
|
cb((version[0] === 1) && (version[1] >= 2));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
cb(false);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// Add all files from test root directory
|
x11.createClient(function(err, display) {
|
||||||
async.forEach(
|
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'),
|
fs.readdirSync('./test'),
|
||||||
function(file, cb) {
|
function(file, cb) {
|
||||||
if (file === 'dpms.js') {
|
if (file === 'dpms.js') {
|
||||||
run_dpms_test(function(run) {
|
run_dpms_test(X, function(run) {
|
||||||
if (run) {
|
if (run) {
|
||||||
mocha.addFile(path.join('./test', file));
|
mocha.addFile(path.join('./test', file));
|
||||||
}
|
}
|
||||||
|
|
@ -71,7 +79,16 @@ async.forEach(
|
||||||
cb();
|
cb();
|
||||||
});
|
});
|
||||||
} else if (file === 'xtest.js') {
|
} else if (file === 'xtest.js') {
|
||||||
run_xtest_test(function(run) {
|
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) {
|
if (run) {
|
||||||
mocha.addFile(path.join('./test', file));
|
mocha.addFile(path.join('./test', file));
|
||||||
}
|
}
|
||||||
|
|
@ -83,9 +100,14 @@ async.forEach(
|
||||||
cb();
|
cb();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
function(err) {
|
function() {
|
||||||
|
X.terminate();
|
||||||
|
X.on('end', function() {
|
||||||
mocha.run(function() {
|
mocha.run(function() {
|
||||||
process.exit();
|
process.exit();
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
});
|
||||||
|
|
|
||||||
42
test/randr.js
Normal file
42
test/randr.js
Normal 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);
|
||||||
|
});
|
||||||
|
});
|
||||||
Loading…
Reference in a new issue