|
1 // Copyright (c) 2002-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 // Contain the implementation of the class for this null agent test |
|
15 // |
|
16 // |
|
17 |
|
18 #include "NullAgentTestSteps.h" |
|
19 #include "dummynifvar.h" |
|
20 #include "commdbconnpref.h" |
|
21 #include "in_sock.h" |
|
22 |
|
23 CTestStepNullAgtMultipleConnections::CTestStepNullAgtMultipleConnections(TPtrC aName) |
|
24 { |
|
25 iTestStepName=aName; |
|
26 } |
|
27 |
|
28 enum TVerdict CTestStepNullAgtMultipleConnections::doTestStepL(void) |
|
29 { |
|
30 __UHEAP_MARK; |
|
31 |
|
32 TInt r; // the result of various operations |
|
33 TRequestStatus status; // status of asynchronous ops |
|
34 |
|
35 // connection paraphanelia, two of each |
|
36 RSocketServ server1, server2; |
|
37 RConnection connection1, connection2; |
|
38 RSocket socket1, socket2; |
|
39 |
|
40 TInetAddr dest; |
|
41 dest.SetAddress(KDummyNifLocalAddressBase + 4); |
|
42 dest.SetPort(KPortNo); |
|
43 |
|
44 TBuf8<KBufferLength> buffer; |
|
45 |
|
46 // as ever we need a socket server to create connections... |
|
47 r = server1.Connect(); |
|
48 TESTEL(r == KErrNone, r); |
|
49 CleanupClosePushL(server1); |
|
50 // let's have two |
|
51 r = server2.Connect(); |
|
52 TESTEL(r == KErrNone, r); |
|
53 CleanupClosePushL(server2); |
|
54 |
|
55 // create the first (default connection using commdb settings) |
|
56 // Which according to connetion preferences, the one with ranking 1 |
|
57 // is IAP 5 |
|
58 r = connection1.Open(server1, KAfInet); |
|
59 TESTEL(r == KErrNone, r); |
|
60 CleanupClosePushL(connection1); |
|
61 |
|
62 // create the second connection (overrides this time) |
|
63 // on the same IAP, ie IAP5 |
|
64 r = connection2.Open(server2, KAfInet); |
|
65 TESTEL(r == KErrNone, r); |
|
66 // Don't push this connection as it will be stopped by connection1 |
|
67 |
|
68 // create the overrides |
|
69 TCommDbConnPref prefs; |
|
70 prefs.SetIapId(5); |
|
71 prefs.SetDialogPreference(ECommDbDialogPrefDoNotPrompt); |
|
72 |
|
73 connection1.Start(status); |
|
74 User::WaitForRequest(status); |
|
75 TESTEL(status.Int() == KErrNone, status.Int()); |
|
76 |
|
77 // start the connection with the overrides |
|
78 connection2.Start(prefs, status); |
|
79 User::WaitForRequest(status); |
|
80 TESTEL(status.Int() == KErrNone, status.Int()); |
|
81 |
|
82 // open a socket over the first connection |
|
83 r = socket1.Open(server1, KAfInet, KSockDatagram, KProtocolInetUdp); |
|
84 TESTEL(r == KErrNone, r); |
|
85 CleanupClosePushL(socket1); |
|
86 TESTL(socket1.SetOpt(KSoReuseAddr, KSolInetIp, 1)==KErrNone); |
|
87 // set the source port number |
|
88 r = socket1.SetLocalPort(KPortNo); |
|
89 TESTEL(r == KErrNone, r); |
|
90 |
|
91 // open a socket over the second connection |
|
92 r = socket2.Open(server2, KAfInet, KSockDatagram, KProtocolInetUdp); |
|
93 TESTEL(r == KErrNone, r); |
|
94 CleanupClosePushL(socket2); |
|
95 TESTL(socket2.SetOpt(KSoReuseAddr, KSolInetIp, 1)==KErrNone); |
|
96 // set the source port number - otherwise will panic cos it's zero |
|
97 r = socket2.SetLocalPort(KPortNo); |
|
98 TESTEL(r == KErrNone, r); |
|
99 |
|
100 // build some data to send on the socket |
|
101 buffer.SetMax(); |
|
102 buffer.FillZ(); |
|
103 buffer[0] = (TUint8) 0x8; |
|
104 buffer[1] = (TUint8) 0x0; |
|
105 buffer[2] = (TUint8) 0xF7; |
|
106 buffer[3] = (TUint8) 0xFF; |
|
107 |
|
108 // send the data out the first socket |
|
109 socket1.SendTo(buffer, dest, 0, status); |
|
110 User::WaitForRequest(status); |
|
111 TESTEL(status.Int() == KErrNone, status.Int()); |
|
112 |
|
113 buffer.Zero(); |
|
114 // I expect to get the data looped back from the dummy NIF |
|
115 socket1.RecvFrom(buffer, dest, 0, status); |
|
116 User::WaitForRequest(status); |
|
117 TESTEL(status.Int() == KErrNone, status.Int()); |
|
118 |
|
119 if (status.Int() == KErrNone) |
|
120 { |
|
121 // if the receive times out and we access buffer we get a panic |
|
122 TESTL(buffer[0] == 0x08); |
|
123 TESTL(buffer[1] == 0x00); |
|
124 TESTL(buffer[2] == 0xF7); |
|
125 TESTL(buffer[3] == 0xFF); |
|
126 } |
|
127 |
|
128 // send the same data out over the second socket |
|
129 socket2.SendTo(buffer, dest, 0, status); |
|
130 User::WaitForRequest(status); |
|
131 TESTEL(status.Int() == KErrNone, status.Int()); |
|
132 |
|
133 buffer.Zero(); |
|
134 // again, I expect it to be looped back by the dummy NIF |
|
135 socket2.RecvFrom(buffer, dest, 0, status); |
|
136 User::WaitForRequest(status); |
|
137 |
|
138 if (status.Int() == KErrNone) |
|
139 { |
|
140 // if the receive times out and we access buffer we get a panic |
|
141 TESTL(buffer[0] == 0x08); |
|
142 TESTL(buffer[1] == 0x00); |
|
143 TESTL(buffer[2] == 0xF7); |
|
144 TESTL(buffer[3] == 0xFF); |
|
145 } |
|
146 |
|
147 // close down both of the sockets |
|
148 socket2.Shutdown(RSocket::ENormal, status); |
|
149 User::WaitForRequest(status); |
|
150 TESTEL(status.Int() == KErrNone, status.Int()); |
|
151 CleanupStack::Pop(); |
|
152 socket1.Shutdown(RSocket::ENormal, status); |
|
153 User::WaitForRequest(status); |
|
154 TESTEL(status.Int() == KErrNone, status.Int()); |
|
155 CleanupStack::Pop(); |
|
156 |
|
157 // Stop only connection1, as this points to the same IAP |
|
158 // as connection2 |
|
159 r = connection1.Stop(); |
|
160 TESTEL(r == KErrNone, r); |
|
161 CleanupStack::Pop(); |
|
162 |
|
163 // close the socket servers |
|
164 server2.Close(); |
|
165 CleanupStack::Pop(); |
|
166 server1.Close(); |
|
167 CleanupStack::Pop(); |
|
168 |
|
169 __UHEAP_MARKEND; |
|
170 |
|
171 return iTestStepResult; |
|
172 } |