all files / sync/gpii/node_modules/xrandr/nodexrandr/ nodexrandr_tests.js

100% Statements 25/25
75% Branches 3/4
100% Functions 4/4
100% Lines 25/25
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                                                                                                                               
/*
 * 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);
    }
});