ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/fbintf/testsuite/Test16.pas
Revision: 380
Committed: Mon Jan 10 10:13:17 2022 UTC (2 years, 11 months ago) by tony
Content type: text/x-pascal
File size: 8457 byte(s)
Log Message:
propset for eol-style

File Contents

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