summaryrefslogtreecommitdiff
path: root/jsonrpc/qooxdoo/test.esp
blob: 5fd893c21796a125bc45a1dc5d9d334ec8b1344d (plain)
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
<%
/*
 * Copyright:
 *   (C) 2006 by Derrell Lipman
 *       All rights reserved
 *
 * License:
 *   LGPL 2.1: http://creativecommons.org/licenses/LGPL/2.1/
 */

/*
 * This is the standard qooxdoo test class.  There are tests for each of the
 * primitive types here, along with standard named tests "echo", "sink" and
 * "sleep".
 */

/**
 * Echo the (one and only) parameter.
 *
 * @param params
 *   An array containing the parameters to this method
 *
 * @param error
 *   An object of class JsonRpcError.
 *
 * @return
 *   Success: The object containing the result of the method;
 *   Failure: null
 */
function _echo(params, error)
{
    if (params.length != 1)
    {
        error.SetError(JsonRpcError_ParameterMismatch,
                       "Expected 1 parameter; got " + params.length);
        return error;
    }
    return "Client said: [" + params[0] + "]";
}
jsonrpc.method.echo = _echo;

/**
 * Sink all data and never return.
 *
 * @param params
 *   An array containing the parameters to this method (none expected)
 *
 * @param error
 *   An object of class JsonRpcError.
 *
 * @return
 *   "Never"
 */
function _sink(params, error)
{
    /* We're never supposed to return.  Just sleep for a very long time. */
    sleep(240);
}
jsonrpc.method.sink = _sink;

/**
 * Sleep for the number of seconds specified by the parameter.
 *
 * @param params
 *   An array containing the parameters to this method (one expected)
 *
 * @param error
 *   An object of class JsonRpcError.
 *
 * @return
 *   Success: The object containing the result of the method;
 *   Failure: null
 */
function _sleep(params, error)
{
    if (params.length != 1)
    {
        error.SetError(JsonRpcError_ParameterMismatch,
                       "Expected 1 parameter; got " + params.length);
        return null;
    }
    
    sleep(params[0]);
    return params[0];
}
jsonrpc.method.sleep = _sleep;

/*************************************************************************/

/*
 * The remainder of the functions test each individual primitive type, and
 * test echoing arbitrary types.  Hopefully the name is self-explanatory.
 */

function _getInteger(params, error)
{
    return 1;
}
jsonrpc.method.getInteger = _getInteger;

function _getFloat(params, error)
{
    return 1/3;
}
jsonrpc.method.getFloat = _getFloat;

function _getString(params, error)
{
    return "Hello world";
}
jsonrpc.method.getString = _getString;

function _getBadString(params, error)
{
    return "<!DOCTYPE HTML \"-//IETF//DTD HTML 2.0//EN\">";
}
jsonrpc.method.getBadString = _getBadString;

function _getArrayInteger(params, error)
{
    return new Array(1, 2, 3, 4);
}
jsonrpc.method.getArrayInteger = _getArrayInteger;

function _getArrayString(params, error)
{
    return new Array("one", "two", "three", "four");
}
jsonrpc.method.getArrayString = _getArrayString;

function _getObject(params, error)
{
    o = new Object(); // some arbitrary object
    o.something = 23;
    o.garbage = 'lkasjdff;lajsdfkl;sadf';
    return o;    
}
jsonrpc.method.getObject = _getObject;

function _getTrue(params, error)
{
    return true;
}
jsonrpc.method.getTrue = _getTrue;

function _getFalse(params, error)
{
    return false;
}
jsonrpc.method.getFalse = _getFalse;

function _getNull(params, error)
{
    return null;
}
jsonrpc.method.getNull = _getNull;

function _isInteger(params, error)
{
    var type = nativeTypeOf(params[0]);
    return type == "integer" || type == "integer64";
}
jsonrpc.method.isInteger = _isInteger;

function _isFloat(params, error)
{
    return nativeTypeOf(params[0]) == "float";
}
jsonrpc.method.isFloat = _isFloat;

function _isString(params, error)
{
    return nativeTypeOf(params[0]) == "string";
}
jsonrpc.method.isString = _isString;

function _isBoolean(params, error)
{
    return nativeTypeOf(params[0]) == "boolean";
}
jsonrpc.method.isBoolean = _isBoolean;

function _isArray(params, error)
{
    return nativeTypeOf(params[0]) == "object" && params.length != undefined;
}
jsonrpc.method.isArray = _isArray;

function _isObject(params, error)
{
    return nativeTypeOf(params[0]) == "object";
}
jsonrpc.method.isObject = _isObject;

function _isNull(params, error)
{
    return nativeTypeOf(params[0]) == "null";
}
jsonrpc.method.isNull = _isNull;

function _getParams(params, error)
{
    return params;
}	
jsonrpc.method.getParams = _getParams;

function _getParam(params, error)
{
    return params[0];
}	
jsonrpc.method.getParam = _getParam;

function _getCurrentTimestamp()
{
    now = gettimeofday();
    obj = new Object();
    obj.now = now.sec;
    obj.json = JSON_Date.create(now);
    return obj;
}
jsonrpc.method.getCurrentTimestamp = _getCurrentTimestamp;

function _getError(params, error)
{
    error.SetError(23, "This is an application-provided error");
    return error;
}	
jsonrpc.method.getError = _getError;

%>