/*
* GPII Xrandr Bridge Tests
*
* Copyright 2013 Emergya
*
* Licensed under the New BSD license. You may not use this file except in
* compliance with this License.
*
* You may obtain a copy of the License at
* https://github.com/GPII/linux/blob/master/LICENSE.txt
*
* The research leading to these results has received funding from the European Union's
* Seventh Framework Programme (FP7/2007-2013)
* under grant agreement no. 289016.
*/
"use strict";
var fluid = require("universal"),
jqUnit = fluid.require("node-jqunit"),
xrandr = require("./build/Release/nodexrandr.node");
var convert = fluid.registerNamespace("gpii.tests.xrandr.convert");
convert.toString = function (size) {
return size.width + "x" + size.height;
};
convert.toSize = function (sizeString) {
var wPos = sizeString.indexOf("x");
return {
width: parseInt(sizeString.substring(0, wPos), 10),
height: parseInt(sizeString.substring(wPos + 1), 10)
};
};
jqUnit.module("GPII Xrandr Module");
jqUnit.test("Running tests for Xrandr Bridge", function () {
// Check if all required methods are available through the Xrandr Bridge
//
var methods = ["getDisplays", "setScreenResolution"];
for (var method in methods) {
jqUnit.assertTrue("Checking availability of method '" + method + "'",
(methods[method] in xrandr));
}
// Check getDisplays and setScreenResolution methods
//
jqUnit.assertTrue("Checking that 'getDisplays' method is callable",
xrandr.getDisplays());
// Get the current resolution. Use a value below its minimum size to check
// that setScreenResolution() correctly returns false (can't set an
// impossible resolution).
//
var display = xrandr.getDisplays()[0];
jqUnit.assertFalse("Checking 'setScreenResolution' with impossible size",
xrandr.setScreenResolution(-1, -1));
// Convert the current resolution to a string, and see if there is a
// different available resolution to test setScreenResolution().
//
var resolution0 = convert.toString(display.resolution);
var newResolution = fluid.find(display.available_resolutions, function (aResolution) {
if (resolution0 !== aResolution) {
return (convert.toSize(aResolution));
}
}, null);
Eif (newResolution !== null) {
var oldResolution = display.resolution;
jqUnit.assertTrue("Checking that 'setScreenSize' is callable",
xrandr.setScreenResolution(
newResolution.width, newResolution.height));
jqUnit.assertDeepEq("Checking that 'setScreenSize' sets the resolution",
xrandr.getDisplays()[0].resolution,
{width: newResolution.width,
height: newResolution.height,
mwidth: oldResolution.mwidth,
mheight: oldResolution.mheight});
xrandr.setScreenResolution(oldResolution.width, oldResolution.height);
jqUnit.assertDeepEq("Checking that 'setScreenSize' sets the resolution",
xrandr.getDisplays()[0].resolution,
oldResolution);
}
});
|