|
1 // Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // This contains ESock Test cases from section 2 |
|
15 // |
|
16 // |
|
17 |
|
18 // EPOC includes |
|
19 #include <e32base.h> |
|
20 #include <in_sock.h> |
|
21 |
|
22 // Test system includes |
|
23 #include "EsockTestSection2.h" |
|
24 |
|
25 |
|
26 // Test step 2.1 |
|
27 const TDesC& CEsockTest2_1::GetTestName() |
|
28 { |
|
29 // store the name of this test case |
|
30 _LIT(ret,"Test2.1"); |
|
31 |
|
32 return ret; |
|
33 } |
|
34 |
|
35 CEsockTest2_1::~CEsockTest2_1() |
|
36 { |
|
37 } |
|
38 |
|
39 enum TVerdict CEsockTest2_1::easyTestStepPreambleL() |
|
40 { |
|
41 if (KErrNone != OpenMinSockets(_L("Test_2.1"),KAfInet, KSockStream, KProtocolInetTcp)) |
|
42 { |
|
43 return EFail; |
|
44 } |
|
45 |
|
46 return EPass; |
|
47 } |
|
48 |
|
49 enum TVerdict CEsockTest2_1::easyTestStepL() |
|
50 { |
|
51 TESTL(EPass == TestStepResult()); |
|
52 TInt nSockets = iEsockSuite->GetSocketListCount(); |
|
53 // bind to n sockets on port 0 |
|
54 |
|
55 // get ip address |
|
56 TInetAddr addr, addr1; |
|
57 TESTL(GetIpAddressFromConfig(SectionName(_L("Test_2.1")), _L("ipAddress"), addr)); |
|
58 |
|
59 // set the port number to 0 |
|
60 addr.SetPort(0); |
|
61 |
|
62 // for each open socket |
|
63 TInt nRet; |
|
64 TUint port; |
|
65 for (TInt n = 0; n < nSockets; n++) |
|
66 { |
|
67 // bind the socket |
|
68 nRet = iEsockSuite->GetSocketHandle(n + 1).Bind(addr); |
|
69 TESTEL(nRet == KErrNone, nRet); |
|
70 |
|
71 // get the socket name |
|
72 iEsockSuite->GetSocketHandle(n + 1).LocalName(addr1); |
|
73 |
|
74 // check address has been set correctly |
|
75 TESTL(addr.Match(addr1)); |
|
76 |
|
77 // get port number - check it is non-zero |
|
78 port = iEsockSuite->GetSocketHandle(n + 1).LocalPort(); |
|
79 TESTL(port > 0); |
|
80 } |
|
81 |
|
82 return EPass; |
|
83 } |
|
84 |
|
85 |
|
86 // Test step 2.2 |
|
87 const TDesC& CEsockTest2_2::GetTestName() |
|
88 { |
|
89 // store the name of this test case |
|
90 _LIT(ret,"Test2.2"); |
|
91 |
|
92 return ret; |
|
93 } |
|
94 |
|
95 CEsockTest2_2::~CEsockTest2_2() |
|
96 { |
|
97 } |
|
98 |
|
99 enum TVerdict CEsockTest2_2::easyTestStepPreambleL() |
|
100 { |
|
101 if (KErrNone != OpenMinSockets(_L("Test_2.2"),KAfInet, KSockStream, KProtocolInetTcp)) |
|
102 { |
|
103 return EFail; |
|
104 } |
|
105 |
|
106 return EPass; |
|
107 } |
|
108 |
|
109 enum TVerdict CEsockTest2_2::easyTestStepL() |
|
110 { |
|
111 TESTL(EPass == TestStepResult()); |
|
112 // bind to an illegal port number |
|
113 |
|
114 // get IP address |
|
115 TInetAddr addr; |
|
116 TESTL(GetIpAddressFromConfig(SectionName(_L("Test_2.2")), _L("ipAddress"), addr)); |
|
117 |
|
118 // set port number to invalid value |
|
119 addr.SetPort(65537); |
|
120 |
|
121 // socket already opened - retrieve |
|
122 // socket handle and bind |
|
123 TInt nRet = iEsockSuite->GetSocketHandle(1).Bind(addr); |
|
124 |
|
125 TESTEL(nRet == KErrTooBig, nRet); |
|
126 |
|
127 return EPass; |
|
128 } |
|
129 |
|
130 |
|
131 // Test step 2.3 |
|
132 const TDesC& CEsockTest2_3::GetTestName() |
|
133 { |
|
134 // store the name of this test case |
|
135 _LIT(ret,"Test2.3"); |
|
136 |
|
137 return ret; |
|
138 |
|
139 } |
|
140 |
|
141 CEsockTest2_3::~CEsockTest2_3() |
|
142 { |
|
143 } |
|
144 |
|
145 enum TVerdict CEsockTest2_3::easyTestStepPreambleL() |
|
146 { |
|
147 if (KErrNone != OpenMinSockets(_L("Test_2.3"),KAfInet, KSockStream, KProtocolInetTcp)) |
|
148 { |
|
149 return EFail; |
|
150 } |
|
151 |
|
152 return EPass; |
|
153 } |
|
154 |
|
155 enum TVerdict CEsockTest2_3::easyTestStepL() |
|
156 { |
|
157 TESTL(EPass == TestStepResult()); |
|
158 // bind to an illegal address |
|
159 |
|
160 // get IP address |
|
161 TInetAddr addr; |
|
162 TESTL(GetIpAddressFromConfig(SectionName(_L("Test_2.3")), _L("ipAddress"), addr)); |
|
163 |
|
164 // set port number to a valid value |
|
165 addr.SetPort(7); |
|
166 |
|
167 // socket already opened - retrieve |
|
168 // socket handle and bind |
|
169 TInt nRet = iEsockSuite->GetSocketHandle(1).Bind(addr); |
|
170 |
|
171 TESTEL(nRet == KErrNotFound, nRet); |
|
172 |
|
173 return EPass; |
|
174 } |
|
175 |
|
176 |
|
177 // Test step 2.4 |
|
178 const TDesC& CEsockTest2_4::GetTestName() |
|
179 { |
|
180 // store the name of this test case |
|
181 _LIT(ret,"Test2.4"); |
|
182 |
|
183 return ret; |
|
184 } |
|
185 |
|
186 CEsockTest2_4::~CEsockTest2_4() |
|
187 { |
|
188 } |
|
189 |
|
190 enum TVerdict CEsockTest2_4::easyTestStepPreambleL() |
|
191 { |
|
192 if (KErrNone != OpenMinSockets(_L("Test_2.4"),KAfInet, KSockStream, KProtocolInetTcp, 2)) |
|
193 { |
|
194 return EFail; |
|
195 } |
|
196 |
|
197 return EPass; |
|
198 } |
|
199 |
|
200 enum TVerdict CEsockTest2_4::easyTestStepL() |
|
201 { |
|
202 TESTL(EPass == TestStepResult()); |
|
203 // double bind on different sockets |
|
204 |
|
205 // get IP address |
|
206 TInetAddr addr; |
|
207 TESTL(GetIpAddressFromConfig(SectionName(_L("Test_2.4")), _L("ipAddress"), addr)); |
|
208 |
|
209 // set port number to a valid value |
|
210 addr.SetPort(9); |
|
211 |
|
212 // socket already opened - retrieve |
|
213 // socket handle and bind |
|
214 TInt nRet = iEsockSuite->GetSocketHandle(1).Bind(addr); |
|
215 |
|
216 // bind should succeed |
|
217 TESTEL(nRet == KErrNone, nRet); |
|
218 |
|
219 // socket already opened - retrieve |
|
220 // socket handle and bind again to same address |
|
221 nRet = iEsockSuite->GetSocketHandle(2).Bind(addr); |
|
222 |
|
223 // second bind should fail |
|
224 TESTEL(nRet == KErrInUse, nRet); |
|
225 |
|
226 return EPass; |
|
227 } |
|
228 |
|
229 |
|
230 // Test step 2.5 |
|
231 const TDesC& CEsockTest2_5::GetTestName() |
|
232 { |
|
233 // store the name of this test case |
|
234 _LIT(ret,"Test2.5"); |
|
235 |
|
236 return ret; |
|
237 } |
|
238 |
|
239 CEsockTest2_5::~CEsockTest2_5() |
|
240 { |
|
241 } |
|
242 |
|
243 enum TVerdict CEsockTest2_5::easyTestStepPreambleL() |
|
244 { |
|
245 if (KErrNone != OpenMinSockets(_L("Test_2.5"),KAfInet, KSockStream, KProtocolInetTcp)) |
|
246 { |
|
247 return EFail; |
|
248 } |
|
249 |
|
250 return EPass; |
|
251 } |
|
252 |
|
253 enum TVerdict CEsockTest2_5::easyTestStepL() |
|
254 { |
|
255 TESTL(EPass == TestStepResult()); |
|
256 |
|
257 // get port numbers |
|
258 TInt port1, port2; |
|
259 TESTL(GetIntFromConfig(SectionName(_L("Test_2.5")), _L("port1"), port1)); |
|
260 TESTL(GetIntFromConfig(SectionName(_L("Test_2.5")), _L("port2"), port2)); |
|
261 |
|
262 // set the local port number to port1 |
|
263 TInt nRet = iEsockSuite->GetSocketHandle(1).SetLocalPort(port1); |
|
264 TESTEL(nRet == KErrNone, nRet); |
|
265 |
|
266 // check port has been set correctly |
|
267 TUint port = iEsockSuite->GetSocketHandle(1).LocalPort(); |
|
268 TESTL(port == (TUint)port1); |
|
269 |
|
270 // set the local port number to port2 |
|
271 // check that this is not successful |
|
272 nRet = iEsockSuite->GetSocketHandle(1).SetLocalPort(port2); |
|
273 TESTEL(nRet == KErrAlreadyExists, nRet); |
|
274 |
|
275 // check port has not been changed |
|
276 port = iEsockSuite->GetSocketHandle(1).LocalPort(); |
|
277 TESTL(port == (TUint)port1); |
|
278 |
|
279 return EPass; |
|
280 } |
|
281 |