ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/fbintf/testsuite/Test16.pas
Revision: 270
Committed: Fri Jan 18 11:10:37 2019 UTC (5 years, 11 months ago) by tony
Content type: text/x-pascal
File size: 5784 byte(s)
Log Message:
Fixes merged

File Contents

# User Rev Content
1 tony 45 unit Test16;
2 tony 56 {$IFDEF MSWINDOWS}
3     {$DEFINE WINDOWS}
4     {$ENDIF}
5 tony 45
6 tony 56 {$IFDEF FPC}
7     {$mode delphi}
8 tony 45 {$codepage UTF8}
9 tony 56 {$ENDIF}
10 tony 45
11     {Test 16: Error handling}
12    
13     { This test tests for correct responses to various error conditions:
14    
15     - Malformed database name.
16     - Invalid User Name
17     - Invalid password
18     - Invalid Update SQL Statement
19     - Invalid Select SQL
20     - Transaction not started
21     - Invalid parameter by name when should be positional
22     - Invalid server name
23     - invalid user name - logon to server
24     - invalid password
25     }
26    
27     interface
28    
29     uses
30     Classes, SysUtils, TestManager, IB;
31    
32     type
33    
34     { TTest16 }
35    
36     TTest16 = class(TTestBase)
37     private
38 tony 56 procedure DBTests(CharSet: AnsiString; SQLDialect: integer);
39     procedure ServiceTests(CharSet: AnsiString; SQLDialect: integer);
40 tony 45 public
41 tony 56 function TestTitle: AnsiString; override;
42     procedure RunTest(CharSet: AnsiString; SQLDialect: integer); override;
43 tony 45 end;
44    
45    
46     implementation
47    
48     { TTest16 }
49    
50 tony 56 procedure TTest16.DBTests(CharSet: AnsiString; SQLDialect: integer);
51 tony 45 var DPB: IDPB;
52     Attachment: IAttachment;
53     Transaction: ITransaction;
54     Statement: IStatement;
55     begin
56     DPB := FirebirdAPI.AllocateDPB;
57     DPB.Add(isc_dpb_user_name).setAsString(Owner.GetUserName);
58     DPB.Add(isc_dpb_password).setAsString(Owner.GetPassword);
59     DPB.Add(isc_dpb_lc_ctype).setAsString('UTF8');
60     DPB.Add(isc_dpb_set_db_SQL_dialect).setAsByte(SQLDialect);
61     try
62     writeln(OutFile,'Invalid Database Name Test');
63     Attachment := FirebirdAPI.OpenDatabase('localhost:Malformed Name',DPB);
64     except on E: Exception do
65     writeln(OutFile,'Error Handled: ',E.Message);
66     end;
67     DPB.Find(isc_dpb_user_name).setAsString('Captain Nemo');
68     try
69     writeln(OutFile,'Invalid User Name Test');
70     Attachment := FirebirdAPI.OpenDatabase(Owner.GetEmployeeDatabaseName,DPB);
71     except on E: Exception do
72     writeln(OutFile,'Error Handled: ',E.Message);
73     end;
74     DPB.Find(isc_dpb_user_name).setAsString(Owner.GetUserName);
75     DPB.Find(isc_dpb_password).setAsString('not a pwd');
76     try
77     writeln(OutFile,'Invalid password Test');
78     Attachment := FirebirdAPI.OpenDatabase(Owner.GetEmployeeDatabaseName,DPB);
79     except on E: Exception do
80     writeln(OutFile,'Error Handled: ',E.Message);
81     end;
82     DPB.Find(isc_dpb_password).setAsString(Owner.GetPassword);
83     Attachment := FirebirdAPI.OpenDatabase(Owner.GetEmployeeDatabaseName,DPB);
84     Transaction := Attachment.StartTransaction([isc_tpb_write,isc_tpb_nowait,isc_tpb_concurrency],taRollback);
85     try
86     writeln(OutFile,'Invalid Prepare SQL Test');
87     Statement := Attachment.Prepare(Transaction,'Update Employee Set Unknown_Date = ? Where EMP_NO = ?',3);
88     except on E: Exception do
89     writeln(OutFile,'Error Handled: ',E.Message);
90     end;
91     try
92     writeln(OutFile,'Invalid Open Cursor SQL Test');
93     Attachment.OpenCursorAtStart(Transaction,
94     'Select X,count(*) As Counter from EMPLOYEE',3);
95     except on E: Exception do
96     writeln(OutFile,'Error Handled: ',E.Message);
97     end;
98     Transaction.Rollback;
99     try
100     writeln(OutFile,'Transaction not started Test');
101     Attachment.OpenCursorAtStart(Transaction,
102     'Select count(*) As Counter from EMPLOYEE',3);
103     except on E: Exception do
104     writeln(OutFile,'Error Handled: ',E.Message);
105     end;
106     Transaction.Start;
107     try
108     writeln(OutFile,'Invalid Param SQL Type Test');
109     Statement := Attachment.Prepare(Transaction,'Update Employee Set Hire_Date = ? Where EMP_NO = ?',3);
110     Statement.SQLParams.ByName('EMP_NO').AsDate := EncodeDate(2016,11,5);
111     except on E: Exception do
112     writeln(OutFile,'Error Handled: ',E.Message);
113     end;
114 tony 270 Transaction.Rollback;
115     Transaction.Start;
116     try
117     writeln(OutFile,'Case sensitive Param SQL Test');
118     Statement := Attachment.PrepareWithNamedParameters(Transaction,'Update Employee Set Hire_Date = :Hire_Date Where emp_no = :emp_no',3,false,true);
119     Statement.SQLParams.ByName('Hire_Date').AsDate := EncodeDate(2016,11,5);
120     Statement.SQLParams.ByName('emp_no').AsInteger := 1;
121     Statement.SQLParams.ByName('EMP_NO').AsInteger := 1;
122     except on E: Exception do
123     writeln(OutFile,'Error Handled: ',E.Message);
124     end;
125 tony 45 end;
126    
127 tony 56 procedure TTest16.ServiceTests(CharSet: AnsiString; SQLDialect: integer);
128 tony 45 var SPB: ISPB;
129     Service: IServiceManager;
130     I: integer;
131 tony 56 ServerName: AnsiString;
132     DBName: AnsiString;
133 tony 45 begin
134     if not FirebirdAPI.HasServiceAPI then Exit;
135    
136     ServerName := Owner.GetEmployeeDatabaseName;
137     I := Pos(':',ServerName);
138     if i > 0 then
139     DBName := system.copy(ServerName,i+1,length(ServerName) - 2);
140     system.Delete(ServerName,i,Length(ServerName)-i+1);
141    
142     SPB := FirebirdAPI.AllocateSPB;
143     SPB.Add(isc_spb_user_name).setAsString(Owner.GetUserName);
144     SPB.Add(isc_spb_password).setAsString(Owner.GetPassword);
145     try
146     writeln(OutFile,'Invalid Server Name Test');
147     Service := FirebirdAPI.GetServiceManager('unknown',TCP,SPB);
148     except on E: Exception do
149     writeln(OutFile,'Error Handled: ',E.Message);
150     end;
151    
152     SPB.Find(isc_spb_user_name).setAsString('Captain Nemo');
153     try
154     writeln(OutFile,'Invalid User Name Test');
155     Service := FirebirdAPI.GetServiceManager(ServerName,TCP,SPB);
156     except on E: Exception do
157     writeln(OutFile,'Error Handled: ',E.Message);
158     end;
159     SPB.Find(isc_spb_user_name).setAsString(Owner.GetUserName);
160     SPB.Find(isc_spb_password).setAsString('Bad pwd');
161     try
162     writeln(OutFile,'Invalid password Test');
163     Service := FirebirdAPI.GetServiceManager(ServerName,TCP,SPB);
164     except on E: Exception do
165     writeln(OutFile,'Error Handled: ',E.Message);
166     end;
167     end;
168    
169 tony 56 function TTest16.TestTitle: AnsiString;
170 tony 45 begin
171     Result := 'Test 16: Error handling';
172     end;
173    
174 tony 56 procedure TTest16.RunTest(CharSet: AnsiString; SQLDialect: integer);
175 tony 45 begin
176     DBTests(Charset,SQLDialect);
177     ServiceTests(Charset,SQLDialect);
178     end;
179    
180     initialization
181     RegisterTest(TTest16);
182     end.
183