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:
Santiago Gimeno 2012-11-26 16:34:54 +01:00
parent 39e85aa20c
commit 9b8cef815b
4 changed files with 97 additions and 23 deletions

View file

@ -8,16 +8,18 @@ exports.requireExt = function(display, callback)
X.QueryExtension('XTEST', function(err, ext) {
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.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] = [
function(buf, opt) {
var res = buf.unpack('LL');
return res;
var res = buf.unpack('S');
// Major version is in byte 1 of Reply Header
// Minor version is in the body of the reply
return [ opt, res[0] ];
},
callback
];

View file

@ -12,12 +12,13 @@
, "bugs" : { "url" : "http://github.com/sidorares/node-x11/issues" }
, "licenses" : [ { "type" : "MIT" } ]
, "repository" : { "type" : "git", "url" : "http://github.com/sidorares/node-x11.git" }
, "main" : "./lib/x11"
, "engines" : { "node" : "*" }
, "devDependencies": {
"mocha": "*",
"should": "*"
"should": "*",
"async": "*"
}
, "scripts": {
"test": "node test-runner.js",

View file

@ -3,9 +3,10 @@ var Mocha = require('mocha');
var fs = require('fs');
var path = require('path');
var util = require('util');
var async = require('async');
var mocha = new Mocha({
timeout : 80000
timeout : 80000
});
// To be able to perform the tests we need the server:
@ -40,19 +41,49 @@ var run_dpms_test = function(cb) {
});
};
// Add all files from test root directory
fs.readdirSync('./test').forEach(function(file) {
if (file === 'dpms.js') {
run_dpms_test(function(run) {
if (run) {
mocha.addFile(path.join('./test', file));
}
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);
});
});
mocha.run(function(){
process.exit();
});
});
} else {
mocha.addFile(path.join('./test', file));
}
});
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));
}
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();
}
},
function(err) {
mocha.run(function() {
process.exit();
});
}
);

40
test/xtest.js Normal file
View 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);
});
});