webunit.js 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. // jsreporter.js
  2. // Script to support JsReporter class
  3. // Relies heavily on the X library in x.js
  4. // X v3.14.1, Cross-Browser DHTML Library from Cross-Browser.com
  5. // Copyright (c) 2004 Jason E. Sweat (jsweat_php@yahoo.com)
  6. //
  7. // SimpleTest - http://simpletest.sf.net/
  8. // Copyright (c) 2003,2004 Marcus Baker (marcus@lastcraft.com)
  9. // $Id: webunit.js 506 2004-02-14 18:24:13Z jsweat $
  10. // Variables:
  11. min_x=500;
  12. min_y=400;
  13. groups = new Array();
  14. cases = new Array();
  15. methods = new Array();
  16. current_group=0;
  17. current_case=0;
  18. current_method=0;
  19. Hash = {
  20. Set : function(foo,bar) {this[foo] = bar;},
  21. Get : function(foo) {return this[foo];}
  22. }
  23. // Functions:
  24. function wait_start() {
  25. var wait_x;
  26. var wait_y;
  27. wait_x = xWidth('wait');
  28. wait_y = xHeight('wait');
  29. xMoveTo('wait', (xClientWidth()-wait_x)/2, (xClientHeight()-wait_y)/2);
  30. xShow('wait');
  31. }
  32. function layout() {
  33. xResizeTo('webunit', max(xClientWidth()-30,min_x), max(xClientHeight()-20,min_y));
  34. xMoveTo('webunit', 5, 5);
  35. xResizeTo('tabs', xWidth('webunit')-10, xHeight('webunit')/3);
  36. xLeft('tabs', 5);
  37. xShow('webunit');
  38. xShow('tabs');
  39. activate_tab('fail');
  40. xShow('visible_tab');
  41. xZIndex('visible_tab', 2)
  42. xResizeTo('msg', xWidth('webunit')-17, xHeight('webunit')/3-20);
  43. xLeft('msg', 2);
  44. xTop('msg',2*xHeight('webunit')/3);
  45. xShow('msg');
  46. }
  47. function set_div_content(div, content) {
  48. xGetElementById(div).innerHTML = content;
  49. }
  50. function copy_div_content(divsrc, divtrgt) {
  51. xGetElementById(divtrgt).innerHTML = xGetElementById(divsrc).innerHTML;
  52. }
  53. function activate_tab(tab) {
  54. if (tab == 'fail') {
  55. copy_div_content('fail', 'visible_tab');
  56. xGetElementById('failtab').className = 'activetab';
  57. xZIndex('failtab', 3)
  58. xGetElementById('treetab').className = 'inactivetab';
  59. xZIndex('treetab', 1)
  60. }
  61. if (tab == 'tree') {
  62. copy_div_content('tree', 'visible_tab');
  63. xGetElementById('failtab').className = 'inactivetab';
  64. xZIndex('failtab', 1)
  65. xGetElementById('treetab').className = 'activetab';
  66. xZIndex('treetab', 3)
  67. }
  68. }
  69. function add_group(group_name) {
  70. var add;
  71. add = {
  72. Set : function(foo,bar) {this[foo] = bar;},
  73. Get : function(foo) {return this[foo];}
  74. }
  75. add.Set('desc', group_name);
  76. add.Set('pass', true);
  77. groups[groups.length] = add;
  78. current_group = groups.length - 1;
  79. cases[current_group] = new Array();
  80. methods[current_group] = new Array();
  81. }
  82. function add_case(case_name) {
  83. var curgroup;
  84. var add;
  85. add = {
  86. Set : function(foo,bar) {this[foo] = bar;},
  87. Get : function(foo) {return this[foo];}
  88. }
  89. add.Set('desc', case_name);
  90. add.Set('pass', true);
  91. curgroup = cases[current_group];
  92. cases[current_group][curgroup.length] = add;
  93. current_case = curgroup.length - 1;
  94. methods[current_group][current_case] = new Array();
  95. }
  96. function add_method(method_name) {
  97. var curcase;
  98. var add;
  99. add = {
  100. Set : function(foo,bar) {this[foo] = bar;},
  101. Get : function(foo) {return this[foo];}
  102. }
  103. add.Set('desc', method_name);
  104. add.Set('pass', true);
  105. add.Set('msg','');
  106. curcase = methods[current_group][current_case];
  107. methods[current_group][current_case][curcase.length] = add;
  108. current_method = curcase.length - 1;
  109. }
  110. function add_fail(msg) {
  111. var oldmsg;
  112. add_log(msg);
  113. groups[current_group].Set('pass', false);
  114. cases[current_group][current_case].Set('pass', false);
  115. methods[current_group][current_case][current_method].Set('pass', false);
  116. oldmsg = methods[current_group][current_case][current_method].Get('msg');
  117. methods[current_group][current_case][current_method].Set('msg', oldmsg+msg);
  118. }
  119. function add_log(msg) {
  120. var faildiv;
  121. faildiv = xGetElementById('fail');
  122. faildiv.innerHTML = faildiv.innerHTML + msg;
  123. }
  124. function set_msg(gid, cid, mid) {
  125. var passfail;
  126. var msg=methods[gid][cid][mid].Get('msg');
  127. if ('' == msg) {
  128. passfail = (methods[gid][cid][mid].Get('pass')) ? 'pass' : 'fail';
  129. msg = 'No output for <span class="' + passfail + '">'
  130. + groups[gid].Get('desc') + '-&gt;'
  131. + cases[gid][cid].Get('desc') + '-&gt;'
  132. + methods[gid][cid][mid].Get('desc') + '</span><br />';
  133. }
  134. xGetElementById('msg').innerHTML = msg;
  135. }
  136. function make_tree() {
  137. var content;
  138. var passfail;
  139. content = '<ul>';
  140. for (x in groups) {
  141. passfail = (groups[x].Get('pass')) ? 'pass' : 'fail';
  142. content += '<li class="'+passfail+'">'+groups[x].Get('desc')+'<ul>';
  143. for (y in cases[x]) {
  144. passfail = (cases[x][y].Get('pass')) ? 'pass' : 'fail';
  145. content += '<li class="'+passfail+'">'+cases[x][y].Get('desc')+'<ul>';
  146. for (z in methods[x][y]) {
  147. passfail = (methods[x][y][z].Get('pass')) ? 'pass' : 'fail';
  148. content += '<li class="'+passfail+'"><a href="javascript:set_msg('+x+','+y+','+z+')">'+methods[x][y][z].Get('desc')+'</a></li>';
  149. }
  150. content += '</ul></li>';
  151. }
  152. content += '</ul></li>';
  153. }
  154. content += '</ul>';
  155. xGetElementById('tree').innerHTML = content;
  156. if (xGetElementById('treetab').className == 'activetab') {
  157. activate_tab('tree');
  158. } else {
  159. activate_tab('fail');
  160. }
  161. }
  162. function make_output(data) {
  163. }
  164. function make_fail_msg(id, msg) {
  165. }
  166. function max(n1, n2) {
  167. if (n1 > n2) {
  168. return n1;
  169. } else {
  170. return n2;
  171. }
  172. }