mirror of
https://github.com/danbulant/node-x11
synced 2026-05-27 14:01:52 +00:00
A couple of fixes in xtest extension
- Return directly in case of error retrieving the extension. - QueryVersion should be GetVersion and fix its format. - Add a test for GetVersion. - Modify test-runner.js so it uses async library to add dynamically the test files to be used.
This commit is contained in:
parent
39e85aa20c
commit
9b8cef815b
4 changed files with 97 additions and 23 deletions
|
|
@ -8,16 +8,18 @@ exports.requireExt = function(display, callback)
|
||||||
X.QueryExtension('XTEST', function(err, ext) {
|
X.QueryExtension('XTEST', function(err, ext) {
|
||||||
|
|
||||||
if (!ext.present)
|
if (!ext.present)
|
||||||
callback(new Error('extension not available'));
|
return callback(new Error('extension not available'));
|
||||||
|
|
||||||
ext.QueryVersion = function(clientMaj, clientMin, callback)
|
ext.GetVersion = function(clientMaj, clientMin, callback)
|
||||||
{
|
{
|
||||||
X.seq_num++;
|
X.seq_num++;
|
||||||
X.pack_stream.pack('CCSLL', [ext.majorOpcode, 0, 3, clientMaj, clientMin]);
|
X.pack_stream.pack('CCSCxS', [ext.majorOpcode, 0, 2, clientMaj, clientMin]);
|
||||||
X.replies[X.seq_num] = [
|
X.replies[X.seq_num] = [
|
||||||
function(buf, opt) {
|
function(buf, opt) {
|
||||||
var res = buf.unpack('LL');
|
var res = buf.unpack('S');
|
||||||
return res;
|
// Major version is in byte 1 of Reply Header
|
||||||
|
// Minor version is in the body of the reply
|
||||||
|
return [ opt, res[0] ];
|
||||||
},
|
},
|
||||||
callback
|
callback
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,8 @@
|
||||||
, "engines" : { "node" : "*" }
|
, "engines" : { "node" : "*" }
|
||||||
, "devDependencies": {
|
, "devDependencies": {
|
||||||
"mocha": "*",
|
"mocha": "*",
|
||||||
"should": "*"
|
"should": "*",
|
||||||
|
"async": "*"
|
||||||
}
|
}
|
||||||
, "scripts": {
|
, "scripts": {
|
||||||
"test": "node test-runner.js",
|
"test": "node test-runner.js",
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ var Mocha = require('mocha');
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var util = require('util');
|
var util = require('util');
|
||||||
|
var async = require('async');
|
||||||
|
|
||||||
var mocha = new Mocha({
|
var mocha = new Mocha({
|
||||||
timeout : 80000
|
timeout : 80000
|
||||||
|
|
@ -40,19 +41,49 @@ var run_dpms_test = function(cb) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var run_xtest_test = function(cb) {
|
||||||
|
var client = x11.createClient(function(dpy) {
|
||||||
|
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
|
// Add all files from test root directory
|
||||||
fs.readdirSync('./test').forEach(function(file) {
|
async.forEach(
|
||||||
|
fs.readdirSync('./test'),
|
||||||
|
function(file, cb) {
|
||||||
if (file === 'dpms.js') {
|
if (file === 'dpms.js') {
|
||||||
run_dpms_test(function(run) {
|
run_dpms_test(function(run) {
|
||||||
if (run) {
|
if (run) {
|
||||||
mocha.addFile(path.join('./test', file));
|
mocha.addFile(path.join('./test', file));
|
||||||
}
|
}
|
||||||
|
|
||||||
mocha.run(function(){
|
cb();
|
||||||
process.exit();
|
|
||||||
});
|
});
|
||||||
|
} else if (file === 'xtest.js') {
|
||||||
|
run_xtest_test(function(run) {
|
||||||
|
if (run) {
|
||||||
|
mocha.addFile(path.join('./test', file));
|
||||||
|
}
|
||||||
|
|
||||||
|
cb();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
mocha.addFile(path.join('./test', file));
|
mocha.addFile(path.join('./test', file));
|
||||||
|
cb();
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
function(err) {
|
||||||
|
mocha.run(function() {
|
||||||
|
process.exit();
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
|
||||||
40
test/xtest.js
Normal file
40
test/xtest.js
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
var x11 = require('../lib/x11');
|
||||||
|
var should = require('should');
|
||||||
|
var assert = require('assert');
|
||||||
|
var util = require('util');
|
||||||
|
|
||||||
|
describe('XTEST extension', function() {
|
||||||
|
var display;
|
||||||
|
var X;
|
||||||
|
var xtest;
|
||||||
|
before(function(done) {
|
||||||
|
var client = x11.createClient(function(dpy) {
|
||||||
|
display = dpy;
|
||||||
|
X = display.client;
|
||||||
|
X.require('xtest', function(ext) {
|
||||||
|
if (util.isError(ext)) {
|
||||||
|
done(ext);
|
||||||
|
} else {
|
||||||
|
xtest = ext;
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
client.on('error', done);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('GetVersion', function() {
|
||||||
|
it('should return version 2.2', function(done) {
|
||||||
|
xtest.GetVersion(2, 2, function(err, version) {
|
||||||
|
version.should.eql([2, 2]);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
after(function(done) {
|
||||||
|
X.terminate();
|
||||||
|
X.on('end', done);
|
||||||
|
});
|
||||||
|
});
|
||||||
Loading…
Reference in a new issue