ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/branches/udr/testsuite/Test22.pas
Revision: 370
Committed: Wed Jan 5 14:59:15 2022 UTC (2 years, 3 months ago) by tony
Content type: text/x-pascal
File size: 7397 byte(s)
Log Message:
Initialise UDR branch

File Contents

# Content
1 (*
2 * Firebird Interface (fbintf) Test suite. This program is used to
3 * test the Firebird Pascal Interface and provide a semi-automated
4 * pass/fail check for each test.
5 *
6 * The contents of this file are subject to the Initial Developer's
7 * Public License Version 1.0 (the "License"); you may not use this
8 * file except in compliance with the License. You may obtain a copy
9 * of the License here:
10 *
11 * http://www.firebirdsql.org/index.php?op=doc&id=idpl
12 *
13 * Software distributed under the License is distributed on an "AS
14 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
15 * implied. See the License for the specific language governing rights
16 * and limitations under the License.
17 *
18 * The Initial Developer of the Original Code is Tony Whyman.
19 *
20 * The Original Code is (C) 2016 Tony Whyman, MWA Software
21 * (http://www.mwasoftware.co.uk).
22 *
23 * All Rights Reserved.
24 *
25 * Contributor(s): ______________________________________.
26 *
27 *)
28
29 unit Test22;
30 {$IFDEF MSWINDOWS}
31 {$DEFINE WINDOWS}
32 {$ENDIF}
33
34 {$IFDEF FPC}
35 {$mode delphi}
36 {$codepage utf8}
37 {$ENDIF}
38
39 {Test 22: Journalling}
40
41
42 interface
43
44 uses
45 Classes, SysUtils, TestApplication, FBTestApp, IB, IBUtils;
46
47 type
48
49 { TTest22 }
50
51 TTest22 = class(TFBTestBase)
52 private
53 procedure UpdateDatabase(Attachment: IAttachment);
54 procedure QueryDatabase(Attachment: IAttachment);
55 procedure ValidateStrToNumeric;
56 public
57 function TestTitle: AnsiString; override;
58 procedure RunTest(CharSet: AnsiString; SQLDialect: integer); override;
59 end;
60
61
62 implementation
63
64 const
65 sqlCreateTable =
66 'Create Table TestData ('+
67 'RowID Integer not null,'+
68 'iType Integer,'+
69 'i64Type BIGINT,'+
70 'CurrType Numeric(12,4),'+
71 'dType DOUBLE PRECISION,'+
72 'FixedPoint Numeric(10,6),'+
73 'Str VarChar(256),' +
74 'TextBlob BLOB sub_type 1,'+
75 'OtherBlob Blob sub_type 0,'+
76 'MyArray Integer [0:16],'+
77 'Primary Key (RowID)'+
78 ')';
79
80 sqlInsert = 'Insert into TestData(RowID,iType,i64Type,CurrType,dType,FixedPoint) Values(?,?,?,?,?,?)';
81 sqlInsertText = 'Insert into TestData(RowID, Str, TextBlob) Values(?,?,?)';
82 sqlInsertArray = 'Insert into TestData(RowID,MyArray) Values (?,?)';
83 sqlInsertBlob = 'Insert into TestData(RowID,OtherBlob) Values (?,?)';
84
85 { TTest22 }
86
87 procedure TTest22.UpdateDatabase(Attachment: IAttachment);
88 var Transaction: ITransaction;
89 Statement: IStatement;
90 i,j: integer;
91 ar: IArray;
92 begin
93 Transaction := Attachment.StartTransaction([isc_tpb_write,isc_tpb_nowait,isc_tpb_concurrency],taCommit,'Transaction_29_1');
94 Statement := Attachment.Prepare(Transaction,sqlInsert);
95 ParamInfo(Statement.GetSQLParams);
96 with Statement.GetSQLParams do
97 begin
98 Params[0].AsInteger := 1;
99 Params[1].AsString := '101';
100 Params[2].AsString := ' 9223372036854775807';
101 Params[3].AsString := '10000.1234';
102 Params[4].AsString := '9999.123456780';
103 Params[5].AsString := '1234567890.12345678';
104 end;
105 Statement.Execute;
106 with Statement.GetSQLParams do
107 begin
108 Params[0].AsInteger := 2;
109 Params[1].AsString := '-32457';
110 Params[2].AsString := ' -9223372036854775808 ';
111 Params[3].AsString := '+1000001.12';
112 Params[4].AsString := '1.7E308';
113 Params[5].AsString := '-1234567890.12345678';
114 end;
115 Statement.Execute;
116 Transaction.CommitRetaining;
117 with Statement.GetSQLParams do
118 begin
119 Params[0].AsInteger := 3;
120 Params[1].AsString := '0';
121 Params[2].AsString := '0';
122 Params[3].AsString := '0';
123 Params[4].AsString := '0';
124 Params[5].AsString := '0';
125 end;
126 Statement.Execute;
127 Transaction.RollbackRetaining;
128 with Statement.GetSQLParams do
129 begin
130 Params[0].AsInteger := 4;
131 Params[1].AsString := '1.0';
132 Params[2].AsString := '10.';
133 Params[3].AsString := '2.3E-2';
134 Params[4].AsString := '11e-4';
135 Params[5].AsString := '2.33456E2';
136 end;
137 Statement.Execute;
138 writeln(OutFile);
139 writeln(OutFile,'Text Tests');
140 Transaction := Attachment.StartTransaction([isc_tpb_write,isc_tpb_nowait,isc_tpb_concurrency],taRollback,'Transaction_29_2');
141 Statement := Attachment.Prepare(Transaction,sqlInsertText);
142 ParamInfo(Statement.GetSQLParams);
143 with Statement.GetSQLParams do
144 begin
145 Params[0].AsInteger := 5;
146 Params[1].AsString := 'It''s the quick brown fox jumps over the lazy dog';
147 Params[2].AsBlob := Attachment.CreateBlob(Transaction,'TestData','TextBlob').LoadFromFile('testtext.txt');
148 end;
149 Statement.Execute;
150 writeln(OutFile);
151 writeln(OutFile,'Binary Blob Tests');
152 Statement := Attachment.Prepare(Transaction,sqlInsertBlob);
153 with Statement.GetSQLParams do
154 begin
155 Params[0].AsInteger := 6;
156 Params[1].AsBlob := Attachment.CreateBlob(Transaction,'TestData','OtherBlob').LoadFromFile('Test22.dat');
157 end;
158 Statement.Execute;
159 writeln(OutFile);
160 writeln(OutFile,'Array Test');
161 Statement := Attachment.Prepare(Transaction,sqlInsertArray);
162 ar := Attachment.CreateArray(Transaction,'TestData','MyArray');
163 j := 100;
164 for i := 0 to 16 do
165 begin
166 ar.SetAsInteger([i],j);
167 dec(j);
168 end;
169 ParamInfo(Statement.GetSQLParams);
170 with Statement.GetSQLParams do
171 begin
172 Params[0].AsInteger := 7;
173 Params[1].AsArray := ar;
174 end;
175 Statement.Execute;
176 end;
177
178 procedure TTest22.QueryDatabase(Attachment: IAttachment);
179 var Transaction: ITransaction;
180 Statement: IStatement;
181 begin
182 Transaction := Attachment.StartTransaction([isc_tpb_read,isc_tpb_nowait,isc_tpb_concurrency],taCommit);
183 Statement := Attachment.Prepare(Transaction,'Select * from TestData');
184 ReportResults(Statement);
185 end;
186
187 procedure TTest22.ValidateStrToNumeric;
188 const
189 TestValues: array of string = ['1234.567','-765.4321','0.1','0.01','+123',
190 '1.23456E308','-1.2e-02','10.','.12', '0.12',
191 '1.2E1.2', '1,000', '1e1e1', '1.2+3']; {bad syntax}
192 var
193 i: integer;
194 aValue: Int64;
195 aScale: integer;
196 begin
197 for i := 0 to Length(TestValues) - 1 do
198 begin
199 if TryStrToNumeric(TestValues[i],aValue,aScale) then
200 begin
201 writeln(Outfile,TestValues[i],' parsed to ',aValue,' scale = ',aScale);
202 writeln(Outfile,'As Float = ',NumericToDouble(aValue,aScale));
203 end
204 else
205 writeln(Outfile,'Parsing of ',TestValues[i],' failed');
206 end;
207 end;
208
209 function TTest22.TestTitle: AnsiString;
210 begin
211 Result := 'Test 22: Journalling';
212 end;
213
214 procedure TTest22.RunTest(CharSet: AnsiString; SQLDialect: integer);
215 var DPB: IDPB;
216 Attachment: IAttachment;
217 begin
218 DPB := FirebirdAPI.AllocateDPB;
219 DPB.Add(isc_dpb_user_name).setAsString(Owner.GetUserName);
220 DPB.Add(isc_dpb_password).setAsString(Owner.GetPassword);
221 DPB.Add(isc_dpb_lc_ctype).setAsString(CharSet);
222 DPB.Add(isc_dpb_set_db_SQL_dialect).setAsByte(SQLDialect);
223 Attachment := FirebirdAPI.CreateDatabase(Owner.GetNewDatabaseName,DPB);
224 try
225 Attachment.ExecImmediate([isc_tpb_write,isc_tpb_wait,isc_tpb_consistency],sqlCreateTable);
226 writeln(OutFile,'Start Journaling. Session ID = ',
227 Attachment.StartJournaling('Test'+GetTestID+'.log'));
228 ValidateStrToNumeric;
229 SetFloatTemplate('#,###.00000000');
230 UpdateDatabase(Attachment);
231 QueryDatabase(Attachment);
232 PrintJournalTable(Attachment);
233 Attachment.StopJournaling(true);
234 finally
235 Attachment.DropDatabase;
236 end;
237 writeln(OutFile);
238 PrintJournalFile('Test'+GetTestID+'.log');
239 end;
240
241 initialization
242 RegisterTest(TTest22);
243
244 end.
245