2 Copyright © 2008 Movial Creative Technologies Inc
3 Feel free to use the contents of this file in any way you want
4 If you can make money with it, please contact info@movial.com
5 and you have almost-guaranteed sales position waiting for you!
10 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
12 <script type='text/javascript' src='DBus.js'></script>
13 <script type='text/javascript'>
18 var current_test = null;
20 function Test(method_name, arg, convert, xfail, signature, next_test)
22 this.method_name = method_name;
24 this.convert = convert;
25 this.signature = signature;
31 this.next = next_test;
47 if (!this.method_name)
49 alert("Test error: No method name specified!");
53 if (typeof this.arg != 'boolean' && !this.arg)
55 alert("Test error: No argument specified!");
59 var method = DBus.getMethod(DBus.SESSION, 'org.movial.Unit',
61 this.method_name, 'org.movial.Unit', this.signature,
63 this.signal = DBus.getSignal(DBus.SESSION, 'org.movial.Unit', this.method_name,
65 this.signal.onemit = this.onemit;
67 // We need to receive replies as we go to get a meaningful report
68 // but do test with async replies too!
71 var status = document.getElementById('status');
74 if (this.convert instanceof Function)
76 send_arg = this.convert(this.arg);
87 status.innerHTML += '<p>Result: <span style="color: ' + color + ';">Converting "' + this.arg + '" failed</span>';
88 current_test = this.next;
89 setTimeout(run_next, 10);
96 method.onreply = this.method_reply;
97 method.onerror = this.error_reply;
100 if (this.arg instanceof Array || this.arg instanceof Object)
104 for (var propname in this.arg)
111 argstr += propname + ":" + this.arg[propname];
115 argstr = this.arg.toString();
118 status.innerHTML += '<p>Sending ' + this.method_name + ':<span style="color: blue; padding-left: 1em;">' + argstr + ' of type ' + typeof send_arg + ' with signature ' + this.signature + '</span>';
120 this.signal.enabled = !this.xfail;
124 onemit: function (reply_arg)
126 var status = document.getElementById('status');
127 status.innerHTML += '<p>Got signal "' + this.method_name + '"';
128 this.signal.enabled = false;
129 this.method_reply(reply_arg);
131 current_test = this.next;
132 setTimeout(run_next, 10);
136 method_reply: function (reply_arg)
138 var status = document.getElementById('status');
142 status.innerHTML += '<p style="margin-top: -0.5em"><span style="color:red; padding-left: 1em;">This test should have failed, but did not!</span>';
144 current_test = this.next;
145 setTimeout(run_next, 10);
151 if (!is_equal(this.arg, reply_arg))
156 if (reply_arg instanceof Array || reply_arg instanceof Object)
160 for (var propname in reply_arg)
167 argstr += propname + ":" + reply_arg[propname];
171 if (typeof this.arg == 'boolean')
173 argstr = reply_arg.toString();
174 } else if (reply_arg) {
175 argstr = reply_arg.toString();
188 status.innerHTML += '<p style="margin-top: -0.5em">Result: <span style="color: ' + color + '; padding-left: 1em;">' + argstr + ', ' + typeof reply_arg + '</span>';
193 error_reply: function (error_name, error_message)
195 var status = document.getElementById('status');
199 status.innerHTML += '<p style="color: green;">Expected failure:';
202 status.innerHTML += '<p style="color: red;">' + error_name + ':';
205 status.innerHTML += '<span style="color: red; padding-left: 1em;">' + error_message + '</span>';
207 current_test = this.next;
208 setTimeout(run_next, 10);
214 function is_equal(a, b)
216 if ((a instanceof Array && b instanceof Array)
217 || (a instanceof Object && b instanceof Object))
221 if (!is_equal(a[i], b[i]))
241 var status = document.getElementById('status');
242 status.innerHTML += "<p>Ending test...";
243 var end = DBus.getMethod(DBus.SESSION, 'org.movial.Unit',
245 "end", 'org.movial.Unit');
250 function show_results()
252 var results = document.getElementById('results');
253 results.innerHTML = '<p>Total of ' + n_tests + ' tests, <span style="color: green">passed ' + good + '</span>, <span style="color:red">failed ' + bad + '</span>, unknown ' + (n_tests - good - bad) + ", " + Math.round((good/n_tests)*100) + '% success rate';
256 var tests = new Array();
260 var status = document.getElementById('status');
262 setTimeout(show_results, 1000);
264 status.innerHTML += "<p>Starting test...";
265 var start = DBus.getMethod(DBus.SESSION, 'org.movial.Unit',
267 "start", 'org.movial.Unit');
272 tests[i++] = new Test('Boolean', true, null, false);
273 tests[i++] = new Test('Boolean', true, null, false, 'b');
275 tests[i++] = new Test('Int16', 32767, DBus.Int16, false);
276 tests[i++] = new Test('Int16', 32767, null, true);
277 tests[i++] = new Test('Int16', 32767, DBus.Int16, false, 'n');
278 tests[i++] = new Test('Int16', 32767, null, false, 'n');
280 tests[i++] = new Test('Int32', 2147483647, DBus.Int32, false);
281 tests[i++] = new Test('Int32', 2147483647, null, true);
282 tests[i++] = new Test('Int32', 2147483647, DBus.Int32, false, 'i');
283 tests[i++] = new Test('Int32', 2147483647, null, false, 'i');
285 // There's problems with the (u)int64 types since doubles can't hold
286 // large enough values accurately.
287 tests[i++] = new Test('Int64', 17179869176, DBus.Int64, false);
288 tests[i++] = new Test('Int64', 17179869176, null, true);
289 tests[i++] = new Test('Int64', 17179869176, DBus.Int64, false, 'x');
290 tests[i++] = new Test('Int64', 17179869176, null, false, 'x');
292 tests[i++] = new Test('UInt16', 32767, DBus.UInt16, false);
293 tests[i++] = new Test('UInt16', 32767, null, true);
294 tests[i++] = new Test('UInt16', 32767, DBus.UInt16, false, 'q');
295 tests[i++] = new Test('UInt16', 32767, null, false, 'q');
297 tests[i++] = new Test('UInt32', 2147483647, DBus.UInt32, false);
298 tests[i++] = new Test('UInt32', 2147483647, null, true);
299 tests[i++] = new Test('UInt32', 2147483647, DBus.UInt32, false, 'u');
300 tests[i++] = new Test('UInt32', 2147483647, null, false, 'u');
302 tests[i++] = new Test('UInt64', 17179869176, DBus.UInt64, false);
303 tests[i++] = new Test('UInt64', 17179869176, null, true);
304 tests[i++] = new Test('UInt64', 17179869176, DBus.UInt64, false, 't');
305 tests[i++] = new Test('UInt64', 17179869176, null, false, 't');
307 tests[i++] = new Test('Double', 1024.1024, null, false);
308 tests[i++] = new Test('Double', 1024.1024, null, false, 'd');
310 tests[i++] = new Test('Byte', 1, DBus.Byte, false);
311 tests[i++] = new Test('Byte', 1, null, true);
312 tests[i++] = new Test('Byte', 1, DBus.Byte, false, 'y');
313 tests[i++] = new Test('Byte', 1, null, false, 'y');
315 tests[i++] = new Test('String', "Test string", null, false);
316 tests[i++] = new Test('String', "Test string", null, false, 's');
318 tests[i++] = new Test('ObjectPath', "/org/movial/Unit", DBus.ObjectPath, false);
319 tests[i++] = new Test('ObjectPath', "/org/movial/Unit", null, true);
320 tests[i++] = new Test('ObjectPath', "/org/movial/Unit", DBus.ObjectPath, false, 'o');
321 tests[i++] = new Test('ObjectPath', "I'm invalid object path", DBus.ObjectPath, true);
322 tests[i++] = new Test('ObjectPath', "/not//valid/either", DBus.ObjectPath, true);
324 tests[i++] = new Test('Signature', "sib", DBus.Signature, false);
325 tests[i++] = new Test('Signature', "sib", null, true);
326 tests[i++] = new Test('Signature', "sib", DBus.Signature, false, 'g');
327 tests[i++] = new Test('Signature', "sib", null, false, 'g');
329 tests[i++] = new Test("Array", ["woot", "bleep", "wap"], null, false, null);
330 tests[i++] = new Test("Array", [1, 2, 3], null, false, null);
331 tests[i++] = new Test("Array", ["woot", "bleep", "wap"], null, false, 'as');
332 tests[i++] = new Test("Array", [1, 2, 3], null, false, 'ai');
334 var dict = new Object();
336 dict["test2"] = "you";
338 tests[i++] = new Test("Dict", dict, null, false, 'a{ss}');
339 tests[i++] = new Test("Dict", dict, null, false);
341 var dict = new Object();
342 dict["test"] = [100, 2, 3000];
343 tests[i++] = new Test("Dict", dict, null, false, 'a{sad}');
345 var dict = new Object();
346 dict["test"] = [100, 2, 3000];
347 tests[i++] = new Test("Dict", dict, null, false, 'a{sai}');
349 var dict = new Object();
350 var array = new Array("fää", "woo", "boo");
351 dict["test"] = array;
352 tests[i++] = new Test("Dict", dict, null, false, 'a{sas}');
354 /* TODO: We don't really yet know how exactly we want these to go...
355 tests[i++] = new Test("Variant", "woot", DBus.Variant, false);
356 tests[i++] = new Test("Variant", 1, DBus.Variant, false);
357 tests[i++] = new Test("Variant", "woot", DBus.Variant, false, 'v');
358 tests[i++] = new Test("Variant", ["woot", "bar"], DBus.Variant, false, 'v');
360 var struct = new Object();
361 struct.what = "that";
362 struct.how_many = 42;
364 tests[i++] = new Test("Struct", struct, DBus.Struct, false);
365 tests[i++] = new Test("Struct", struct, DBus.Struct, false, '(si)');
368 for (var j = 0; j < i-1; j++)
370 tests[j].next = tests[j+1]
372 current_test = tests[0];
379 <body onload='do_unit();'>
380 <div><a href="unit.html">Run again</a> <a href="http://google.fi">Leave the page</a></div>
381 <div id='results' style='border: solid blue 0.1em; padding: 1em; margin: 1em;'></div>
382 <div id='status' style='border: dashed black 0.1em; padding: 1em;'></div>