|
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 "in_sock.h" |
|
21 |
|
22 CTestStepNullAgtNotifications::CTestStepNullAgtNotifications(TPtrC aName) |
|
23 { |
|
24 iTestStepName=aName; |
|
25 } |
|
26 |
|
27 enum TVerdict CTestStepNullAgtNotifications::doTestStepL(void) |
|
28 { |
|
29 __UHEAP_MARK; |
|
30 |
|
31 TRequestStatus status; // status of asynchronous ops |
|
32 TInt r; // the result of various operations |
|
33 |
|
34 RSocketServ server; // connection paraphanelia |
|
35 RConnection connection; |
|
36 RSocket socket; |
|
37 |
|
38 TInetAddr dest; |
|
39 dest.SetAddress(KDummyNifLocalAddressBase + 4); |
|
40 dest.SetPort(KDummyNifCmdPort); |
|
41 |
|
42 TBuf8<KBufferLength> buffer; |
|
43 |
|
44 // connect to the socket server |
|
45 r = server.Connect(); |
|
46 TESTEL(r == KErrNone, r); |
|
47 CleanupClosePushL(server); |
|
48 |
|
49 // this is why we needed a socket server... |
|
50 r = connection.Open(server, KAfInet); |
|
51 TESTEL(r == KErrNone, r); |
|
52 CleanupClosePushL(connection); |
|
53 |
|
54 // start the connection up (outgoing) |
|
55 connection.Start(status); |
|
56 User::WaitForRequest(status); |
|
57 TESTEL(status.Int() == KErrNone, status.Int()); |
|
58 |
|
59 // to send commands to the dummy nif we need to send pseudo-traffic which |
|
60 // it will interpret as a command... hence all the socket stuff that follows |
|
61 |
|
62 // open a udp socket |
|
63 r = socket.Open(server, KAfInet, KSockDatagram, KProtocolInetUdp); |
|
64 TESTEL(r == KErrNone, r); |
|
65 CleanupClosePushL(socket); |
|
66 TESTL(socket.SetOpt(KSoReuseAddr, KSolInetIp, 1)==KErrNone); |
|
67 // set the source port number - otherwise will panic cos it's zero |
|
68 r = socket.SetLocalPort(KDummyNifCmdPort); |
|
69 TESTEL(r == KErrNone, r); |
|
70 |
|
71 // put the command we want into the udp payload... |
|
72 buffer.SetMax(); |
|
73 buffer.FillZ(); |
|
74 buffer[0] = (TUint8) KSendNotification; |
|
75 |
|
76 // send the data out over the socket |
|
77 socket.SendTo(buffer, dest, 0, status); |
|
78 User::WaitForRequest(status); |
|
79 TESTEL(status.Int() == KErrNone, status.Int()); |
|
80 |
|
81 buffer.Zero(); |
|
82 // I expect to get the data looped back from the dummy NIF |
|
83 socket.RecvFrom(buffer, dest, 0, status); |
|
84 User::WaitForRequest(status); |
|
85 TESTEL(status.Int() == KErrNone, status.Int()); |
|
86 |
|
87 // check what we got back somehow |
|
88 TESTEL(buffer[1] != (unsigned char) KErrGeneral, buffer[1]); |
|
89 |
|
90 // close the socket |
|
91 socket.Shutdown(RSocket::ENormal, status); |
|
92 User::WaitForRequest(status); |
|
93 TESTEL(status.Int() == KErrNone, status.Int()); |
|
94 CleanupStack::Pop(); |
|
95 |
|
96 // force the destruction of the connection |
|
97 r = connection.Stop(); |
|
98 TESTEL(r == KErrNone, r); |
|
99 CleanupStack::Pop(); |
|
100 |
|
101 // close the socket server |
|
102 server.Close(); |
|
103 CleanupStack::Pop(); |
|
104 |
|
105 __UHEAP_MARKEND; |
|
106 |
|
107 return iTestStepResult; |
|
108 } |