forked from sidorares/node-x11
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-runner.js
110 lines (100 loc) · 2.91 KB
/
test-runner.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
var x11 = require('./lib');
var Mocha = require('mocha');
var fs = require('fs');
var path = require('path');
var async = require('async');
var mocha = new Mocha({
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(X, cb) {
X.require('dpms', function(err, ext) {
if (!err) {
var 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);
}
});
};
var run_xtest_test = function(X, cb) {
X.require('xtest', function(err) {
if (!err) cb(true);
else cb(false);
});
};
var run_randr_test = function(X, cb) {
X.require('randr', function(err, ext) {
if (!err) {
var randr = ext;
randr.QueryVersion(1, 2, function(err, version) {
if (err) {
cb(false);
} else {
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) {
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(failures) {
process.exit(failures);
});
});
}
);
});