|
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 10 |
|
15 // |
|
16 // |
|
17 |
|
18 // EPOC includes |
|
19 #include <e32base.h> |
|
20 #include <in_sock.h> |
|
21 |
|
22 // Test system includes |
|
23 #include "EsockTestSection10.h" |
|
24 |
|
25 |
|
26 // Test step 10.1 |
|
27 const TDesC& CEsockTest10_1::GetTestName() |
|
28 { |
|
29 // store the name of this test case |
|
30 _LIT(ret,"Test10.1"); |
|
31 |
|
32 return ret; |
|
33 } |
|
34 |
|
35 CEsockTest10_1::~CEsockTest10_1() |
|
36 { |
|
37 } |
|
38 |
|
39 enum TVerdict CEsockTest10_1::easyTestStepPreambleL() |
|
40 { |
|
41 TInt connections; |
|
42 TRAPD(ret, connections = OpenConnectionsL(_L("Test_10.1"), iSockIndex2, iSockIndex3)); |
|
43 if (KErrNone != ret) |
|
44 { |
|
45 return EFail; |
|
46 } |
|
47 if (0 >= connections) |
|
48 { |
|
49 return EFail; |
|
50 } |
|
51 |
|
52 return EPass; |
|
53 } |
|
54 |
|
55 enum TVerdict CEsockTest10_1::easyTestStepL() |
|
56 { |
|
57 TESTL(EPass == TestStepResult()); |
|
58 TPckgBuf<TUint> flags; |
|
59 |
|
60 // get select state of server socket |
|
61 TRequestStatus stat; |
|
62 flags() = KSockSelectRead | KSockSelectWrite | KSockSelectExcept; |
|
63 iEsockSuite->GetSocketHandle(iSockIndex3).Ioctl(KIOctlSelect, stat, &flags, KSOLSocket); |
|
64 User::WaitForRequest(stat); |
|
65 TESTL(stat==KErrNone); |
|
66 TESTL(flags()==KSockSelectWrite); |
|
67 |
|
68 // send data from client to server (2 bytes, 1 urgent) |
|
69 TInt ret = iEsockSuite->GetSocketHandle(iSockIndex2).SetOpt(KSoTcpNextSendUrgentData, KSolInetTcp, 1); |
|
70 TESTEL(KErrNone == ret, ret); |
|
71 iEsockSuite->GetSocketHandle(iSockIndex2).Write(_L8("12"), stat); |
|
72 User::WaitForRequest(stat); |
|
73 TESTEL(stat==KErrNone, stat.Int()); |
|
74 |
|
75 // delay for 1 second |
|
76 User::After(1000000); |
|
77 |
|
78 // get select state of the server socket |
|
79 flags() = KSockSelectRead | KSockSelectWrite | KSockSelectExcept; |
|
80 iEsockSuite->GetSocketHandle(iSockIndex3).Ioctl(KIOctlSelect, stat, &flags, KSOLSocket); |
|
81 User::WaitForRequest(stat); |
|
82 TESTL(stat==KErrNone); |
|
83 TESTL(flags()==(KSockSelectRead | KSockSelectWrite | KSockSelectExcept)); |
|
84 |
|
85 // read data (server) |
|
86 TBuf8<20> rbuf2; |
|
87 iEsockSuite->GetSocketHandle(iSockIndex3).Read(rbuf2, stat); |
|
88 User::WaitForRequest(stat); |
|
89 TESTEL(stat==KErrUrgentData, stat.Int()); |
|
90 |
|
91 // get select state of the server socket |
|
92 flags() = KSockSelectRead | KSockSelectWrite | KSockSelectExcept; |
|
93 iEsockSuite->GetSocketHandle(iSockIndex3).Ioctl(KIOctlSelect, stat, &flags, KSOLSocket); |
|
94 User::WaitForRequest(stat); |
|
95 TESTL(stat==KErrNone); |
|
96 |
|
97 TESTL(flags()==(KSockSelectWrite | KSockSelectExcept)); |
|
98 |
|
99 // read the urgent data byte |
|
100 TInt nRet; |
|
101 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSoTcpReadUrgentData, KSolInetTcp, nRet); |
|
102 TESTEL(KErrNone == ret, ret); |
|
103 TESTL(nRet=='2'); |
|
104 ret = iEsockSuite->GetSocketHandle(iSockIndex3).GetOpt(KSoTcpReadUrgentData, KSolInetTcp, nRet); |
|
105 TESTEL(KErrNotFound == ret, ret); |
|
106 |
|
107 // get select state of the server socket |
|
108 flags() = KSockSelectRead | KSockSelectWrite | KSockSelectExcept; |
|
109 iEsockSuite->GetSocketHandle(iSockIndex3).Ioctl(KIOctlSelect, stat, &flags, KSOLSocket); |
|
110 User::WaitForRequest(stat); |
|
111 TESTL(stat==KErrNone); |
|
112 TESTL(flags()==KSockSelectWrite); |
|
113 |
|
114 return EPass; |
|
115 } |
|
116 |
|
117 |
|
118 // Test step 10.2 |
|
119 const TDesC& CEsockTest10_2::GetTestName() |
|
120 { |
|
121 // store the name of this test case |
|
122 _LIT(ret,"Test10.2"); |
|
123 |
|
124 return ret; |
|
125 } |
|
126 |
|
127 CEsockTest10_2::~CEsockTest10_2() |
|
128 { |
|
129 } |
|
130 |
|
131 enum TVerdict CEsockTest10_2::easyTestStepL() |
|
132 { |
|
133 |
|
134 // Ioctl on an unconnected socket |
|
135 |
|
136 // open a TCP socket |
|
137 RSocket sock; |
|
138 CleanupClosePushL(sock); |
|
139 TInt nRet = sock.Open(iEsockSuite->iSocketServer, KAfInet, KSockStream, KProtocolInetTcp); |
|
140 TESTEL(KErrNone == nRet, nRet); |
|
141 |
|
142 // get select state of the socket |
|
143 sock.GetOpt (KSOSelectPoll, KSOLSocket, (nRet = 0)); |
|
144 |
|
145 // socket is blocked for writing, has no data for reading |
|
146 // and has no exception condition |
|
147 TESTEL(0 == nRet, nRet); |
|
148 |
|
149 // close the socket |
|
150 CleanupStack::PopAndDestroy(); |
|
151 |
|
152 return EPass; |
|
153 } |
|
154 |
|
155 |
|
156 // Test step 10.3 |
|
157 const TDesC& CEsockTest10_3::GetTestName() |
|
158 { |
|
159 // store the name of this test case |
|
160 _LIT(ret,"Test10.3"); |
|
161 |
|
162 return ret; |
|
163 } |
|
164 |
|
165 CEsockTest10_3::~CEsockTest10_3() |
|
166 { |
|
167 } |
|
168 |
|
169 enum TVerdict CEsockTest10_3::easyTestStepPreambleL() |
|
170 { |
|
171 TInt connections; |
|
172 TRAPD(ret, connections = OpenConnectionsL(_L("Test_10.3"), iSockIndex2, iSockIndex3)); |
|
173 if (KErrNone != ret) |
|
174 { |
|
175 return EFail; |
|
176 } |
|
177 if (0 >= connections) |
|
178 { |
|
179 return EFail; |
|
180 } |
|
181 |
|
182 return EPass; |
|
183 } |
|
184 |
|
185 enum TVerdict CEsockTest10_3::easyTestStepL() |
|
186 { |
|
187 TESTL(EPass == TestStepResult()); |
|
188 |
|
189 // cancel an Ioctl operation |
|
190 |
|
191 TPckgBuf<TUint> flags; |
|
192 flags() = KSockSelectExcept; |
|
193 |
|
194 // get select state of the server socket |
|
195 // do not wait for operation to complete |
|
196 TRequestStatus stat; |
|
197 iEsockSuite->GetSocketHandle(iSockIndex3).Ioctl(KIOctlSelect, stat, &flags, KSOLSocket); |
|
198 TESTEL(KRequestPending == stat.Int(), stat.Int()); |
|
199 |
|
200 // cancel the Ioctl operation |
|
201 iEsockSuite->GetSocketHandle(iSockIndex3).CancelIoctl(); |
|
202 |
|
203 // wait for operation to complete |
|
204 User::WaitForRequest(stat); |
|
205 |
|
206 // completion status will be KErrNone or KErrCancel |
|
207 TESTEL(KErrCancel == stat.Int(), stat.Int()); |
|
208 |
|
209 // get select state of the server socket |
|
210 flags() = KSockSelectRead | KSockSelectWrite | KSockSelectExcept; |
|
211 iEsockSuite->GetSocketHandle(iSockIndex3).Ioctl(KIOctlSelect, stat, &flags, KSOLSocket); |
|
212 |
|
213 User::WaitForRequest(stat); |
|
214 TESTEL(KErrNone == stat.Int(), stat.Int()); |
|
215 |
|
216 // socket is not blocked for writing |
|
217 TESTL(flags()==KSockSelectWrite); |
|
218 |
|
219 return EPass; |
|
220 } |
|
221 |