/*
* Windows Display Settings Handler Tests
*
* Copyright 2016 Raising the Floor - US
*
* 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/universal/blob/master/LICENSE.txt
*/
"use strict";
var fluid = require("universal");
var jqUnit = fluid.require("node-jqunit");
var gpii = fluid.registerNamespace("gpii");
require("../../WindowsUtilities/WindowsUtilities.js");
require("../src/displaySettingsHandler.js");
jqUnit.module("Windows Display Settings Handler Tests");
jqUnit.test("Testing GetScreenResolution", function () {
jqUnit.expect(3);
var screenRes = gpii.windows.display.getScreenResolution();
jqUnit.assertDeepEq("getScreenResolution returns an object", "object", typeof(screenRes));
jqUnit.assertDeepEq("value for width is a number", "number", typeof(screenRes.width));
jqUnit.assertDeepEq("value for height is a number", "number", typeof(screenRes.height));
});
jqUnit.test("Testing setScreenResolution ", function () {
var oldRes = gpii.windows.display.getScreenResolution();
// We can change resolution
// Not such a good unit test as depends on available modes and current screen resolution
jqUnit.expect(2);
var targetRes = { width: 800, height: 600 };
jqUnit.assertTrue("We can call to setScreenResolution, it returns 'true'", gpii.windows.display.setScreenResolution(targetRes));
var newRes = gpii.windows.display.getScreenResolution();
jqUnit.assertDeepEq("New resolution is set", targetRes, newRes);
// Restore old resolution
jqUnit.expect(2);
jqUnit.assertTrue("Resetting to old resolution", gpii.windows.display.setScreenResolution(oldRes));
var restoredRes = gpii.windows.display.getScreenResolution();
jqUnit.assertDeepEq("Old resolution appear to be restored", oldRes, restoredRes);
// test can't change to invalid resolution
var badRes = { width: -123, height: -123 };
jqUnit.expectFrameworkDiagnostic("setScreenResolution fails when receives an invalid resolution such as {w: -123, h: -123}", function () {
gpii.windows.display.setScreenResolution(badRes);
}, "invalid screen resolution");
// test that setScreenResolution fails when it receives a faulty screen resolution
var faulty1 = 2;
jqUnit.expectFrameworkDiagnostic("setScreenResolution fails when receives a non-object parameter", function () {
gpii.windows.display.setScreenResolution(faulty1);
}, "invalid screen resolution");
var faulty2 = { w: 0, h: 1 };
jqUnit.expectFrameworkDiagnostic("setScreenResolution fails when receives a wrong object", function () {
gpii.windows.display.setScreenResolution(faulty2);
}, ["invalid screen resolution"]);
var faulty3 = { width: 0, height: "" };
jqUnit.expectFrameworkDiagnostic("setScreenResolution fails when receives one string as value for height", function () {
gpii.windows.display.setScreenResolution(faulty3);
}, "invalid screen resolution");
});
|