ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/fbintf/testsuite/Test21.pas
Revision: 356
Committed: Sun Oct 24 14:00:52 2021 UTC (3 years, 1 month ago) by tony
Content type: text/x-pascal
File size: 5887 byte(s)
Log Message:
Fixes Merged

File Contents

# User Rev Content
1 tony 351 (*
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 Test21;
30    
31     {$IFDEF MSWINDOWS}
32     {$DEFINE WINDOWS}
33     {$ENDIF}
34    
35     {$IFDEF FPC}
36     {$mode delphi}
37     {$codepage utf8}
38     {$ENDIF}
39    
40     {Test 21: Exercise setting and getting of numeric data types}
41    
42     interface
43    
44     uses
45     Classes, SysUtils, TestApplication, FBTestApp, IB;
46    
47     type
48    
49     { TTest21 }
50    
51     TTest21 = class(TFBTestBase)
52     private
53     procedure UpdateDatabase(Attachment: IAttachment);
54     procedure QueryDatabase(Attachment: IAttachment);
55 tony 356 procedure ValidateStrToNumeric;
56 tony 351 public
57     function TestTitle: AnsiString; override;
58     procedure RunTest(CharSet: AnsiString; SQLDialect: integer); override;
59     end;
60    
61    
62    
63     implementation
64    
65 tony 356 uses IBUtils;
66    
67 tony 351 const
68     sqlCreateTable =
69     'Create Table TestData ('+
70     'RowID Integer not null,'+
71     'iType Integer,'+
72     'i64Type BIGINT,'+
73     'CurrType Numeric(12,4),'+
74     'dType DOUBLE PRECISION,'+
75     'FixedPoint Numeric(10,6),'+
76     'Primary Key (RowID)'+
77     ')';
78    
79     sqlInsert = 'Insert into TestData(RowID,iType,i64Type,CurrType,dType,FixedPoint) Values(?,?,?,?,?,?)';
80    
81    
82     { TTest21 }
83    
84     procedure TTest21.UpdateDatabase(Attachment: IAttachment);
85     var Transaction: ITransaction;
86     Statement: IStatement;
87     begin
88     Transaction := Attachment.StartTransaction([isc_tpb_write,isc_tpb_nowait,isc_tpb_concurrency],taCommit);
89     Statement := Attachment.Prepare(Transaction,sqlInsert);
90     ParamInfo(Statement.GetSQLParams);
91     with Statement.GetSQLParams do
92     begin
93     Params[0].AsInteger := 1;
94     Params[1].AsString := '101';
95     Params[2].AsString := ' 9223372036854775807';
96     Params[3].AsString := '10000.1234';
97     Params[4].AsString := '9999.123456780';
98     Params[5].AsString := '1234567890.12345678';
99     end;
100     Statement.Execute;
101     with Statement.GetSQLParams do
102     begin
103     Params[0].AsInteger := 2;
104     Params[1].AsString := '-32457';
105     Params[2].AsString := ' -9223372036854775808 ';
106     Params[3].AsString := '+1000001.12';
107     Params[4].AsString := '1.7E308';
108     Params[5].AsString := '-1234567890.12345678';
109     end;
110     Statement.Execute;
111     with Statement.GetSQLParams do
112     begin
113     Params[0].AsInteger := 3;
114     Params[1].AsString := '0';
115     Params[2].AsString := '0';
116     Params[3].AsString := '0';
117     Params[4].AsString := '0';
118     Params[5].AsString := '0';
119     end;
120     Statement.Execute;
121     with Statement.GetSQLParams do
122     begin
123     Params[0].AsInteger := 4;
124     Params[1].AsString := '1.0';
125     Params[2].AsString := '10.';
126     Params[3].AsString := '2.3E-2';
127 tony 353 Params[4].AsString := '11e-4';
128 tony 351 Params[5].AsString := '2.33456E2';
129     end;
130     Statement.Execute;
131     {error handling}
132     with Statement.GetSQLParams do
133     try
134     Params[0].AsInteger := 5;
135     Params[1].AsString := '1,000';
136     Statement.Execute;
137     except on E: Exception do
138     writeln(Outfile,'Expected Error - ',E.Message);
139     end;
140     with Statement.GetSQLParams do
141     try
142     Params[0].AsInteger := 6;
143     Params[5].AsString := '10.0.0';
144     Statement.Execute;
145     except on E: Exception do
146     writeln(Outfile,'Expected Error - ',E.Message);
147     end;
148    
149     end;
150    
151     procedure TTest21.QueryDatabase(Attachment: IAttachment);
152     var Transaction: ITransaction;
153     Statement: IStatement;
154     begin
155     Transaction := Attachment.StartTransaction([isc_tpb_read,isc_tpb_nowait,isc_tpb_concurrency],taCommit);
156     Statement := Attachment.Prepare(Transaction,'Select * from TestData');
157     ReportResults(Statement);
158     end;
159    
160 tony 356 procedure TTest21.ValidateStrToNumeric;
161     const
162     TestValues: array of string = ['1234.567','-765.4321','0.1','0.01','+123',
163     '1.23456E308','-1.2e-02','10.','.12', '0.12',
164     '1.2E1.2', '1,000', '1e1e1', '1.2+3']; {bad syntax}
165     var
166     i: integer;
167     aValue: Int64;
168     aScale: integer;
169     begin
170     for i := 0 to Length(TestValues) - 1 do
171     begin
172     if TryStrToNumeric(TestValues[i],aValue,aScale) then
173     begin
174     writeln(Outfile,TestValues[i],' parsed to ',aValue,' scale = ',aScale);
175     writeln(Outfile,'As Float = ',NumericToDouble(aValue,aScale));
176     end
177     else
178     writeln(Outfile,'Parsing of ',TestValues[i],' failed');
179     end;
180     end;
181    
182 tony 351 function TTest21.TestTitle: AnsiString;
183     begin
184     Result := 'Test 21: Exercise setting and getting of numeric data types';
185     end;
186    
187     procedure TTest21.RunTest(CharSet: AnsiString; SQLDialect: integer);
188     var DPB: IDPB;
189     Attachment: IAttachment;
190     begin
191     DPB := FirebirdAPI.AllocateDPB;
192     DPB.Add(isc_dpb_user_name).setAsString(Owner.GetUserName);
193     DPB.Add(isc_dpb_password).setAsString(Owner.GetPassword);
194     DPB.Add(isc_dpb_lc_ctype).setAsString(CharSet);
195     DPB.Add(isc_dpb_set_db_SQL_dialect).setAsByte(SQLDialect);
196     Attachment := FirebirdAPI.CreateDatabase(Owner.GetNewDatabaseName,DPB);
197     try
198     Attachment.ExecImmediate([isc_tpb_write,isc_tpb_wait,isc_tpb_consistency],sqlCreateTable);
199 tony 356 ValidateStrToNumeric;
200 tony 351 SetFloatTemplate('#,###.00000000');
201     UpdateDatabase(Attachment);
202     QueryDatabase(Attachment);
203     finally
204     Attachment.DropDatabase;
205     end;
206     end;
207    
208     initialization
209     RegisterTest(TTest21);
210     end.
211