ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/fbintf/testsuite/TestManager.pas
Revision: 292
Committed: Fri Apr 17 11:30:36 2020 UTC (4 years ago) by tony
Content type: text/x-pascal
File size: 23356 byte(s)
Log Message:
Fix LineEnding problem with Delphi

File Contents

# User Rev Content
1 tony 45 unit TestManager;
2 tony 56 {$IFDEF MSWINDOWS}
3     {$DEFINE WINDOWS}
4     {$ENDIF}
5 tony 45
6 tony 56 {$IFDEF FPC}
7     {$mode delphi}
8 tony 45 {$codepage utf8}
9 tony 56 {$ENDIF}
10 tony 45
11     interface
12    
13     uses
14     Classes, SysUtils, IB;
15    
16 tony 292 {$IFDEF MSWINDOWS}
17     const LineEnding = #$0D#$0A;
18     {$ENDIF}
19    
20 tony 45 type
21     TTestManager = class;
22    
23     { TTestBase }
24    
25     TTestBase = class
26     private
27     FOwner: TTestManager;
28     protected
29     FHexStrings: boolean;
30     function ReportResults(Statement: IStatement): IResultSet;
31     procedure ReportResult(aValue: IResults);
32 tony 56 procedure PrintHexString(s: AnsiString);
33 tony 45 procedure PrintDPB(DPB: IDPB);
34     procedure PrintMetaData(meta: IMetaData);
35     procedure ParamInfo(SQLParams: ISQLParams);
36     procedure WriteArray(ar: IArray);
37     procedure WriteAffectedRows(Statement: IStatement);
38     function WriteServiceQueryResult(QueryResult: IServiceQueryResults): boolean;
39     procedure writeLicence(Item: IServiceQueryResultItem);
40     procedure WriteConfig(config: IServiceQueryResultItem);
41     procedure WriteUsers(users: IServiceQueryResultItem);
42     procedure WriteDBAttachments(att: IServiceQueryResultItem);
43     procedure WriteLimboTransactions(limbo: IServiceQueryResultItem);
44     procedure WriteDBInfo(DBInfo: IDBInformation);
45     procedure WriteBytes(Bytes: TByteArray);
46 tony 56 procedure WriteOperationCounts(Category: AnsiString; ops: TDBOperationCounts);
47 tony 47 procedure WritePerfStats(stats: TPerfCounters);
48 tony 45 procedure CheckActivity(Attachment: IAttachment); overload;
49     procedure CheckActivity(Transaction: ITransaction); overload;
50     public
51     constructor Create(aOwner: TTestManager); virtual;
52 tony 56 function TestTitle: AnsiString; virtual; abstract;
53     procedure RunTest(CharSet: AnsiString; SQLDialect: integer); virtual; abstract;
54 tony 45 property Owner: TTestManager read FOwner;
55     end;
56    
57     TTest = class of TTestBase;
58    
59     { TTestManager }
60    
61     TTestManager = class
62     private
63     FTests: TList;
64 tony 56 FEmployeeDatabaseName: AnsiString;
65     FNewDatabaseName: AnsiString;
66     FSecondNewDatabaseName: AnsiString;
67     FUserName: AnsiString;
68     FPassword: AnsiString;
69     FBackupFileName: AnsiString;
70 tony 45 FShowStatistics: boolean;
71     procedure CleanUp;
72     public
73     constructor Create;
74     destructor Destroy; override;
75 tony 56 function GetUserName: AnsiString;
76     function GetPassword: AnsiString;
77     function GetEmployeeDatabaseName: AnsiString;
78     function GetNewDatabaseName: AnsiString;
79     function GetSecondNewDatabaseName: AnsiString;
80     function GetBackupFileName: AnsiString;
81 tony 45 procedure RunAll;
82     procedure Run(TestID: integer);
83 tony 56 procedure SetUserName(aValue: AnsiString);
84     procedure SetPassword(aValue: AnsiString);
85     procedure SetEmployeeDatabaseName(aValue: AnsiString);
86     procedure SetNewDatabaseName(aValue: AnsiString);
87     procedure SetSecondNewDatabaseName(aValue: AnsiString);
88     procedure SetBackupFileName(aValue: AnsiString);
89 tony 45 property ShowStatistics: boolean read FShowStatistics write FShowStatistics;
90     end;
91    
92 tony 56 var
93 tony 45 TestMgr: TTestManager = nil;
94    
95     var OutFile: text;
96    
97     procedure RegisterTest(aTest: TTest);
98    
99     implementation
100    
101 tony 56 {$IFDEF MSWINDOWS}
102     uses windows;
103 tony 45
104 tony 56 function GetTempDir: AnsiString;
105     var
106     tempFolder: array[0..MAX_PATH] of Char;
107     begin
108     GetTempPath(MAX_PATH, @tempFolder);
109     result := StrPas(tempFolder);
110     end;
111     {$ENDIF}
112    
113 tony 45 procedure RegisterTest(aTest: TTest);
114     begin
115     if TestMgr = nil then
116     TestMgr := TTestManager.Create;
117     TestMgr.FTests.Add(aTest.Create(TestMgr));
118     end;
119    
120     { TTestBase }
121    
122     constructor TTestBase.Create(aOwner: TTestManager);
123     begin
124     inherited Create;
125     FOwner := aOwner;
126     end;
127    
128    
129     function TTestBase.ReportResults(Statement: IStatement): IResultSet;
130     begin
131     Result := Statement.OpenCursor;
132     try
133     while Result.FetchNext do
134     ReportResult(Result);
135     finally
136     Result.Close;
137     end;
138     writeln(OutFile);
139     end;
140    
141     procedure TTestBase.ReportResult(aValue: IResults);
142     var i: integer;
143 tony 56 s: AnsiString;
144 tony 45 begin
145     for i := 0 to aValue.getCount - 1 do
146     begin
147     if aValue[i].IsNull then
148     writeln(OutFile,aValue[i].Name,' = NULL')
149     else
150     case aValue[i].SQLType of
151     SQL_ARRAY:
152     begin
153     if not aValue[i].IsNull then
154     WriteArray(aValue[i].AsArray);
155     end;
156     SQL_FLOAT,SQL_DOUBLE,
157     SQL_D_FLOAT:
158     writeln(OutFile, aValue[i].Name,' = ',FormatFloat('#,##0.00',aValue[i].AsFloat));
159    
160     SQL_INT64:
161     if aValue[i].Scale <> 0 then
162     writeln(OutFile, aValue[i].Name,' = ',FormatFloat('#,##0.00',aValue[i].AsFloat))
163     else
164     writeln(OutFile,aValue[i].Name,' = ',aValue[i].AsString);
165    
166     SQL_BLOB:
167     if aValue[i].IsNull then
168     writeln(OutFile,aValue[i].Name,' = (null blob)')
169     else
170     if aValue[i].SQLSubType = 1 then
171     begin
172     s := aValue[i].AsString;
173     if FHexStrings then
174     begin
175     write(OutFile,aValue[i].Name,' = ');
176     PrintHexString(s);
177     writeln(OutFile,' (Charset Id = ',aValue[i].GetCharSetID, ' Codepage = ',StringCodePage(s),')');
178     end
179     else
180     begin
181     writeln(OutFile,aValue[i].Name,' (Charset Id = ',aValue[i].GetCharSetID, ' Codepage = ',StringCodePage(s),')');
182     writeln(OutFile);
183     writeln(OutFile,s);
184     end
185     end
186     else
187     writeln(OutFile,aValue[i].Name,' = (blob), Length = ',aValue[i].AsBlob.GetBlobSize);
188    
189     SQL_TEXT,SQL_VARYING:
190     begin
191     s := aValue[i].AsString;
192     if FHexStrings then
193     begin
194     write(OutFile,aValue[i].Name,' = ');
195     PrintHexString(s);
196     writeln(OutFile,' (Charset Id = ',aValue[i].GetCharSetID, ' Codepage = ',StringCodePage(s),')');
197     end
198     else
199     if aValue[i].GetCharSetID > 0 then
200     writeln(OutFile,aValue[i].Name,' = ',s,' (Charset Id = ',aValue[i].GetCharSetID, ' Codepage = ',StringCodePage(s),')')
201     else
202     writeln(OutFile,aValue[i].Name,' = ',s);
203     end;
204    
205     else
206     writeln(OutFile,aValue[i].Name,' = ',aValue[i].AsString);
207     end;
208     end;
209     end;
210    
211 tony 56 procedure TTestBase.PrintHexString(s: AnsiString);
212 tony 45 var i: integer;
213     begin
214     for i := 1 to length(s) do
215     write(OutFile,Format('%x ',[byte(s[i])]));
216     end;
217    
218     procedure TTestBase.PrintDPB(DPB: IDPB);
219     var i: integer;
220     begin
221     writeln(OutFile,'DPB');
222     writeln(OutFile,'Count = ', DPB.getCount);
223     for i := 0 to DPB.getCount - 1 do
224     writeln(OutFile,DPB[i].getParamType,' = ', DPB[i].AsString);
225     writeln(OutFile);
226     end;
227    
228     procedure TTestBase.PrintMetaData(meta: IMetaData);
229     var i, j: integer;
230     ar: IArrayMetaData;
231     bm: IBlobMetaData;
232     Bounds: TArrayBounds;
233     begin
234     writeln(OutFile,'Metadata');
235     for i := 0 to meta.GetCount - 1 do
236     with meta[i] do
237     begin
238     writeln(OutFile,'SQLType =',GetSQLTypeName);
239     writeln(OutFile,'sub type = ',getSubType);
240     writeln(OutFile,'Table = ',getRelationName);
241     writeln(OutFile,'Owner = ',getOwnerName);
242     writeln(OutFile,'Column Name = ',getSQLName);
243     writeln(OutFile,'Alias Name = ',getAliasName);
244     writeln(OutFile,'Field Name = ',getName);
245     writeln(OutFile,'Scale = ',getScale);
246     writeln(OutFile,'Charset id = ',getCharSetID);
247     if getIsNullable then writeln(OutFile,'Nullable') else writeln(OutFile,'Not Null');
248     writeln(OutFile,'Size = ',GetSize);
249     case getSQLType of
250     SQL_ARRAY:
251     begin
252     writeln(OutFile,'Array Meta Data:');
253     ar := GetArrayMetaData;
254     writeln(OutFile,'SQLType =',ar.GetSQLTypeName);
255     writeln(OutFile,'Scale = ',ar.getScale);
256     writeln(OutFile,'Charset id = ',ar.getCharSetID);
257     writeln(OutFile,'Size = ',ar.GetSize);
258     writeln(OutFile,'Table = ',ar.GetTableName);
259     writeln(OutFile,'Column = ',ar.GetColumnName);
260     writeln(OutFile,'Dimensions = ',ar.GetDimensions);
261     write(OutFile,'Bounds: ');
262     Bounds := ar.GetBounds;
263     for j := 0 to Length(Bounds) - 1 do
264     write(OutFile,'(',Bounds[j].LowerBound,':',Bounds[j].UpperBound,') ');
265     writeln(OutFile);
266     end;
267     SQL_BLOB:
268     begin
269     writeln(OutFile);
270     writeln(OutFile,'Blob Meta Data');
271     bm := GetBlobMetaData;
272     writeln(OutFile,'SQL SubType =',bm.GetSubType);
273     writeln(OutFile,'Table = ',bm.GetRelationName);
274     writeln(OutFile,'Column = ',bm.GetColumnName);
275     writeln(OutFile,'CharSetID = ',bm.GetCharSetID);
276     writeln(OutFile,'Segment Size = ',bm.GetSegmentSize);
277     writeln(OutFile);
278     end;
279     end;
280     writeln(OutFile);
281     end;
282     end;
283    
284     procedure TTestBase.ParamInfo(SQLParams: ISQLParams);
285     var i: integer;
286     begin
287     writeln(OutFile,'SQL Params');
288     for i := 0 to SQLParams.Count - 1 do
289     with SQLParams[i] do
290     begin
291     writeln(OutFile,'SQLType =',GetSQLTypeName);
292     writeln(OutFile,'sub type = ',getSubType);
293     writeln(OutFile,'Field Name = ',getName);
294     writeln(OutFile,'Scale = ',getScale);
295     writeln(OutFile,'Charset id = ',getCharSetID);
296     if getIsNullable then writeln(OutFile,'Nullable') else writeln(OutFile,'Not Null');
297     writeln(OutFile,'Size = ',GetSize);
298     writeln(OutFile);
299     end;
300     end;
301    
302     procedure TTestBase.WriteArray(ar: IArray);
303     var Bounds: TArrayBounds;
304     i,j: integer;
305     begin
306     write(OutFile,'Array: ');
307     Bounds := ar.GetBounds;
308     case ar.GetDimensions of
309     1:
310     begin
311     for i := Bounds[0].LowerBound to Bounds[0].UpperBound do
312     write(OutFile,'(',i,': ',ar.GetAsVariant([i]),') ');
313     end;
314    
315     2:
316     begin
317     for i := Bounds[0].LowerBound to Bounds[0].UpperBound do
318     for j := Bounds[1].LowerBound to Bounds[1].UpperBound do
319     write(OutFile,'(',i,',',j,': ',ar.GetAsVariant([i,j]),') ');
320     end;
321     end;
322     writeln(OutFile);
323     end;
324    
325     procedure TTestBase.WriteAffectedRows(Statement: IStatement);
326     var SelectCount, InsertCount, UpdateCount, DeleteCount: integer;
327     begin
328     Statement.GetRowsAffected(SelectCount, InsertCount, UpdateCount, DeleteCount);
329     writeln(OutFile,'Select Count = ', SelectCount,' InsertCount = ',InsertCount,' UpdateCount = ', UpdateCount, ' DeleteCount = ',DeleteCount);
330     end;
331    
332     function TTestBase.WriteServiceQueryResult(QueryResult: IServiceQueryResults): boolean;
333     var i: integer;
334 tony 56 line: AnsiString;
335 tony 45 begin
336     Result := true;
337     for i := 0 to QueryResult.GetCount - 1 do
338     with QueryResult[i] do
339     case getItemType of
340     isc_info_svc_version:
341     writeln(OutFile,'Service Manager Version = ',getAsInteger);
342     isc_info_svc_server_version:
343     writeln(OutFile,'Server Version = ',getAsString);
344     isc_info_svc_implementation:
345     writeln(OutFile,'Implementation = ',getAsString);
346     isc_info_svc_get_license:
347     writeLicence(QueryResult[i]);
348     isc_info_svc_get_license_mask:
349     writeln(OutFile,'Licence Mask = ',getAsInteger);
350     isc_info_svc_capabilities:
351     writeln(OutFile,'Capabilities = ',getAsInteger);
352     isc_info_svc_get_config:
353     WriteConfig(QueryResult[i]);
354     isc_info_svc_get_env:
355     writeln(OutFile,'Root Directory = ',getAsString);
356     isc_info_svc_get_env_lock:
357     writeln(OutFile,'Lock Directory = ',getAsString);
358     isc_info_svc_get_env_msg:
359     writeln(OutFile,'Message File = ',getAsString);
360     isc_info_svc_user_dbpath:
361     writeln(OutFile,'Security File = ',getAsString);
362     isc_info_svc_get_licensed_users:
363     writeln(OutFile,'Max Licenced Users = ',getAsInteger);
364     isc_info_svc_get_users:
365     WriteUsers(QueryResult[i]);
366     isc_info_svc_svr_db_info:
367     WriteDBAttachments(QueryResult[i]);
368     isc_info_svc_line:
369     begin
370     line := getAsString;
371     writeln(OutFile,line);
372     Result := line <> '';
373     end;
374     isc_info_svc_running:
375     writeln(OutFile,'Is Running = ',getAsInteger);
376     isc_info_svc_limbo_trans:
377     WriteLimboTransactions(QueryResult[i]);
378     isc_info_svc_to_eof,
379     isc_info_svc_timeout,
380     isc_info_truncated,
381     isc_info_data_not_ready,
382     isc_info_svc_stdin:
383     {ignore};
384     else
385     writeln(OutFile,'Unknown Service Response Item ', getItemType);
386     end;
387     writeln(OutFile);
388     end;
389    
390     procedure TTestBase.writeLicence(Item: IServiceQueryResultItem);
391     var i: integer;
392     begin
393     for i := 0 to Item.getCount - 1 do
394     with Item[i] do
395     case getItemType of
396     isc_spb_lic_id:
397     writeln(OutFile,'Licence ID = ',GetAsString);
398     isc_spb_lic_key:
399     writeln(OutFile,'Licence Key = ',GetAsString);
400     end;
401     end;
402    
403     procedure TTestBase.WriteConfig(config: IServiceQueryResultItem);
404     var i: integer;
405     begin
406     writeln(OutFile,'Firebird Configuration File');
407     for i := 0 to config.getCount - 1 do
408 tony 87 writeln(OutFile,'Key = ',config[i].getItemType,', Value = ',config[i].getAsInteger);
409 tony 45 writeln(OutFile);
410     end;
411    
412     procedure TTestBase.WriteUsers(users: IServiceQueryResultItem);
413     var i: integer;
414     begin
415     writeln(OutFile,'Sec. Database User');
416     for i := 0 to users.getCount - 1 do
417     with users[i] do
418     case getItemType of
419     isc_spb_sec_username:
420     writeln(OutFile,'User Name = ',getAsString);
421     isc_spb_sec_firstname:
422     writeln(OutFile,'First Name = ',getAsString);
423     isc_spb_sec_middlename:
424     writeln(OutFile,'Middle Name = ',getAsString);
425     isc_spb_sec_lastname:
426     writeln(OutFile,'Last Name = ',getAsString);
427     isc_spb_sec_userid:
428     writeln(OutFile,'User ID = ',getAsInteger);
429     isc_spb_sec_groupid:
430     writeln(OutFile,'Group ID = ',getAsInteger);
431     else
432     writeln(OutFile,'Unknown user info ', getItemType);
433     end;
434     writeln(OutFile);
435     end;
436    
437     procedure TTestBase.WriteDBAttachments(att: IServiceQueryResultItem);
438     var i: integer;
439     begin
440     writeln(OutFile,'DB Attachments');
441     for i := 0 to att.getCount - 1 do
442     with att[i] do
443     case getItemType of
444     isc_spb_num_att:
445     writeln(OutFile,'No. of Attachments = ',getAsInteger);
446     isc_spb_num_db:
447     writeln(OutFile,'Databases In Use = ',getAsInteger);
448     isc_spb_dbname:
449     writeln(OutFile,'DB Name = ',getAsString);
450     end;
451     end;
452    
453     procedure TTestBase.WriteLimboTransactions(limbo: IServiceQueryResultItem);
454     var i: integer;
455     begin
456     writeln(OutFile,'Limbo Transactions');
457     for i := 0 to limbo.getCount - 1 do
458     with limbo[i] do
459     case getItemType of
460     isc_spb_single_tra_id:
461     writeln(OutFile,'Single DB Transaction = ',getAsInteger);
462     isc_spb_multi_tra_id:
463     writeln(OutFile,'Multi DB Transaction = ',getAsInteger);
464     isc_spb_tra_host_site:
465     writeln(OutFile,'Host Name = ',getAsString);
466     isc_spb_tra_advise:
467     writeln(OutFile,'Resolution Advisory = ',getAsInteger);
468     isc_spb_tra_remote_site:
469     writeln(OutFile,'Server Name = ',getAsString);
470     isc_spb_tra_db_path:
471     writeln(OutFile,'DB Primary File Name = ',getAsString);
472     isc_spb_tra_state:
473     begin
474     write(OutFile,'State = ');
475     case getAsInteger of
476     isc_spb_tra_state_limbo:
477     writeln(OutFile,'limbo');
478     isc_spb_tra_state_commit:
479     writeln(OutFile,'commit');
480     isc_spb_tra_state_rollback:
481     writeln(OutFile,'rollback');
482     isc_spb_tra_state_unknown:
483     writeln(OutFile,'Unknown');
484     end;
485     end;
486     end;
487     end;
488    
489     procedure TTestBase.WriteDBInfo(DBInfo: IDBInformation);
490     var i, j: integer;
491     bytes: TByteArray;
492     ConType: integer;
493 tony 56 DBFileName: AnsiString;
494     DBSiteName: AnsiString;
495 tony 45 Version: byte;
496 tony 56 VersionString: AnsiString;
497 tony 45 Users: TStringList;
498     begin
499     for i := 0 to DBInfo.GetCount - 1 do
500     with DBInfo[i] do
501     case getItemType of
502 tony 61 isc_info_db_read_only:
503     if getAsInteger <> 0 then
504     writeln(OutFile,'Database is Read Only')
505     else
506     writeln(OutFile,'Database is Read/Write');
507 tony 45 isc_info_allocation:
508     writeln(OutFile,'Pages =',getAsInteger);
509     isc_info_base_level:
510     begin
511     bytes := getAsBytes;
512     write(OutFile,'Base Level = ');
513     WriteBytes(Bytes);
514     end;
515     isc_info_db_id:
516     begin
517     DecodeIDCluster(ConType,DBFileName,DBSiteName);
518     writeln(OutFile,'Database ID = ', ConType,' FB = ', DBFileName, ' SN = ',DBSiteName);
519     end;
520     isc_info_implementation:
521     begin
522     bytes := getAsBytes;
523     write(OutFile,'Implementation = ');
524     WriteBytes(Bytes);
525     end;
526     isc_info_no_reserve:
527     writeln(OutFile,'Reserved = ',getAsInteger);
528     isc_info_ods_minor_version:
529     writeln(OutFile,'ODS minor = ',getAsInteger);
530     isc_info_ods_version:
531     writeln(OutFile,'ODS major = ',getAsInteger);
532     isc_info_page_size:
533     writeln(OutFile,'Page Size = ',getAsInteger);
534     isc_info_version:
535     begin
536     DecodeVersionString(Version,VersionString);
537     writeln(OutFile,'Version = ',Version,': ',VersionString);
538     end;
539     isc_info_current_memory:
540     writeln(OutFile,'Server Memory = ',getAsInteger);
541     isc_info_forced_writes:
542     writeln(OutFile,'Forced Writes = ',getAsInteger);
543     isc_info_max_memory:
544     writeln(OutFile,'Max Memory = ',getAsInteger);
545     isc_info_num_buffers:
546     writeln(OutFile,'Num Buffers = ',getAsInteger);
547     isc_info_sweep_interval:
548     writeln(OutFile,'Sweep Interval = ',getAsInteger);
549     isc_info_user_names:
550     begin
551     Users := TStringList.Create;
552     try
553     write(OutFile,'Logged in Users: ');
554     DecodeUserNames(Users);
555     for j := 0 to Users.Count - 1 do
556     write(OutFile,Users[j],',');
557    
558     finally
559     Users.Free;
560     end;
561     writeln(OutFile);
562     end;
563     isc_info_fetches:
564     writeln(OutFile,'Fetches = ',getAsInteger);
565     isc_info_marks:
566     writeln(OutFile,'Writes = ',getAsInteger);
567     isc_info_reads:
568     writeln(OutFile,'Reads = ',getAsInteger);
569     isc_info_writes:
570     writeln(OutFile,'Page Writes = ',getAsInteger);
571     isc_info_backout_count:
572     WriteOperationCounts('Record Version Removals',getOperationCounts);
573     isc_info_delete_count:
574     WriteOperationCounts('Deletes',getOperationCounts);
575     isc_info_expunge_count:
576     WriteOperationCounts('Expunge Count',getOperationCounts);
577     isc_info_insert_count:
578     WriteOperationCounts('Insert Count',getOperationCounts);
579     isc_info_purge_count:
580     WriteOperationCounts('Purge Count Countites',getOperationCounts);
581     isc_info_read_idx_count:
582     WriteOperationCounts('Indexed Reads Count',getOperationCounts);
583     isc_info_read_seq_count:
584     WriteOperationCounts('Sequential Table Scans',getOperationCounts);
585     isc_info_update_count:
586     WriteOperationCounts('Update Count',getOperationCounts);
587 tony 47 isc_info_db_SQL_Dialect:
588     writeln(OutFile,'SQL Dialect = ',getAsInteger);
589 tony 143 isc_info_creation_date:
590     writeln(OutFile,'Database Created: ',DateTimeToStr(getAsDateTime));
591     isc_info_active_tran_count:
592     writeln(OutFile,'Active Transaction Count = ',getAsInteger);
593     fb_info_page_contents:
594     begin
595     writeln('Database Page');
596     PrintHexString(getAsString);
597     writeln;
598     end;
599     fb_info_pages_used:
600     writeln(OutFile,'Pages Used = ',getAsInteger);
601     fb_info_pages_free:
602     writeln(OutFile,'Pages Free = ',getAsInteger);
603    
604     isc_info_truncated:
605     writeln(OutFile,'Results Truncated');
606 tony 45 else
607     writeln(OutFile,'Unknown Response ',getItemType);
608     end;
609     end;
610    
611     procedure TTestBase.WriteBytes(Bytes: TByteArray);
612     var i: integer;
613     begin
614     for i := 0 to length(Bytes) - 1 do
615     write(OutFile,Bytes[i],',');
616     writeln(OutFile);
617     end;
618    
619 tony 56 procedure TTestBase.WriteOperationCounts(Category: AnsiString;
620 tony 45 ops: TDBOperationCounts);
621     var i: integer;
622     begin
623     writeln(OutFile,Category,' Operation Counts');
624     for i := 0 to Length(ops) - 1 do
625     begin
626     writeln(OutFile,'Table ID = ',ops[i].TableID);
627     writeln(OutFile,'Count = ',ops[i].Count);
628     end;
629     writeln(OutFile);
630     end;
631    
632 tony 47 procedure TTestBase.WritePerfStats(stats: TPerfCounters);
633     begin
634     writeln(OutFile,'Current memory = ', stats[psCurrentMemory]);
635     writeln(OutFile,'Delta memory = ', stats[psDeltaMemory]);
636     writeln(OutFile,'Max memory = ', stats[psMaxMemory]);
637     writeln(OutFile,'Elapsed time= ', FormatFloat('#0.000',stats[psRealTime]/1000),' sec');
638     writeln(OutFile,'Cpu = ', FormatFloat('#0.000',stats[psUserTime]/1000),' sec');
639     writeln(OutFile,'Buffers = ', stats[psBuffers]);
640     writeln(OutFile,'Reads = ', stats[psReads]);
641     writeln(OutFile,'Writes = ', stats[psWrites]);
642     writeln(OutFile,'Fetches = ', stats[psFetches]);
643     end;
644    
645 tony 45 procedure TTestBase.CheckActivity(Attachment: IAttachment);
646     begin
647     writeln(OutFile,'Database Activity = ',Attachment.HasActivity)
648     end;
649    
650     procedure TTestBase.CheckActivity(Transaction: ITransaction);
651     begin
652     writeln(OutFile,'Transaction Activity = ',Transaction.HasActivity)
653     end;
654    
655     { TTestManager }
656    
657     procedure TTestManager.CleanUp;
658     var DPB: IDPB;
659     Attachment: IAttachment;
660     begin
661     DPB := FirebirdAPI.AllocateDPB;
662     DPB.Add(isc_dpb_user_name).setAsString(GetUserName);
663     DPB.Add(isc_dpb_password).setAsString(GetPassword);
664     Attachment := FirebirdAPI.OpenDatabase(GetNewDatabaseName,DPB,false);
665     if Attachment <> nil then
666     Attachment.DropDatabase;
667     Attachment := FirebirdAPI.OpenDatabase(GetSecondNewDatabaseName,DPB,false);
668     if Attachment <> nil then
669     Attachment.DropDatabase;
670     end;
671    
672     constructor TTestManager.Create;
673     begin
674     inherited Create;
675     FTests := TList.Create;
676     FNewDatabaseName := 'localhost:' + GetTempDir + 'fbtestsuite.fdb';
677     FSecondNewDatabaseName := 'localhost:' + GetTempDir + 'fbtestsuite2.fdb';
678     FUserName := 'SYSDBA';
679     FPassword := 'masterkey';
680     FEmployeeDatabaseName := 'localhost:employee';
681     FBackupFileName := GetTempDir + 'testbackup.gbk';
682     end;
683    
684     destructor TTestManager.Destroy;
685     var i: integer;
686     begin
687     if assigned(FTests) then
688     begin
689     for i := 0 to FTests.Count - 1 do
690     TObject(FTests[i]).Free;
691     FTests.Free;
692     end;
693     inherited Destroy;
694     end;
695    
696 tony 56 function TTestManager.GetUserName: AnsiString;
697 tony 45 begin
698     Result := FUserName;
699     end;
700    
701 tony 56 function TTestManager.GetPassword: AnsiString;
702 tony 45 begin
703     Result := FPassword;
704     end;
705    
706 tony 56 function TTestManager.GetEmployeeDatabaseName: AnsiString;
707 tony 45 begin
708     Result := FEmployeeDatabaseName;
709     end;
710    
711 tony 56 function TTestManager.GetNewDatabaseName: AnsiString;
712 tony 45 begin
713     Result := FNewDatabaseName;
714     end;
715    
716 tony 56 function TTestManager.GetSecondNewDatabaseName: AnsiString;
717 tony 45 begin
718     Result := FSecondNewDatabaseName;
719     end;
720    
721 tony 56 function TTestManager.GetBackupFileName: AnsiString;
722 tony 45 begin
723     Result := FBackupFileName;
724     end;
725    
726     procedure TTestManager.RunAll;
727     var i: integer;
728     begin
729     CleanUP;
730     for i := 0 to FTests.Count - 1 do
731     with TTestBase(FTests[i]) do
732     begin
733     writeln(OutFile,'Running ' + TestTitle);
734 tony 56 writeln(ErrOutput,'Running ' + TestTitle);
735 tony 45 try
736     RunTest('UTF8',3);
737     except on E:Exception do
738     begin
739     writeln(OutFile,'Test Completed with Error: ' + E.Message);
740     Exit;
741     end;
742     end;
743     writeln(OutFile);
744     writeln(OutFile);
745     end;
746     end;
747    
748     procedure TTestManager.Run(TestID: integer);
749     begin
750     CleanUp;
751 tony 56 if (TestID <= 0 ) or (TestID > FTests.Count) then
752     begin
753     writeln(OutFile,'Invalid Test ID - ',TestID);
754     Exit;
755     end;
756 tony 45 with TTestBase(FTests[TestID-1]) do
757     begin
758     writeln(OutFile,'Running ' + TestTitle);
759 tony 56 writeln(ErrOutput,'Running ' + TestTitle);
760 tony 45 try
761     RunTest('UTF8',3);
762     except on E:Exception do
763     begin
764     writeln(OutFile,'Test Completed with Error: ' + E.Message);
765     Exit;
766     end;
767     end;
768     writeln(OutFile);
769     writeln(OutFile);
770     end;
771     end;
772    
773 tony 56 procedure TTestManager.SetUserName(aValue: AnsiString);
774 tony 45 begin
775     FUserName := aValue;
776     end;
777    
778 tony 56 procedure TTestManager.SetPassword(aValue: AnsiString);
779 tony 45 begin
780     FPassword := aValue;
781     end;
782    
783 tony 56 procedure TTestManager.SetEmployeeDatabaseName(aValue: AnsiString);
784 tony 45 begin
785     FEmployeeDatabaseName := aValue;
786     end;
787    
788 tony 56 procedure TTestManager.SetNewDatabaseName(aValue: AnsiString);
789 tony 45 begin
790     FNewDatabaseName := aValue;
791     end;
792    
793 tony 56 procedure TTestManager.SetSecondNewDatabaseName(aValue: AnsiString);
794 tony 45 begin
795     FSecondNewDatabaseName := aValue;
796     end;
797    
798 tony 56 procedure TTestManager.SetBackupFileName(aValue: AnsiString);
799 tony 45 begin
800     FBackupFileName := aValue;
801     end;
802    
803     end.
804