2
0

utests.pp 75 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528
  1. {$mode objfpc}
  2. {$h+}
  3. unit utests;
  4. interface
  5. {$ifdef FPC}
  6. {$ifdef VER2_4}
  7. {$define USE_FPCGI}
  8. {$endif VER2_4}
  9. {$ifdef VER2_5}
  10. {$define USE_FPCGI}
  11. {$endif VER2_5}
  12. {$endif FPC}
  13. {$undef USE_FPCGI}
  14. uses
  15. {$ifdef USE_FPCGI}
  16. fpcgi,
  17. {$else not USE_FPCGI}
  18. cgiapp,
  19. {$endif not USE_FPCGI}
  20. sysutils,mysql50conn,sqldb,whtml,dbwhtml,db,
  21. tresults,
  22. Classes,ftFont,fpimage,fpimgcanv,fpWritePng,fpcanvas;
  23. const
  24. TestsuiteURLPrefix='http://www.freepascal.org/testsuite/';
  25. TestsuiteBin='testsuite.cgi';
  26. ViewURL='http://svn.freepascal.org/cgi-bin/viewvc.cgi/';
  27. TestsSubDir='/tests/';
  28. DataBaseSubDir='/packages/fcl-db/tests/';
  29. var
  30. TestsuiteCGIURL : string;
  31. Type
  32. TTestSuite = Class(TCgiApplication)
  33. Private
  34. FHTMLWriter : THtmlWriter;
  35. FComboBoxProducer : TComboBoxProducer;
  36. FDB : TSQLConnection;
  37. FTrans : TSQLTransaction;
  38. FRunID,
  39. FCompareRunID,
  40. FTestFileID,
  41. FTestFileName,
  42. FVersion,
  43. FVersionBranch,
  44. FCond,
  45. FSubmitter,
  46. FMachine,
  47. FComment,
  48. FCPU,
  49. FOS : String;
  50. FViewVCURL : String;
  51. FDate : TDateTime;
  52. FDebug,
  53. FListAll,
  54. FNoSkipped,
  55. FOnlyFailed : Boolean;
  56. FRunSkipCount,
  57. FRunFailedCount,
  58. FRunCount : Integer;
  59. FAction,
  60. FLimit : Integer;
  61. FTestLastDays : Integer;
  62. FNeedEnd : boolean;
  63. Procedure GetOverviewRowAttr(Sender : TObject; Var BGColor : String;
  64. Var Align : THTMLAlign; Var VAlign : THTMLValign;
  65. Var CustomAttr : String) ;
  66. Procedure GetRunRowAttr(Sender : TObject; Var BGColor : String;
  67. Var Align : THTMLAlign; Var VAlign : THTMLValign;
  68. Var CustomAttr : String) ;
  69. Procedure FormatFailedOverview(Sender : TObject; Var CellData : String);
  70. Procedure FormatTestRunOverview(Sender : TObject; Var CellData : String);
  71. Procedure FormatFileDetails(Sender: TObject; var CellData: String);
  72. Procedure FormatFileIDDetails(Sender: TObject; var CellData: String);
  73. Procedure FormatTestResult(Sender: TObject; var CellData: String);
  74. Function FormatDetailURL(const RunIdStr, CellData : String) : string;
  75. Procedure DoDrawPie(Img : TFPCustomImage; Skipped,Failed,Total : Integer);
  76. Public
  77. Function CreateDataset(Qry : String) : TSQLQuery;
  78. Function CreateTableProducer(DS : TDataset) :TTableProducer;
  79. Procedure DefaultTableFromQuery(Qry,ALink : String; IncludeRecordCount : Boolean);
  80. Procedure ComboBoxFromQuery(Const ComboName,Qry : String);
  81. Procedure ComboBoxFromQuery(Const ComboName,Qry,Value : String);
  82. Function GetSingleTon(Const Qry : String) : String;
  83. Function GetOSName(ID : String) : String;
  84. Function GetCPUName(ID : String) : String;
  85. Function GetVersionName(ID : String) : String;
  86. Function GetTestFileName(ID : String) : String;
  87. Function GetFailCount(RunID : longint) : string;
  88. Function InitCGIVars : Integer;
  89. Procedure DoRun; override;
  90. Procedure EmitOverviewForm;
  91. Procedure EmitHistoryForm;
  92. Procedure ShowRunResults;
  93. Procedure ShowRunComparison;
  94. Procedure ShowOneTest;
  95. Procedure ShowHistory;
  96. Function ConnectToDB : Boolean;
  97. procedure DisconnectFromDB;
  98. Procedure EmitTitle(ATitle : String);
  99. Procedure EmitEnd;
  100. Procedure ShowRunOverview;
  101. Procedure CreateRunPie;
  102. Function ShowRunData : Boolean;
  103. end;
  104. implementation
  105. Const
  106. {$i utests.cfg}
  107. { if utests.cfg is missed, create one with the following contents:
  108. DefDatabase = 'TESTSUITE';
  109. DefHost = '';
  110. DefDBUser = ''; // fill this in when compiling.
  111. DefPassword = ''; // fill this in, too.
  112. }
  113. Var
  114. SDetailsURL : string;
  115. type
  116. known_versions = (
  117. ver_unknown,
  118. ver_1_0_10,
  119. ver_2_0_0,
  120. ver_2_0_1,
  121. ver_2_0_2,
  122. ver_2_0_3,
  123. ver_2_0_4,
  124. ver_2_0_5,
  125. ver_2_1_2,
  126. ver_2_1_4,
  127. ver_2_2_0,
  128. ver_2_2_1,
  129. ver_2_2_2,
  130. ver_2_2_3,
  131. ver_2_2_4,
  132. ver_2_2_5,
  133. ver_2_3_1,
  134. ver_2_4_0,
  135. ver_2_4_1,
  136. ver_2_5_1);
  137. const
  138. ver_trunk = high (known_versions);
  139. const
  140. ver_string : array[known_versions] of string =
  141. (
  142. 'unknown',
  143. '1.0.10',
  144. '2.0.0',
  145. '2.0.1',
  146. '2.0.2',
  147. '2.0.3',
  148. '2.0.4',
  149. '2.0.5',
  150. '2.1.2',
  151. '2.1.4',
  152. '2.2.0',
  153. '2.2.1',
  154. '2.2.2',
  155. '2.2.3',
  156. '2.2.4',
  157. '2.2.5',
  158. '2.3.1',
  159. '2.4.0',
  160. '2.4.1',
  161. '2.5.1'
  162. );
  163. ver_branch : array [known_versions] of string =
  164. (
  165. '',
  166. '',
  167. 'tags/release_2_0_0',
  168. 'branches/fixes_2_0',
  169. 'tags/release_2_0_2',
  170. 'branches/fixes_2_0',
  171. 'tags/release_2_0_4',
  172. 'branches/fixes_2_0',
  173. 'tags/release_2_1_2',
  174. 'tags/release_2_1_4',
  175. 'tags/release_2_2_0',
  176. 'branches/fixes_2_2',
  177. 'tags/release_2_2_2',
  178. 'branches/fixes_2_2',
  179. 'tags/release_2_2_4',
  180. 'branches/fixes_2_2',
  181. 'tags/release_2_4_0',
  182. 'tags/release_2_4_0',
  183. 'branches/fixes_2_4',
  184. 'trunk'
  185. );
  186. Procedure TTestSuite.DoRun;
  187. begin
  188. Try
  189. Try
  190. Case InitCGIVars of
  191. 0 : EmitOverviewForm;
  192. 1 :
  193. if Length(FCompareRunID) = 0 then
  194. ShowRunResults
  195. else
  196. ShowRunComparison;
  197. 2 : CreateRunPie;
  198. 3 : ShowOneTest;
  199. 4 : ShowHistory;
  200. {$ifdef TEST}
  201. 98 :
  202. begin
  203. ///EmitOverviewForm;
  204. system.Writeln(stdout,'<PRE>');
  205. system.Writeln(stdout,'paramstr(0) is ',paramstr(0));
  206. system.FreeMem(pointer($ffffffff));
  207. system.Writeln(stdout,'</PRE>');
  208. system.Flush(stdout);
  209. end;
  210. 99 :
  211. begin
  212. EmitOverviewForm;
  213. system.Writeln(stdout,'<PRE>');
  214. system.Dump_stack(stdout,get_frame);
  215. system.Writeln(stdout,'</PRE>');
  216. system.Flush(stdout);
  217. end;
  218. {$endif TEST}
  219. end;
  220. finally
  221. EmitEnd;
  222. DisConnectFromDB;
  223. end;
  224. Finally
  225. Terminate;
  226. end;
  227. end;
  228. Function TTestSuite.InitCGIVars : Integer;
  229. Var
  230. S : String;
  231. begin
  232. FHtmlWriter:=THTMLWriter.Create(Response);
  233. FComboBoxProducer:=TComboBoxProducer.Create(Self);
  234. DateSeparator:='/';
  235. Result:=0;
  236. S:=RequestVariables['action'];
  237. if Length(S) = 0 then
  238. S:=RequestVariables['TESTACTION'];
  239. if S='View history' then
  240. FAction:=4
  241. else
  242. FAction:=StrToIntDef(S,0);
  243. S:=RequestVariables['limit'];
  244. if Length(S) = 0 then
  245. S:=RequestVariables['TESTLIMIT'];
  246. FLimit:=StrToIntDef(S,50);
  247. FVersion:=RequestVariables['version'];
  248. if Length(FVersion) = 0 then
  249. FVersion:=RequestVariables['TESTVERSION'];
  250. FOS:=RequestVariables['os'];
  251. if Length(FOS) = 0 then
  252. FOS:=RequestVariables['TESTOS'];
  253. FCPU:=RequestVariables['cpu'];
  254. if Length(FCPU) = 0 then
  255. FCPU:=RequestVariables['TESTCPU'];
  256. FCond:=RequestVariables['cond'];
  257. if Length(FCond) = 0 then
  258. FCond:=RequestVariables['TESTCOND'];
  259. FComment:=RequestVariables['comment'];
  260. if Length(FComment) = 0 then
  261. FComment:=RequestVariables['TESTCOMMENT'];
  262. FSubmitter:=RequestVariables['submitter'];
  263. if Length(FSubmitter) = 0 then
  264. FSubmitter:=RequestVariables['TESTSUBMITTER'];
  265. FMachine:=RequestVariables['machine'];
  266. if Length(FMachine) = 0 then
  267. FMachine:=RequestVariables['TESTMACHINE'];
  268. FRunID:=RequestVariables['run1id'];
  269. if Length(FRunID) = 0 then
  270. FRunID:=RequestVariables['TESTRUN'];
  271. S:=RequestVariables['lastdays'];
  272. if Length(S) = 0 then
  273. S:=RequestVariables['TESTLASTDAYS'];
  274. FTestLastDays:=StrToIntDef(S,31);
  275. S:=RequestVariables['date'];
  276. if Length(S) = 0 then
  277. S:=RequestVariables['TESTDATE'];
  278. if Length(S) > 0 then
  279. try
  280. FDate:=StrToDate(S);
  281. except
  282. FDate:=0;
  283. end;
  284. S:=RequestVariables['failedonly'];
  285. if Length(S) = 0 then
  286. S:=RequestVariables['TESTFAILEDONLY'];
  287. FOnlyFailed:=(S='1');
  288. S:=RequestVariables['noskipped'];
  289. if Length(S) = 0 then
  290. S:=RequestVariables['TESTNOSKIPPED'];
  291. FNoSkipped:=(S='1');
  292. FCompareRunID:=RequestVariables['run2id'];
  293. FTestFileID:=RequestVariables['testfileid'];
  294. FTestFileName:=RequestVariables['testfilename'];
  295. FRunCount:=StrToIntDef(RequestVariables['PIETOTAL'],0);
  296. FRunSkipCount:=StrToIntDef(RequestVariables['PIESKIPPED'],0);
  297. FRunFailedCount:=StrToIntDef(RequestVariables['PIEFAILED'],0);
  298. S:=RequestVariables['DEBUGCGI'];
  299. FDebug:=(S='1');
  300. S:=RequestVariables['listall'];
  301. FListAll:=(S='1');
  302. Result:=FAction;
  303. end;
  304. Function TTestSuite.ConnectToDB : Boolean;
  305. begin
  306. Result:=False;
  307. FDB:=TMySQl50Connection.Create(Self);
  308. FDB.HostName:=DefHost;
  309. FDB.DatabaseName:=DefDatabase;
  310. FDB.UserName:=DefDBUser;
  311. FDB.Password:=DefPassword;
  312. FTrans := TSQLTransaction.Create(nil);
  313. FTrans.DataBase := FDB;
  314. FDB.Transaction := FTrans;
  315. FDB.Connected:=True;
  316. Result:=True;
  317. end;
  318. procedure TTestSuite.DisconnectFromDB;
  319. begin
  320. If Assigned(FDB) then
  321. begin
  322. if (FDB.Connected) then
  323. FDB.Connected:=False;
  324. FreeAndNil(FDB);
  325. FreeAndNil(FTrans);
  326. end;
  327. end;
  328. Procedure TTestSuite.ComboBoxFromQuery(Const ComboName,Qry: String);
  329. begin
  330. ComboBoxFromQuery(ComboName,Qry,'')
  331. end;
  332. Procedure TTestSuite.ComboBoxFromQuery(Const ComboName,Qry,Value : String);
  333. Var
  334. Q : TSQLQuery;
  335. begin
  336. Q:=TSQLQuery.Create(Self);
  337. try
  338. Q.Database:=FDB;
  339. Q.Transaction:=FTrans;
  340. Q.SQL.Text:=Qry;
  341. Q.Open;
  342. FComboboxProducer.Dataset:=Q;
  343. FComboBoxProducer.ValueField:=Q.Fields[0].FieldName;
  344. FComboBoxProducer.DataField:=Q.Fields[1].FieldName;
  345. FComboBoxProducer.Value:=Value;
  346. FComboBoxProducer.InputName:=ComboName;
  347. FComboBoxProducer.CreateComboBox(Response);
  348. Finally
  349. Q.Free;
  350. end;
  351. end;
  352. Function TTestSuite.GetSingleton(Const Qry : String) : String;
  353. Var
  354. Q : TSQLQuery;
  355. begin
  356. Result:='';
  357. if FDEbug then
  358. begin
  359. system.Writeln('Query=',Qry);
  360. system.flush(output);
  361. end;
  362. Q:=TSQLQuery.Create(Self);
  363. try
  364. Q.Database:=FDB;
  365. Q.Transaction:=FTrans;
  366. Q.SQL.Text:=Qry;
  367. Q.Open;
  368. Try
  369. if FDebug and (Q.FieldCount<>1) then
  370. begin
  371. system.Writeln('GetSingleton number of fields is not 1, but ',
  372. Q.FieldCount);
  373. system.flush(output);
  374. end;
  375. If Not (Q.EOF and Q.BOF) then
  376. Result:=Q.Fields[0].AsString;
  377. Finally
  378. Q.Close;
  379. end;
  380. finally
  381. Q.Free;
  382. end;
  383. end;
  384. Procedure TTestSuite.EmitTitle(ATitle : String);
  385. begin
  386. AddResponseLn('<HTML>');
  387. AddResponseLn('<TITLE>'+ATitle+'</TITLE>');
  388. AddResponseLn('<BODY>');
  389. FNeedEnd:=true;
  390. end;
  391. Procedure TTestSuite.EmitOverviewForm;
  392. begin
  393. ConnectToDB;
  394. ContentType:='text/html';
  395. EmitContentType;
  396. EmitTitle(Title);
  397. With FHTMLWriter do
  398. begin
  399. HeaderStart(1);
  400. Write('View Test suite results');
  401. HeaderEnd(1);
  402. Write('Please specify search criteria:');
  403. ParagraphStart;
  404. FormStart(TestsuiteCGIURL,'');
  405. if FDebug then
  406. EmitHiddenVar('DEBUGCGI', '1');
  407. TableStart(2,true);
  408. RowStart;
  409. CellStart;
  410. Write('Operating system:');
  411. CellNext;
  412. ComboBoxFromQuery('os','SELECT TO_ID,TO_NAME FROM TESTOS ORDER BY TO_NAME',FOS);
  413. CellEnd;
  414. RowNext;
  415. CellStart;
  416. Write('Processor:');
  417. CellNext;
  418. ComboBoxFromQuery('cpu','SELECT TC_ID,TC_NAME FROM TESTCPU ORDER BY TC_NAME',FCPU);
  419. CellEnd;
  420. RowNext;
  421. CellStart;
  422. Write('Version');
  423. CellNext;
  424. ComboBoxFromQuery('version','SELECT TV_ID,TV_VERSION FROM TESTVERSION ORDER BY TV_VERSION DESC',FVERSION);
  425. CellEnd;
  426. RowNext;
  427. CellStart;
  428. Write('Date');
  429. CellNext;
  430. If (FDate=0) then
  431. EmitInput('date','')
  432. else
  433. EmitInput('date',DateToStr(FDate));
  434. CellEnd;
  435. //if FDebug then
  436. begin
  437. RowNext;
  438. CellStart;
  439. Write('Submitter');
  440. CellNext;
  441. If (FSubmitter='') then
  442. EmitInput('submitter','')
  443. else
  444. EmitInput('submitter',FSubmitter);
  445. CellEnd;
  446. RowNext;
  447. CellStart;
  448. Write('Machine');
  449. CellNext;
  450. If (FMachine='') then
  451. EmitInput('machine','')
  452. else
  453. EmitInput('machine',FMachine);
  454. CellEnd;
  455. RowNext;
  456. CellStart;
  457. Write('Comment');
  458. CellNext;
  459. If (FComment='') then
  460. EmitInput('comment','')
  461. else
  462. EmitInput('comment',FComment);
  463. CellEnd;
  464. RowNext;
  465. CellStart;
  466. Write('Cond');
  467. CellNext;
  468. If (FCond='') then
  469. EmitInput('cond','')
  470. else
  471. EmitInput('cond',FCond);
  472. CellEnd;
  473. end;
  474. RowNext;
  475. CellStart;
  476. Write('Only failed tests');
  477. CellNext;
  478. EmitCheckBox('failedonly','1',FonlyFailed);
  479. CellEnd;
  480. RowNext;
  481. CellStart;
  482. Write('Hide skipped tests');
  483. CellNext;
  484. EmitCheckBox('noskipped','1',FNoSkipped);
  485. CellEnd;
  486. RowEnd;
  487. TableEnd;
  488. ParaGraphStart;
  489. EmitSubmitButton('','Search');
  490. EmitSubmitButton('action','View history');
  491. EmitResetButton('','Reset form');
  492. FormEnd;
  493. end;
  494. ShowRunOverview;
  495. end;
  496. Procedure TTestSuite.EmitHistoryForm;
  497. begin
  498. ConnectToDB;
  499. ContentType:='text/html';
  500. EmitContentType;
  501. EmitTitle(Title);
  502. With FHTMLWriter do
  503. begin
  504. HeaderStart(1);
  505. Write('View Test suite results');
  506. HeaderEnd(1);
  507. Write('Please specify search criteria:');
  508. ParagraphStart;
  509. FormStart(TestsuiteCGIURL,'');
  510. if FDebug then
  511. EmitHiddenVar('DEBUGCGI', '1');
  512. EmitHiddenVar('action','4');
  513. TableStart(2,true);
  514. RowStart;
  515. CellStart;
  516. Write('File:');
  517. CellNext;
  518. EmitInput('testfilename',FTestfilename);
  519. CellEnd;
  520. RowNext;
  521. (* CellStart;
  522. Write('FileID:');
  523. CellNext;
  524. EmitInput('testfileid',FTestfileid);
  525. CellEnd;
  526. RowNext; *)
  527. CellStart;
  528. Write('Operating system:');
  529. CellNext;
  530. ComboBoxFromQuery('os','SELECT TO_ID,TO_NAME FROM TESTOS ORDER BY TO_NAME',FOS);
  531. CellEnd;
  532. RowNext;
  533. CellStart;
  534. Write('Processor:');
  535. CellNext;
  536. ComboBoxFromQuery('cpu','SELECT TC_ID,TC_NAME FROM TESTCPU ORDER BY TC_NAME',FCPU);
  537. CellEnd;
  538. RowNext;
  539. CellStart;
  540. Write('Version');
  541. CellNext;
  542. ComboBoxFromQuery('version','SELECT TV_ID,TV_VERSION FROM TESTVERSION ORDER BY TV_VERSION DESC',FVERSION);
  543. CellEnd;
  544. RowNext;
  545. CellStart;
  546. Write('Date');
  547. CellNext;
  548. If (FDate=0) then
  549. EmitInput('date','')
  550. else
  551. EmitInput('date',DateToStr(FDate));
  552. CellEnd;
  553. RowNext;
  554. CellStart;
  555. Write('Submitter');
  556. CellNext;
  557. If (FSubmitter='') then
  558. EmitInput('submitter','')
  559. else
  560. EmitInput('submitter',FSubmitter);
  561. CellEnd;
  562. RowNext;
  563. CellStart;
  564. Write('Machine');
  565. CellNext;
  566. If (FMachine='') then
  567. EmitInput('machine','')
  568. else
  569. EmitInput('machine',FMachine);
  570. CellEnd;
  571. RowNext;
  572. CellStart;
  573. Write('Comment');
  574. CellNext;
  575. If (FComment='') then
  576. EmitInput('comment','')
  577. else
  578. EmitInput('comment',FComment);
  579. CellEnd;
  580. RowNext;
  581. CellStart;
  582. Write('Limit');
  583. CellNext;
  584. EmitInput('limit',IntToStr(FLimit));
  585. CellEnd;
  586. RowNext;
  587. CellStart;
  588. Write('Cond');
  589. CellNext;
  590. If (FCond='') then
  591. EmitInput('cond','')
  592. else
  593. EmitInput('cond',FCond);
  594. CellEnd;
  595. RowNext;
  596. CellStart;
  597. Write('Only failed tests');
  598. CellNext;
  599. EmitCheckBox('failedonly','1',FonlyFailed);
  600. CellEnd;
  601. RowNext;
  602. CellStart;
  603. Write('Hide skipped tests');
  604. CellNext;
  605. EmitCheckBox('noskipped','1',FNoSkipped);
  606. CellEnd;
  607. RowNext;
  608. CellStart;
  609. Write('List all tests');
  610. CellNext;
  611. EmitCheckBox('listall','1',FListAll);
  612. CellEnd;
  613. RowEnd;
  614. TableEnd;
  615. ParaGraphStart;
  616. EmitSubmitButton('','Search');
  617. EmitResetButton('','Reset form');
  618. FormEnd;
  619. end;
  620. end;
  621. procedure TTestSuite.EmitEnd;
  622. begin
  623. if not FNeedEnd then
  624. exit;
  625. AddResponseLn('</BODY>');
  626. AddResponseLn('</HTML>');
  627. end;
  628. procedure TTestSuite.GetOverviewRowAttr(Sender: TObject; var BGColor: String;
  629. var Align: THTMLAlign; var VAlign: THTMLValign; var CustomAttr: String);
  630. begin
  631. If ((Sender as TTAbleProducer).CurrentRow mod 2=0) then
  632. BGColor:='#EEEEEE'
  633. end;
  634. Function TTestSuite.CreateDataset(Qry : String) : TSQLQuery;
  635. begin
  636. Result:=TSQLQuery.Create(Self);
  637. With Result do
  638. begin
  639. Database:=FDB;
  640. Transaction := FTrans;
  641. SQL.Text:=Qry;
  642. end;
  643. end;
  644. Function TTestSuite.CreateTableProducer(DS : TDataset) :TTableProducer;
  645. begin
  646. Result:=TTableProducer.Create(Self);
  647. Result.Dataset:=DS;
  648. end;
  649. Procedure TTestSuite.DefaultTableFromQuery(Qry,Alink : String; IncludeRecordCount : Boolean);
  650. Var
  651. Q : TSQLQuery;
  652. begin
  653. If FDebug then
  654. Writeln('Query : '+Qry);
  655. Q:=CreateDataset(Qry);
  656. With Q do
  657. try
  658. Open;
  659. Try
  660. With CreateTableProducer(Q) do
  661. Try
  662. Border:=True;
  663. If (Alink<>'') then
  664. begin
  665. CreateColumns(Nil);
  666. If TableColumns.Count>0 then
  667. (TableColumns.Items[0] as TTableColumn).ActionURL:=ALink;
  668. end;
  669. CreateTable(Response);
  670. Finally
  671. Free;
  672. end;
  673. If IncludeRecordCount then
  674. FHTMLWriter.DumpLn(Format('<p>Record count: %d </p>',[Q.RecordCount]));
  675. Finally
  676. Close;
  677. end;
  678. finally
  679. Free;
  680. end;
  681. end;
  682. Procedure TTestSuite.ShowRunOverview;
  683. Const
  684. SOverview = 'SELECT TU_ID as ID,TU_DATE as Date,TC_NAME as CPU,TO_NAME as OS,'+
  685. 'TV_VERSION as Version,COUNT(TR_ID) as Count,'+
  686. '(TU_SUCCESSFULLYFAILED+TU_SUCCESFULLYCOMPILED+TU_SUCCESSFULLYRUN) AS OK,'+
  687. '(TU_FAILEDTOCOMPILE+TU_FAILEDTORUN+TU_FAILEDTOFAIL) as Failed,'+
  688. '(TU_SUCCESSFULLYFAILED+TU_SUCCESFULLYCOMPILED+TU_SUCCESSFULLYRUN+'+
  689. 'TU_FAILEDTOCOMPILE+TU_FAILEDTORUN+TU_FAILEDTOFAIL) as Total,'+
  690. 'TU_SUBMITTER as Submitter, TU_MACHINE as Machine, TU_COMMENT as Comment '+
  691. 'FROM TESTRESULTS,TESTRUN,TESTCPU,TESTOS,TESTVERSION '+
  692. 'WHERE '+
  693. '(TC_ID=TU_CPU_FK) AND '+
  694. '(TO_ID=TU_OS_FK) AND '+
  695. '(TV_ID=TU_VERSION_FK) AND '+
  696. '(TR_TESTRUN_FK=TU_ID) '+
  697. '%s '+
  698. 'GROUP BY TU_ID '+
  699. 'ORDER BY TU_ID DESC LIMIT %d';
  700. Var
  701. S,A,Qry : String;
  702. Q : TSQLQuery;
  703. begin
  704. S:='';
  705. If (FCPU<>'') and (GetCPUName(FCPU)<>'All') then
  706. S:=S+' AND (TU_CPU_FK='+FCPU+')';
  707. If (FVersion<>'') and (GetVersionName(FVersion)<>'All') then
  708. S:=S+' AND (TU_VERSION_FK='+FVERSION+')';
  709. if (FOS<>'') and (GetOSName(FOS)<>'All') then
  710. S:=S+' AND (TU_OS_FK='+FOS+')';
  711. If (Round(FDate)<>0) then
  712. S:=S+' AND (TU_DATE LIKE '''+FormatDateTime('YYYY-MM-DD',FDate)+'%'')';
  713. If FSubmitter<>'' then
  714. S:=S+' AND (TU_SUBMITTER='''+FSubmitter+''')';
  715. If FMachine<>'' then
  716. S:=S+' AND (TU_MACHINE='''+FMachine+''')';
  717. If FComment<>'' then
  718. S:=S+' AND (TU_COMMENT LIKE '''+Fcomment+''')';
  719. If FCond<>'' then
  720. S:=S+' AND ('+FCond+')';
  721. If FOnlyFailed then
  722. S:=S+' AND (TR_OK="-")';
  723. A:=SDetailsURL;
  724. If FOnlyFailed then
  725. A:=A+'&failedonly=1';
  726. If FNoSkipped then
  727. A:=A+'&noskipped=1';
  728. Qry:=Format(SOverview,[S,FLimit]);
  729. If FDebug then
  730. Writeln('Query : '+Qry);
  731. Q:=CreateDataset(Qry);
  732. With Q do
  733. try
  734. Open;
  735. Try
  736. With CreateTableProducer(Q) do
  737. Try
  738. Border:=True;
  739. OnGetRowAttributes:=@GetOverViewRowAttr;
  740. CreateColumns(Nil);
  741. TableColumns.ColumnByName('ID').ActionURL:=A;
  742. TableColumns.ColumnByNAme('Failed').OnGetCellContents:=@FormatFailedOverview;
  743. CreateTable(Response);
  744. Finally
  745. Free;
  746. end;
  747. FHTMLWriter.DumpLn(Format('<p>Record count: %d</p>',[Q.RecordCount]));
  748. Finally
  749. Close;
  750. end;
  751. finally
  752. Free;
  753. end;
  754. end;
  755. Function TTestSuite.GetOSName(ID : String) : String;
  756. begin
  757. if (ID<>'') then
  758. Result:=GetSingleTon('SELECT TO_NAME FROM TESTOS WHERE TO_ID='+ID);
  759. end;
  760. Function TTestSuite.GetTestFileName(ID : String) : String;
  761. begin
  762. if (ID<>'') then
  763. Result:=GetSingleTon('SELECT T_NAME FROM TESTS WHERE T_ID='+ID);
  764. end;
  765. Function TTestsuite.GetFailCount(RunID : longint) : string;
  766. begin
  767. if RunID<>0 then
  768. Result:=GetSingleTon('SELECT (TU_FAILEDTOCOMPILE + TU_FAILEDTOFAIL + TU_FAILEDTORUN) FROM TESTRUN WHERE TU_ID='+IntToStr(RunID));
  769. end;
  770. Function TTestSuite.GetCPUName(ID : String) : String;
  771. begin
  772. if (ID<>'') then
  773. Result:=GetSingleTon('SELECT TC_NAME FROM TESTCPU WHERE TC_ID='+ID);
  774. end;
  775. Function TTestSuite.GetVersionName(ID : String) : String;
  776. begin
  777. if (ID<>'') then
  778. Result:=GetSingleton('SELECT TV_VERSION FROM TESTVERSION WHERE TV_ID='+ID);
  779. end;
  780. Function TTestSuite.ShowRunData : Boolean;
  781. Const
  782. SGetRunData = 'SELECT TU_ID,TU_DATE,TC_NAME,TO_NAME,' +
  783. 'TU_SUBMITTER,TU_MACHINE,TU_COMMENT,TV_VERSION,'+
  784. '(TU_SUCCESSFULLYFAILED+TU_SUCCESFULLYCOMPILED+TU_SUCCESSFULLYRUN) AS OK,'+
  785. '(TU_FAILEDTOCOMPILE+TU_FAILEDTORUN+TU_FAILEDTOFAIL) as Failed,'+
  786. '(TU_SUCCESSFULLYFAILED+TU_SUCCESFULLYCOMPILED+TU_SUCCESSFULLYRUN+'+
  787. 'TU_FAILEDTOCOMPILE+TU_FAILEDTORUN+TU_FAILEDTOFAIL) as Total'+
  788. ' FROM TESTRUN,TESTCPU,TESTOS,TESTVERSION '+
  789. 'WHERE '+
  790. ' (TC_ID=TU_CPU_FK) AND '+
  791. ' (TO_ID=TU_OS_FK) AND '+
  792. ' (TV_ID=TU_VERSION_FK) AND '+
  793. ' (TU_ID=%s)';
  794. Var
  795. Q1,Q2 : TSQLQuery;
  796. F : TField;
  797. Date1, Date2: TDateTime;
  798. begin
  799. Result:=(FRunID<>'');
  800. If Result then
  801. begin
  802. Q1:=CreateDataset(Format(SGetRunData,[FRunID]));
  803. if Length(FCompareRunID) > 0 then
  804. Q2:=CreateDataset(Format(SGetRunData,[FCompareRunID]))
  805. else
  806. Q2:=nil;
  807. Try
  808. Q1.Open;
  809. if Q2 <> nil then
  810. Q2.Open;
  811. Result:=Not (Q1.EOF and Q1.BOF);
  812. If Result then
  813. With FHTMLWriter do
  814. begin
  815. FormStart(TestsuiteCGIURL,'get');
  816. EmitHiddenVar('action', '1');
  817. TableStart(3,true);
  818. RowStart;
  819. CellStart;
  820. Write('Run ID:');
  821. CellNext;
  822. EmitInput('run1id',FRunID);
  823. CellNext;
  824. EmitInput('run2id',FCompareRunID);
  825. CellEnd;
  826. RowNext;
  827. CellStart;
  828. Write('Operating system:');
  829. CellNext;
  830. Write(Q1.FieldByName('TO_NAME').AsString);
  831. CellNext;
  832. if Q2 <> nil then
  833. Write(Q2.FieldByName('TO_NAME').AsString);
  834. CellEnd;
  835. RowNext;
  836. CellStart;
  837. Write('Processor:');
  838. CellNext;
  839. Write(Q1.FieldByName('TC_NAME').AsString);
  840. CellNext;
  841. if Q2 <> nil then
  842. Write(Q2.FieldByName('TC_NAME').AsString);
  843. CellEnd;
  844. RowNext;
  845. CellStart;
  846. Write('Version:');
  847. CellNext;
  848. Write(Q1.FieldByNAme('TV_VERSION').AsString);
  849. CellNext;
  850. if Q2 <> nil then
  851. Write(Q2.FieldByNAme('TV_VERSION').AsString);
  852. CellEnd;
  853. RowNext;
  854. CellStart;
  855. Write('Fails/OK/Total:');
  856. CellNext;
  857. Write(Q1.FieldByName('Failed').AsString);
  858. Write('/'+Q1.FieldByName('OK').AsString);
  859. Write('/'+Q1.FieldByName('Total').AsString);
  860. CellNext;
  861. if Q2 <> nil then
  862. begin
  863. Write(Q2.FieldByName('Failed').AsString);
  864. Write('/'+Q2.FieldByName('Ok').AsString);
  865. Write('/'+Q2.FieldByName('Total').AsString);
  866. end;
  867. CellEnd;
  868. RowNext;
  869. CellStart;
  870. Write('Comment:');
  871. CellNext;
  872. Write(Q1.FieldByName('TU_COMMENT').AsString);
  873. CellNext;
  874. if Q2 <> nil then
  875. Write(Q2.FieldByName('TU_COMMENT').AsString);
  876. CellEnd;
  877. RowNext;
  878. CellStart;
  879. Write('Machine:');
  880. CellNext;
  881. Write(Q1.FieldByName('TU_MACHINE').AsString);
  882. CellNext;
  883. if Q2 <> nil then
  884. Write(Q2.FieldByName('TU_MACHINE').AsString);
  885. CellEnd;
  886. RowNext;
  887. CellStart;
  888. Write('Submitter:');
  889. CellNext;
  890. Write(Q1.FieldByName('TU_SUBMITTER').AsString);
  891. CellNext;
  892. if Q2 <> nil then
  893. Write(Q2.FieldByName('TU_SUBMITTER').AsString);
  894. CellEnd;
  895. RowNext;
  896. CellStart;
  897. Write('Date:');
  898. CellNext;
  899. F := Q1.FieldByName('TU_DATE');
  900. Date1 := F.AsDateTime;
  901. Write(F.AsString);
  902. CellNext;
  903. if Q2 <> nil then
  904. begin
  905. F := Q2.FieldByName('TU_DATE');
  906. Date2 := F.AsDateTime;
  907. Write(F.AsString);
  908. end;
  909. CellEnd;
  910. RowEnd;
  911. TableEnd;
  912. ParagraphStart;
  913. EmitCheckBox('noskipped','1',FNoSkipped);
  914. Write(' Hide skipped tests');
  915. ParagraphEnd;
  916. ParagraphStart;
  917. EmitCheckBox('failedonly','1',FonlyFailed);
  918. Write(' Hide successful tests');
  919. ParagraphEnd;
  920. ParaGraphStart;
  921. EmitSubmitButton('','Show/Compare');
  922. EmitResetButton('','Reset form');
  923. ParagraphEnd;
  924. FormEnd;
  925. { give warning if dates reversed }
  926. if (Q2 <> nil) and (Date1 > Date2) then
  927. begin
  928. ParagraphStart;
  929. Write('Warning: testruns are not compared in chronological order.');
  930. ParagraphEnd;
  931. end;
  932. end;
  933. Finally
  934. Q1.Close;
  935. Q1.Free;
  936. if Q2 <> nil then
  937. begin
  938. Q2.Close;
  939. Q2.Free;
  940. end;
  941. end;
  942. end;
  943. end;
  944. Procedure TTestSuite.ShowRunResults;
  945. Var
  946. S : String;
  947. Qry : String;
  948. Q : TSQLQuery;
  949. FL : String;
  950. begin
  951. ConnectToDB;
  952. ContentType:='text/html';
  953. EmitContentType;
  954. EmitTitle(Title+' : Search Results');
  955. With FHTMLWriter do
  956. begin
  957. HeaderStart(1);
  958. Write('Test suite results for run '+FRunID);
  959. HeaderEnd(1);
  960. HeaderStart(2);
  961. Write('Test run data : ');
  962. HeaderEnd(2);
  963. If ShowRunData then
  964. begin
  965. HeaderStart(2);
  966. Write('Detailed test run results:');
  967. FL:='';
  968. If FOnlyFailed or FNoSkipped then
  969. begin
  970. FL:='';
  971. If FOnlyFailed then
  972. FL:='successful';
  973. if FNoSkipped then
  974. begin
  975. If (FL<>'') then
  976. FL:=FL+' and ';
  977. FL:=FL+'skipped';
  978. end;
  979. Write(' ('+FL+' tests are hidden)');
  980. end;
  981. HeaderEnd(2);
  982. ParaGraphStart;
  983. S:='SELECT T_ID as Id,T_NAME as Filename,TR_SKIP as Skipped'
  984. +',TR_OK as OK,TR_RESULT as Result'
  985. +' FROM TESTRESULTS,TESTS'
  986. +' WHERE (TR_TEST_FK=T_ID) AND (TR_TESTRUN_FK='+FRunID+') ';
  987. If FOnlyFailed then
  988. S:=S+' AND (TR_OK="-")';
  989. If FNoSkipped then
  990. S:=S+' AND (TR_SKIP="-")';
  991. S:=S+' ORDER BY TR_ID ';
  992. Qry:=S;
  993. If FDebug then
  994. begin
  995. Writeln('Query : '+Qry);
  996. Flush(stdout);
  997. end;
  998. FRunCount:=0;
  999. FRunSkipCount:=0;
  1000. FRunFailedCount:=0;
  1001. Q:=CreateDataset(Qry);
  1002. With Q do
  1003. try
  1004. Open;
  1005. while not EOF do
  1006. Next;
  1007. RecNo:=0;
  1008. DumpLn(Format('<p>Record count: %d </p>',[Q.RecordCount]));
  1009. Try
  1010. With CreateTableProducer(Q) do
  1011. Try
  1012. Border:=True;
  1013. FL:='Id,Filename';
  1014. If Not FNoSkipped then
  1015. FL:=FL+',Skipped';
  1016. If Not FOnlyFailed then
  1017. FL:=FL+',OK';
  1018. FL:=FL+',Result';
  1019. CreateColumns(FL);
  1020. OnGetRowAttributes:=@GetRunRowAttr;
  1021. TableColumns.ColumnByNAme('Id').OnGetCellContents:=
  1022. @FormatFileIDDetails;
  1023. TableColumns.ColumnByNAme('Filename').OnGetCellContents:=
  1024. @FormatFileDetails;
  1025. TableColumns.ColumnByNAme('Result').OnGetCellContents:=
  1026. @FormatTestResult;
  1027. //(TableColumns.Items[0] as TTableColumn).ActionURL:=ALink;
  1028. CreateTable(Response);
  1029. Finally
  1030. Free;
  1031. end;
  1032. Finally
  1033. Close;
  1034. end;
  1035. finally
  1036. Free;
  1037. end;
  1038. If Not (FRunCount=0) and not (FNoSkipped or FOnlyFailed) then
  1039. begin
  1040. ParaGraphStart;
  1041. TagStart('IMG',Format('Src="'+TestsuiteCGIURL+'?action=2&pietotal=%d&piefailed=%d&pieskipped=%d"',[FRunCount,FRunFailedCount,FRunSkipCount]));
  1042. end;
  1043. end
  1044. else
  1045. Write('No data for test run with ID: '+FRunID);
  1046. end;
  1047. end;
  1048. Procedure TTestSuite.ShowOneTest;
  1049. Var
  1050. S : String;
  1051. Qry : String;
  1052. Base, Category : string;
  1053. Q : TSQLQuery;
  1054. i : longint;
  1055. FieldName,FieldValue,
  1056. Log,Source : String;
  1057. Res : Boolean;
  1058. ver : known_versions;
  1059. begin
  1060. ConnectToDB;
  1061. ContentType:='text/html';
  1062. EmitContentType;
  1063. if FTestFileID='' then
  1064. FTestFileID:=GetSingleton('SELECT T_ID FROM TESTS WHERE T_NAME LIKE ''%'+
  1065. FTestFileName+'%''');
  1066. if FTestFileID<>'' then
  1067. FTestFileName:=GetTestFileName(FTestFileID);
  1068. EmitTitle(Title+' : File '+FTestFileName+' Results');
  1069. With FHTMLWriter do
  1070. begin
  1071. HeaderStart(1);
  1072. Write('Test suite results for test file '+FTestFileName);
  1073. HeaderEnd(1);
  1074. HeaderStart(2);
  1075. Write('Test run data : ');
  1076. HeaderEnd(2);
  1077. if FRunID<>'' then
  1078. begin
  1079. Res:=ShowRunData;
  1080. Res:=true;
  1081. end
  1082. else
  1083. begin
  1084. // This is useless as it is now
  1085. // It should be integrated into a form probably PM
  1086. Write('Only failed tests');
  1087. EmitCheckBox('failedonly','1',FonlyFailed);
  1088. Write('Hide skipped tests');
  1089. EmitCheckBox('noskipped','1',FNoSkipped);
  1090. Res:=true;
  1091. end;
  1092. If Res then
  1093. begin
  1094. HeaderStart(2);
  1095. Write('Test file "'+FTestFileName+'" information:');
  1096. HeaderEnd(2);
  1097. ParaGraphStart;
  1098. if FTestFileID<>'' then
  1099. S:='SELECT * FROM TESTS WHERE T_ID='+FTestFileID
  1100. else
  1101. S:='SELECT * FROM TESTS WHERE T_NAME='+FTestFileName;
  1102. Q:=CreateDataSet(S);
  1103. With Q do
  1104. Try
  1105. Open;
  1106. Try
  1107. For i:=0 to FieldCount-1 do
  1108. begin
  1109. FieldValue:=Fields[i].AsString;
  1110. FieldName:=Fields[i].DisplayName;
  1111. if (FieldValue<>'') and (FieldValue<>'-') and
  1112. (FieldName<>'T_NAME') and (FieldName<>'T_SOURCE') then
  1113. begin
  1114. if (FieldValue='+') then
  1115. Write('Flag ');
  1116. Write(FieldName);
  1117. Write(' ');
  1118. if FieldValue='+' then
  1119. Write(' set')
  1120. else
  1121. Write(FieldValue);
  1122. DumpLn('<BR>');
  1123. end;
  1124. end;
  1125. Finally
  1126. Close;
  1127. end;
  1128. Finally
  1129. Free;
  1130. end;
  1131. ParaGraphEnd;
  1132. HeaderStart(2);
  1133. Write('Detailed test run results:');
  1134. HeaderEnd(2);
  1135. ParaGraphStart;
  1136. S:='SELECT TR_ID,TR_TESTRUN_FK,TR_TEST_FK,TR_OK, TR_SKIP,TR_RESULT '
  1137. //S:='SELECT * '
  1138. +' FROM TESTRESULTS '
  1139. +' WHERE (TR_TEST_FK='+FTestFileID+')';
  1140. If FOnlyFailed then
  1141. S:=S+' AND (TR_OK="-")';
  1142. if Fcomparerunid<>'' then
  1143. S:=S+' AND ((TR_TESTRUN_FK='+Frunid+') OR '+
  1144. '(TR_TESTRUN_FK='+Fcomparerunid+'))'
  1145. else if Frunid<>'' then
  1146. S:=S+' AND (TR_TESTRUN_FK='+Frunid+')'
  1147. else
  1148. S:=S+' ORDER BY TR_TESTRUN_FK DESC LIMIT '+IntToStr(FLimit);
  1149. Qry:=S;
  1150. If FDebug then
  1151. begin
  1152. Writeln('Query : '+Qry);
  1153. Flush(stdout);
  1154. end;
  1155. FRunCount:=0;
  1156. FRunSkipCount:=0;
  1157. FRunFailedCount:=0;
  1158. Q:=CreateDataset(Qry);
  1159. With Q do
  1160. try
  1161. Open;
  1162. Try
  1163. With CreateTableProducer(Q) do
  1164. Try
  1165. Border:=True;
  1166. //FL:='TR_ID,TR_TESTRUN_FK,T_NAME,T_CPU,T_VERSION';
  1167. CreateColumns(Nil);
  1168. TableColumns.Delete(TableColumns.ColumnByName('TR_TEST_FK').Index);
  1169. TableColumns.ColumnByNAme('TR_TESTRUN_FK').OnGetCellContents:=
  1170. @FormatTestRunOverview;
  1171. //OnGetRowAttributes:=@GetRunRowAttr;
  1172. TableColumns.ColumnByNAme('TR_RESULT').OnGetCellContents:=
  1173. @FormatTestResult;
  1174. //(TableColumns.Items[0] as TTableColumn).ActionURL:=ALink;
  1175. CreateTable(Response);
  1176. Finally
  1177. Free;
  1178. end;
  1179. DumpLn(Format('<p>Record count: %d </p>',[Q.RecordCount]));
  1180. Finally
  1181. Close;
  1182. end;
  1183. finally
  1184. Free;
  1185. end;
  1186. //If FDebug then
  1187. Category:='1';
  1188. if FRunId<>'' then
  1189. begin
  1190. Category:=getsingleton('select TU_CATEGORY_FK from TESTRUN where TU_ID='+FRunId);
  1191. FVersionBranch:=GetVersionName(getsingleton('select TU_VERSION_FK from TESTRUN where TU_ID='+fRunId));
  1192. log:='';
  1193. Try
  1194. log:=getsingleton('select TR_LOG from TESTRESULTS where (TR_TEST_FK='+ftestfileid
  1195. +') and (TR_TESTRUN_FK='+frunid+')');
  1196. if Log<>'' then
  1197. begin
  1198. HeaderStart(2);
  1199. Write('Log of '+FRunId+':');
  1200. HeaderEnd(2);
  1201. PreformatStart;
  1202. system.Write(Log);
  1203. system.flush(output);
  1204. PreformatEnd;
  1205. end;
  1206. Finally
  1207. if Log='' then
  1208. begin
  1209. HeaderStart(2);
  1210. Write('No log of '+FRunId+'.');
  1211. HeaderEnd(2);
  1212. end;
  1213. end;
  1214. end;
  1215. if FCompareRunId<>'' then
  1216. begin
  1217. log:='';
  1218. Try
  1219. log:=getsingleton('select TR_LOG from TESTRESULTS where (TR_TEST_FK='+ftestfileid
  1220. +') and (TR_TESTRUN_FK='+fcomparerunid+')');
  1221. if Log<>'' then
  1222. begin
  1223. HeaderStart(2);
  1224. Write('Log of '+FCompareRunId+':');
  1225. HeaderEnd(2);
  1226. PreformatStart;
  1227. system.Write(Log);
  1228. system.flush(output);
  1229. PreformatEnd;
  1230. end;
  1231. Finally
  1232. if Log='' then
  1233. begin
  1234. HeaderStart(2);
  1235. Write('No log of '+FCompareRunId+'.');
  1236. HeaderEnd(2);
  1237. end;
  1238. end;
  1239. end;
  1240. if FDebug then
  1241. Write('After Log.');
  1242. Source:='';
  1243. Try
  1244. Source:=getsingleton('select T_SOURCE from TESTS where T_ID='+ftestfileid);
  1245. if Source<>'' then
  1246. begin
  1247. HeaderStart(2);
  1248. Write('Source:');
  1249. HeaderEnd(2);
  1250. PreformatStart;
  1251. system.Write(Source);
  1252. system.flush(output);
  1253. PreformatEnd;
  1254. end;
  1255. Finally
  1256. Base:='trunk';
  1257. if FVersionBranch<>'' then
  1258. begin
  1259. // Test all but last version, which is assumed to be trunk
  1260. for ver:=low(known_versions) to pred(high(known_versions)) do
  1261. if ver_string[ver]=FVersionBranch then
  1262. begin
  1263. base:=ver_branch[ver];
  1264. break;
  1265. end;
  1266. end;
  1267. FViewVCURL:=ViewURL+Base;
  1268. if Category='1' then
  1269. FViewVCUrl:=FViewVCURL+TestsSubDir
  1270. else
  1271. begin
  1272. FViewVCUrl:=FViewVCURL+DataBaseSubDir;
  1273. // This assumes that type TAnyType is
  1274. // defined in anytype.pas source PM
  1275. if pos('/',FTestFileName)>0 then
  1276. FTestfilename:=lowercase(copy(FTestFilename,2,pos('/',FTestFilename)-2)+'.pas');
  1277. end;
  1278. if Source='' then
  1279. begin
  1280. HeaderStart(3);
  1281. DumpLn('<P>No Source in TestSuite DataBase.</P>');
  1282. DumpLn('Link to SVN view of '+
  1283. '<A HREF="'+FViewVCURL+FTestFileName+'?view=markup'+
  1284. '" TARGET="fpc_source"> '+FTestFileName+'</A> source. ');
  1285. HeaderEnd(3);
  1286. end
  1287. else
  1288. begin
  1289. HeaderStart(3);
  1290. DumpLn('Link to SVN view of '+
  1291. '<A HREF="'+FViewVCURL+FTestFileName+'?view=markup'+
  1292. '" TARGET="fpc_source"> '+FTestFileName+'</A> source. ');
  1293. HeaderEnd(3);
  1294. end;
  1295. end;
  1296. if FDebug then
  1297. Write('After Source.');
  1298. end
  1299. else
  1300. Write(Format('No data for test file with ID: %s',[FTestFileID]));
  1301. end;
  1302. end;
  1303. Procedure TTestSuite.ShowHistory;
  1304. Const
  1305. MaxCombo = 50;
  1306. Type
  1307. StatusLongintArray = Array [TTestStatus] of longint;
  1308. StatusDateTimeArray = Array [TTestStatus] of TDateTime;
  1309. AStatusLA = Array[1..MaxCombo] of StatusLongintArray;
  1310. AStatusDTA = Array[1..MaxCombo] of StatusDateTimeArray;
  1311. PStatusLA = ^AStatusLA;
  1312. PStatusDTA = ^AStatusDTA;
  1313. Var
  1314. S,FL,cpu,version,os : String;
  1315. date : TDateTime;
  1316. Qry : String;
  1317. Base, Category : string;
  1318. Q : TSQLQuery;
  1319. i,run_id,os_id,version_id,cpu_id : longint;
  1320. run_ind,os_ind,version_ind,cpu_ind,
  1321. ok_ind,skip_ind,result_ind,date_ind : longint;
  1322. os_size, cpu_size, version_size : longint;
  1323. os_last, cpu_last, version_last : longint;
  1324. error : word;
  1325. OK_count, not_OK_count,resi,
  1326. total_count, skip_count, not_skip_count : longint;
  1327. TS : TTestStatus;
  1328. result_count : StatusLongintArray;
  1329. os_count,cpu_count,version_count: PStatusLA;
  1330. first_date, last_date : array[TTestStatus] of TDateTime;
  1331. first_date_id, last_date_id : array[TTestStatus] of longint;
  1332. os_first_date, os_last_date,
  1333. cpu_first_date, cpu_last_date,
  1334. version_first_date, version_last_date : PStatusDTA;
  1335. os_first_date_id, os_last_date_id,
  1336. cpu_first_date_id, cpu_last_date_id,
  1337. version_first_date_id, version_last_date_id : PStatusLA;
  1338. FieldName,FieldValue,
  1339. Log,Source : String;
  1340. Res : Boolean;
  1341. ver : known_versions;
  1342. begin
  1343. os_count:=nil;
  1344. cpu_count:=nil;
  1345. version_count:=nil;
  1346. ConnectToDB;
  1347. ContentType:='text/html';
  1348. EmitContentType;
  1349. if FTestFileID='' then
  1350. FTestFileID:=GetSingleton('SELECT T_ID FROM TESTS WHERE T_NAME LIKE ''%'+
  1351. FTestFileName+'%''');
  1352. if FTestFileID<>'' then
  1353. FTestFileName:=GetTestFileName(FTestFileID);
  1354. EmitTitle(Title+' : File '+FTestFileName+' Results');
  1355. With FHTMLWriter do
  1356. begin
  1357. HeaderStart(1);
  1358. Write('Test suite results for test file '+FTestFileName);
  1359. HeaderEnd(1);
  1360. HeaderStart(2);
  1361. Write('Test run data : ');
  1362. HeaderEnd(2);
  1363. if FRunID<>'' then
  1364. begin
  1365. Res:=ShowRunData;
  1366. Res:=true;
  1367. end
  1368. else
  1369. begin
  1370. // This is useless as it is now
  1371. // It should be integrated into a form probably PM
  1372. //Write('Only failed tests');
  1373. //EmitCheckBox('failedonly','1',FonlyFailed);
  1374. //Write('Hide skipped tests');
  1375. //EmitCheckBox('noskipped','1',FNoSkipped);
  1376. Res:=true;
  1377. EmitHistoryForm;
  1378. end;
  1379. If Res then
  1380. begin
  1381. HeaderStart(2);
  1382. Write('Test file "'+FTestFileName+'" information:');
  1383. HeaderEnd(2);
  1384. ParaGraphStart;
  1385. S:='SELECT * FROM TESTS WHERE T_ID='+FTestFileID;
  1386. Q:=CreateDataSet(S);
  1387. With Q do
  1388. Try
  1389. Open;
  1390. Try
  1391. For i:=0 to FieldCount-1 do
  1392. begin
  1393. FieldValue:=Fields[i].AsString;
  1394. FieldName:=Fields[i].DisplayName;
  1395. if (FieldValue<>'') and (FieldValue<>'-') and
  1396. (FieldName<>'T_NAME') and (FieldName<>'T_SOURCE') then
  1397. begin
  1398. if (FieldValue='+') then
  1399. Write('Flag ');
  1400. Write(FieldName);
  1401. Write(' ');
  1402. if FieldValue='+' then
  1403. Write(' set')
  1404. else
  1405. Write(FieldValue);
  1406. DumpLn('<BR>');
  1407. end;
  1408. end;
  1409. Finally
  1410. Close;
  1411. end;
  1412. Finally
  1413. Free;
  1414. end;
  1415. ParaGraphEnd;
  1416. HeaderStart(2);
  1417. Write('Detailed test run results:');
  1418. HeaderEnd(2);
  1419. ParaGraphStart;
  1420. S:='SELECT TR_ID,TR_TESTRUN_FK,TR_TEST_FK,TR_OK, TR_SKIP,TR_RESULT '
  1421. //S:='SELECT * '
  1422. +',TC_NAME AS CPU, TV_VERSION AS VERSION, TO_NAME AS OS'
  1423. +',TU_ID,TU_DATE,TU_SUBMITTER,TU_MACHINE,TU_COMMENT '
  1424. +',TO_ID,TC_ID,TV_ID'
  1425. +' FROM TESTRUN '
  1426. +' LEFT JOIN TESTRESULTS ON (TR_TESTRUN_FK=TU_ID)'
  1427. +' LEFT JOIN TESTOS ON (TU_OS_FK=TO_ID)'
  1428. +' LEFT JOIN TESTCPU ON (TU_CPU_FK=TC_ID)'
  1429. +' LEFT JOIN TESTVERSION ON (TU_VERSION_FK=TV_ID)'
  1430. +' WHERE (TR_TEST_FK='+FTestFileID+')';
  1431. If FOnlyFailed then
  1432. S:=S+' AND (TR_OK="-")';
  1433. If FNoSkipped then
  1434. S:=S+' AND (TR_SKIP="-")';
  1435. If (FCPU<>'') and (GetCPUName(FCPU)<>'All') then
  1436. begin
  1437. S:=S+' AND (TU_CPU_FK='+FCPU+')';
  1438. cpu_size:=0;
  1439. end
  1440. else
  1441. begin
  1442. cpu_last:=StrToInt(GetSingleton('SELECT COUNT(*) FROM TESTCPU'));
  1443. cpu_size:=Sizeof(StatusLongintArray)*(1+cpu_last);
  1444. cpu_count:=GetMem(cpu_size);
  1445. FillChar(cpu_count^,cpu_size,#0);
  1446. cpu_first_date_id:=GetMem(cpu_size);
  1447. FillChar(cpu_first_date_id^,cpu_size,#0);
  1448. cpu_last_date_id:=GetMem(cpu_size);
  1449. FillChar(cpu_last_date_id^,cpu_size,#0);
  1450. cpu_first_date:=GetMem(cpu_last*SizeOf(StatusDateTimeArray));
  1451. FillChar(cpu_first_date^,cpu_last*Sizeof(StatusDateTimeArray),#0);
  1452. cpu_last_date:=GetMem(cpu_last*SizeOf(StatusDateTimeArray));
  1453. FillChar(cpu_last_date^,cpu_last*Sizeof(StatusDateTimeArray),#0);
  1454. end;
  1455. If (FVersion<>'') and (GetVersionName(FVersion)<>'All') then
  1456. begin
  1457. S:=S+' AND (TU_VERSION_FK='+FVERSION+')';
  1458. version_size:=0;
  1459. end
  1460. else
  1461. begin
  1462. version_last:=StrToInt(GetSingleton('SELECT COUNT(*) FROM TESTVERSION'));
  1463. version_size:=Sizeof(StatusLongintArray)*(1+version_last);
  1464. version_count:=GetMem(version_size);
  1465. FillChar(version_count^,version_size,#0);
  1466. version_first_date_id:=GetMem(version_size);
  1467. FillChar(version_first_date_id^,version_size,#0);
  1468. version_last_date_id:=GetMem(version_size);
  1469. FillChar(version_last_date_id^,version_size,#0);
  1470. version_first_date:=GetMem(version_last*SizeOf(StatusDateTimeArray));
  1471. FillChar(version_first_date^,version_last*Sizeof(StatusDateTimeArray),#0);
  1472. version_last_date:=GetMem(version_last*SizeOf(StatusDateTimeArray));
  1473. FillChar(version_last_date^,version_last*Sizeof(StatusDateTimeArray),#0);
  1474. end;
  1475. if (FOS<>'') and (GetOSName(FOS)<>'All') then
  1476. begin
  1477. S:=S+' AND (TU_OS_FK='+FOS+')';
  1478. os_size:=0;
  1479. end
  1480. else
  1481. begin
  1482. os_last:=StrToInt(GetSingleton('SELECT COUNT(*) FROM TESTOS'));
  1483. os_size:=Sizeof(StatusLongintArray)*(1+os_last);
  1484. os_count:=GetMem(os_size);
  1485. FillChar(os_count^,os_size,#0);
  1486. os_first_date_id:=GetMem(os_size);
  1487. FillChar(os_first_date_id^,os_size,#0);
  1488. os_last_date_id:=GetMem(os_size);
  1489. FillChar(os_last_date_id^,os_size,#0);
  1490. os_first_date:=GetMem(os_last*SizeOf(StatusDateTimeArray));
  1491. FillChar(os_first_date^,os_last*Sizeof(StatusDateTimeArray),#0);
  1492. os_last_date:=GetMem(os_last*SizeOf(StatusDateTimeArray));
  1493. FillChar(os_last_date^,os_last*Sizeof(StatusDateTimeArray),#0);
  1494. end;
  1495. If FSubmitter<>'' then
  1496. S:=S+' AND (TU_SUBMITTER='''+FSubmitter+''')';
  1497. If FMachine<>'' then
  1498. S:=S+' AND (TU_MACHINE='''+FMachine+''')';
  1499. If FComment<>'' then
  1500. S:=S+' AND (TU_COMMENT LIKE '''+FComment+''')';
  1501. if FDATE<>0 then
  1502. S:=S+' AND (TU_DATE >= '''+FormatDateTime('YYYY-MM-DD',FDate)+''')';
  1503. S:=S+' ORDER BY TU_ID DESC';
  1504. if FDATE=0 then
  1505. S:=S+' LIMIT '+IntToStr(FLimit);
  1506. Qry:=S;
  1507. If FDebug then
  1508. begin
  1509. Writeln(system.stdout,'Query : '+Qry);
  1510. system.Flush(system.stdout);
  1511. end;
  1512. FRunCount:=0;
  1513. FRunSkipCount:=0;
  1514. FRunFailedCount:=0;
  1515. Q:=CreateDataset(Qry);
  1516. With Q do
  1517. try
  1518. Open;
  1519. while not EOF do
  1520. Next;
  1521. DumpLn(Format('<p>Record count: %d </p>',[Q.RecordCount]));
  1522. if RecordCount>0 then
  1523. RecNo:=0;
  1524. Try
  1525. if FDebug then
  1526. begin
  1527. Writeln(stdout,'FieldKind=',Fields[0].FieldKind);
  1528. Writeln(stdout,'DataType=',Fields[0].DataType);
  1529. system.flush(stdout);
  1530. end;
  1531. total_count:=0;
  1532. OK_count:=0;
  1533. not_OK_count:=0;
  1534. skip_count:=0;
  1535. not_skip_count:=0;
  1536. fillchar(Result_Count,Sizeof(Result_count),#0);
  1537. ok_ind:=FieldByName('TR_OK').Index;
  1538. skip_ind:=FieldBYName('TR_SKIP').Index;
  1539. result_ind:=FieldByName('TR_RESULT').Index;
  1540. cpu_ind:=FieldByName('TC_ID').Index;
  1541. os_ind:=FieldByName('TO_ID').Index;
  1542. version_ind:=FieldByName('TV_ID').Index;
  1543. date_ind:=FieldByName('TU_DATE').Index;
  1544. run_ind:=FieldByName('TU_ID').Index;
  1545. For i:=0 to Q.RecordCount-1 do
  1546. begin
  1547. Q.RecNo:=i;
  1548. inc(total_count);
  1549. S:=Fields[ok_ind].AsString;
  1550. if S='+' then
  1551. inc(OK_count)
  1552. else
  1553. inc(not_OK_count);
  1554. S:=Fields[skip_ind].AsString;
  1555. if S='+' then
  1556. inc(skip_count)
  1557. else
  1558. inc(not_skip_count);
  1559. S:=Fields[result_ind].AsString;
  1560. cpu:=Fields[cpu_ind].ASString;
  1561. version:=Fields[version_ind].AsString;
  1562. os:=Fields[os_ind].AsString;
  1563. date:=Fields[date_ind].ASDateTime;
  1564. os_id:=Fields[os_ind].AsLongint;
  1565. cpu_id:=Fields[cpu_ind].AsLongint;
  1566. version_id:=Fields[version_ind].AsLongint;
  1567. system.val(S,resi,error);
  1568. run_id:=Fields[run_ind].ASLongint;
  1569. if (error=0) and (Resi>=longint(FirstStatus)) and
  1570. (Resi<=longint(LastStatus)) then
  1571. begin
  1572. TS:=TTestStatus(Resi);
  1573. if Result_count[TS]=0 then
  1574. begin
  1575. first_date[TS]:=date;
  1576. last_date[TS]:=date;
  1577. first_date_id[TS]:=run_id;
  1578. last_date_id[TS]:=run_id;
  1579. end
  1580. else
  1581. begin
  1582. if (date>last_date[TS]) then
  1583. begin
  1584. last_date[TS]:=date;
  1585. last_date_id[TS]:=run_id;
  1586. end;
  1587. if date<first_date[TS] then
  1588. begin
  1589. first_date[TS]:=date;
  1590. first_date_id[TS]:=run_id;
  1591. end;
  1592. end;
  1593. inc(Result_count[TS]);
  1594. if assigned(cpu_count) and (cpu_id<=cpu_last) then
  1595. begin
  1596. if cpu_count^[cpu_id,TS]=0 then
  1597. begin
  1598. cpu_first_date^[cpu_id,TS]:=date;
  1599. cpu_last_date^[cpu_id,TS]:=date;
  1600. cpu_first_date_id^[cpu_id,TS]:=run_id;
  1601. cpu_last_date_id^[cpu_id,TS]:=run_id;
  1602. end
  1603. else
  1604. begin
  1605. if (date>cpu_last_date^[cpu_id,TS]) then
  1606. begin
  1607. cpu_last_date^[cpu_id,TS]:=date;
  1608. cpu_last_date_id^[cpu_id,TS]:=run_id;
  1609. end;
  1610. if date<cpu_first_date^[cpu_id,TS] then
  1611. begin
  1612. cpu_first_date^[cpu_id,TS]:=date;
  1613. cpu_first_date_id^[cpu_id,TS]:=run_id;
  1614. end;
  1615. end;
  1616. inc(cpu_count^[cpu_id,TS]);
  1617. end;
  1618. if assigned(os_count) and (os_id<=os_last) then
  1619. begin
  1620. if os_count^[os_id,TS]=0 then
  1621. begin
  1622. os_first_date^[os_id,TS]:=date;
  1623. os_last_date^[os_id,TS]:=date;
  1624. os_first_date_id^[os_id,TS]:=run_id;
  1625. os_last_date_id^[os_id,TS]:=run_id;
  1626. end
  1627. else
  1628. begin
  1629. if (date>os_last_date^[os_id,TS]) then
  1630. begin
  1631. os_last_date^[os_id,TS]:=date;
  1632. os_last_date_id^[os_id,TS]:=run_id;
  1633. end;
  1634. if date<os_first_date^[os_id,TS] then
  1635. begin
  1636. os_first_date^[os_id,TS]:=date;
  1637. os_first_date_id^[os_id,TS]:=run_id;
  1638. end;
  1639. end;
  1640. inc(os_count^[os_id,TS]);
  1641. end;
  1642. if assigned(version_count) and (version_id<=version_last) then
  1643. begin
  1644. if version_count^[version_id,TS]=0 then
  1645. begin
  1646. version_first_date^[version_id,TS]:=date;
  1647. version_last_date^[version_id,TS]:=date;
  1648. version_first_date_id^[version_id,TS]:=run_id;
  1649. version_last_date_id^[version_id,TS]:=run_id;
  1650. end
  1651. else
  1652. begin
  1653. if (date>version_last_date^[version_id,TS]) then
  1654. begin
  1655. version_last_date^[version_id,TS]:=date;
  1656. version_last_date_id^[version_id,TS]:=run_id;
  1657. end;
  1658. if date<version_first_date^[version_id,TS] then
  1659. begin
  1660. version_first_date^[version_id,TS]:=date;
  1661. version_first_date_id^[version_id,TS]:=run_id;
  1662. end;
  1663. end;
  1664. inc(version_count^[version_id,TS]);
  1665. end;
  1666. end
  1667. else if Fdebug then
  1668. writeln(stdout,'Error for Result, S=',S);
  1669. end;
  1670. DumpLn(Format('<p>Total = %d </p>',[total_count]));
  1671. if Total_count > 0 then
  1672. DumpLn(Format('<p>OK=%d Percentage= %3.2f </p>',[OK_count,OK_count*100/total_count]));
  1673. if Skip_count > 0 then
  1674. DumpLn(Format('<p>Skipped=%d Percentage= %3.2f </p>',[Skip_count,Skip_count*100/total_count]));
  1675. if total_count>0 then
  1676. begin
  1677. TableStart(5,True);
  1678. RowStart;
  1679. CellStart;
  1680. Write('Result type');
  1681. CellNext;
  1682. Write('Cat.');
  1683. CellNext;
  1684. Write('Count');
  1685. CellNext;
  1686. Write('Percentage');
  1687. CellNext;
  1688. Write('First date');
  1689. CellNext;
  1690. Write('Last Date');
  1691. CellEnd;
  1692. end;
  1693. For TS:=FirstStatus to LastStatus do
  1694. if Result_count[TS]>0 then
  1695. begin
  1696. RowNext;
  1697. CellStart;
  1698. Write(StatusText[TS]);
  1699. CellNext;
  1700. CellNext;
  1701. Write(Format('%d',[Result_count[TS]]));
  1702. CellNext;
  1703. Write(Format('%3.1f',[Result_count[TS]*100/total_count]));
  1704. CellNext;
  1705. DumpLn(FormatDetailURL(IntToStr(first_date_id[TS]),
  1706. DateTimeToStr(first_date[TS])));
  1707. Write(' '+GetFailCount(first_date_id[TS]));
  1708. CellNext;
  1709. DumpLn(FormatDetailURL(IntToStr(last_date_id[TS]),
  1710. DateTimeToStr(last_date[TS])));
  1711. Write(' '+GetFailCount(last_date_id[TS]));
  1712. CellEnd;
  1713. if assigned(cpu_count) then
  1714. begin
  1715. for i:=1 to cpu_last do
  1716. if cpu_count^[i,TS]>0 then
  1717. begin
  1718. RowNext;
  1719. CellStart;
  1720. CellNext;
  1721. Write(GetSingleton('SELECT TC_NAME FROM TESTCPU WHERE TC_ID='+IntToStr(i)));
  1722. CellNext;
  1723. Write(Format('%d',[cpu_count^[i,TS]]));
  1724. CellNext;
  1725. Write(Format('%3.1f',[cpu_count^[i,TS]*100/result_count[TS]]));
  1726. CellNext;
  1727. DumpLn(FormatDetailURL(IntToStr(cpu_first_date_id^[i,TS]),
  1728. DateTimeToStr(cpu_first_date^[i,TS])));
  1729. Write(' '+GetFailCount(cpu_first_date_id^[i,TS]));
  1730. CellNext;
  1731. DumpLn(FormatDetailURL(IntToStr(cpu_last_date_id^[i,TS]),
  1732. DateTimeToStr(cpu_last_date^[i,TS])));
  1733. Write(' '+GetFailCount(cpu_last_date_id^[i,TS]));
  1734. CellEnd;
  1735. end;
  1736. end;
  1737. if assigned(os_count) then
  1738. begin
  1739. for i:=1 to os_last do
  1740. if os_count^[i,TS]>0 then
  1741. begin
  1742. RowNext;
  1743. CellStart;
  1744. CellNext;
  1745. Write(GetSingleton('SELECT TO_NAME FROM TESTOS WHERE TO_ID='+IntToStr(i)));
  1746. CellNext;
  1747. Write(Format('%d',[os_count^[i,TS]]));
  1748. CellNext;
  1749. Write(Format('%3.1f',[os_count^[i,TS]*100/result_count[TS]]));
  1750. CellNext;
  1751. DumpLn(FormatDetailURL(IntToStr(os_first_date_id^[i,TS]),
  1752. DateTimeToStr(os_first_date^[i,TS])));
  1753. Write(' '+GetFailCount(os_first_date_id^[i,TS]));
  1754. CellNext;
  1755. DumpLn(FormatDetailURL(IntToStr(os_last_date_id^[i,TS]),
  1756. DateTimeToStr(os_last_date^[i,TS])));
  1757. Write(' '+GetFailCount(os_last_date_id^[i,TS]));
  1758. CellEnd;
  1759. end;
  1760. end;
  1761. if assigned(version_count) then
  1762. begin
  1763. for i:=1 to version_last do
  1764. if version_count^[i,TS]>0 then
  1765. begin
  1766. RowNext;
  1767. CellStart;
  1768. CellNext;
  1769. Write(GetSingleton('SELECT TV_VERSION FROM TESTVERSION WHERE TV_ID='+IntToStr(i)));
  1770. CellNext;
  1771. Write(Format('%d',[version_count^[i,TS]]));
  1772. CellNext;
  1773. Write(Format('%3.1f',[version_count^[i,TS]*100/result_count[TS]]));
  1774. CellNext;
  1775. DumpLn(FormatDetailURL(IntToStr(version_first_date_id^[i,TS]),
  1776. DateTimeToStr(version_first_date^[i,TS])));
  1777. Write(' '+GetFailCount(version_first_date_id^[i,TS]));
  1778. CellNext;
  1779. DumpLn(FormatDetailURL(IntToStr(version_last_date_id^[i,TS]),
  1780. DateTimeToStr(version_last_date^[i,TS])));
  1781. Write(' '+GetFailCount(version_last_date_id^[i,TS]));
  1782. CellEnd;
  1783. end;
  1784. end;
  1785. end;
  1786. if total_count>0 then
  1787. begin
  1788. TableEnd;
  1789. RecNo:=0;
  1790. end;
  1791. If FDebug or FListAll then
  1792. begin
  1793. With CreateTableProducer(Q) do
  1794. Try
  1795. Border:=True;
  1796. FL:='TR_TESTRUN_FK,TU_DATE,TR_OK,TR_SKIP,TR_RESULT';
  1797. if FSubmitter='' then
  1798. FL:=FL+',TU_SUBMITTER';
  1799. if FMachine='' then
  1800. FL:=FL+',TU_MACHINE';
  1801. if Fcomment='' then
  1802. FL:=FL+',TU_COMMENT';
  1803. if (FOS='') or (GetOSName(FOS)='All') then
  1804. FL:=FL+',OS';
  1805. if (FCPU='') or (GetCPUName(FCPU)='All') then
  1806. FL:=FL+',CPU';
  1807. if (FVersion='') or (GetVersionName(FVersion)='All') then
  1808. FL:=FL+',VERSION';
  1809. CreateColumns(FL);
  1810. //TableColumns.Delete(TableColumns.ColumnByName('TR_TEST_FK').Index);
  1811. TableColumns.ColumnByNAme('TR_TESTRUN_FK').OnGetCellContents:=
  1812. @FormatTestRunOverview;
  1813. //OnGetRowAttributes:=@GetRunRowAttr;
  1814. TableColumns.ColumnByNAme('TR_RESULT').OnGetCellContents:=
  1815. @FormatTestResult;
  1816. //(TableColumns.Items[0] as TTableColumn).ActionURL:=ALink;
  1817. CreateTable(Response);
  1818. Finally
  1819. Free;
  1820. end;
  1821. end;
  1822. Finally
  1823. Close;
  1824. end;
  1825. finally
  1826. Free;
  1827. end;
  1828. //If FDebug then
  1829. Category:='1';
  1830. if FRunId<>'' then
  1831. begin
  1832. Category:=getsingleton('select TU_CATEGORY_FK from TESTRUN where TU_ID='+FRunId);
  1833. FVersionBranch:=GetVersionName(getsingleton('select TU_VERSION_FK from TESTRUN where TU_ID='+fRunId));
  1834. log:='';
  1835. Try
  1836. log:=getsingleton('select TR_LOG from TESTRESULTS where (TR_TEST_FK='+ftestfileid
  1837. +') and (TR_TESTRUN_FK='+frunid+')');
  1838. if Log<>'' then
  1839. begin
  1840. HeaderStart(2);
  1841. Write('Log of '+FRunId+':');
  1842. HeaderEnd(2);
  1843. PreformatStart;
  1844. system.Write(Log);
  1845. system.flush(output);
  1846. PreformatEnd;
  1847. end;
  1848. Finally
  1849. if Log='' then
  1850. begin
  1851. HeaderStart(2);
  1852. Write('No log of '+FRunId+'.');
  1853. HeaderEnd(2);
  1854. end;
  1855. end;
  1856. end;
  1857. if FCompareRunId<>'' then
  1858. begin
  1859. log:='';
  1860. Try
  1861. log:=getsingleton('select TR_LOG from TESTRESULTS where (TR_TEST_FK='+ftestfileid
  1862. +') and (TR_TESTRUN_FK='+fcomparerunid+')');
  1863. if Log<>'' then
  1864. begin
  1865. HeaderStart(2);
  1866. Write('Log of '+FCompareRunId+':');
  1867. HeaderEnd(2);
  1868. PreformatStart;
  1869. system.Write(Log);
  1870. system.flush(output);
  1871. PreformatEnd;
  1872. end;
  1873. Finally
  1874. if Log='' then
  1875. begin
  1876. HeaderStart(2);
  1877. Write('No log of '+FCompareRunId+'.');
  1878. HeaderEnd(2);
  1879. end;
  1880. end;
  1881. end;
  1882. if FDebug then
  1883. Write('After Log.');
  1884. Source:='';
  1885. Try
  1886. Source:=getsingleton('select T_SOURCE from TESTS where T_ID='+ftestfileid);
  1887. if Source<>'' then
  1888. begin
  1889. HeaderStart(2);
  1890. Write('Source:');
  1891. HeaderEnd(2);
  1892. PreformatStart;
  1893. system.Write(Source);
  1894. system.flush(output);
  1895. PreformatEnd;
  1896. end;
  1897. Finally
  1898. Base:='trunk';
  1899. if FVersionBranch<>'' then
  1900. begin
  1901. // Test all but last version, which is assumed to be trunk
  1902. for ver:=low(known_versions) to pred(high(known_versions)) do
  1903. if ver_string[ver]=FVersionBranch then
  1904. begin
  1905. base:=ver_branch[ver];
  1906. break;
  1907. end;
  1908. end;
  1909. FViewVCURL:=ViewURL+Base;
  1910. if Category='1' then
  1911. FViewVCUrl:=FViewVCURL+TestsSubDir
  1912. else
  1913. begin
  1914. FViewVCUrl:=FViewVCURL+DataBaseSubDir;
  1915. // This assumes that type TAnyType is
  1916. // defined in anytype.pas source PM
  1917. if pos('/',FTestFileName)>0 then
  1918. FTestfilename:=lowercase(copy(FTestFilename,2,pos('/',FTestFilename)-2)+'.pas');
  1919. end;
  1920. if Source='' then
  1921. begin
  1922. HeaderStart(3);
  1923. DumpLn('<P>No Source in TestSuite DataBase.</P>');
  1924. DumpLn('Link to SVN view of '+
  1925. '<A HREF="'+FViewVCURL+FTestFileName+'?view=markup'+
  1926. '" TARGET="fpc_source"> '+FTestFileName+'</A> source. ');
  1927. HeaderEnd(3);
  1928. end
  1929. else
  1930. begin
  1931. HeaderStart(3);
  1932. DumpLn('Link to SVN view of '+
  1933. '<A HREF="'+FViewVCURL+FTestFileName+'?view=markup'+
  1934. '" TARGET="fpc_source"> '+FTestFileName+'</A> source. ');
  1935. HeaderEnd(3);
  1936. end;
  1937. end;
  1938. if FDebug then
  1939. Write('After Source.');
  1940. end
  1941. else
  1942. Write(Format('No data for test file with ID: %s',[FTestFileID]));
  1943. end;
  1944. if assigned(os_count) then
  1945. begin
  1946. FreeMem(os_count);
  1947. FreeMem(os_first_date);
  1948. FreeMem(os_first_date_id);
  1949. FreeMem(os_last_date);
  1950. FreeMem(os_last_date_id);
  1951. end;
  1952. if assigned(cpu_count) then
  1953. begin
  1954. FreeMem(cpu_count);
  1955. FreeMem(cpu_first_date);
  1956. FreeMem(cpu_first_date_id);
  1957. FreeMem(cpu_last_date);
  1958. FreeMem(cpu_last_date_id);
  1959. end;
  1960. if assigned(version_count) then
  1961. begin
  1962. FreeMem(version_count);
  1963. FreeMem(version_first_date);
  1964. FreeMem(version_first_date_id);
  1965. FreeMem(version_last_date);
  1966. FreeMem(version_last_date_id);
  1967. end;
  1968. end;
  1969. Procedure TTestSuite.ShowRunComparison;
  1970. Var
  1971. S : String;
  1972. Qry : String;
  1973. Q : TSQLQuery;
  1974. FL : String;
  1975. begin
  1976. ConnectToDB;
  1977. ContentType:='text/html';
  1978. EmitContentType;
  1979. EmitTitle(Title+' : Compare 2 runs');
  1980. With FHTMLWriter do
  1981. begin
  1982. HeaderStart(1);
  1983. Write('Test suite results for run '+FRunID+' vs. '+FCompareRunID);
  1984. HeaderEnd(1);
  1985. HeaderStart(2);
  1986. Write('Test run data: ');
  1987. HeaderEnd(2);
  1988. If ShowRunData then
  1989. begin
  1990. HeaderStart(2);
  1991. Write('Detailed test run results:');
  1992. FL:='';
  1993. If FOnlyFailed or FNoSkipped then
  1994. begin
  1995. FL:='';
  1996. If FOnlyFailed then
  1997. FL:='successful';
  1998. if FNoSkipped then
  1999. begin
  2000. If (FL<>'') then
  2001. FL:=FL+' and ';
  2002. FL:=FL+'skipped';
  2003. end;
  2004. Write(' ('+FL+' tests are hidden)');
  2005. end;
  2006. HeaderEnd(2);
  2007. ParaGraphStart;
  2008. Q:=CreateDataset('');
  2009. Q.SQL.Text:='CREATE TEMPORARY TABLE tr1 like TESTRESULTS;';
  2010. Q.ExecSQL;
  2011. Q.SQL.Text:='CREATE TEMPORARY TABLE tr2 like TESTRESULTS;';
  2012. Q.ExecSQL;
  2013. Q.SQL.Text:='INSERT INTO tr1 SELECT * FROM TESTRESULTS '+
  2014. 'WHERE TR_TESTRUN_FK='+FRunID+';';
  2015. Q.ExecSQL;
  2016. Q.SQL.Text:='INSERT INTO tr2 SELECT * FROM TESTRESULTS '+
  2017. 'WHERE TR_TESTRUN_FK='+FCompareRunID+';';
  2018. Q.ExecSQL;
  2019. S:='SELECT T_ID as Id,T_NAME as Filename,tr1.TR_SKIP as Run1_Skipped,'
  2020. +'tr2.TR_SKIP as Run2_Skipped,tr1.TR_OK as Run1_OK,'
  2021. +'tr2.TR_OK as Run2_OK, tr1.TR_Result as Run1_Result,'
  2022. +'tr2.TR_RESULT as Run2_Result '
  2023. +'FROM TESTS, tr2 LEFT JOIN tr1 USING (TR_TEST_FK) '
  2024. +'WHERE ((tr1.TR_SKIP IS NULL) or'
  2025. +' (tr2.TR_SKIP IS NULL) or '
  2026. +' (%s (tr1.TR_Result<>tr2.TR_Result)))'
  2027. +'and (T_ID=tr2.TR_TEST_FK)';
  2028. If FNoSkipped then
  2029. begin
  2030. Qry:='(((tr1.TR_SKIP="+") and (tr2.TR_OK="-") and (tr2.TR_SKIP="-")) or '
  2031. +'((tr1.TR_OK="-") and (tr1.TR_SKIP="-") and (tr2.TR_SKIP="+")) or '
  2032. +'((tr1.TR_SKIP="-") and (tr2.TR_SKIP="-"))) and ';
  2033. end
  2034. else
  2035. Qry:='';
  2036. Qry:=Format(S,[Qry]);
  2037. If FDebug then
  2038. begin
  2039. Writeln('Query: '+Qry);
  2040. Flush(stdout);
  2041. end;
  2042. FRunCount:=0;
  2043. FRunSkipCount:=0;
  2044. FRunFailedCount:=0;
  2045. Q.SQL.Text:=Qry;
  2046. With Q do
  2047. try
  2048. Open;
  2049. Try
  2050. With CreateTableProducer(Q) do
  2051. Try
  2052. Border:=True;
  2053. FL:='Filename,Run1_OK,Run2_OK';
  2054. If Not FNoSkipped then
  2055. FL:=FL+',Run1_Skipped,Run2_Skipped';
  2056. FL:=FL+',Run1_Result,Run2_Result';
  2057. CreateColumns(FL);
  2058. OnGetRowAttributes:=@GetRunRowAttr;
  2059. TableColumns.ColumnByNAme('Run1_Result').OnGetCellContents:=
  2060. @FormatTestResult;
  2061. TableColumns.ColumnByNAme('Run2_Result').OnGetCellContents:=
  2062. @FormatTestResult;
  2063. TableColumns.ColumnByNAme('Filename').OnGetCellContents:=
  2064. @FormatFileDetails;
  2065. //(TableColumns.Items[0] as TTableColumn).ActionURL:=ALink;
  2066. CreateTable(Response);
  2067. Finally
  2068. Free;
  2069. end;
  2070. Writeln('<p>Record count: ',Q.RecordCount,'</p>');
  2071. Finally
  2072. Close;
  2073. end;
  2074. finally
  2075. Free;
  2076. end;
  2077. If Not (FRunCount=0) and not (FNoSkipped or FOnlyFailed) then
  2078. begin
  2079. ParaGraphStart;
  2080. TagStart('IMG',Format('Src="'+TestsuiteCGIURL+'?action=2&pietotal=%d&piefailed=%d&pieskipped=%d"',[FRunCount,FRunFailedCount,FRunSkipCount]));
  2081. end;
  2082. end
  2083. else
  2084. Write('No data for test run with ID: '+FRunID);
  2085. end;
  2086. end;
  2087. procedure TTestSuite.GetRunRowAttr(Sender: TObject; var BGColor: String;
  2088. var Align: THTMLAlign; var VAlign: THTMLValign; var CustomAttr: String);
  2089. Var
  2090. P : TTableProducer;
  2091. Skip1Field, Skip2Field, Run1Field, Run2Field : TField;
  2092. begin
  2093. P:=(Sender as TTAbleProducer);
  2094. Inc(FRunCount);
  2095. If (FOnlyFailed and FNoSkipped) then
  2096. begin
  2097. If (P.CurrentRow Mod 2)=0 then
  2098. BGColor:='#EEEEEE'
  2099. end
  2100. else
  2101. begin
  2102. Skip1Field := P.Dataset.FindField('Skipped');
  2103. if Skip1Field = nil then
  2104. begin
  2105. Skip1Field := P.Dataset.FindField('Run1_Skipped');
  2106. Skip2Field := P.Dataset.FindField('Run2_Skipped');
  2107. end
  2108. else
  2109. Skip2Field := nil;
  2110. Run1Field := P.Dataset.FindField('OK');
  2111. if Run1Field = nil then
  2112. Run1Field := P.Dataset.FindField('Run1_OK');
  2113. Run2Field := P.Dataset.FindField('OK');
  2114. if Run2Field = nil then
  2115. Run2Field := P.Dataset.FindField('Run2_OK');
  2116. If (not FNoSkipped) and ((Skip1Field.AsString='+')
  2117. or ((Skip2Field <> nil) and (Skip2Field.AsString = '+'))) then
  2118. begin
  2119. Inc(FRunSkipCount);
  2120. BGColor:='yellow'; // Yellow
  2121. end
  2122. else If Run2Field.AsString='+' then
  2123. begin
  2124. if Run1Field.AsString='' then
  2125. BGColor:='#68DFB8'
  2126. else if Run1Field.ASString<>'+' then
  2127. BGColor:='#98FB98'; // pale Green
  2128. end
  2129. else if Run2Field.AsString='-' then
  2130. begin
  2131. Inc(FRunFailedCount);
  2132. if Run1Field.AsString='' then
  2133. BGColor:='#FF82AB' // Light red
  2134. else if Run1Field.AsString<>'-' then
  2135. BGColor:='#FF225B';
  2136. end;
  2137. end;
  2138. end;
  2139. procedure TTestSuite.FormatFailedOverview(Sender: TObject; var CellData: String);
  2140. Var
  2141. S: String;
  2142. P : TTableProducer;
  2143. begin
  2144. P:=(Sender as TTableProducer);
  2145. S:=Format(SDetailsURL,[P.DataSet.FieldByName('ID').AsString]);
  2146. S:=S+'&failedonly=1&noskipped=1';
  2147. CellData:=Format('<A HREF="%s">%s</A>',[S,CellData]);
  2148. end;
  2149. function TTestSuite.FormatDetailURL(const RunIdStr, CellData : String) : string;
  2150. Var
  2151. S : String;
  2152. begin
  2153. S:=Format(SDetailsURL,[RunIdStr]);
  2154. if FOnlyFailed then
  2155. S:=S+'&failedonly=1';
  2156. if FNoSkipped then
  2157. S:=S+'&noskipped=1';
  2158. FormatDetailURL:=Format('<A HREF="%s">%s</A>',[S,CellData]);
  2159. end;
  2160. procedure TTestSuite.FormatTestRunOverview(Sender: TObject; var CellData: String);
  2161. Var
  2162. S: String;
  2163. P : TTableProducer;
  2164. begin
  2165. P:=(Sender as TTableProducer);
  2166. S:=Format(SDetailsURL,[P.DataSet.FieldByName('TR_TESTRUN_FK').AsString]);
  2167. if FOnlyFailed then
  2168. S:=S+'&failedonly=1';
  2169. if FNoSkipped then
  2170. S:=S+'&noskipped=1';
  2171. CellData:=Format('<A HREF="%s">%s</A>',[S,CellData]);
  2172. end;
  2173. procedure TTestSuite.FormatFileIDDetails(Sender: TObject; var CellData: String);
  2174. Var
  2175. S: String;
  2176. P : TTableProducer;
  2177. begin
  2178. P:=(Sender as TTableProducer);
  2179. if FVersion<>'' then
  2180. S:=Format(TestSuiteCGIURL + '?action=4&version=%s&testfileid=%s',
  2181. [FVersion,P.DataSet.FieldByName('Id').AsString])
  2182. else
  2183. S:=Format(TestSuiteCGIURL + '?action=4&testfileid=%s',
  2184. [P.DataSet.FieldByName('Id').AsString]);
  2185. CellData:=Format('<A HREF="%s">%s</A>',[S,CellData]);
  2186. end;
  2187. procedure TTestSuite.FormatFileDetails(Sender: TObject; var CellData: String);
  2188. Var
  2189. S: String;
  2190. P : TTableProducer;
  2191. begin
  2192. P:=(Sender as TTableProducer);
  2193. if FCompareRunID<>'' then
  2194. S:=Format(TestSuiteCGIURL + '?action=3&run1id=%s&run2id=%s&testfileid=%s',
  2195. [FRunID,FCompareRunID,P.DataSet.FieldByName('Id').AsString])
  2196. else
  2197. S:=Format(TestSuiteCGIURL + '?action=3&run1id=%s&testfileid=%s',
  2198. [FRunID,P.DataSet.FieldByName('Id').AsString]);
  2199. CellData:=Format('<A HREF="%s">%s</A>',[S,CellData]);
  2200. end;
  2201. procedure TTestSuite.FormatTestResult(Sender: TObject; var CellData: String);
  2202. Var
  2203. Res : longint;
  2204. Error:word;
  2205. TS : TTestStatus;
  2206. begin
  2207. Val(CellData,Res,Error);
  2208. if (Error=0) and (Res>=longint(FirstStatus)) and
  2209. (Res<=longint(LastStatus)) then
  2210. begin
  2211. TS:=TTestStatus(Res);
  2212. CellData:=StatusText[TS];
  2213. end;
  2214. end;
  2215. Procedure TTestSuite.CreateRunPie;
  2216. Var
  2217. I : TFPMemoryImage;
  2218. M : TMemoryStream;
  2219. begin
  2220. ftFont.InitEngine;
  2221. FontMgr.SearchPath:='/usr/lib/X11/fonts/truetype';
  2222. I:=TFPMemoryImage.Create(320,320);
  2223. try
  2224. If FRunCount=0 Then
  2225. Raise Exception.Create('Invalid parameters passed to script: No total count');
  2226. DoDrawPie(I,FRunSkipCount,FRunFailedCount,FRunCount);
  2227. M:=TMemoryStream.Create;
  2228. Try
  2229. With TFPWriterPNG.Create do
  2230. try
  2231. UseAlpha:=True;
  2232. ImageWrite(M,I);
  2233. Finally
  2234. Free;
  2235. end;
  2236. ContentType:='image/png';
  2237. EmitContentType;
  2238. M.Position:=0;
  2239. Response.CopyFrom(M,M.Size);
  2240. Finally
  2241. M.Free;
  2242. end;
  2243. Finally
  2244. I.Free;
  2245. end;
  2246. end;
  2247. Procedure TTestSuite.DoDrawPie(Img : TFPCustomImage; Skipped,Failed,Total : Integer);
  2248. Var
  2249. Cnv : TFPImageCanvas;
  2250. W,H,FH,CR,ra : Integer;
  2251. A1,A2,FR,SR,PR : Double;
  2252. R : TRect;
  2253. F : TFreeTypeFont;
  2254. Procedure AddPie(X,Y,R : Integer; AStart,AStop : Double; Col : TFPColor);
  2255. Var
  2256. DX,Dy : Integer;
  2257. begin
  2258. DX:=Round(R*Cos(A1));
  2259. DY:=Round(R*Sin(A1));
  2260. Cnv.Line(X,Y,X+DX,Y-DY);
  2261. DX:=Round(Ra*Cos(A2));
  2262. DY:=Round(Ra*Sin(A2));
  2263. Cnv.Line(X,Y,X+DX,Y-Dy);
  2264. DX:=Round(R/2*Cos((A1+A2)/2));
  2265. DY:=Round(R/2*Sin((A1+A2)/2));
  2266. Cnv.Brush.FpColor:=Col;
  2267. Cnv.FloodFill(X+DX,Y-DY);
  2268. end;
  2269. Function FractionAngle(F,T : Integer): Double;
  2270. begin
  2271. Result:=(2*Pi*(F/T))
  2272. end;
  2273. begin
  2274. F:=TFreeTypeFont.Create;
  2275. With F do
  2276. begin
  2277. Name:='arial';
  2278. FontIndex:=0;
  2279. Size:=12;
  2280. FPColor:=colred;
  2281. AntiAliased:=False;
  2282. Resolution:=96;
  2283. end;
  2284. if FDebug then
  2285. Writeln(stdout,'Creating image');
  2286. Cnv:=TFPImageCanvas.Create(Img);
  2287. if FDebug then
  2288. Writeln(stdout,'CNV=0x',hexstr(ptruint(cnv),16));
  2289. if FDebug then
  2290. Writeln(stdout,'Getting width and height');
  2291. W:=Img.Width;
  2292. H:=Img.Height;
  2293. if FDebug then
  2294. begin
  2295. Writeln(stdout,'width=',W,' height=',H);
  2296. //system.flush(stdout);
  2297. end;
  2298. // Writeln('Transparant');
  2299. cnv.Brush.Style:=bsSolid;
  2300. cnv.Brush.FPColor:=colTransparent;
  2301. cnv.Pen.FPColor:=colWhite;
  2302. Cnv.Rectangle(0,0,W,H);
  2303. if FDEbug then
  2304. Writeln(stdout,'Setting font');
  2305. Cnv.Font:=F;
  2306. if FDebug then
  2307. Writeln(stdout,'Getting textwidth ');
  2308. FH:=CNV.GetTextHeight('A');
  2309. If FH=0 then
  2310. FH:=14; // 3 * 14;
  2311. if FDebug then
  2312. writeln(stdout,'FH=',FH);
  2313. Inc(FH,3);
  2314. R.Top:=FH*4;
  2315. R.Left:=0;
  2316. R.Bottom:=H;
  2317. CR:=H-(FH*4);
  2318. If W>CR then
  2319. R.Right:=CR
  2320. else
  2321. R.Right:=W;
  2322. Ra:=CR div 2;
  2323. if FDEbug then
  2324. begin
  2325. Writeln(stdout,'Setting pen color');
  2326. system.flush(stdout);
  2327. end;
  2328. Cnv.Pen.FPColor:=colBlack;
  2329. if FDebug then
  2330. begin
  2331. Writeln(stdout,'Palette size : ',Img.Palette.Count);
  2332. Writeln(stdout,'Setting brush style');
  2333. system.flush(stdout);
  2334. end;
  2335. cnv.brush.FPColor:=colRed;
  2336. // cnv.pen.width:=1;
  2337. // Writeln('Drawing ellipse');
  2338. Cnv.Ellipse(R);
  2339. if FDebug then
  2340. begin
  2341. Writeln(stdout,'Setting text');
  2342. Writeln(stdout,'Palette size : ',Img.Palette.Count);
  2343. end;
  2344. cnv.font.FPColor:=colred;
  2345. Inc(FH,4);
  2346. FR:=Failed/Total;
  2347. SR:=Skipped/Total;
  2348. PR:=1-(FR+SR);
  2349. Cnv.Textout(1,FH,Format('%d Failed (%3.1f%%)',[Failed,Fr*100]));
  2350. // Writeln('Palette size : ',Img.Palette.Count);
  2351. cnv.font.FPColor:=colYellow;
  2352. Cnv.Textout(1,FH*2,Format('%d Skipped (%3.1f%%)',[Skipped,SR*100]));
  2353. A1:=(Pi*2*(failed/total));
  2354. A2:=A1+(Pi*2*(Skipped/Total));
  2355. AddPie(Ra,R.Top+Ra,Ra,A1,A2,ColYellow);
  2356. cnv.font.FPColor:=colGreen;
  2357. // Writeln('Palette size : ',Img.Palette.Count);
  2358. A1:=A2;
  2359. A2:=A1+(Pi*2*((Total-(Skipped+Failed))/Total));
  2360. Cnv.Textout(1,FH*3,Format('%d Passed (%3.1f%%',[Total-Skipped-Failed,PR*100]));
  2361. AddPie(Ra,R.Top+Ra,Ra,A1,A2,ColGreen);
  2362. // Writeln('Palette size : ',Img.Palette.Count);
  2363. // Writeln('All done');
  2364. end;
  2365. begin
  2366. if paramstr(0)<>'' then
  2367. TestsuiteCGIURL:=TestsuiteURLPrefix+'cgi-bin/'+extractfilename(paramstr(0))
  2368. else
  2369. TestsuiteCGIURL:=TestsuiteURLPrefix+'cgi-bin/'+TestsuiteBin;
  2370. SDetailsURL := TestsuiteCGIURL + '?action=1&run1id=%s';
  2371. end.