ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/fbintf/testsuite/Test16.pas
Revision: 56
Committed: Mon Mar 6 10:20:02 2017 UTC (7 years, 8 months ago) by tony
Content type: text/x-pascal
File size: 5252 byte(s)
Log Message:
Committing updates for Trunk

File Contents

# Content
1 unit Test16;
2 {$IFDEF MSWINDOWS}
3 {$DEFINE WINDOWS}
4 {$ENDIF}
5
6 {$IFDEF FPC}
7 {$mode delphi}
8 {$codepage UTF8}
9 {$ENDIF}
10
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 procedure DBTests(CharSet: AnsiString; SQLDialect: integer);
39 procedure ServiceTests(CharSet: AnsiString; SQLDialect: integer);
40 public
41 function TestTitle: AnsiString; override;
42 procedure RunTest(CharSet: AnsiString; SQLDialect: integer); override;
43 end;
44
45
46 implementation
47
48 { TTest16 }
49
50 procedure TTest16.DBTests(CharSet: AnsiString; SQLDialect: integer);
51 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 end;
115
116 procedure TTest16.ServiceTests(CharSet: AnsiString; SQLDialect: integer);
117 var SPB: ISPB;
118 Service: IServiceManager;
119 I: integer;
120 ServerName: AnsiString;
121 DBName: AnsiString;
122 begin
123 if not FirebirdAPI.HasServiceAPI then Exit;
124
125 ServerName := Owner.GetEmployeeDatabaseName;
126 I := Pos(':',ServerName);
127 if i > 0 then
128 DBName := system.copy(ServerName,i+1,length(ServerName) - 2);
129 system.Delete(ServerName,i,Length(ServerName)-i+1);
130
131 SPB := FirebirdAPI.AllocateSPB;
132 SPB.Add(isc_spb_user_name).setAsString(Owner.GetUserName);
133 SPB.Add(isc_spb_password).setAsString(Owner.GetPassword);
134 try
135 writeln(OutFile,'Invalid Server Name Test');
136 Service := FirebirdAPI.GetServiceManager('unknown',TCP,SPB);
137 except on E: Exception do
138 writeln(OutFile,'Error Handled: ',E.Message);
139 end;
140
141 SPB.Find(isc_spb_user_name).setAsString('Captain Nemo');
142 try
143 writeln(OutFile,'Invalid User Name Test');
144 Service := FirebirdAPI.GetServiceManager(ServerName,TCP,SPB);
145 except on E: Exception do
146 writeln(OutFile,'Error Handled: ',E.Message);
147 end;
148 SPB.Find(isc_spb_user_name).setAsString(Owner.GetUserName);
149 SPB.Find(isc_spb_password).setAsString('Bad pwd');
150 try
151 writeln(OutFile,'Invalid password Test');
152 Service := FirebirdAPI.GetServiceManager(ServerName,TCP,SPB);
153 except on E: Exception do
154 writeln(OutFile,'Error Handled: ',E.Message);
155 end;
156 end;
157
158 function TTest16.TestTitle: AnsiString;
159 begin
160 Result := 'Test 16: Error handling';
161 end;
162
163 procedure TTest16.RunTest(CharSet: AnsiString; SQLDialect: integer);
164 begin
165 DBTests(Charset,SQLDialect);
166 ServiceTests(Charset,SQLDialect);
167 end;
168
169 initialization
170 RegisterTest(TTest16);
171 end.
172