ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/fbintf/testsuite/Test16.pas
Revision: 402
Committed: Mon Aug 1 10:07:24 2022 UTC (2 years, 4 months ago) by tony
Content type: text/x-pascal
File size: 8493 byte(s)
Log Message:
IBX Release 2.5.0

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 Test16;
30 {$IFDEF MSWINDOWS}
31 {$DEFINE WINDOWS}
32 {$ENDIF}
33
34 {$IFDEF FPC}
35 {$mode delphi}
36 {$codepage UTF8}
37 {$ENDIF}
38
39 {Test 16: Error handling}
40
41 { This test tests for correct responses to various error conditions:
42
43 - Malformed database name.
44 - Invalid User Name
45 - Invalid password
46 - Invalid Update SQL Statement
47 - Invalid Select SQL
48 - Transaction not started
49 - Invalid parameter by name when should be positional
50 - Invalid server name
51 - invalid user name - logon to server
52 - invalid password
53 }
54
55 interface
56
57 uses
58 Classes, SysUtils, TestApplication, FBTestApp, IB;
59
60 type
61
62 { TTest16 }
63
64 TTest16 = class(TFBTestBase)
65 private
66 procedure DBTests(CharSet: AnsiString; SQLDialect: integer);
67 procedure ServiceTests(CharSet: AnsiString; SQLDialect: integer);
68 public
69 function TestTitle: AnsiString; override;
70 procedure RunTest(CharSet: AnsiString; SQLDialect: integer); override;
71 end;
72
73
74 implementation
75
76 { TTest16 }
77
78 procedure TTest16.DBTests(CharSet: AnsiString; SQLDialect: integer);
79 var DPB: IDPB;
80 Attachment: IAttachment;
81 Transaction: ITransaction;
82 Statement: IStatement;
83 begin
84 DPB := FirebirdAPI.AllocateDPB;
85 DPB.Add(isc_dpb_user_name).setAsString(Owner.GetUserName);
86 DPB.Add(isc_dpb_password).setAsString(Owner.GetPassword);
87 DPB.Add(isc_dpb_lc_ctype).setAsString('UTF8');
88 try
89 writeln(OutFile,'Invalid Database Name Test');
90 Attachment := FirebirdAPI.OpenDatabase('localhost:Malformed Name',DPB);
91 except on E: Exception do
92 writeln(OutFile,'Error Handled: ',E.Message);
93 end;
94 DPB.Find(isc_dpb_user_name).setAsString('Captain Nemo');
95 try
96 writeln(OutFile,'Invalid User Name Test');
97 Attachment := FirebirdAPI.OpenDatabase(Owner.GetEmployeeDatabaseName,DPB);
98 except on E: Exception do
99 writeln(OutFile,'Error Handled: ',E.Message);
100 end;
101 DPB.Find(isc_dpb_user_name).setAsString(Owner.GetUserName);
102 DPB.Find(isc_dpb_password).setAsString('not a pwd');
103 try
104 writeln(OutFile,'Invalid password Test');
105 Attachment := FirebirdAPI.OpenDatabase(Owner.GetEmployeeDatabaseName,DPB);
106 except on E: Exception do
107 writeln(OutFile,'Error Handled: ',E.Message);
108 end;
109 DPB.Find(isc_dpb_password).setAsString(Owner.GetPassword);
110 Attachment := FirebirdAPI.OpenDatabase(Owner.GetEmployeeDatabaseName,DPB);
111 Transaction := Attachment.StartTransaction([isc_tpb_write,isc_tpb_nowait,isc_tpb_concurrency],taRollback);
112 try
113 writeln(OutFile,'Invalid Prepare SQL Test');
114 Statement := Attachment.Prepare(Transaction,'Update Employee Set Unknown_Date = ? Where EMP_NO = ?',3);
115 except on E: Exception do
116 writeln(OutFile,'Error Handled: ',E.Message);
117 end;
118 try
119 writeln(OutFile,'Invalid Open Cursor SQL Test');
120 Attachment.OpenCursorAtStart(Transaction,
121 'Select X,count(*) As Counter from EMPLOYEE',3);
122 except on E: Exception do
123 writeln(OutFile,'Error Handled: ',E.Message);
124 end;
125 Transaction.Rollback;
126 try
127 writeln(OutFile,'Transaction not started Test');
128 Attachment.OpenCursorAtStart(Transaction,
129 'Select count(*) As Counter from EMPLOYEE',3);
130 except on E: Exception do
131 writeln(OutFile,'Error Handled: ',E.Message);
132 end;
133 Transaction.Start;
134 try
135 writeln(OutFile,'Invalid Param SQL Type Test');
136 Statement := Attachment.Prepare(Transaction,'Update Employee Set Hire_Date = ? Where EMP_NO = ?',3);
137 Statement.SQLParams.ByName('EMP_NO').AsDate := EncodeDate(2016,11,5);
138 except on E: Exception do
139 writeln(OutFile,'Error Handled: ',E.Message);
140 end;
141 Transaction.Rollback;
142 Transaction.Start;
143 try
144 writeln(OutFile,'Case sensitive Param SQL Test');
145 Statement := Attachment.PrepareWithNamedParameters(Transaction,'Update Employee Set Hire_Date = :Hire_Date Where emp_no = :emp_no',3,false,true);
146 Statement.SQLParams.ByName('Hire_Date').AsDate := EncodeDate(2016,11,5);
147 Statement.SQLParams.ByName('emp_no').AsInteger := 1;
148 Statement.SQLParams.ByName('EMP_NO').AsInteger := 1;
149 except on E: Exception do
150 writeln(OutFile,'Error Handled: ',E.Message);
151 end;
152 Transaction.Rollback;
153 Transaction.Start;
154 writeln(Outfile,'Stale Reference Check');
155 writeln(Outfile,'First test correct usage');
156 Statement := Attachment.Prepare(Transaction,'Select count(*) As Counter from EMPLOYEE Where Hire_Date < ?',3);
157 Statement.SQLParams[0].AsDate := EncodeDate(2016,11,5);
158 ReportResults(Statement);
159 try
160 writeln(Outfile,'New Transaction before param set');
161 Statement.Prepare(Transaction);
162 Transaction.Rollback;
163 Transaction.Start;
164 Statement.SQLParams[0].AsDate := EncodeDate(2016,11,5);
165 ReportResults(Statement);
166 except on E: Exception do
167 writeln(OutFile,'Error Handled: ',E.Message);
168 end;
169 Transaction.Rollback;
170 Transaction.Start;
171 try
172 writeln(Outfile,'New Transaction before Open Cursor');
173 Statement.Prepare(Transaction);
174 Statement.SQLParams[0].AsDate := EncodeDate(2016,11,5);
175 Transaction.Rollback;
176 Transaction.Start;
177 ReportResults(Statement);
178 except on E: Exception do
179 writeln(OutFile,'Error Handled: ',E.Message);
180 end;
181 Transaction.Rollback;
182 Transaction.Start;
183 writeln(Outfile,'Stop Stale Reference Checks');
184 Statement.SetStaleReferenceChecks(false);
185 try
186 writeln(Outfile,'New Transaction before param set');
187 Statement.Prepare(Transaction);
188 Transaction.Rollback;
189 Transaction.Start;
190 Statement.SQLParams[0].AsDate := EncodeDate(2016,11,5);
191 ReportResults(Statement);
192 except on E: Exception do
193 writeln(OutFile,'Error Handled: ',E.Message);
194 end;
195 try
196 writeln(Outfile,'New Transaction before Open Cursor');
197 Statement.Prepare(Transaction);
198 Statement.SQLParams[0].AsDate := EncodeDate(2016,11,5);
199 Transaction.Rollback;
200 Transaction.Start;
201 ReportResults(Statement);
202 except on E: Exception do
203 writeln(OutFile,'Error Handled: ',E.Message);
204 end;
205 end;
206
207 procedure TTest16.ServiceTests(CharSet: AnsiString; SQLDialect: integer);
208 var SPB: ISPB;
209 Service: IServiceManager;
210 ServerName: AnsiString;
211 DBName: AnsiString;
212 begin
213 if not FirebirdAPI.HasServiceAPI then Exit;
214
215 DBName := ExtractDBName(Owner.GetEmployeeDatabaseName);
216 ServerName := Owner.Server;
217
218 SPB := FirebirdAPI.AllocateSPB;
219 SPB.Add(isc_spb_user_name).setAsString(Owner.GetUserName);
220 SPB.Add(isc_spb_password).setAsString(Owner.GetPassword);
221 try
222 writeln(OutFile,'Invalid Server Name Test');
223 Service := FirebirdAPI.GetServiceManager('unknown',TCP,SPB);
224 except on E: Exception do
225 writeln(OutFile,'Error Handled: ',E.Message);
226 end;
227
228 SPB.Find(isc_spb_user_name).setAsString('Captain Nemo');
229 try
230 writeln(OutFile,'Invalid User Name Test');
231 Service := FirebirdAPI.GetServiceManager(ServerName,TCP,SPB);
232 except on E: Exception do
233 writeln(OutFile,'Error Handled: ',E.Message);
234 end;
235 SPB.Find(isc_spb_user_name).setAsString(Owner.GetUserName);
236 SPB.Find(isc_spb_password).setAsString('Bad pwd');
237 try
238 writeln(OutFile,'Invalid password Test');
239 Service := FirebirdAPI.GetServiceManager(ServerName,TCP,SPB);
240 except on E: Exception do
241 writeln(OutFile,'Error Handled: ',E.Message);
242 end;
243 end;
244
245 function TTest16.TestTitle: AnsiString;
246 begin
247 Result := 'Test 16: Error handling';
248 end;
249
250 procedure TTest16.RunTest(CharSet: AnsiString; SQLDialect: integer);
251 begin
252 FirebirdAPI.GetStatus.SetIBDataBaseErrorMessages([ShowSQLCode,ShowSQLMessage,ShowIBMessage]);;
253 DBTests(Charset,SQLDialect);
254 ServiceTests(Charset,SQLDialect);
255 end;
256
257 initialization
258 RegisterTest(TTest16);
259 end.
260

Properties

Name Value
svn:eol-style native