ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/fbintf/testsuite/TestManager.pas
Revision: 308
Committed: Sat Jul 18 10:26:30 2020 UTC (3 years, 9 months ago) by tony
Content type: text/x-pascal
File size: 24741 byte(s)
Log Message:
Fixes Merged

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