Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

GPII-22 GPII-35: Merging in Kaspers Gsettings Unit Test Things.

Merge remote-tracking branch 'kaspermarkus/GPII-22'

* kaspermarkus/GPII-22:
  GPII-35: Added fluid.defaults for the single get function as well as the single set function
  GPII-22: Removed outdated reset calls from unit tests, ensured that tests will run even if schemas already exist
  GPII-22: Added test for having a settings block null. Also ensured that it works with the new test framework in universal comitted with GPII-36
  GPII-22: Added basic tests, gsettings schema file and a script to run everything.. currently experiencing issues due to issues with the jqunit framework not allowing running several synchronous tests
  GPII-35: Added single get and single set function to gsettings bridge and made the set function useable as a lifecycle action
  • Loading branch information...
commit b31482e039731968babf6fc536621659dd8bd8a5 2 parents 32baeb0 + a2b2ee7
@sgithens sgithens authored
View
26 node_modules/gsettingsBridge/gsettings_bridge.js
@@ -11,7 +11,6 @@ https://github.com/gpii/universal/LICENSE.txt
*/
(function () {
-
"use strict";
var fluid = require("universal");
@@ -24,6 +23,31 @@ https://github.com/gpii/universal/LICENSE.txt
gpii.gsettings = gpii.gsettings || {};
+ fluid.defaults("gpii.gsettings.setSingleKey", {
+ gradeNames: "fluid.function",
+ argumentMap: {
+ schemaId: 0,
+ key: 1,
+ value: 2
+ }
+ });
+
+ fluid.defaults("gpii.gsettings.getSingleKey", {
+ gradeNames: "fluid.function",
+ argumentMap: {
+ schemaId: 0,
+ key: 1
+ }
+ });
+
+ gpii.gsettings.getSingleKey = function(schemaId, key) {
+ return nodeGSettings.get_gsetting(schemaId,key);
+ };
+
+ gpii.gsettings.setSingleKey = function(schemaId, key, value) {
+ nodeGSettings.set_gsetting(schemaId, key, value);
+ };
+
gpii.gsettings.get = function(settingsarray) {
var app = fluid.copy(settingsarray);
for (var appId in app) {
View
121 node_modules/gsettingsBridge/tests/data/net.gpii.testing.gsettings.gschema.xml
@@ -0,0 +1,121 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<schemalist>
+
+ <schema path="/net/gpii/testing/gsettings/single-get/" id="net.gpii.testing.gsettings.single-get" gettext-domain="gpii-testing-schemas">
+ <key type="d" name="double-setting">
+ <default>5.0</default>
+ <range min="0.1" max="10000.0"/>
+ <summary>double numbers</summary>
+ <description>Any number between 0.1 and 100 - used for testing with the gpii</description>
+ </key>
+ <key type="b" name="boolean-setting">
+ <default>false</default>
+ <summary>Boolean settings</summary>
+ <description>Test field - true or false - used for testing with the gpii</description>
+ </key>
+ <key type="s" name="string-setting">
+ <default>"abcdefg"</default>
+ <summary>String settings</summary>
+ <description>Any string - used for testing with the gpii</description>
+ </key>
+ </schema>
+
+ <schema path="/net/gpii/testing/gsettings/single-set/" id="net.gpii.testing.gsettings.single-set" gettext-domain="gpii-testing-schemas">
+ <key type="d" name="double-setting">
+ <default>5.0</default>
+ <range min="0.1" max="10000.0"/>
+ <summary>double numbers</summary>
+ <description>Any number between 0.1 and 100 - used for testing with the gpii</description>
+ </key>
+ <key type="b" name="boolean-setting">
+ <default>false</default>
+ <summary>Boolean settings</summary>
+ <description>Test field - true or false - used for testing with the gpii</description>
+ </key>
+ <key type="s" name="string-setting">
+ <default>"abcdefg"</default>
+ <summary>String settings</summary>
+ <description>Any string - used for testing with the gpii</description>
+ </key>
+ </schema>
+
+ <schema path="/net/gpii/testing/gsettings/multi-set1/" id="net.gpii.testing.gsettings.multi-set1" gettext-domain="gpii-testing-schemas">
+ <key type="d" name="double-setting">
+ <default>5.0</default>
+ <range min="0.1" max="10000.0"/>
+ <summary>double numbers</summary>
+ <description>Any number between 0.1 and 100 - used for testing with the gpii</description>
+ </key>
+ <key type="b" name="boolean-setting">
+ <default>false</default>
+ <summary>Boolean settings</summary>
+ <description>Test field - true or false - used for testing with the gpii</description>
+ </key>
+ <key type="s" name="string-setting">
+ <default>"abcdefg"</default>
+ <summary>String settings</summary>
+ <description>Any string - used for testing with the gpii</description>
+ </key>
+ </schema>
+
+ <schema path="/net/gpii/testing/gsettings/multi-set2/" id="net.gpii.testing.gsettings.multi-set2" gettext-domain="gpii-testing-schemas">
+ <key type="d" name="double-setting">
+ <default>5.0</default>
+ <range min="0.1" max="10000.0"/>
+ <summary>double numbers</summary>
+ <description>Any number between 0.1 and 100 - used for testing with the gpii</description>
+ </key>
+ <key type="b" name="boolean-setting">
+ <default>false</default>
+ <summary>Boolean settings</summary>
+ <description>Test field - true or false - used for testing with the gpii</description>
+ </key>
+ <key type="s" name="string-setting">
+ <default>"abcdefg"</default>
+ <summary>String settings</summary>
+ <description>Any string - used for testing with the gpii</description>
+ </key>
+ </schema>
+
+ <schema path="/net/gpii/testing/gsettings/multi-set3/" id="net.gpii.testing.gsettings.multi-set3" gettext-domain="gpii-testing-schemas">
+ <key type="d" name="other-double-setting">
+ <default>987.61</default>
+ <range min="1.0" max="1000.0"/>
+ <summary>double numbers</summary>
+ <description>Any number between 0.1 and 100 - used for testing with the gpii</description>
+ </key>
+ <key type="s" name="other-string-setting">
+ <default>"hello world"</default>
+ <summary>String settings</summary>
+ <description>Any string - used for testing with the gpii</description>
+ </key>
+ </schema>
+
+
+ <schema path="/net/gpii/testing/gsettings/multi-get1/" id="net.gpii.testing.gsettings.multi-get1" gettext-domain="gpii-testing-schemas">
+ <key type="d" name="double-setting">
+ <default>5.0</default>
+ <range min="0.1" max="10000.0"/>
+ <summary>double numbers</summary>
+ <description>Any number between 0.1 and 100 - used for testing with the gpii</description>
+ </key>
+ <key type="b" name="boolean-setting">
+ <default>false</default>
+ <summary>Boolean settings</summary>
+ <description>Test field - true or false - used for testing with the gpii</description>
+ </key>
+ <key type="s" name="string-setting">
+ <default>"abcdefg"</default>
+ <summary>String settings</summary>
+ <description>Any string - used for testing with the gpii</description>
+ </key>
+ </schema>
+
+ <schema path="/net/gpii/testing/gsettings/multi-get2/" id="net.gpii.testing.gsettings.multi-get2" gettext-domain="gpii-testing-schemas">
+ <key type="s" name="other-string-setting">
+ <default>"hello world"</default>
+ <summary>String settings</summary>
+ <description>Any string - used for testing with the gpii</description>
+ </key>
+ </schema>
+</schemalist>
View
255 node_modules/gsettingsBridge/tests/gsettingsTests.js
@@ -0,0 +1,255 @@
+/*!
+XML Settings Handler Tests
+
+Copyright 2012 Raising the Floor - International
+
+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/LICENSE.txt
+*/
+
+/*global console, __dirname, setTimeout, require */
+
+(function () {
+ // This loads universal.
+ var fluid = require("universal"),
+ gpii = fluid.registerNamespace("gpii"),
+ jqUnit = fluid.require("jqUnit");
+
+ fluid.require(__dirname+"/../../../../node_modules/universal/gpii/node_modules/testFramework/gpiiTests.js", require);
+ fluid.require("gsettingsBridge", require);
+
+ var gsettingsHandlerTests = gpii.tests.testEnvironment();
+
+ var put1 = {
+ request: {
+ "putreq": [
+ {
+ settings: {
+ "double-setting": 3.1,
+ "boolean-setting": true,
+ "string-setting": "here i am"
+ },
+ options: {
+ schema: "net.gpii.testing.gsettings.multi-set1"
+ }
+ }
+ ]
+ },
+ expected: {
+ "putreq": [
+ {
+ settings: {
+ "double-setting": { "oldValue": 5.0, "newValue": 3.1 },
+ "boolean-setting": { "oldValue": false, "newValue": true },
+ "string-setting": { "oldValue": "abcdefg", "newValue": "here i am" }
+ },
+ options: {
+ schema: "net.gpii.testing.gsettings.multi-set1"
+ }
+ }
+ ]
+ }
+ };
+
+ var put2 = {
+ request: {
+ "putreq": [
+ {
+ settings: {
+ "double-setting": 3.2,
+ "boolean-setting": true,
+ "string-setting": "here i amma"
+ },
+ options: {
+ schema: "net.gpii.testing.gsettings.multi-set2"
+ }
+ }, {
+ settings: {
+ "other-double-setting": 123.0,
+ "other-string-setting": "congratulations"
+ },
+ options: {
+ schema: "net.gpii.testing.gsettings.multi-set3"
+ }
+ }
+ ]
+ },
+ expected: {
+ "putreq": [
+ {
+ settings: {
+ "double-setting": { "oldValue": 5, "newValue": 3.2},
+ "boolean-setting": { "oldValue": false, "newValue": true },
+ "string-setting": { "oldValue": "abcdefg", "newValue": "here i amma" }
+ },
+ options: {
+ schema: "net.gpii.testing.gsettings.multi-set2"
+ }
+ }, {
+ settings: {
+ "other-double-setting": { "oldValue": 987.61, "newValue": 123.0 },
+ "other-string-setting": { "oldValue": "hello world", "newValue": "congratulations" }
+ },
+ options: {
+ schema: "net.gpii.testing.gsettings.multi-set3"
+ }
+ }
+ ]
+ }
+ };
+
+ var get1 = {
+ request: {
+ "getreq": [
+ {
+ settings: {
+ "double-setting": null,
+ "boolean-setting": null,
+ "string-setting": null
+ },
+ options: {
+ schema: "net.gpii.testing.gsettings.multi-get1"
+ }
+ }, {
+ settings: {
+ "other-string-setting": null
+ },
+ options: {
+ schema: "net.gpii.testing.gsettings.multi-get2"
+ }
+ }
+ ]
+ },
+ expected: {
+ "getreq": [
+ {
+ settings: {
+ "double-setting": 5.0,
+ "boolean-setting": false,
+ "string-setting": "abcdefg"
+ },
+ options: {
+ schema: "net.gpii.testing.gsettings.multi-get1"
+ }
+ }, {
+ settings: {
+ "other-string-setting": "hello world"
+ },
+ options: {
+ schema: "net.gpii.testing.gsettings.multi-get2"
+ }
+ }
+ ]
+ }
+ };
+
+ var get2 = {
+ request: {
+ "getreq": [
+ {
+ settings: null,
+ options: {
+ schema: "net.gpii.testing.gsettings.multi-get1"
+ }
+ }, {
+ settings: {
+ "other-string-setting": null
+ },
+ options: {
+ schema: "net.gpii.testing.gsettings.multi-get2"
+ }
+ }
+ ]
+ },
+ expected: {
+ "getreq": [
+ {
+ settings: {
+ "double-setting": 5.0,
+ "boolean-setting": false,
+ "string-setting": "abcdefg"
+ },
+ options: {
+ schema: "net.gpii.testing.gsettings.multi-get1"
+ }
+ }, {
+ settings: {
+ "other-string-setting": "hello world"
+ },
+ options: {
+ schema: "net.gpii.testing.gsettings.multi-get2"
+ }
+ }
+ ]
+ }
+ };
+
+ jqUnit.module("Gsettings Handler Tests");
+
+ gsettingsHandlerTests.asyncTest("Getting single keys via gsettings handler", function() {
+ setTimeout(function() {
+ //First check reading single keys ... the default values:
+ jqUnit.assertEquals("Checking 'double' key", 5.0,
+ gpii.gsettings.getSingleKey("net.gpii.testing.gsettings.single-get", "double-setting"));
+ jqUnit.assertEquals("Checking 'boolean' key", false,
+ gpii.gsettings.getSingleKey("net.gpii.testing.gsettings.single-get", "boolean-setting"));
+ jqUnit.assertEquals("Checking 'string' key", "abcdefg",
+ gpii.gsettings.getSingleKey("net.gpii.testing.gsettings.single-get", "string-setting"));
+ jqUnit.start();
+ }, 10);
+ });
+
+
+ gsettingsHandlerTests.asyncTest("Setting single keys via gsettings handler", function() {
+ setTimeout(function() {
+ //set and check double value
+ gpii.gsettings.setSingleKey("net.gpii.testing.gsettings.single-set", "double-setting", 6.789);
+ jqUnit.assertEquals("Checking 'double' key", 6.789,
+ gpii.gsettings.getSingleKey("net.gpii.testing.gsettings.single-set", "double-setting"));
+ //set and check boolean value
+ gpii.gsettings.setSingleKey("net.gpii.testing.gsettings.single-set", "boolean-setting", true);
+ jqUnit.assertEquals("Checking 'boolean' key", true,
+ gpii.gsettings.getSingleKey("net.gpii.testing.gsettings.single-set", "boolean-setting"));
+ //set and check string value
+ gpii.gsettings.setSingleKey("net.gpii.testing.gsettings.single-set", "string-setting", "Absolutely awesome");
+ jqUnit.assertEquals("Checking 'string' key", "Absolutely awesome",
+ gpii.gsettings.getSingleKey("net.gpii.testing.gsettings.single-set", "string-setting"));
+ jqUnit.start();
+ }, 10);
+ });
+
+ gsettingsHandlerTests.asyncTest("Setting multiple keys", function () {
+ setTimeout(function() {
+ var response = gpii.gsettings.set(put1.request);
+ jqUnit.assertDeepEq("The values should be set and expected payload returned: ", put1.expected, response);
+ jqUnit.start();
+ }, 10);
+ });
+
+ gsettingsHandlerTests.asyncTest("Setting multiple keys in multiple schemas", function () {
+ setTimeout(function() {
+ var response = gpii.gsettings.set(put2.request);
+ jqUnit.assertDeepEq("The values should be set and expected payload returned: ", put2.expected, response);
+ jqUnit.start();
+ }, 10);
+ });
+
+ gsettingsHandlerTests.asyncTest("Getting multiple keys in multiple schemas", function () {
+ setTimeout(function() {
+ var response = gpii.gsettings.get(get1.request);
+ jqUnit.assertDeepEq("The correct values is expected in the returned payload: ", get1.expected, response);
+ jqUnit.start();
+ }, 10);
+ });
+
+ gsettingsHandlerTests.asyncTest("Getting multiple keys with settings block as null", function () {
+ setTimeout(function() {
+ var response = gpii.gsettings.get(get2.request);
+ jqUnit.assertDeepEq("The correct values is expected in the returned payload: ", get2.expected, response);
+ jqUnit.start();
+ }, 10);
+ });
+}());
View
25 node_modules/gsettingsBridge/tests/runUnitTests.sh
@@ -0,0 +1,25 @@
+#!/bin/bash
+LOC="/usr/share/glib-2.0/schemas"
+
+# Copy schemas to global location and compile them
+sudo cp data/net.gpii.testing.gsettings.gschema.xml $LOC
+sudo glib-compile-schemas $LOC
+
+# Make sure they are reset in case they already existed
+gsettings reset-recursively net.gpii.testing.gsettings.single-get
+gsettings reset-recursively net.gpii.testing.gsettings.single-set
+gsettings reset-recursively net.gpii.testing.gsettings.multi-get1
+gsettings reset-recursively net.gpii.testing.gsettings.multi-get2
+gsettings reset-recursively net.gpii.testing.gsettings.multi-set1
+gsettings reset-recursively net.gpii.testing.gsettings.multi-set2
+gsettings reset-recursively net.gpii.testing.gsettings.multi-set3
+
+#Run the tests:
+node gsettingsTests.js
+
+#Delete the schemas when done and recompile:
+sudo rm "$LOC/net.gpii.testing.gsettings.gschema.xml"
+sudo glib-compile-schemas $LOC
+
+
+
Please sign in to comment.
Something went wrong with that request. Please try again.