ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/fbintf/testsuite/Test16.pas
Revision: 315
Committed: Thu Feb 25 11:56:36 2021 UTC (3 years, 1 month ago) by tony
Content type: text/x-pascal
File size: 6641 byte(s)
Log Message:
Updated for IBX 4 release

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 45 end;
154    
155 tony 56 procedure TTest16.ServiceTests(CharSet: AnsiString; SQLDialect: integer);
156 tony 45 var SPB: ISPB;
157     Service: IServiceManager;
158 tony 56 ServerName: AnsiString;
159     DBName: AnsiString;
160 tony 45 begin
161     if not FirebirdAPI.HasServiceAPI then Exit;
162    
163 tony 315 DBName := ExtractDBName(Owner.GetEmployeeDatabaseName);
164 tony 308 ServerName := Owner.Server;
165 tony 45
166     SPB := FirebirdAPI.AllocateSPB;
167     SPB.Add(isc_spb_user_name).setAsString(Owner.GetUserName);
168     SPB.Add(isc_spb_password).setAsString(Owner.GetPassword);
169     try
170     writeln(OutFile,'Invalid Server Name Test');
171     Service := FirebirdAPI.GetServiceManager('unknown',TCP,SPB);
172     except on E: Exception do
173     writeln(OutFile,'Error Handled: ',E.Message);
174     end;
175    
176     SPB.Find(isc_spb_user_name).setAsString('Captain Nemo');
177     try
178     writeln(OutFile,'Invalid User Name Test');
179     Service := FirebirdAPI.GetServiceManager(ServerName,TCP,SPB);
180     except on E: Exception do
181     writeln(OutFile,'Error Handled: ',E.Message);
182     end;
183     SPB.Find(isc_spb_user_name).setAsString(Owner.GetUserName);
184     SPB.Find(isc_spb_password).setAsString('Bad pwd');
185     try
186     writeln(OutFile,'Invalid password Test');
187     Service := FirebirdAPI.GetServiceManager(ServerName,TCP,SPB);
188     except on E: Exception do
189     writeln(OutFile,'Error Handled: ',E.Message);
190     end;
191     end;
192    
193 tony 56 function TTest16.TestTitle: AnsiString;
194 tony 45 begin
195     Result := 'Test 16: Error handling';
196     end;
197    
198 tony 56 procedure TTest16.RunTest(CharSet: AnsiString; SQLDialect: integer);
199 tony 45 begin
200     DBTests(Charset,SQLDialect);
201     ServiceTests(Charset,SQLDialect);
202     end;
203    
204     initialization
205     RegisterTest(TTest16);
206     end.
207