4 * (C) 2006 by Derrell Lipman
8 * LGPL 2.1: http://creativecommons.org/licenses/LGPL/2.1/
12 * This is the standard qooxdoo test class. There are tests for each of the
13 * primitive types here, along with standard named tests "echo", "sink" and
18 * Echo the (one and only) parameter.
21 * An array containing the parameters to this method
24 * An object of class JsonRpcError.
27 * Success: The object containing the result of the method;
30 function _echo(params, error)
32 if (params.length != 1)
34 error.setError(JsonRpcError_ParameterMismatch,
35 "Expected 1 parameter; got " + params.length);
38 return "Client said: [" + params[0] + "]";
40 jsonrpc.method.echo = _echo;
43 * Sink all data and never return.
46 * An array containing the parameters to this method (none expected)
49 * An object of class JsonRpcError.
54 function _sink(params, error)
56 /* We're never supposed to return. Just sleep for a very long time. */
59 jsonrpc.method.sink = _sink;
62 * Sleep for the number of seconds specified by the parameter.
65 * An array containing the parameters to this method (one expected)
68 * An object of class JsonRpcError.
71 * Success: The object containing the result of the method;
74 function _sleep(params, error)
76 if (params.length != 1)
78 error.setError(JsonRpcError_ParameterMismatch,
79 "Expected 1 parameter; got " + params.length);
86 jsonrpc.method.sleep = _sleep;
88 /*************************************************************************/
91 * The remainder of the functions test each individual primitive type, and
92 * test echoing arbitrary types. Hopefully the name is self-explanatory.
95 function _getInteger(params, error)
99 jsonrpc.method.getInteger = _getInteger;
101 function _getFloat(params, error)
105 jsonrpc.method.getFloat = _getFloat;
107 function _getString(params, error)
109 return "Hello world";
111 jsonrpc.method.getString = _getString;
113 function _getBadString(params, error)
115 return "<!DOCTYPE HTML \"-//IETF//DTD HTML 2.0//EN\">";
117 jsonrpc.method.getBadString = _getBadString;
119 function _getArrayInteger(params, error)
121 return new Array(1, 2, 3, 4);
123 jsonrpc.method.getArrayInteger = _getArrayInteger;
125 function _getArrayString(params, error)
127 return new Array("one", "two", "three", "four");
129 jsonrpc.method.getArrayString = _getArrayString;
131 function _getObject(params, error)
133 o = new Object(); // some arbitrary object
135 o.garbage = 'lkasjdff;lajsdfkl;sadf';
138 jsonrpc.method.getObject = _getObject;
140 function _getTrue(params, error)
144 jsonrpc.method.getTrue = _getTrue;
146 function _getFalse(params, error)
150 jsonrpc.method.getFalse = _getFalse;
152 function _getNull(params, error)
156 jsonrpc.method.getNull = _getNull;
158 function _isInteger(params, error)
160 var type = nativeTypeOf(params[0]);
161 return type == "integer" || type == "integer64";
163 jsonrpc.method.isInteger = _isInteger;
165 function _isFloat(params, error)
167 return nativeTypeOf(params[0]) == "float";
169 jsonrpc.method.isFloat = _isFloat;
171 function _isString(params, error)
173 return nativeTypeOf(params[0]) == "string";
175 jsonrpc.method.isString = _isString;
177 function _isBoolean(params, error)
179 return nativeTypeOf(params[0]) == "boolean";
181 jsonrpc.method.isBoolean = _isBoolean;
183 function _isArray(params, error)
185 return nativeTypeOf(params[0]) == "object" && params.length != undefined;
187 jsonrpc.method.isArray = _isArray;
189 function _isObject(params, error)
191 return nativeTypeOf(params[0]) == "object";
193 jsonrpc.method.isObject = _isObject;
195 function _isNull(params, error)
197 return nativeTypeOf(params[0]) == "null";
199 jsonrpc.method.isNull = _isNull;
201 function _getParams(params, error)
205 jsonrpc.method.getParams = _getParams;
207 function _getParam(params, error)
211 jsonrpc.method.getParam = _getParam;
213 function _getCurrentTimestamp()
215 now = gettimeofday();
218 obj.json = JSON_Date.create(now);
221 jsonrpc.method.getCurrentTimestamp = _getCurrentTimestamp;
223 function _getError(params, error)
225 error.setError(23, "This is an application-provided error");
228 jsonrpc.method.getError = _getError;