-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathcode.js
More file actions
188 lines (181 loc) · 4.49 KB
/
code.js
File metadata and controls
188 lines (181 loc) · 4.49 KB
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
/*
We make six calls to the betty server, two to test error reporting, and four to test various combinations of scalars, parameter lists, structs and array. The "betty" server it calls is a clone of the one we used in the earlier work on XML-RPC.
*/
var appConsts = {
version: "0.4.0"
};
var urlEndpoint = "http://betty.userland.com/RPC2";
const format = "xml";
var tests = {
stateStruct: undefined,
stateNames: undefined,
stateName: undefined,
stateList: undefined,
noSuchVerb: undefined,
fault: undefined
};
function viewTests () {
var htmltext = "", indentlevel = 0;
function add (s) {
htmltext += filledString ("\t", indentlevel) + s + "\n";
}
add ("<table>"); indentlevel++;
for (var x in tests) {
let val = "";
if (tests [x] !== undefined) {
if (tests [x]) {
val = "<i class=\"fa fa-check iOK\"></i>";
}
else {
val = "<i class=\"fa fa-times iError\"></i>";
}
}
add ("<tr><td>" + x + "</td><td>" + val + "</td></tr>");
}
add ("</table>"); indentlevel--;
$("#idTests").html (htmltext);
}
function reportTestsResult () {
var flPass = true, s = "";
for (var x in tests) {
if (!getBoolean (tests [x])) {
flPass = false;
break;
}
}
if (flPass) {
s = "Congratulations, your server passed all our tests.";
}
else {
s = "Sorry, your server failed one or more of our tests.";
}
s += " Please let us know about your test in <a href=\"https://github.com/scripting/xml-rpc/issues/7\">this thread</a>.";
s = "<p>" + s + "</p>";
$("#idResult").html (s);
}
function testStateList (callback) {
var whenstart = new Date ();
xmlRpcClient (urlEndpoint, "examples.getStateList", [ [15, 25, 35, 45] ], format, function (err, data) {
if (err) {
console.log ("err.message == " + err.message);
tests.stateList = false;
}
else {
console.log (jsonStringify (data));
tests.stateList = true;
}
viewTests ();
if (callback !== undefined) {
callback ();
}
});
}
function testStateName (callback) {
xmlRpcClient (urlEndpoint, "examples.getStateName", 23, format, function (err, data) {
if (err) {
console.log ("err.message == " + err.message);
tests.stateName = false;
}
else {
console.log (jsonStringify (data));
tests.stateName = true;
}
viewTests ();
if (callback !== undefined) {
callback ();
}
});
}
function testStateNames (callback) {
xmlRpcClient (urlEndpoint, "examples.getStateNames", [12, 22, 32, 42], format, function (err, data) {
if (err) {
console.log ("err.message == " + err.message);
tests.stateNames = false;
}
else {
console.log (jsonStringify (data));
tests.stateNames = true;
}
viewTests ();
if (callback !== undefined) {
callback ();
}
});
}
function testStateStruct (callback) {
xmlRpcClient (urlEndpoint, "examples.getStateStruct", {a: 22, b: 48}, format, function (err, data) {
if (err) {
console.log ("err.message == " + err.message);
tests.stateStruct = false;
}
else {
console.log (jsonStringify (data));
tests.stateStruct = true;
}
viewTests ();
if (callback !== undefined) {
callback ();
}
});
}
function testFault (callback) {
xmlRpcClient (urlEndpoint, "examples.getStateName", 900, format, function (err, data) {
if (err) {
console.log ("err.message == " + err.message);
tests.fault = true; //passed
}
else {
console.log (jsonStringify (data));
tests.fault = false; //failed
}
viewTests ();
if (callback !== undefined) {
callback ();
}
});
}
function testNoSuchVerb (callback) {
xmlRpcClient (urlEndpoint, "doesNotExist", undefined, format, function (err, data) {
if (err) {
console.log ("err.message == " + err.message);
tests.noSuchVerb = true; //passed
}
else {
console.log (jsonStringify (data));
tests.noSuchVerb = false; //failed
}
viewTests ();
if (callback !== undefined) {
callback ();
}
});
}
function testsButtonClick () {
$("#idTestButton").blur ();
urlEndpoint = $("#idEndpointUrl").val ();
localStorage.bettyEndpoint = urlEndpoint;
for (var x in tests) {
tests [x] = undefined;
}
viewTests ();
testNoSuchVerb (function () {
testFault (function () {
testStateList (function () {
testStateName (function () {
testStateNames (function () {
testStateStruct (function () {
reportTestsResult ();
});
});
});
});
});
});
}
function startup () {
console.log ("startup");
if (localStorage.bettyEndpoint !== undefined) {
urlEndpoint = localStorage.bettyEndpoint;
}
$("#idEndpointUrl").val (urlEndpoint);
}